Skip to content

Commit

Permalink
Ap/ssh Implemented SSH by using the exsting infrastructure (#293)
Browse files Browse the repository at this point in the history
* Appveyor builds (#6)

* SSH implemented.

* Implementing SSH by using the existing app infrastructure.

* Refactored to new command instead of a profile

* Update .gitignore
  • Loading branch information
peske authored and felixse committed Apr 5, 2019
1 parent dbd8632 commit 973b1a4
Show file tree
Hide file tree
Showing 13 changed files with 1,073 additions and 893 deletions.
14 changes: 7 additions & 7 deletions FluentTerminal.App.Services.Test/DialogServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public DialogServiceTests()
public void ShowCreateKeyBindingDialog_Default_UsesCreateKeyBindingDialog()
{
var createKeyBindingDialog = new Mock<ICreateKeyBindingDialog>();
var dialogService = new DialogService(Mock.Of<IShellProfileSelectionDialog>, Mock.Of<IMessageDialog>, () => createKeyBindingDialog.Object, Mock.Of<IInputDialog>);
var dialogService = new DialogService(Mock.Of<IShellProfileSelectionDialog>, Mock.Of<IMessageDialog>, () => createKeyBindingDialog.Object, Mock.Of<IInputDialog>, Mock.Of<ISshConnectionInfoDialog>);

dialogService.ShowCreateKeyBindingDialog();

Expand All @@ -36,7 +36,7 @@ public void ShowMessageDialogAsnyc_TitleIsEmpty_ThrowsArgumentNullException()
var title = string.Empty;
var content = _fixture.Create<string>();
var buttons = _fixture.CreateMany<DialogButton>(2);
var dialogService = new DialogService(Mock.Of<IShellProfileSelectionDialog>, Mock.Of<IMessageDialog>, Mock.Of<ICreateKeyBindingDialog>, Mock.Of<IInputDialog>);
var dialogService = new DialogService(Mock.Of<IShellProfileSelectionDialog>, Mock.Of<IMessageDialog>, Mock.Of<ICreateKeyBindingDialog>, Mock.Of<IInputDialog>, Mock.Of<ISshConnectionInfoDialog>);

Func<Task<DialogButton>> showMessageDialogAsnyc = () => dialogService.ShowMessageDialogAsnyc(title, content, buttons.ElementAt(0), buttons.ElementAt(1));

Expand All @@ -49,7 +49,7 @@ public void ShowMessageDialogAsnyc_ContentIsEmpty_ThrowsArgumentNullException()
var title = _fixture.Create<string>();
var content = string.Empty;
var buttons = _fixture.CreateMany<DialogButton>(2);
var dialogService = new DialogService(Mock.Of<IShellProfileSelectionDialog>, Mock.Of<IMessageDialog>, Mock.Of<ICreateKeyBindingDialog>, Mock.Of<IInputDialog>);
var dialogService = new DialogService(Mock.Of<IShellProfileSelectionDialog>, Mock.Of<IMessageDialog>, Mock.Of<ICreateKeyBindingDialog>, Mock.Of<IInputDialog>, Mock.Of<ISshConnectionInfoDialog>);

Func<Task<DialogButton>> showMessageDialogAsnyc = () => dialogService.ShowMessageDialogAsnyc(title, content, buttons.ElementAt(0), buttons.ElementAt(1));

Expand All @@ -61,7 +61,7 @@ public void ShowMessageDialogAsnyc_NoButtonsPassed_ThrowsArgumentException()
{
var title = _fixture.Create<string>();
var content = _fixture.Create<string>();
var dialogService = new DialogService(Mock.Of<IShellProfileSelectionDialog>, Mock.Of<IMessageDialog>, Mock.Of<ICreateKeyBindingDialog>, Mock.Of<IInputDialog>);
var dialogService = new DialogService(Mock.Of<IShellProfileSelectionDialog>, Mock.Of<IMessageDialog>, Mock.Of<ICreateKeyBindingDialog>, Mock.Of<IInputDialog>, Mock.Of<ISshConnectionInfoDialog>);

Func<Task<DialogButton>> showMessageDialogAsnyc = () => dialogService.ShowMessageDialogAsnyc(title, content);

Expand All @@ -75,7 +75,7 @@ public void ShowMessageDialogAsnyc_Default_UsesMessageDialog()
var content = _fixture.Create<string>();
var buttons = _fixture.CreateMany<DialogButton>(2);
var messageDialog = new Mock<IMessageDialog>();
var dialogService = new DialogService(Mock.Of<IShellProfileSelectionDialog>, () => messageDialog.Object, Mock.Of<ICreateKeyBindingDialog>, Mock.Of<IInputDialog>);
var dialogService = new DialogService(Mock.Of<IShellProfileSelectionDialog>, () => messageDialog.Object, Mock.Of<ICreateKeyBindingDialog>, Mock.Of<IInputDialog>, Mock.Of<ISshConnectionInfoDialog>);

dialogService.ShowMessageDialogAsnyc(title, content, buttons.ElementAt(0), buttons.ElementAt(1));

Expand All @@ -86,7 +86,7 @@ public void ShowMessageDialogAsnyc_Default_UsesMessageDialog()
public void ShowProfileSelectionDialogAsync_Default_UsesShellProfileSelectionDialog()
{
var shellProfileSelectionDialog = new Mock<IShellProfileSelectionDialog>();
var dialogService = new DialogService(() => shellProfileSelectionDialog.Object, Mock.Of<IMessageDialog>, Mock.Of<ICreateKeyBindingDialog>, Mock.Of<IInputDialog>);
var dialogService = new DialogService(() => shellProfileSelectionDialog.Object, Mock.Of<IMessageDialog>, Mock.Of<ICreateKeyBindingDialog>, Mock.Of<IInputDialog>, Mock.Of<ISshConnectionInfoDialog>);

dialogService.ShowProfileSelectionDialogAsync();

Expand All @@ -98,7 +98,7 @@ public void ShowInputDialogAsync_UsesIInputDialogSetTitle()
{
var title = "title";
var inputDialog = new Mock<IInputDialog>();
var dialogService = new DialogService(Mock.Of<IShellProfileSelectionDialog>, Mock.Of<IMessageDialog>, Mock.Of<ICreateKeyBindingDialog>, () => inputDialog.Object);
var dialogService = new DialogService(Mock.Of<IShellProfileSelectionDialog>, Mock.Of<IMessageDialog>, Mock.Of<ICreateKeyBindingDialog>, () => inputDialog.Object, Mock.Of<ISshConnectionInfoDialog>);

dialogService.ShowInputDialogAsync(title);

Expand Down
11 changes: 11 additions & 0 deletions FluentTerminal.App.Services/Dialogs/ISshConnectionInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace FluentTerminal.App.Services.Dialogs
{
public interface ISshConnectionInfo
{
string Host { get; set; }

ushort Port { get; set; }

string Username { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Threading.Tasks;

namespace FluentTerminal.App.Services.Dialogs
{
public interface ISshConnectionInfoDialog
{
Task<ISshConnectionInfo> GetSshConnectionInfoAsync();
}
}
3 changes: 3 additions & 0 deletions FluentTerminal.App.Services/IDialogService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using FluentTerminal.Models;
using System.Threading.Tasks;
using FluentTerminal.App.Services.Dialogs;

namespace FluentTerminal.App.Services
{
Expand All @@ -17,5 +18,7 @@ public interface IDialogService

Task<KeyBinding> ShowCreateKeyBindingDialog();
Task<string> ShowInputDialogAsync(string title);

Task<ISshConnectionInfo> ShowSshConnectionInfoDialogAsync();
}
}
13 changes: 13 additions & 0 deletions FluentTerminal.App.Services/Implementation/DefaultValueProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ public ICollection<KeyBinding> GetDefaultKeyBindings(Command command)
}
};

case Command.NewRemoteTab:
return new List<KeyBinding>
{
new KeyBinding
{
Command = nameof(Command.NewRemoteTab),
Ctrl = false,
Alt = true,
Shift = false,
Key = (int)ExtendedVirtualKey.T
}
};

case Command.ChangeTabTitle:
return new List<KeyBinding>
{
Expand Down
9 changes: 8 additions & 1 deletion FluentTerminal.App.Services/Implementation/DialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ public class DialogService : IDialogService
private readonly Func<IMessageDialog> _messageDialogFactory;
private readonly Func<ICreateKeyBindingDialog> _createKeyBindingDialogFactory;
private readonly Func<IInputDialog> _inputDialogFactory;
private readonly Func<ISshConnectionInfoDialog> _sshConnectionInfoDialogFactory;

public DialogService(Func<IShellProfileSelectionDialog> shellProfileSelectionDialogFactory, Func<IMessageDialog> messageDialogFactory, Func<ICreateKeyBindingDialog> createKeyBindingDialogFactory, Func<IInputDialog> inputDialogFactory)
public DialogService(Func<IShellProfileSelectionDialog> shellProfileSelectionDialogFactory,
Func<IMessageDialog> messageDialogFactory, Func<ICreateKeyBindingDialog> createKeyBindingDialogFactory,
Func<IInputDialog> inputDialogFactory, Func<ISshConnectionInfoDialog> sshConnectionInfoDialogFactory)
{
_shellProfileSelectionDialogFactory = shellProfileSelectionDialogFactory;
_messageDialogFactory = messageDialogFactory;
_createKeyBindingDialogFactory = createKeyBindingDialogFactory;
_inputDialogFactory = inputDialogFactory;
_sshConnectionInfoDialogFactory = sshConnectionInfoDialogFactory;
}

public Task<KeyBinding> ShowCreateKeyBindingDialog()
Expand Down Expand Up @@ -70,5 +74,8 @@ public Task<ShellProfile> ShowProfileSelectionDialogAsync()

return dialog.SelectProfile();
}

public Task<ISshConnectionInfo> ShowSshConnectionInfoDialogAsync() =>
_sshConnectionInfoDialogFactory().GetSshConnectionInfoAsync();
}
}
35 changes: 34 additions & 1 deletion FluentTerminal.App.ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Collections.Specialized;
using System.Linq;
using System.Threading.Tasks;
using FluentTerminal.App.Services.Implementation;

namespace FluentTerminal.App.ViewModels
{
Expand All @@ -20,6 +21,7 @@ public class MainViewModel : ViewModelBase
private readonly IKeyboardCommandService _keyboardCommandService;
private readonly ISettingsService _settingsService;
private readonly ITrayProcessCommunicationService _trayProcessCommunicationService;
private readonly IDefaultValueProvider _defaultValueProvider;
private ApplicationSettings _applicationSettings;
private string _background;
private double _backgroundOpacity;
Expand All @@ -28,7 +30,7 @@ public class MainViewModel : ViewModelBase
private string _windowTitle;

public MainViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService, IKeyboardCommandService keyboardCommandService,
IApplicationView applicationView, IDispatcherTimer dispatcherTimer, IClipboardService clipboardService)
IApplicationView applicationView, IDispatcherTimer dispatcherTimer, IClipboardService clipboardService, IDefaultValueProvider defaultValueProvider)
{
_settingsService = settingsService;
_settingsService.CurrentThemeChanged += OnCurrentThemeChanged;
Expand All @@ -42,8 +44,10 @@ public class MainViewModel : ViewModelBase
ApplicationView = applicationView;
_dispatcherTimer = dispatcherTimer;
_clipboardService = clipboardService;
_defaultValueProvider = defaultValueProvider;
_keyboardCommandService = keyboardCommandService;
_keyboardCommandService.RegisterCommandHandler(nameof(Command.NewTab), () => AddTerminal());
_keyboardCommandService.RegisterCommandHandler(nameof(Command.NewRemoteTab), () => AddRemoteTerminal());
_keyboardCommandService.RegisterCommandHandler(nameof(Command.ConfigurableNewTab), () => AddConfigurableTerminal());
_keyboardCommandService.RegisterCommandHandler(nameof(Command.ChangeTabTitle), () => SelectedTerminal.EditTitle());
_keyboardCommandService.RegisterCommandHandler(nameof(Command.CloseTab), CloseCurrentTab);
Expand Down Expand Up @@ -214,6 +218,34 @@ public Task AddConfigurableTerminal()
});
}

public Task AddRemoteTerminal()
{
return ApplicationView.RunOnDispatcherThread(async () =>
{
var connectionInfo = await _dialogService.ShowSshConnectionInfoDialogAsync();
if (connectionInfo == null)
{
if (Terminals.Count == 0)
{
await ApplicationView.TryClose();
}
return;
}
var profile = new ShellProfile
{
Arguments = $"-p {connectionInfo.Port:#####} {connectionInfo.Username}@{connectionInfo.Host}",
Location = @"C:\Windows\System32\OpenSSH\ssh.exe",
WorkingDirectory = string.Empty,
LineEndingTranslation = LineEndingStyle.DoNotModify,
};
AddTerminal(profile);
});
}

public void AddTerminal()
{
var profile = _settingsService.GetDefaultShellProfile();
Expand All @@ -232,6 +264,7 @@ public void AddTerminal(ShellProfile profile)
{
var terminal = new TerminalViewModel(_settingsService, _trayProcessCommunicationService, _dialogService, _keyboardCommandService,
_applicationSettings, profile, ApplicationView, _dispatcherTimer, _clipboardService);
terminal.Closed += OnTerminalClosed;
terminal.ShellTitleChanged += Terminal_ShellTitleChanged;
terminal.CustomTitleChanged += Terminal_CustomTitleChanged;
Expand Down
32 changes: 32 additions & 0 deletions FluentTerminal.App.ViewModels/SshConnectionInfoViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using FluentTerminal.App.Services.Dialogs;
using GalaSoft.MvvmLight;

namespace FluentTerminal.App.ViewModels
{
public class SshConnectionInfoViewModel : ViewModelBase, ISshConnectionInfo
{
private string _host = string.Empty;

public string Host
{
get => _host;
set => Set(ref _host, value);
}

private ushort _port = 22;

public ushort Port
{
get => _port;
set => Set(ref _port, value);
}

private string _username = string.Empty;

public string Username
{
get => _username;
set => Set(ref _username, value);
}
}
}
Loading

0 comments on commit 973b1a4

Please sign in to comment.