extracted a Runtime method to a different class

This commit is contained in:
David Sparer
2017-05-11 15:12:53 -06:00
parent b921964c88
commit cd4d5df4db
3 changed files with 35 additions and 37 deletions

View File

@@ -1,7 +1,6 @@
using mRemoteNG.App.Info;
using mRemoteNG.Config.Connections;
using mRemoteNG.Connection;
using mRemoteNG.Connection.Protocol;
using mRemoteNG.Messages;
using mRemoteNG.Tools;
using mRemoteNG.Tree.Root;
@@ -269,40 +268,5 @@ namespace mRemoteNG.App
}
}
#endregion
#region Opening Connection
public static ConnectionInfo CreateQuickConnect(string connectionString, ProtocolType protocol)
{
try
{
var uri = new Uri("dummyscheme" + Uri.SchemeDelimiter + connectionString);
if (string.IsNullOrEmpty(uri.Host)) return null;
var newConnectionInfo = new ConnectionInfo();
newConnectionInfo.CopyFrom(DefaultConnectionInfo.Instance);
newConnectionInfo.Name = Settings.Default.IdentifyQuickConnectTabs ? string.Format(Language.strQuick, uri.Host) : uri.Host;
newConnectionInfo.Protocol = protocol;
newConnectionInfo.Hostname = uri.Host;
if (uri.Port == -1)
{
newConnectionInfo.SetDefaultPort();
}
else
{
newConnectionInfo.Port = uri.Port;
}
newConnectionInfo.IsQuickConnect = true;
return newConnectionInfo;
}
catch (Exception ex)
{
MessageCollector.AddExceptionMessage(Language.strQuickConnectFailed, ex);
return null;
}
}
#endregion
}
}

View File

@@ -4,6 +4,7 @@ using System.Windows.Forms;
using mRemoteNG.App;
using mRemoteNG.App.Info;
using mRemoteNG.Config.Connections;
using mRemoteNG.Connection.Protocol;
using mRemoteNG.Tree;
using mRemoteNG.Tree.Root;
@@ -78,5 +79,38 @@ namespace mRemoteNG.Connection
{
return ConnectionsFileInfo.DefaultConnectionsPath + "\\" + ConnectionsFileInfo.DefaultConnectionsFile;
}
public ConnectionInfo CreateQuickConnect(string connectionString, ProtocolType protocol)
{
try
{
var uri = new Uri("dummyscheme" + Uri.SchemeDelimiter + connectionString);
if (string.IsNullOrEmpty(uri.Host)) return null;
var newConnectionInfo = new ConnectionInfo();
newConnectionInfo.CopyFrom(DefaultConnectionInfo.Instance);
newConnectionInfo.Name = Settings.Default.IdentifyQuickConnectTabs ? string.Format(Language.strQuick, uri.Host) : uri.Host;
newConnectionInfo.Protocol = protocol;
newConnectionInfo.Hostname = uri.Host;
if (uri.Port == -1)
{
newConnectionInfo.SetDefaultPort();
}
else
{
newConnectionInfo.Port = uri.Port;
}
newConnectionInfo.IsQuickConnect = true;
return newConnectionInfo;
}
catch (Exception ex)
{
Runtime.MessageCollector.AddExceptionMessage(Language.strQuickConnectFailed, ex);
return null;
}
}
}
}

View File

@@ -168,7 +168,7 @@ namespace mRemoteNG.UI.Controls
{
try
{
var connectionInfo = Runtime.CreateQuickConnect(_cmbQuickConnect.Text.Trim(), Converter.StringToProtocol(Settings.Default.QuickConnectProtocol));
var connectionInfo = Runtime.ConnectionsService.CreateQuickConnect(_cmbQuickConnect.Text.Trim(), Converter.StringToProtocol(Settings.Default.QuickConnectProtocol));
if (connectionInfo == null)
{
_cmbQuickConnect.Focus();