public static IConnection CreateConnection(FavoriteConfigurationElement Favorite, TerminalTabControlItem TerminalTabPage, MainForm parentForm)
 {
     IConnection conn = null; ;
     switch (Favorite.Protocol) {
         case "VNC":
             conn = new VNCConnection();
             break;
         case "VMRC":
             conn = new VMRCConnection();
             break;
         case "RAS":
             conn = new RASConnection();
             break;
         case "Telnet":
             conn = new TerminalConnection();
             break;
         case "ICA Citrix":
             conn = new ICAConnection();
             break;
         case "HTTP":
             conn = new HTTPConnection();
             break;
         case "HTTPS":
             conn = new HTTPConnection();
             break;
         default:
             conn = new RDPConnection();
             break;
     }
     conn.Favorite = Favorite;
     TerminalTabPage.Connection = conn;
     conn.TerminalTabPage = TerminalTabPage;
     conn.ParentForm = parentForm;
     return conn;
 }
Beispiel #2
0
 private void CreateTerminalTab(IFavorite origin, IFavorite configured)
 {
     ExternalLinks.CallExecuteBeforeConnected(this.settings);
     ExternalLinks.CallExecuteBeforeConnected(configured.ExecuteBeforeConnect);
     TerminalTabControlItem terminalTabPage = CreateTerminalTabPageByFavoriteName(configured);
     this.TryConnectTabPage(origin, configured, terminalTabPage);
 }
        public static void PerformScreenCapture(TabControl.TabControl tab)
        {
            if (Kohl.Framework.Info.MachineInfo.IsUnixOrMac)
            {
                Log.Fatal("Screen caputure is only supported on Windows at the moment.");
                return;
            }

            TerminalTabControlItem activeTab = tab.SelectedItem as TerminalTabControlItem;
            string name = "";

            if (activeTab != null && activeTab.Favorite != null && !string.IsNullOrEmpty(activeTab.Favorite.Name))
            {
                name = activeTab.Favorite.Name + "-";
            }
            string filename = DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss");

            string rootPath = Settings.CaptureRoot.NormalizePath();

            string        tempFile = Path.Combine(rootPath, string.Format("{0}{1}.png", name, filename));
            ScreenCapture sc       = new ScreenCapture();
            Bitmap        bmp      = sc.CaptureControl(tab, tempFile, ImageFormatTypes.imgPNG);

            if (Settings.EnableCaptureToClipboard)
            {
                Clipboard.SetImage(bmp);
            }
        }
        internal void CreateTerminalTab(IFavorite favorite)
        {
            ExternalLinks.CallExecuteBeforeConnected(this.settings);
            ExternalLinks.CallExecuteBeforeConnected(favorite.ExecuteBeforeConnect);
            TerminalTabControlItem terminalTabPage = CreateTerminalTabPageByFavoriteName(favorite);

            this.TryConnectTabPage(favorite, terminalTabPage);
        }
 private void AssignControls(Connection conn, TerminalTabControlItem terminalTabPage, MainForm parentForm)
 {
     terminalTabPage.Connection = conn;
     conn.Parent            = terminalTabPage;
     conn.ParentForm        = parentForm;
     conn.CredentialFactory = this.guardedCredentialFactory;
     conn.OnDisconnected   += parentForm.OnDisconnected;
 }
 private void ConfigureTabPage(TerminalTabControlItem terminalTabPage, string captureTitle,
                               bool allowDrop = false)
 {
     terminalTabPage.AllowDrop   = allowDrop;
     terminalTabPage.ToolTipText = captureTitle;
     this.mainForm.AssingDoubleClickEventHandler(terminalTabPage);
     this.terminalsControler.AddAndSelect(terminalTabPage);
     this.mainForm.UpdateControls();
 }
        public static PopupTerminal CreateConnectionInPopup(IHostingForm parentForm, FavoriteConfigurationElement favorite)
        {
            TerminalTabControlItem item = CreateTerminalTabPageByFavoriteName(favorite);

            CreateConnection(favorite, parentForm, false, item);
            PopupTerminal popup = new PopupTerminal();

            popup.AddTerminal(item);
            return(popup);
        }
Beispiel #8
0
        public void AddTerminal(TerminalTabControlItem tabControlItem)
        {
            if (tabControlItem == null)
                return;

            while (tabControlItem.Connection == null)
                Application.DoEvents();

            this.tabControl1.AddTab(tabControlItem);
            this.Text = tabControlItem.Connection.Favorite.Name;
        }
Beispiel #9
0
 private void ConfigureTabPage<TControl>(string title, string controlName,
     Action<TControl> executeExtra, TerminalTabControlItem terminalTabPage)
     where TControl : UserControl
 {
     this.ConfigureTabPage(terminalTabPage, title);
     var control = Activator.CreateInstance<TControl>();
     control.Name = controlName;
     control.Dock = DockStyle.Fill;
     control.Parent = terminalTabPage;
     executeExtra(control);
     this.BringToFrontOnMainForm(control);
 }
Beispiel #10
0
        private Connection CreateConnection(IFavorite origin, IFavorite configured, TerminalTabControlItem terminalTabPage)
        {
            Connection conn = this.connectionManager.CreateConnection(configured);
            conn.Favorite = configured;
            conn.OriginFavorite = origin;

            var consumer = conn as ISettingsConsumer;
            if (consumer != null)
                consumer.Settings = this.settings;

            AssignControls(conn, terminalTabPage, this.mainForm);
            return conn;
        }
Beispiel #11
0
        public void AddTerminal(TerminalTabControlItem tabControlItem)
        {
            if (tabControlItem == null)
            {
                return;
            }

            while (tabControlItem.Connection == null)
            {
                Application.DoEvents();
            }

            this.tabControl1.AddTab(tabControlItem);
            this.Text = tabControlItem.Connection.Favorite.Name;
        }
Beispiel #12
0
        private void attachToTerminalsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (mainTabsControler == null)
            {
                return;
            }

            TerminalTabControlItem activeTab = this.tabControl1.SelectedItem as TerminalTabControlItem;

            if (activeTab != null)
            {
                this.mainTabsControler.AttachTabFromWindow(activeTab);
                this.tabControl1.CloseTab(activeTab);
            }
        }
Beispiel #13
0
        private Connection CreateConnection(IFavorite favorite, TerminalTabControlItem terminalTabPage, MainForm parentForm)
        {
            Connection conn = this.connectionManager.CreateConnection(favorite);

            conn.Favorite = favorite;

            var consumer = conn as ISettingsConsumer;

            if (consumer != null)
            {
                consumer.Settings = this.settings;
            }

            AssignControls(conn, terminalTabPage, parentForm);
            return(conn);
        }
Beispiel #14
0
 private void OpenTabControl<TControl>(string titleResourceKey,  string controlName,
     string openErrorMessage, Action<TControl> executeExtra)
     where TControl : UserControl
 {
     string title = Program.Resources.GetString(titleResourceKey);
     var terminalTabPage = new TerminalTabControlItem(title);
     try
     {
         this.ConfigureTabPage(title, controlName, executeExtra, terminalTabPage);
     }
     catch (Exception exc)
     {
         Logging.Error(openErrorMessage, exc);
         this.terminalsControler.RemoveAndUnSelect(terminalTabPage);
         terminalTabPage.Dispose();
     }
 }
Beispiel #15
0
 private void UpdateConnectionTabPageByConnectionState(IFavorite favorite, TerminalTabControlItem terminalTabPage, Connection conn)
 {
     if (conn.Connect())
     {
         this.BringToFrontOnMainForm(conn);
         if (favorite.Display.DesktopSize == DesktopSize.FullScreen)
             this.mainForm.FullScreen = true;
     }
     else
     {
         String msg = Program.Resources.GetString("SorryTerminalswasunabletoconnecttotheremotemachineTryagainorcheckthelogformoreinformation");
         if (!string.IsNullOrEmpty(conn.LastError))
             msg = msg + "\r\n\r\nDetails:\r\n" + conn.LastError;
         MessageBox.Show(msg);
         this.terminalsControler.RemoveAndUnSelect(terminalTabPage);
     }
 }
Beispiel #16
0
        public static void PerformScreenCapture(TabControl.TabControl tab)
        {
            TerminalTabControlItem activeTab = tab.SelectedItem as TerminalTabControlItem;
            string name = "";

            if (activeTab != null && activeTab.Favorite != null && !string.IsNullOrEmpty(activeTab.Favorite.Name))
            {
                name = activeTab.Favorite.Name + "-";
            }
            string filename = DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss");

            string rootPath = Settings.CaptureRoot.NormalizePath();

            string        tempFile = Path.Combine(rootPath, string.Format("{0}{1}.png", name, filename));
            ScreenCapture sc       = new ScreenCapture();
            Bitmap        bmp      = sc.CaptureControl(tab, tempFile, ImageFormatTypes.imgPNG);

            if (Settings.EnableCaptureToClipboard)
            {
                Clipboard.SetImage(bmp);
            }
        }
        private void TryConnectTabPage(IFavorite origin, IFavorite configured, TerminalTabControlItem terminalTabPage)
        {
            try
            {
                this.mainForm.AssignEventsToConnectionTab(terminalTabPage);
                var toolTipBuilder = new ToolTipBuilder(this.persistence.Security);
                var toolTipText    = toolTipBuilder.BuildTooTip(configured);
                this.ConfigureTabPage(terminalTabPage, toolTipText, true);

                var conn = CreateConnection(origin, configured, terminalTabPage);
                this.UpdateConnectionTabPageByConnectionState(configured, terminalTabPage, conn);

                if (conn.Connected && configured.NewWindow)
                {
                    this.terminalsControler.DetachTabToNewWindow(terminalTabPage);
                }
            }
            catch (Exception exc)
            {
                Logging.Error("Error Creating A Terminal Tab", exc);
                this.terminalsControler.UnSelect();
            }
        }
        public static IConnection CreateConnection(FavoriteConfigurationElement Favorite, TerminalTabControlItem TerminalTabPage, MainForm parentForm)
        {
            IConnection conn = null;;

            switch (Favorite.Protocol)
            {
            case "VNC":
                conn = new VNCConnection();
                break;

            case "VMRC":
                conn = new VMRCConnection();
                break;

            case "RAS":
                conn = new RASConnection();
                break;

            case "Telnet":
                conn = new TerminalConnection();
                break;

            case "ICA Citrix":
                conn = new ICAConnection();
                break;

            case "HTTP":
                conn = new HTTPConnection();
                break;

            case "HTTPS":
                conn = new HTTPConnection();
                break;

            default:
                conn = new RDPConnection();
                break;
            }
            conn.Favorite = Favorite;
            TerminalTabPage.Connection = conn;
            conn.TerminalTabPage       = TerminalTabPage;
            conn.ParentForm            = parentForm;
            return(conn);
        }
        /// <summary>
        ///     Creates a new connection by spawning a new thread.
        /// </summary>
        /// <param name="favorite"> </param>
        /// <param name="TerminalTabPage"> </param>
        /// <param name="parentForm"> </param>
        /// <remarks>
        ///     This method calls the <see cref="ConnectionBase.Connect" /> method and requires it to be thread safe.
        /// </remarks>
        public static void CreateConnection(FavoriteConfigurationElement favorite, IHostingForm parentForm, bool waitforEnd, TerminalTabControlItem terminalTabPage, ConnectionBase conn = null)
        {
            // This might happen if the user is not allowed to
            // use all available connections e.g.
            // if the user has a freeware version.
            if (Limit.Contains(favorite.Protocol.ToUpper()) || terminalTabPage == null)
            {
                MessageBox.Show("You are not allowed to use that kind of connection!", AssemblyInfo.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (!waitforEnd)
            {
                Thread t = new Thread((ThreadStart) delegate
                {
                    Code(terminalTabPage, parentForm, favorite, conn);
                });

                t.SetApartmentState(ApartmentState.STA);
                t.Start();
            }
            else
            {
                Code(terminalTabPage, parentForm, favorite, conn);
            }
        }
        private static void Code(TerminalTabControlItem terminalTabPage, IHostingForm parentForm, FavoriteConfigurationElement favorite, ConnectionBase conn = null)
        {
            if (conn == null)
            {
                conn = CreateConnection(favorite);
                conn.TerminalTabPage       = terminalTabPage;
                terminalTabPage.TabColor   = FavoriteConfigurationElement.TranslateColor(favorite.TabColor);
                terminalTabPage.Connection = conn;
            }

            conn.Favorite   = favorite;
            conn.ParentForm = parentForm;

            if (conn.Connect())
            {
                if (conn.InvokeRequired)
                {
                    conn.Invoke(new MethodInvoker(delegate
                    {
                        conn.BringToFront();
                        conn.Update();
                    }));
                }
                else
                {
                    conn.BringToFront();
                    conn.Update();
                }

                if (parentForm.InvokeRequired)
                {
                    parentForm.Invoke(new MethodInvoker(delegate
                    {
                        parentForm.UpdateControls();

                        if (favorite.DesktopSize == DesktopSize.FullScreen)
                        {
                            parentForm.FullScreen = true;
                        }
                    }));
                }
                else
                {
                    parentForm.UpdateControls();

                    if (favorite.DesktopSize == DesktopSize.FullScreen)
                    {
                        parentForm.FullScreen = true;
                    }
                }

                conn.AfterConnectPlugins();
            }
            else
            {
                string message = "Sorry, " + AssemblyInfo.Title + " was unable to create the connection. Try again or check the log for more information.";

                Log.Error(message);
                MessageBox.Show(message, AssemblyInfo.Title, MessageBoxButtons.OK, MessageBoxIcon.Error);

                if (parentForm.InvokeRequired)
                {
                    parentForm.Invoke(new MethodInvoker(delegate { parentForm.RemoveAndUnSelect(terminalTabPage); }));
                }
                else
                {
                    parentForm.RemoveAndUnSelect(terminalTabPage);
                }
            }

            if (conn.Connected && favorite.NewWindow)
            {
                if (parentForm.InvokeRequired)
                {
                    parentForm.Invoke(new MethodInvoker(delegate { parentForm.DetachTabToNewWindow(terminalTabPage); }));
                }
                else
                {
                    parentForm.DetachTabToNewWindow(terminalTabPage);
                }
            }
        }