public async Task <ISshConnectionInfo> GetSshConnectionInfoAsync(ISshConnectionInfo input) { DataContext = input; Focus(FocusState.Programmatic); return(await ShowAsync() == ContentDialogResult.Primary ? (SshProfileViewModel)DataContext : null); }
public async Task <ISshConnectionInfo> GetSshConnectionInfoAsync(ISshConnectionInfo input = null) { if (input != null) { DataContext = ((SshConnectionInfoViewModel)input).Clone(); } this.Focus(FocusState.Programmatic); return(await ShowAsync() == ContentDialogResult.Primary ? (SshConnectionInfoViewModel)DataContext : null); }
public async Task <ISshConnectionInfo> GetSshConnectionInfoAsync(ISshConnectionInfo input) { DataContext = input; Focus(FocusState.Programmatic); if (await ShowAsync() != ContentDialogResult.Primary) { return(null); } var vm = (SshProfileViewModel)DataContext; await vm.AcceptChangesAsync(); return(vm); }
public static SshConnectionInfoValidationResult GetValidationResult(this ISshConnectionInfo sshConnectionInfo, bool allowNoUser = false) { var result = SshConnectionInfoValidationResult.Valid; if (!allowNoUser && string.IsNullOrEmpty(sshConnectionInfo.Username)) { result |= SshConnectionInfoValidationResult.UsernameEmpty; } if (string.IsNullOrEmpty(sshConnectionInfo.Host)) { result |= SshConnectionInfoValidationResult.HostEmpty; } if (sshConnectionInfo.SshPort < 1) { result |= SshConnectionInfoValidationResult.SshPortZeroOrNegative; } if (!sshConnectionInfo.UseMosh) { return(result); } if (sshConnectionInfo.MoshPortFrom < 1) { result |= SshConnectionInfoValidationResult.MoshPortZeroOrNegative; } if (sshConnectionInfo.MoshPortFrom > sshConnectionInfo.MoshPortTo) { result |= SshConnectionInfoValidationResult.MoshPortRangeInvalid; } return(result); }
public async Task <string> ConvertToUriAsync(ISshConnectionInfo sshConnectionInfo) { var result = await sshConnectionInfo.ValidateAsync(); if (result != SshConnectionInfoValidationResult.Valid && // We can ignore empty username here result != SshConnectionInfoValidationResult.UsernameEmpty) { throw new ArgumentException(result.GetErrorString(), nameof(sshConnectionInfo)); } SshProfileViewModel sshConnectionInfoVm = (SshProfileViewModel)sshConnectionInfo; StringBuilder sb = new StringBuilder(sshConnectionInfoVm.UseMosh ? MoshUriScheme : SshUriScheme); sb.Append("://"); bool containsUserInfo = false; if (!string.IsNullOrEmpty(sshConnectionInfoVm.Username)) { sb.Append(HttpUtility.UrlEncode(sshConnectionInfoVm.Username)); containsUserInfo = true; } if (!string.IsNullOrEmpty(sshConnectionInfoVm.IdentityFile)) { sb.Append(";"); if (!string.IsNullOrEmpty(sshConnectionInfoVm.IdentityFile)) { sb.Append($"{IdentityFileOptionName}={HttpUtility.UrlEncode(sshConnectionInfoVm.IdentityFile)}"); } containsUserInfo = true; } if (containsUserInfo) { sb.Append("@"); } sb.Append(sshConnectionInfoVm.Host); if (sshConnectionInfoVm.SshPort != SshProfile.DefaultSshPort) { sb.Append(":"); sb.Append(sshConnectionInfoVm.SshPort.ToString("#####")); } sb.Append("/"); bool queryStringAdded = false; if (sshConnectionInfoVm.UseMosh) { sb.Append( $"?{ValidMoshPortsNames[0]}={sshConnectionInfo.MoshPortFrom:#####}-{sshConnectionInfo.MoshPortTo:#####}"); queryStringAdded = true; } if (!sshConnectionInfo.TerminalThemeId.Equals(Guid.Empty)) { if (!queryStringAdded) { sb.Append("?"); queryStringAdded = true; } else { sb.Append("&"); } sb.Append($"{ThemeQueryStringParam}={sshConnectionInfo.TerminalThemeId}"); } if (sshConnectionInfo.TabThemeId != 0) { if (!queryStringAdded) { sb.Append("?"); } else { sb.Append("&"); } sb.Append($"{TabQueryStringParam}={sshConnectionInfo.TabThemeId:##########}"); } return(sb.ToString()); }
public Task <ISshConnectionInfo> ShowSshConnectionInfoDialogAsync(ISshConnectionInfo input = null) => _sshConnectionInfoDialogFactory().GetSshConnectionInfoAsync(input);