Skip to content

Commit

Permalink
Major rework on MVVM, referenced assemblies and others (#841)
Browse files Browse the repository at this point in the history
***NO_CI***
  • Loading branch information
josesimoes authored Nov 15, 2024
1 parent 7ab82e1 commit 642e2ce
Show file tree
Hide file tree
Showing 39 changed files with 1,687 additions and 4,129 deletions.
9 changes: 9 additions & 0 deletions REAME-BEFORE-UPDATE-REFS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Developer Notes

!! Be extremely careful when updating NuGet packages !!
We are pushing the limits of the VS extensibility SDK, and it's very easy to break things. In particular, the most critical symptom to check for with each package update is the ability to start a debug session.
On failure, a CompositionException is usually silently thrown, and the debugger refuses to start without any further clue on what is wrong.

VS2019

- ICSharpCode cannot be updated beyond v7.2.1.6856 because System.Collections.Immutable cannot go beyond v5.0.0.
3 changes: 2 additions & 1 deletion Tools.BuildTasks-2019/Tools.BuildTasks-2019.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
</ItemGroup>
<ItemGroup>
<None Include="key.snk" />
<None Include="packages.lock.json" />
<None Include="version.json" />
</ItemGroup>
<ItemGroup>
Expand All @@ -81,7 +82,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Nerdbank.GitVersioning">
<Version>3.5.104</Version>
<Version>3.6.146</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
6 changes: 3 additions & 3 deletions Tools.BuildTasks-2019/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
},
"Nerdbank.GitVersioning": {
"type": "Direct",
"requested": "[3.5.104, )",
"resolved": "3.5.104",
"contentHash": "U2rlnA+5RxROC53NXtcbX+ZZUajdcuBLQ/OgZF9abOZZzCBuqxUThx1rsQ+Lw8MMy8CU2o6Ctz0q3zz0bM5J8g=="
"requested": "[3.6.146, )",
"resolved": "3.6.146",
"contentHash": "W1eQ8hD9Y/cZ2+ilgxECl003xr1hybpN3fMxoTlMqg++BixETBMWzS4y9s08oHJKXgKtudsoxhITNOEf1OR66w=="
},
"Microsoft.CodeAnalysis.BannedApiAnalyzers": {
"type": "Transitive",
Expand Down
9 changes: 3 additions & 6 deletions Tools.BuildTasks-2022/Tools.BuildTasks-2022.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,13 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build.Framework">
<Version>17.10.4</Version>
<Version>17.12.6</Version>
</PackageReference>
<PackageReference Include="Microsoft.Build.Utilities.Core">
<Version>17.10.4</Version>
</PackageReference>
<PackageReference Include="Microsoft.IO.Redist">
<Version>6.0.1</Version>
<Version>17.11.4</Version>
</PackageReference>
<PackageReference Include="Nerdbank.GitVersioning">
<Version>3.6.139</Version>
<Version>3.6.146</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
39 changes: 19 additions & 20 deletions Tools.BuildTasks-2022/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,47 @@
".NETFramework,Version=v4.7.2": {
"Microsoft.Build.Framework": {
"type": "Direct",
"requested": "[17.10.4, )",
"resolved": "17.10.4",
"contentHash": "4qXCwNOXBR1dyCzuks9SwTwFJQO/xmf2wcMislotDWJu7MN/r3xDNoU8Ae5QmKIHPaLG1xmfDkYS7qBVzxmeKw==",
"requested": "[17.12.6, )",
"resolved": "17.12.6",
"contentHash": "jleteC0seumLGTmTVwob97lcwPj/dfgzL/V3g/VVcMZgo2Ic7jzdy8AYpByPDh8e3uRq0SjCl6HOFCjhy5GzRQ==",
"dependencies": {
"System.Runtime.CompilerServices.Unsafe": "6.0.0"
}
},
"Microsoft.Build.Utilities.Core": {
"type": "Direct",
"requested": "[17.10.4, )",
"resolved": "17.10.4",
"contentHash": "eEB/tcXkSV+nQgvoa/l53UPtn+KVtKZ8zBceDZsXVTrfE4fA+4+/olrx9W8n2tq4XiESsL9UuGJgCKzqBwQCoQ==",
"requested": "[17.11.4, )",
"resolved": "17.11.4",
"contentHash": "b2CEJMgVuv5fkhaR6TXjgocIa6YQbseowRj15q3/IyH343EPr+CrxXAZs6Xp6uZDE8A3ynsLPlufFUMkjUl37A==",
"dependencies": {
"Microsoft.Build.Framework": "17.10.4",
"Microsoft.Build.Framework": "17.11.4",
"Microsoft.IO.Redist": "6.0.0",
"Microsoft.NET.StringTools": "17.10.4",
"Microsoft.NET.StringTools": "17.11.4",
"System.Collections.Immutable": "8.0.0",
"System.Configuration.ConfigurationManager": "8.0.0",
"System.Memory": "4.5.5",
"System.Runtime.CompilerServices.Unsafe": "6.0.0"
}
},
"Microsoft.IO.Redist": {
"Nerdbank.GitVersioning": {
"type": "Direct",
"requested": "[6.0.1, )",
"resolved": "6.0.1",
"contentHash": "bSapbVhuyHtTHXRJwLwhzkOIUPXXMxxJ9a1/gjXb7gtk9949aggm17v+Hb1biv6CTl1DWoZ6YcxVFrGQRGeETQ==",
"requested": "[3.6.146, )",
"resolved": "3.6.146",
"contentHash": "W1eQ8hD9Y/cZ2+ilgxECl003xr1hybpN3fMxoTlMqg++BixETBMWzS4y9s08oHJKXgKtudsoxhITNOEf1OR66w=="
},
"Microsoft.IO.Redist": {
"type": "Transitive",
"resolved": "6.0.0",
"contentHash": "uxXZ8pAcYtIJm8iqu/0e+CkM/VSwfgbHpnCDu7s8+gn/VUD5R6PxH3RGZFPaHgTisrlwD+BIyL5TqG6qwuZtOQ==",
"dependencies": {
"System.Buffers": "4.5.1",
"System.Memory": "4.5.4"
}
},
"Nerdbank.GitVersioning": {
"type": "Direct",
"requested": "[3.6.139, )",
"resolved": "3.6.139",
"contentHash": "rq0Ub/Jik7PtMtZtLn0tHuJ01Yt36RQ+eeBe+S7qnJ/EFOX6D4T9zuYD3vQPYKGI6Ro4t2iWgFm3fGDgjBrMfg=="
},
"Microsoft.NET.StringTools": {
"type": "Transitive",
"resolved": "17.10.4",
"contentHash": "wyABaqY+IHCMMSTQmcc3Ca6vbmg5BaEPgicnEgpll+4xyWZWlkQqUwafweUd9VAhBb4jqplMl6voUHQ6yfdUcg==",
"resolved": "17.11.4",
"contentHash": "mudqUHhNpeqIdJoUx2YDWZO/I9uEDYVowan89R6wsomfnUJQk6HteoQTlNjZDixhT2B4IXMkMtgZtoceIjLRmA==",
"dependencies": {
"System.Memory": "4.5.5",
"System.Runtime.CompilerServices.Unsafe": "6.0.0"
Expand Down
30 changes: 14 additions & 16 deletions VisualStudio.Extension-2019/AutomaticUpdates/UpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
using System.Collections.Concurrent;
using System.Linq;
using System.Threading.Tasks;
using GalaSoft.MvvmLight.Messaging;
using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.VisualStudio.Shell;
using nanoFramework.Tools.Debugger;
using nanoFramework.Tools.Debugger.NFDevice;
using nanoFramework.Tools.VisualStudio.Extension.FirmwareUpdate;
using nanoFramework.Tools.VisualStudio.Extension.ToolWindow.ViewModel;
using static nanoFramework.Tools.VisualStudio.Extension.ToolWindow.ViewModel.DeviceExplorerViewModel.Messages;
using Task = System.Threading.Tasks.Task;

namespace nanoFramework.Tools.VisualStudio.Extension.AutomaticUpdates
Expand All @@ -19,7 +21,6 @@ public class UpdateManager
{
private const int ExclusiveAccessTimeout = 3000;
private static UpdateManager s_instance;
private ViewModelLocator ViewModelLocator;
private readonly Package _package;

private readonly ConcurrentDictionary<string, object> devicesUpdatING = new ConcurrentDictionary<string, object>();
Expand All @@ -30,17 +31,12 @@ private UpdateManager(Package package)
_package = package ?? throw new ArgumentNullException($"{package} can't be null.");
}

public static void Initialize(
AsyncPackage package,
ViewModelLocator vmLocator)
public static void Initialize(AsyncPackage package)
{
s_instance = new UpdateManager(package)
{
ViewModelLocator = vmLocator
};
s_instance = new UpdateManager(package);

Messenger.Default.Register<NotificationMessage>(s_instance, DeviceExplorerViewModel.MessagingTokens.LaunchFirmwareUpdateForNanoDevice, (message) => s_instance.LaunchUpdate(message.Notification));
Messenger.Default.Register<NotificationMessage>(s_instance, DeviceExplorerViewModel.MessagingTokens.NanoDeviceHasDeparted, (message) => s_instance.ProcessNanoDeviceDeparture(message.Notification));
WeakReferenceMessenger.Default.Register<LaunchFirmwareUpdateForNanoDeviceMessage>(s_instance, (r, message) => s_instance.LaunchUpdate(message.Value));
WeakReferenceMessenger.Default.Register<NanoDeviceHasDepartedMessage>(s_instance, (r, message) => s_instance.ProcessNanoDeviceDeparture(message.Value));
}

private void ProcessNanoDeviceDeparture(string deviceId)
Expand Down Expand Up @@ -69,7 +65,9 @@ private void LaunchUpdate(string deviceId)

var deviceUniqueId = Guid.Parse(deviceId);

var nanoDevice = ViewModelLocator.DeviceExplorer.AvailableDevices.FirstOrDefault(d => d.DeviceUniqueId == deviceUniqueId);
var deviceExplorer = Ioc.Default.GetService<DeviceExplorerViewModel>();

var nanoDevice = deviceExplorer.AvailableDevices.FirstOrDefault(d => d.DeviceUniqueId == deviceUniqueId);

// sanity check
if (
Expand Down Expand Up @@ -219,7 +217,7 @@ private void LaunchUpdate(string deviceId)
}

// check if the device is still there
if (ViewModelLocator.DeviceExplorer.AvailableDevices.FirstOrDefault(d => d.DeviceUniqueId == deviceUniqueId) == null)
if (deviceExplorer.AvailableDevices.FirstOrDefault(d => d.DeviceUniqueId == deviceUniqueId) == null)
{
#if DEBUG
Console.WriteLine($"[Automatic Updates] {nanoDevice.TargetName} is not available anymore.");
Expand Down Expand Up @@ -267,10 +265,10 @@ private void LaunchUpdate(string deviceId)
}

// if this is the selected device...
if (ViewModelLocator.DeviceExplorer.SelectedDevice?.DeviceUniqueId == deviceUniqueId)
if (deviceExplorer.SelectedDevice?.DeviceUniqueId == deviceUniqueId)
{
// ...reset property to force that device capabilities to be retrieved on next connection
ViewModelLocator.DeviceExplorer.LastDeviceConnectedHash = 0;
deviceExplorer.LastDeviceConnectedHash = 0;
}

if (attemptToLaunchBooter)
Expand All @@ -281,7 +279,7 @@ private void LaunchUpdate(string deviceId)
devicesUpdatING.TryRemove(deviceId, out var dummy);

// check if the device is still there
if (ViewModelLocator.DeviceExplorer.AvailableDevices.FirstOrDefault(d => d.DeviceUniqueId == Guid.Parse(deviceId)) == null)
if (deviceExplorer.AvailableDevices.FirstOrDefault(d => d.DeviceUniqueId == Guid.Parse(deviceId)) == null)
{
return;
}
Expand Down
5 changes: 0 additions & 5 deletions VisualStudio.Extension-2019/FodyWeavers.xml

This file was deleted.

51 changes: 23 additions & 28 deletions VisualStudio.Extension-2019/NanoFrameworkPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
// See LICENSE file in the project root for full license information.
//

using GalaSoft.MvvmLight.Ioc;
using Microsoft;
using Microsoft.VisualStudio.ProjectSystem.VS;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TextTemplating.VSHost;
using Microsoft.VisualStudio.Threading;
using nanoFramework.Tools.VisualStudio.Extension;
using nanoFramework.Tools.VisualStudio.Extension.AutomaticUpdates;
using nanoFramework.Tools.VisualStudio.Extension.ToolWindow.ViewModel;
using System;
using System.ComponentModel;
using System.Diagnostics;
Expand All @@ -22,7 +12,17 @@
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.ProjectSystem.VS;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TextTemplating.VSHost;
using Microsoft.VisualStudio.Threading;
using nanoFramework.Tools.VisualStudio.Extension;
using nanoFramework.Tools.VisualStudio.Extension.AutomaticUpdates;
using nanoFramework.Tools.VisualStudio.Extension.ToolWindow.ViewModel;
using Task = System.Threading.Tasks.Task;

[assembly: ProjectTypeRegistration(projectTypeGuid: NanoFrameworkPackage.ProjectTypeGuid,
Expand Down Expand Up @@ -579,37 +579,32 @@ public NanoFrameworkPackage()
/// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{

// make sure "our" key exists and it's writable
s_instance.UserRegistryRoot.CreateSubKey(EXTENSION_SUBKEY, true);

AddService(typeof(NanoDeviceCommService), CreateNanoDeviceCommServiceAsync);
AddService(typeof(VirtualDeviceService), CreateVirtualDeviceManagerServiceAsync);

ViewModelLocator viewModelLocator = null;

// Need to add the View model Locator to the application resource dictionary programmatically
// because at the extension level we don't have 'XAML' access to it
// try to find if the view model locator is already in the app resources dictionary
if (Application.Current.TryFindResource("Locator") == null)
{
// instantiate the view model locator...
viewModelLocator = new ViewModelLocator();

// ... and add it there
Application.Current.Resources.Add("Locator", viewModelLocator);
}
// Configure IoC container
Ioc.Default.ConfigureServices(
new ServiceCollection()
.AddSingleton<DeviceExplorerViewModel>()
.BuildServiceProvider());

SimpleIoc.Default.GetInstance<DeviceExplorerViewModel>().Package = this;
Ioc.Default.GetService<DeviceExplorerViewModel>().Package = this;

await MessageCentre.InitializeAsync(this, ".NET nanoFramework Extension");

DeployProvider.Initialize(this, viewModelLocator);
UpdateManager.Initialize(this, viewModelLocator);
DeployProvider.Initialize(this);
UpdateManager.Initialize(this);

await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

// Enable debugger UI context
UIContext.FromUIContextGuid(CorDebug.EngineGuid).IsActive = true;

await DeviceExplorerCommand.InitializeAsync(this, viewModelLocator);
await DeviceExplorerCommand.InitializeAsync(this);
VirtualDeviceService.InitVirtualDeviceAsync().FireAndForget();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
x:Name="DeviceExplorer">
<UserControl.DataContext>
<!--It's OK to use this static resource this way because it has been added programatically in the VS package constructor.-->
<Binding Mode="OneWay" Path="DeviceExplorer" Source="{StaticResource Locator}"/>
</UserControl.DataContext>

<AdornerDecorator>
<Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

namespace nanoFramework.Tools.VisualStudio.Extension
{
using GalaSoft.MvvmLight.Messaging;
using System;
using System.Windows.Controls;
using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.VisualStudio.Shell;
using nanoFramework.Tools.Debugger;
using nanoFramework.Tools.VisualStudio.Extension.ToolWindow.ViewModel;
using System;
using System.Windows.Controls;
using static nanoFramework.Tools.VisualStudio.Extension.ToolWindow.ViewModel.DeviceExplorerViewModel.Messages;

/// <summary>
/// Interaction logic for DeviceExplorerControl.
Expand All @@ -27,10 +29,12 @@ public DeviceExplorerControl()
{
InitializeComponent();

DataContext = Ioc.Default.GetService<DeviceExplorerViewModel>();

Loaded += DeviceExplorerControl_Loaded;

deviceTreeView.SelectedItemChanged += DevicesTreeView_SelectedItemChanged;
Messenger.Default.Register<NotificationMessage>(this, DeviceExplorerViewModel.MessagingTokens.ForceSelectionOfNanoDevice, (message) => ForceSelectionOfNanoDeviceHandlerAsync().ConfigureAwait(false));
WeakReferenceMessenger.Default.Register<ForceSelectionOfNanoDeviceMessage>(this, (r, message) => ForceSelectionOfNanoDeviceHandlerAsync().ConfigureAwait(false));
}

private void DeviceExplorerControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
Expand Down Expand Up @@ -103,11 +107,7 @@ private async System.Threading.Tasks.Task ForceSelectionOfNanoDeviceHandlerAsync
// need to disable the event handler otherwise it will mess the selection
deviceTreeView.SelectedItemChanged -= DevicesTreeView_SelectedItemChanged;


if (deviceItem != null)
{
deviceItem.IsSelected = true;
}
deviceItem.IsSelected = true;

// enabled it back
deviceTreeView.SelectedItemChanged += DevicesTreeView_SelectedItemChanged;
Expand All @@ -120,7 +120,7 @@ private async System.Threading.Tasks.Task ForceSelectionOfNanoDeviceHandlerAsync
}
while (tryCount-- > 0);

Messenger.Default.Send(new NotificationMessage(""), DeviceExplorerViewModel.MessagingTokens.SelectedNanoDeviceHasChanged);
WeakReferenceMessenger.Default.Send(new SelectedNanoDeviceHasChangedMessage());

// force redrawing to show selection
deviceTreeView.InvalidateVisual();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
<Converters:WirelessAP_OptionsTypeConverter x:Key="WirelessAP_OptionsTypeConverter"/>
</vsp:DialogWindow.Resources>

<vsp:DialogWindow.DataContext>
<Binding Path="DeviceExplorer" Source="{StaticResource Locator}" NotifyOnSourceUpdated="True" NotifyOnTargetUpdated="True"/>
</vsp:DialogWindow.DataContext>

<Grid Margin="0,0,0,4">
<TabControl x:Name="IPversionOptions" HorizontalAlignment="Left" Height="333" Margin="10,10,0,0" VerticalAlignment="Top" Width="372">
<TabItem Header="IPv4">
Expand Down
Loading

0 comments on commit 642e2ce

Please sign in to comment.