internal Edit(RemoteConnection connection, string baseFolder)
 {
     //
     // The InitializeComponent() call is required for Windows Forms designer support.
     //
     InitializeComponent();
     this.connection = connection;
 }
 internal static void removeConnection(RemoteConnection connection)
 {
     var removed = connection;
     RemoteConnection.CACHE.TryTake(out removed);
 }
        private void EditShown(object sender, EventArgs e)
        {
            if(this.connection == null)
            {
                using(var chooser = new ChooseType())
                {
                    chooser.ShowDialog(this);
                    var type = chooser.__getType();
                    if(type == string.Empty)
                    {
                        this.DialogResult = DialogResult.Cancel;
                        return;
                    }
                    else if(type == "RDP")
                    {
                        this.connection = new RDP(this.baseFolder);
                        this.wasNewConnection = true;
                    }
                    else if(type == "WinSCP")
                    {
                        this.connection = new WinSCP(baseFolder);
                        this.wasNewConnection = true;
                    }
                    else if(type == "PuTTY")
                    {
                        this.connection = new PuTTY(this.baseFolder);
                        this.wasNewConnection = true;
                    }
                    else if(type == "SSHTunnel")
                    {
                        this.connection = new SSHTunnel(this.baseFolder);
                        this.wasNewConnection = true;
                    }
                    else
                    {
                        this.DialogResult = DialogResult.Cancel;
                        return;
                    }
                }
            }

            this.textBoxName.Text = this.connection.Name;
            if (this.connection is RDP)
            {
                var rdp = new EditRDP(this.connection as RDP);
                rdp.Dock = DockStyle.Fill;
                this.panelEditor.Controls.Add(rdp);
                this.editor = rdp;
            }
            else if(this.connection is WinSCP)
            {
                var winSCP = new EditWinSCP(this.connection as WinSCP);
                winSCP.Dock = DockStyle.Fill;
                this.panelEditor.Controls.Add(winSCP);
                this.editor = winSCP;
            }
            else if(this.connection is PuTTY)
            {
                var putty = new EditPuTTY(this.connection as PuTTY);
                putty.Dock = DockStyle.Fill;
                this.panelEditor.Controls.Add(putty);
                this.editor = putty;
            }
            else if(this.connection is SSHTunnel)
            {
                var tunnel = new EditSSHTunnel(this.connection as SSHTunnel);
                tunnel.Dock = DockStyle.Fill;
                this.panelEditor.Controls.Add(tunnel);
                this.editor = tunnel;
            }
        }