Skip to content

Commit 41b4565

Browse files
committed
Feature: PowerShell path
1 parent b2bfbd7 commit 41b4565

File tree

7 files changed

+198
-137
lines changed

7 files changed

+198
-137
lines changed

Source/GlobalAssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
[assembly: AssemblyTrademark("")]
77
[assembly: AssemblyCulture("")]
88

9-
[assembly: AssemblyVersion("2024.11.18.0")]
10-
[assembly: AssemblyFileVersion("2024.11.18.0")]
9+
[assembly: AssemblyVersion("2025.1.18.0")]
10+
[assembly: AssemblyFileVersion("2025.1.18.0")]

Source/NETworkManager/ViewModels/AWSSessionManagerHostViewModel.cs

Lines changed: 79 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Collections.ObjectModel;
4-
using System.Collections.Specialized;
5-
using System.ComponentModel;
6-
using System.Diagnostics;
7-
using System.IO;
8-
using System.Linq;
9-
using System.Text.RegularExpressions;
10-
using System.Threading.Tasks;
11-
using System.Windows;
12-
using System.Windows.Data;
13-
using System.Windows.Input;
14-
using System.Windows.Threading;
15-
using Amazon;
1+
using Amazon;
162
using Amazon.EC2;
173
using Amazon.EC2.Model;
184
using Amazon.Runtime.CredentialManagement;
@@ -31,7 +17,21 @@
3117
using NETworkManager.Settings;
3218
using NETworkManager.Utilities;
3319
using NETworkManager.Views;
34-
using AWSSessionManager = NETworkManager.Profiles.Application.AWSSessionManager;
20+
using System;
21+
using System.Collections.Generic;
22+
using System.Collections.ObjectModel;
23+
using System.Collections.Specialized;
24+
using System.ComponentModel;
25+
using System.Diagnostics;
26+
using System.IO;
27+
using System.Linq;
28+
using System.Text.RegularExpressions;
29+
using System.Threading.Tasks;
30+
using System.Windows;
31+
using System.Windows.Data;
32+
using System.Windows.Input;
33+
using System.Windows.Threading;
34+
using AWSSessionManagerProfile = NETworkManager.Profiles.Application.AWSSessionManager;
3535

3636
namespace NETworkManager.ViewModels;
3737

@@ -40,7 +40,7 @@ public class AWSSessionManagerHostViewModel : ViewModelBase, IProfileManager
4040
#region Variables
4141

4242
private static readonly ILog Log = LogManager.GetLogger(typeof(AWSSessionManagerHostViewModel));
43-
43+
4444
private readonly IDialogCoordinator _dialogCoordinator;
4545
private readonly DispatcherTimer _searchDispatcherTimer = new();
4646

@@ -65,7 +65,7 @@ public string InterTabPartition
6565

6666
private readonly bool _isLoading;
6767
private bool _isViewActive = true;
68-
68+
6969
private bool _isAWSCLIInstalled;
7070

7171
public bool IsAWSCLIInstalled
@@ -155,7 +155,7 @@ public int SelectedTabIndex
155155
OnPropertyChanged();
156156
}
157157
}
158-
158+
159159
private bool _headerContextMenuIsOpen;
160160

161161
public bool HeaderContextMenuIsOpen
@@ -317,16 +317,16 @@ public AWSSessionManagerHostViewModel(IDialogCoordinator instance)
317317

318318
// Check if AWS tools are installed
319319
CheckRequirements();
320-
320+
321321
// Check if PowerShell executable is configured
322322
CheckExecutable();
323323

324324
// Try to find PowerShell executable
325-
if(!IsExecutableConfigured)
325+
if (!IsExecutableConfigured)
326326
TryFindExecutable();
327-
327+
328328
WriteDefaultProfileToRegistry();
329-
329+
330330
InterTabClient = new DragablzInterTabClient(ApplicationName.AWSSessionManager);
331331
InterTabPartition = ApplicationName.AWSSessionManager.ToString();
332332

@@ -571,37 +571,37 @@ private void CheckRequirements()
571571
}
572572

573573
/// <summary>
574-
/// Check if the PowerShell executable is configured and exists.
574+
/// Check if the executable is configured and exists.
575575
/// </summary>
576576
private void CheckExecutable()
577577
{
578578
IsExecutableConfigured = !string.IsNullOrEmpty(SettingsManager.Current.AWSSessionManager_ApplicationFilePath) &&
579579
File.Exists(SettingsManager.Current.AWSSessionManager_ApplicationFilePath);
580-
581-
if(IsExecutableConfigured)
580+
581+
if (IsExecutableConfigured)
582582
Log.Info($"PowerShell executable found: \"{SettingsManager.Current.AWSSessionManager_ApplicationFilePath}\"");
583583
else
584584
Log.Warn("PowerShell executable not found!");
585585
}
586-
586+
587587
/// <summary>
588-
/// Try to find PuTTY executable.
588+
/// Try to find executable.
589589
/// </summary>
590590
private void TryFindExecutable()
591591
{
592592
Log.Info("Try to find PowerShell executable...");
593593

594-
var applicationFilePath = ApplicationHelper.Find(Models.PowerShell.PowerShell.PwshFileName);
595-
596-
if(string.IsNullOrEmpty(applicationFilePath))
597-
applicationFilePath = ApplicationHelper.Find(Models.PowerShell.PowerShell.WindowsPowerShellFileName);
598-
594+
var applicationFilePath = ApplicationHelper.Find(PowerShell.PwshFileName);
595+
596+
if (string.IsNullOrEmpty(applicationFilePath))
597+
applicationFilePath = ApplicationHelper.Find(PowerShell.WindowsPowerShellFileName);
598+
599599
SettingsManager.Current.AWSSessionManager_ApplicationFilePath = applicationFilePath;
600-
600+
601601
CheckExecutable();
602-
603-
if(!IsExecutableConfigured)
604-
Log.Warn("Install PowerShell or configure the path in the settings.");
602+
603+
if (!IsExecutableConfigured)
604+
Log.Warn("Install PowerShell or configure the path in the settings.");
605605
}
606606

607607
private bool IsConfigured => IsAWSCLIInstalled && IsAWSSessionManagerPluginInstalled && IsExecutableConfigured;
@@ -724,33 +724,33 @@ private async Task SyncInstanceIDsFromAWS(string profile, string region)
724724
};
725725

726726
foreach (var reservation in response.Reservations)
727-
foreach (var instance in reservation.Instances)
728-
{
729-
if (SettingsManager.Current.AWSSessionManager_SyncOnlyRunningInstancesFromAWS &&
730-
instance.State.Name.Value != "running")
731-
continue;
732-
733-
var tagName = instance.Tags.FirstOrDefault(x => x.Key == "Name");
734-
735-
var name = tagName == null || tagName.Value == null
736-
? instance.InstanceId
737-
: $"{tagName.Value} ({instance.InstanceId})";
738-
739-
groupInfo.Profiles.Add(new ProfileInfo
727+
foreach (var instance in reservation.Instances)
740728
{
741-
Name = name,
742-
Host = instance.InstanceId,
743-
Group = $"~ [{profile}\\{region}]",
744-
IsDynamic = true,
745-
746-
AWSSessionManager_Enabled = true,
747-
AWSSessionManager_InstanceID = instance.InstanceId,
748-
AWSSessionManager_OverrideProfile = true,
749-
AWSSessionManager_Profile = profile,
750-
AWSSessionManager_OverrideRegion = true,
751-
AWSSessionManager_Region = region
752-
});
753-
}
729+
if (SettingsManager.Current.AWSSessionManager_SyncOnlyRunningInstancesFromAWS &&
730+
instance.State.Name.Value != "running")
731+
continue;
732+
733+
var tagName = instance.Tags.FirstOrDefault(x => x.Key == "Name");
734+
735+
var name = tagName == null || tagName.Value == null
736+
? instance.InstanceId
737+
: $"{tagName.Value} ({instance.InstanceId})";
738+
739+
groupInfo.Profiles.Add(new ProfileInfo
740+
{
741+
Name = name,
742+
Host = instance.InstanceId,
743+
Group = $"~ [{profile}\\{region}]",
744+
IsDynamic = true,
745+
746+
AWSSessionManager_Enabled = true,
747+
AWSSessionManager_InstanceID = instance.InstanceId,
748+
AWSSessionManager_OverrideProfile = true,
749+
AWSSessionManager_Profile = profile,
750+
AWSSessionManager_OverrideRegion = true,
751+
AWSSessionManager_Region = region
752+
});
753+
}
754754

755755
// Remove, replace or add group
756756
var profilesChangedCurrentState = ProfileManager.ProfilesChanged;
@@ -846,14 +846,14 @@ private async Task Connect()
846846

847847
private void ConnectProfile()
848848
{
849-
var sessionInfo = AWSSessionManager.CreateSessionInfo(SelectedProfile);
849+
var sessionInfo = AWSSessionManagerProfile.CreateSessionInfo(SelectedProfile);
850850

851851
Connect(sessionInfo, SelectedProfile.Name);
852852
}
853853

854854
private void ConnectProfileExternal()
855855
{
856-
var sessionInfo = AWSSessionManager.CreateSessionInfo(SelectedProfile);
856+
var sessionInfo = AWSSessionManagerProfile.CreateSessionInfo(SelectedProfile);
857857

858858
Process.Start(new ProcessStartInfo
859859
{
@@ -959,7 +959,7 @@ public void FocusEmbeddedWindow()
959959

960960
// Focus embedded window in the selected tab
961961
(((DragablzTabItem)tabablzControl.SelectedItem)?.View as IEmbeddedWindow)?.FocusEmbeddedWindow();
962-
962+
963963
break;
964964
}
965965
}
@@ -1044,17 +1044,17 @@ public void OnProfileManagerDialogClose()
10441044
{
10451045
ConfigurationManager.OnDialogClose();
10461046
}
1047-
1047+
10481048
private void WriteDefaultProfileToRegistry()
10491049
{
10501050
if (!SettingsManager.Current.Appearance_PowerShellModifyGlobalProfile)
10511051
return;
1052-
1053-
if(!IsExecutableConfigured)
1052+
1053+
if (!IsExecutableConfigured)
10541054
return;
1055-
1055+
10561056
Log.Info("Write PowerShell profile to registry...");
1057-
1057+
10581058
PowerShell.WriteDefaultProfileToRegistry(
10591059
SettingsManager.Current.Appearance_Theme,
10601060
SettingsManager.Current.AWSSessionManager_ApplicationFilePath);
@@ -1069,15 +1069,15 @@ private void SettingsManager_PropertyChanged(object sender, PropertyChangedEvent
10691069
switch (e.PropertyName)
10701070
{
10711071
case nameof(SettingsInfo.AWSSessionManager_EnableSyncInstanceIDsFromAWS):
1072-
{
1073-
IsSyncEnabled = SettingsManager.Current.AWSSessionManager_EnableSyncInstanceIDsFromAWS;
1072+
{
1073+
IsSyncEnabled = SettingsManager.Current.AWSSessionManager_EnableSyncInstanceIDsFromAWS;
10741074

1075-
if (IsSyncEnabled)
1076-
SyncAllInstanceIDsFromAWS().ConfigureAwait(false);
1077-
else
1078-
RemoveDynamicGroups();
1079-
break;
1080-
}
1075+
if (IsSyncEnabled)
1076+
SyncAllInstanceIDsFromAWS().ConfigureAwait(false);
1077+
else
1078+
RemoveDynamicGroups();
1079+
break;
1080+
}
10811081
case nameof(SettingsInfo.AWSSessionManager_SyncOnlyRunningInstancesFromAWS):
10821082
SyncAllInstanceIDsFromAWS().ConfigureAwait(false);
10831083
break;

0 commit comments

Comments
 (0)