public SshProfilesCollection(string settingName) { Items = new BindingList <DefaultProfile>(); var str = settings[settingName] as string; if (str != "") { var profileStrs = str.Split('\n'); for (int i = 0; i < profileStrs.Length; i++) { var profile = new SshProfile(profileStrs[i]); Items.Add(profile); } } Items.ListChanged += (sender, e) => { var profileStrs = new List <string>(); for (int i = 0; i < Items.Count; i++) { profileStrs.Add(Items[i].ToSettingString()); } var newSetting = String.Join("\n", profileStrs.ToArray()); if (settings[settingName] as string != newSetting) { settings[settingName] = newSetting; } }; }
public static OsProfile CreateOsProfile(PSCredential sshCredential, string sshPublicKey) { string sshUserName = sshCredential?.UserName; string sshPassword = sshCredential?.Password?.ConvertToString(); List <SshPublicKey> sshPublicKeys = new List <SshPublicKey>(); if (!string.IsNullOrEmpty(sshPublicKey)) { sshPublicKeys.Add(new SshPublicKey { CertificateData = sshPublicKey }); } SshProfile sshProfile = null; if (sshPublicKeys.Count > 0) { sshProfile = new SshProfile { PublicKeys = sshPublicKeys.ToArray() }; } return(new OsProfile { LinuxOperatingSystemProfile = new LinuxOperatingSystemProfile { SshProfile = sshProfile, Password = sshPassword, Username = sshUserName } }); }
private static OsProfile GetOsProfile(ClusterCreateParameters createProperties) { List <SshPublicKey> sshPublicKeys = new List <SshPublicKey>(); if (!string.IsNullOrEmpty(createProperties.SshPublicKey)) { sshPublicKeys.Add(new SshPublicKey { CertificateData = createProperties.SshPublicKey }); } SshProfile sshProfile = null; if (sshPublicKeys.Count > 0) { sshProfile = new SshProfile { PublicKeys = sshPublicKeys.ToArray() }; } return(new OsProfile { LinuxOperatingSystemProfile = new LinuxOperatingSystemProfile { SshProfile = sshProfile, Password = createProperties.SshPassword, Username = createProperties.SshUserName } }); }
public SshProfile(SshProfile profile) { Name = profile.Name; Server = profile.Server; Port = profile.Port; Username = profile.Username; Password = profile.Password; }
public SshProfilesCollection(string settingName) { Items = new BindingList<DefaultProfile>(); var str = settings[settingName] as string; if (str != "") { var profileStrs = str.Split('\n'); for (int i = 0; i < profileStrs.Length; i++) { var profile = new SshProfile(profileStrs[i]); Items.Add(profile); } } Items.ListChanged += (sender, e) => { var profileStrs = new List<string>(); for (int i = 0; i < Items.Count; i++) { profileStrs.Add(Items[i].ToSettingString()); } var newSetting = String.Join("\n", profileStrs.ToArray()); if (settings[settingName] as string != newSetting) { settings[settingName] = newSetting; } }; }
public async Task <SshProfile> GetSshProfileAsync(SshProfile profile) { SshProfileViewModel vm = new SshProfileViewModel(profile, _settingsService, _dialogService, _fileSystemService, _applicationView, _defaultValueProvider, _trayProcessCommunicationService, true); vm = (SshProfileViewModel)await _dialogService.ShowSshConnectionInfoDialogAsync(vm); return((SshProfile)vm?.Model); }
public SshProfileViewModel(SshProfile sshProfile, ISettingsService settingsService, IDialogService dialogService, IFileSystemService fileSystemService, IApplicationView applicationView, ITrayProcessCommunicationService trayProcessCommunicationService, IApplicationDataContainer historyContainer, bool isNew) : base(sshProfile, settingsService, dialogService, isNew) { ProfileVm = new SshConnectViewModel(settingsService, applicationView, trayProcessCommunicationService, fileSystemService, sshProfile); }
public SshProfileSelectionDialog(ISettingsService settingsService, IDialogService dialogService) { _dialogService = dialogService; Profiles = settingsService.GetSshProfiles(); SelectedProfile = Profiles.FirstOrDefault(); this.InitializeComponent(); var currentTheme = settingsService.GetCurrentTheme(); RequestedTheme = ContrastHelper.GetIdealThemeForBackgroundColor(currentTheme.Colors.Background); }
private void AddSshProfile(SshProfile sshProfile) { var viewModel = new SshProfileViewModel(sshProfile, _settingsService, _dialogService, _fileSystemService, _applicationView, _trayProcessCommunicationService, _historyContainer, true); viewModel.EditCommand.Execute(null); viewModel.Deleted += OnSshProfileDeleted; SshProfiles.Add(viewModel); SelectedSshProfile = viewModel; }
private void AddSshProfile(SshProfile sshProfile) { var viewModel = new SshProfileViewModel(sshProfile, _settingsService, _dialogService, _fileSystemService, _applicationView, _defaultValueProvider, _trayProcessCommunicationService, true); viewModel.EditCommand.Execute(null); viewModel.SetAsDefault += OnSshProfileSetAsDefault; viewModel.Deleted += OnSshProfileDeleted; SshProfiles.Add(viewModel); SelectedSshProfile = viewModel; }
public void CreateSshProfile() { var shellProfile = new SshProfile { Id = Guid.NewGuid(), PreInstalled = false, Name = "New SSH profile", KeyBindings = new List <KeyBinding>() }; AddSshProfile(shellProfile); }
public void CreateSshProfile() { var shellProfile = new SshProfile { Id = Guid.NewGuid(), PreInstalled = false, Name = "New SSH profile", KeyBindings = new List <KeyBinding>(), UseMosh = _settingsService.GetApplicationSettings().UseMoshByDefault }; AddSshProfile(shellProfile); }
public async Task <SshProfile> GetSshProfileAsync(SshProfile profile) { SshProfileViewModel vm = new SshProfileViewModel(profile, _settingsService, _dialogService, _fileSystemService, _applicationView, _trayProcessCommunicationService, true); vm = (SshProfileViewModel)await _dialogService.ShowSshConnectionInfoDialogAsync(vm); if (vm != null) { await vm.AcceptChangesAsync(); } return(vm?.Model); }
public async Task <SshProfile> GetSshConnectionInfoAsync(SshProfile input = null) { ViewModel = new SshConnectViewModel(_settingsService, _applicationView, _trayProcessCommunicationService, _fileSystemService, input); if (string.IsNullOrEmpty(ViewModel.Username)) { ViewModel.Username = await _trayProcessCommunicationService.GetUserName(); } SetupFocus(); return(await ShowAsync() == ContentDialogResult.Primary ? (SshProfile)ViewModel.Model : null); }
public void CreateSshProfile() { var shellProfile = new SshProfile(_applicationView.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 7)) { Id = Guid.NewGuid(), PreInstalled = false, Name = "New SSH profile", KeyBindings = new List <KeyBinding>(), UseMosh = _settingsService.GetApplicationSettings().UseMoshByDefault, RequestConPty = _settingsService.GetApplicationSettings().UseConPty }; AddSshProfile(shellProfile); }
public async Task <SshProfile> GetSshConnectionInfoAsync(SshProfile input = null) { var vm = new SshConnectViewModel(_settingsService, _applicationView, _trayProcessCommunicationService, _fileSystemService, input); DataContext = vm; if (await ShowAsync() != ContentDialogResult.Primary) { return(null); } return((SshProfile)vm.Model); }
private void Clone(SshProfileViewModel shellProfile) { var cloned = new SshProfile(shellProfile.Model) { Id = Guid.NewGuid(), PreInstalled = false, Name = $"Copy of {shellProfile.Name}" }; foreach (KeyBinding keyBinding in cloned.KeyBindings) { keyBinding.Command = cloned.Id.ToString(); } AddSshProfile(cloned); }
public void SaveSshProfile(SshProfile sshProfile, bool newShell = false) { _sshProfiles.WriteValueAsJson(sshProfile.Id.ToString(), sshProfile); // When saving the shell profile, we also need to update keybindings for everywhere. Messenger.Default.Send(new KeyBindingsChangedMessage()); if (newShell) { Messenger.Default.Send(new ShellProfileAddedMessage(sshProfile)); } else { Messenger.Default.Send(new ShellProfileChangedMessage(sshProfile)); } }
public SshProfileSelectionDialog(ISettingsService settingsService, IDialogService dialogService) { _dialogService = dialogService; Profiles = new ObservableCollection <SshProfile>(settingsService.GetSshProfiles().OrderBy(p => p.Name)); var selectedProfile = settingsService.GetDefaultSshProfile(); if (selectedProfile != null) { selectedProfile = Profiles.FirstOrDefault(p => p.Id.Equals(selectedProfile.Id)); } SelectedProfile = selectedProfile ?? Profiles.FirstOrDefault(); this.InitializeComponent(); var currentTheme = settingsService.GetCurrentTheme(); RequestedTheme = ContrastHelper.GetIdealThemeForBackgroundColor(currentTheme.Colors.Background); }
public async Task <SshProfile> GetSshConnectionInfoAsync(SshProfile input = null) { var vm = new SshConnectViewModel(_settingsService, _applicationView, _trayProcessCommunicationService, _fileSystemService, _historyContainer, input); DataContext = vm; if (await ShowAsync() != ContentDialogResult.Primary) { return(null); } var profile = (SshProfile)vm.Model; if (vm.CommandInput) { vm.SaveCommand(profile.Location, profile.Arguments); } return(profile); }
public SshProfileAddedMessage(SshProfile sshProfile) { SshProfile = sshProfile ?? throw new ArgumentNullException(); }
private static IEnumerable <Role> GetRoleCollection(ClusterCreateParameters clusterCreateParameters) { //OS Profile var osProfile = new OsProfile(); if (clusterCreateParameters.OSType == OSType.Windows) { RdpSettings rdpSettings = null; if (!string.IsNullOrEmpty(clusterCreateParameters.RdpUsername)) { rdpSettings = new RdpSettings { UserName = clusterCreateParameters.RdpUsername, Password = clusterCreateParameters.RdpPassword, ExpiryDate = clusterCreateParameters.RdpAccessExpiry }; } osProfile = new OsProfile { WindowsOperatingSystemProfile = new WindowsOperatingSystemProfile { RdpSettings = rdpSettings } }; } else if (clusterCreateParameters.OSType == OSType.Linux) { var sshPublicKeys = new List <SshPublicKey>(); if (!string.IsNullOrEmpty(clusterCreateParameters.SshPublicKey)) { var sshPublicKey = new SshPublicKey { CertificateData = clusterCreateParameters.SshPublicKey }; sshPublicKeys.Add(sshPublicKey); } SshProfile sshProfile; if (sshPublicKeys.Count > 0) { sshProfile = new SshProfile { SshPublicKeys = sshPublicKeys }; } else { sshProfile = null; } osProfile = new OsProfile { LinuxOperatingSystemProfile = new LinuxOperatingSystemProfile { UserName = clusterCreateParameters.SshUserName, Password = clusterCreateParameters.SshPassword, SshProfile = sshProfile } }; } //VNet Profile var vnetProfile = new VirtualNetworkProfile(); if (!string.IsNullOrEmpty(clusterCreateParameters.VirtualNetworkId)) { vnetProfile.Id = clusterCreateParameters.VirtualNetworkId; } if (!string.IsNullOrEmpty(clusterCreateParameters.SubnetName)) { vnetProfile.SubnetName = clusterCreateParameters.SubnetName; } if (string.IsNullOrEmpty(vnetProfile.Id) && string.IsNullOrEmpty(vnetProfile.SubnetName)) { vnetProfile = null; } List <ScriptAction> workernodeactions = null; List <ScriptAction> headnodeactions = null; List <ScriptAction> zookeepernodeactions = null; //Script Actions foreach (var scriptAction in clusterCreateParameters.ScriptActions) { if (scriptAction.Key.ToString().ToLower().Equals("workernode")) { workernodeactions = scriptAction.Value; } else if (scriptAction.Key.ToString().ToLower().Equals("headnode")) { headnodeactions = scriptAction.Value; } else if (scriptAction.Key.ToString().ToLower().Equals("zookeepernode")) { zookeepernodeactions = scriptAction.Value; } } //Roles var roles = new List <Role>(); var headNodeSize = GetHeadNodeSize(clusterCreateParameters); var headNode = new Role { Name = "headnode", TargetInstanceCount = 2, HardwareProfile = new HardwareProfile { VmSize = headNodeSize }, OsProfile = osProfile, VirtualNetworkProfile = vnetProfile, ScriptActions = headnodeactions }; roles.Add(headNode); var workerNodeSize = GetWorkerNodeSize(clusterCreateParameters); var workerNode = new Role { Name = "workernode", TargetInstanceCount = clusterCreateParameters.ClusterSizeInNodes, HardwareProfile = new HardwareProfile { VmSize = workerNodeSize }, OsProfile = osProfile, ScriptActions = workernodeactions }; roles.Add(workerNode); if (clusterCreateParameters.OSType == OSType.Windows) { if (clusterCreateParameters.ClusterType.Equals("Hadoop", StringComparison.OrdinalIgnoreCase) || clusterCreateParameters.ClusterType.Equals("Spark", StringComparison.OrdinalIgnoreCase)) { return(roles); } } if (clusterCreateParameters.OSType == OSType.Linux) { if (clusterCreateParameters.ClusterType.Equals("Hadoop", StringComparison.OrdinalIgnoreCase) || clusterCreateParameters.ClusterType.Equals("Spark", StringComparison.OrdinalIgnoreCase)) { clusterCreateParameters.ZookeeperNodeSize = "Small"; } } string zookeeperNodeSize = clusterCreateParameters.ZookeeperNodeSize ?? "Medium"; var zookeepernode = new Role { Name = "zookeepernode", ScriptActions = zookeepernodeactions, TargetInstanceCount = 3, OsProfile = osProfile, HardwareProfile = new HardwareProfile { VmSize = zookeeperNodeSize } }; roles.Add(zookeepernode); return(roles); }
protected override async void OnActivated(IActivatedEventArgs args) { if (args is ProtocolActivatedEventArgs protocolActivated) { MainViewModel mainViewModel = null; // IApplicationView to use for creating view models IApplicationView applicationView; if (_alreadyLaunched) { applicationView = (_mainViewModels.FirstOrDefault(o => o.ApplicationView.Id == _activeWindowId) ?? _mainViewModels.Last()).ApplicationView; } else { // App wasn't launched before double clicking a shortcut, so we have to create a window // in order to be able to communicate with user. mainViewModel = _container.Resolve <MainViewModel>(); await CreateMainView(typeof(MainPage), mainViewModel, true); applicationView = mainViewModel.ApplicationView; } bool isSsh; try { isSsh = SshConnectViewModel.CheckScheme(protocolActivated.Uri); } catch (Exception ex) { await new MessageDialog( $"{I18N.TranslateWithFallback("InvalidLink", "Invalid link.")} {ex.Message}", "Invalid Link") .ShowAsync(); mainViewModel?.ApplicationView.TryClose(); return; } if (isSsh) { SshConnectViewModel vm; try { vm = SshConnectViewModel.ParseUri(protocolActivated.Uri, _settingsService, applicationView, _trayProcessCommunicationService, _container.Resolve <IFileSystemService>(), _container.Resolve <ApplicationDataContainers>().HistoryContainer); } catch (Exception ex) { await new MessageDialog( $"{I18N.TranslateWithFallback("InvalidLink", "Invalid link.")} {ex.Message}", "Invalid Link") .ShowAsync(); mainViewModel?.ApplicationView.TryClose(); return; } if (_applicationSettings.AutoFallbackToWindowsUsernameInLinks && string.IsNullOrEmpty(vm.Username)) { vm.Username = await _trayProcessCommunicationService.GetUserName(); } var error = await vm.AcceptChangesAsync(true); SshProfile profile = (SshProfile)vm.Model; if (!string.IsNullOrEmpty(error)) { // Link is valid, but incomplete (i.e. username missing), so we need to show dialog. profile = await _dialogService.ShowSshConnectionInfoDialogAsync(profile); if (profile == null) { // User clicked "Cancel" in the dialog. mainViewModel?.ApplicationView.TryClose(); return; } } if (mainViewModel == null) { await CreateTerminal(profile, _applicationSettings.NewTerminalLocation, protocolActivated.ViewSwitcher); } else { await mainViewModel.AddTerminalAsync(profile); } return; } if (CommandProfileProviderViewModel.CheckScheme(protocolActivated.Uri)) { CommandProfileProviderViewModel vm; try { vm = CommandProfileProviderViewModel.ParseUri(protocolActivated.Uri, _settingsService, applicationView, _trayProcessCommunicationService, _container.Resolve <ApplicationDataContainers>().HistoryContainer); } catch (Exception ex) { await new MessageDialog( $"{I18N.TranslateWithFallback("InvalidLink", "Invalid link.")} {ex.Message}", "Invalid Link") .ShowAsync(); mainViewModel?.ApplicationView.TryClose(); return; } var error = await vm.AcceptChangesAsync(true); var profile = vm.Model; if (!string.IsNullOrEmpty(error)) { // Link is valid, but incomplete, so we need to show dialog. profile = await _dialogService.ShowCustomCommandDialogAsync(profile); if (profile == null) { // User clicked "Cancel" in the dialog. mainViewModel?.ApplicationView.TryClose(); return; } } if (mainViewModel == null) { await CreateTerminal(profile, _applicationSettings.NewTerminalLocation, protocolActivated.ViewSwitcher); } else { await mainViewModel.AddTerminalAsync(profile); } return; } await new MessageDialog( $"{I18N.TranslateWithFallback("InvalidLink", "Invalid link.")} {protocolActivated.Uri}", "Invalid Link") .ShowAsync(); mainViewModel?.ApplicationView.TryClose(); return; } if (args is CommandLineActivatedEventArgs commandLineActivated) { if (string.IsNullOrWhiteSpace(commandLineActivated.Operation.Arguments)) { return; } _commandLineParser.ParseArguments(SplitArguments(commandLineActivated.Operation.Arguments), typeof(NewVerb), typeof(RunVerb), typeof(SettingsVerb)).WithParsed(async verb => { if (verb is SettingsVerb settingsVerb) { if (!settingsVerb.Import && !settingsVerb.Export) { await ShowSettings().ConfigureAwait(true); } else if (settingsVerb.Export) { var exportFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("config.json", CreationCollisionOption.OpenIfExists); var settings = _settingsService.ExportSettings(); await FileIO.WriteTextAsync(exportFile, settings); await new MessageDialog($"{I18N.Translate("SettingsExported")} {exportFile.Path}").ShowAsync(); } else if (settingsVerb.Import) { var file = await ApplicationData.Current.LocalFolder.GetFileAsync("config.json"); var content = await FileIO.ReadTextAsync(file); _settingsService.ImportSettings(content); await new MessageDialog($"{I18N.Translate("SettingsImported")} {file.Path}").ShowAsync(); } } else if (verb is NewVerb newVerb) { var profile = default(ShellProfile); if (!string.IsNullOrWhiteSpace(newVerb.Profile)) { profile = _settingsService.GetShellProfiles().FirstOrDefault(x => x.Name.Equals(newVerb.Profile, StringComparison.CurrentCultureIgnoreCase)); } if (profile == null) { profile = _settingsService.GetDefaultShellProfile(); } if (!string.IsNullOrWhiteSpace(newVerb.Directory)) { profile.WorkingDirectory = newVerb.Directory; } var location = newVerb.Target == Target.Default ? _applicationSettings.NewTerminalLocation : newVerb.Target == Target.Tab ? NewTerminalLocation.Tab : NewTerminalLocation.Window; await CreateTerminal(profile, location).ConfigureAwait(true); } else if (verb is RunVerb runVerb) { var profile = new ShellProfile { Id = Guid.Empty, Location = null, Arguments = runVerb.Command, WorkingDirectory = runVerb.Directory }; if (!string.IsNullOrWhiteSpace(runVerb.Theme)) { var theme = _settingsService.GetThemes().FirstOrDefault(x => x.Name.Equals(runVerb.Theme, StringComparison.CurrentCultureIgnoreCase)); if (theme != null) { profile.TerminalThemeId = theme.Id; } } if (string.IsNullOrWhiteSpace(profile.WorkingDirectory)) { profile.WorkingDirectory = commandLineActivated.Operation.CurrentDirectoryPath; } var location = runVerb.Target == Target.Default ? _applicationSettings.NewTerminalLocation : runVerb.Target == Target.Tab ? NewTerminalLocation.Tab : NewTerminalLocation.Window; await CreateTerminal(profile, location).ConfigureAwait(true); } }); } }
public Task <SshProfile> ShowSshConnectionInfoDialogAsync(SshProfile input = null) => _sshConnectionInfoDialogFactory().GetSshConnectionInfoAsync(input);
public AzureHDInsightSshProfile(SshProfile sshProfile) { PublicKeys = sshProfile?.PublicKeys?.Select(key => new AzureHDInsightSshPublicKey(key)).ToList(); }