Esempio n. 1
0
        private void tvConnections_NodeMouseSingleClick(object sender, CellClickEventArgs e)
        {
            try
            {
                if (e.ClickCount > 1)
                {
                    return;
                }
                var clickedNode = e.Model as ConnectionInfo;

                if (clickedNode == null)
                {
                    return;
                }
                if (clickedNode.GetTreeNodeType() != TreeNodeType.Connection && clickedNode.GetTreeNodeType() != TreeNodeType.PuttySession)
                {
                    return;
                }
                if (Settings.Default.SingleClickOnConnectionOpensIt)
                {
                    ConnectionInitiator.OpenConnection(SelectedNode);
                }

                if (Settings.Default.SingleClickSwitchesToOpenConnection)
                {
                    ConnectionInitiator.SwitchToOpenConnection(SelectedNode);
                }
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddExceptionStackTrace("tvConnections_NodeMouseClick (UI.Window.ConnectionTreeWindow) failed", ex);
            }
        }
Esempio n. 2
0
        private void mMenReconnectAll_Click(object sender, EventArgs e)
        {
            if (Runtime.WindowList == null || Runtime.WindowList.Count == 0)
            {
                return;
            }
            foreach (BaseWindow window in Runtime.WindowList)
            {
                var connectionWindow = window as ConnectionWindow;
                if (connectionWindow == null)
                {
                    return;
                }

                var ICList = new List <InterfaceControl>();
                foreach (Crownwood.Magic.Controls.TabPage tab in connectionWindow.TabController.TabPages)
                {
                    var tag = tab.Tag as InterfaceControl;
                    if (tag != null)
                    {
                        ICList.Add(tag);
                    }
                }

                foreach (var i in ICList)
                {
                    i.Protocol.Close();
                    ConnectionInitiator.OpenConnection(i.Info, ConnectionInfo.Force.DoNotJump);
                }

                // throw it on the garbage collector
                // ReSharper disable once RedundantAssignment
                ICList = null;
            }
        }
Esempio n. 3
0
        private CRAErrorCode ConnectSharded(
            string fromVertexName,
            List <int> fromVertexShards,
            string fromEndpoint,
            string toVertexName,
            List <int> toVertexShards,
            string toEndpoint,
            ConnectionInitiator direction)
        {
            var fromVertexNames = fromVertexShards
                                  .Select(e => fromVertexName + "$" + e)
                                  .ToArray();

            var toVertexNames = toVertexShards
                                .Select(e => toVertexName + "$" + e)
                                .ToArray();

            var fromEndpoints = toVertexShards
                                .Select(e => fromEndpoint + "$" + e)
                                .ToArray();

            var toEndpoints = fromVertexShards
                              .Select(e => toEndpoint + "$" + e)
                              .ToArray();

            return(ConnectShardedVerticesWithFullMesh(
                       fromVertexNames,
                       fromEndpoints,
                       toVertexNames,
                       toEndpoints,
                       direction));
        }
Esempio n. 4
0
        /// <summary>
        /// Connect a set of vertices in one sharded CRA vertex to another with a full mesh toplogy, via pre-defined endpoints. We contact the "from" vertex
        /// to initiate the creation of the link.
        /// </summary>
        /// <param name="fromVerticesNames"></param>
        /// <param name="fromEndpoints"></param>
        /// <param name="toVerticesNames"></param>
        /// <param name="toEndpoints"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        public CRAErrorCode ConnectShardedVerticesWithFullMesh(
            string[] fromVerticesNames,
            string[] fromEndpoints,
            string[] toVerticesNames,
            string[] toEndpoints,
            ConnectionInitiator direction)
        {
            // Check if the number of output endpoints in any fromVertex is equal to
            // the number of toVertices
            if (fromEndpoints.Length != toVerticesNames.Length)
            {
                return(CRAErrorCode.VerticesEndpointsNotMatched);
            }

            // Check if the number of input endpoints in any toVertex is equal to
            // the number of fromVertices
            if (toEndpoints.Length != fromVerticesNames.Length)
            {
                return(CRAErrorCode.VerticesEndpointsNotMatched);
            }

            //Connect the sharded vertices in parallel
            List <Task <CRAErrorCode> > tasks = new List <Task <CRAErrorCode> >();

            for (int i = 0; i < fromEndpoints.Length; i++)
            {
                for (int j = 0; j < fromVerticesNames.Length; j++)
                {
                    int fromEndpointIndex = i;
                    int fromVertexIndex   = j;
                    tasks.Add(ConnectAsync(fromVerticesNames[fromVertexIndex], fromEndpoints[fromEndpointIndex],
                                           toVerticesNames[fromEndpointIndex], toEndpoints[fromVertexIndex], direction));
                }
            }
            CRAErrorCode[] results = Task.WhenAll(tasks.ToArray()).Result;

            //Check for the status of connected vertices
            CRAErrorCode result = CRAErrorCode.VertexEndpointNotFound;

            for (int i = 0; i < results.Length; i++)
            {
                if (results[i] != CRAErrorCode.Success)
                {
                    Console.WriteLine("We received an error code " + results[i] + " while vertexing the connection pair with number (" + i + ")");
                    result = results[i];
                }
                else
                {
                    result = CRAErrorCode.Success;
                }
            }

            if (result != CRAErrorCode.Success)
            {
                Console.WriteLine("All CRA instances appear to be down. Restart them and connect these two sharded vertices again!");
            }

            return(result);
        }
Esempio n. 5
0
 private static void ConnectionsMenuItem_MouseUp(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         var tag = ((ToolStripMenuItem)sender).Tag as ConnectionInfo;
         if (tag != null)
         {
             ConnectionInitiator.OpenConnection(tag);
         }
     }
 }
Esempio n. 6
0
 private void StartIntegrated()
 {
     try
     {
         ConnectionInfo newConnectionInfo = BuildConnectionInfoForIntegratedApp();
         ConnectionInitiator.OpenConnection(newConnectionInfo);
     }
     catch (Exception ex)
     {
         Runtime.MessageCollector.AddExceptionMessage(message: "ExternalApp.StartIntegrated() failed.", ex: ex, logOnly: true);
     }
 }
Esempio n. 7
0
        private static void GoToUrl(string url)
        {
            var connectionInfo = new ConnectionInfo();

            connectionInfo.CopyFrom(DefaultConnectionInfo.Instance);

            connectionInfo.Name     = "";
            connectionInfo.Hostname = url;
            connectionInfo.Protocol = url.StartsWith("https:") ? ProtocolType.HTTPS : ProtocolType.HTTP;
            connectionInfo.SetDefaultPort();
            connectionInfo.IsQuickConnect = true;
            ConnectionInitiator.OpenConnection(connectionInfo, ConnectionInfo.Force.DoNotJump);
        }
Esempio n. 8
0
        private void tvConnections_NodeMouseDoubleClick(object sender, CellClickEventArgs e)
        {
            if (e.ClickCount < 2)
            {
                return;
            }
            var clickedNode = e.Model as ConnectionInfo;

            if (clickedNode?.GetTreeNodeType() == TreeNodeType.Connection |
                clickedNode?.GetTreeNodeType() == TreeNodeType.PuttySession)
            {
                ConnectionInitiator.OpenConnection(SelectedNode);
            }
        }
Esempio n. 9
0
 private void ConMenItem_MouseUp(Object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         if (((Control)sender).Tag is ConnectionInfo)
         {
             if (frmMain.Default.Visible == false)
             {
                 ShowForm();
             }
             ConnectionInitiator.OpenConnection((ConnectionInfo)((Control)sender).Tag);
         }
     }
 }
Esempio n. 10
0
        public void OpenConnectionsFromLastSession()
        {
            if (!Settings.Default.OpenConsFromLastSession || Settings.Default.NoReconnect)
            {
                return;
            }
            var connectionInfoList          = GetRootConnectionNode().GetRecursiveChildList().Where(node => !(node is ContainerInfo));
            var previouslyOpenedConnections = connectionInfoList.Where(item => item.PleaseConnect);

            foreach (var connectionInfo in previouslyOpenedConnections)
            {
                ConnectionInitiator.OpenConnection(connectionInfo);
            }
        }
Esempio n. 11
0
 private void Reconnect()
 {
     try
     {
         var interfaceControl = TabController.SelectedTab?.Tag as InterfaceControl;
         if (interfaceControl == null)
         {
             return;
         }
         interfaceControl.Protocol.Close();
         ConnectionInitiator.OpenConnection(interfaceControl.Info, ConnectionInfo.Force.DoNotJump);
     }
     catch (Exception ex)
     {
         Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, "Reconnect (UI.Window.ConnectionWindow) failed" + Environment.NewLine + ex.Message, true);
     }
 }
Esempio n. 12
0
 private void DuplicateTab()
 {
     try
     {
         var interfaceControl = TabController.SelectedTab?.Tag as InterfaceControl;
         if (interfaceControl == null)
         {
             return;
         }
         ConnectionInitiator.OpenConnection(interfaceControl.Info, ConnectionInfo.Force.DoNotJump);
         _ignoreChangeSelectedTabClick = false;
     }
     catch (Exception ex)
     {
         Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, "DuplicateTab (UI.Window.ConnectionWindow) failed" + Environment.NewLine + ex.Message, true);
     }
 }
Esempio n. 13
0
 private void btnQuickConnect_ButtonClick(object sender, EventArgs e)
 {
     try
     {
         var connectionInfo = Runtime.CreateQuickConnect(cmbQuickConnect.Text.Trim(), Converter.StringToProtocol(Settings.Default.QuickConnectProtocol));
         if (connectionInfo == null)
         {
             cmbQuickConnect.Focus();
             return;
         }
         cmbQuickConnect.Add(connectionInfo);
         ConnectionInitiator.OpenConnection(connectionInfo, ConnectionInfo.Force.DoNotJump);
     }
     catch (Exception ex)
     {
         Runtime.MessageCollector.AddExceptionMessage("btnQuickConnect_ButtonClick() failed.", ex, MessageClass.ErrorMsg, true);
     }
 }
Esempio n. 14
0
 private void tvConnections_KeyDown(object sender, KeyEventArgs e)
 {
     try
     {
         if (e.KeyCode == Keys.Enter)
         {
             e.Handled = true;
             ConnectionInitiator.OpenConnection(SelectedNode);
         }
         else if (e.Control && e.KeyCode == Keys.F)
         {
             txtSearch.Focus();
             txtSearch.SelectAll();
             e.Handled = true;
         }
     }
     catch (Exception ex)
     {
         Runtime.MessageCollector.AddExceptionStackTrace("tvConnections_KeyDown (UI.Window.ConnectionTreeWindow) failed", ex);
     }
 }
Esempio n. 15
0
        private void TabController_DragDrop(object sender, DragEventArgs e)
        {
            var dropDataAsOlvDataObject = e.Data as OLVDataObject;

            if (dropDataAsOlvDataObject == null)
            {
                return;
            }
            var modelObjects = dropDataAsOlvDataObject.ModelObjects;

            foreach (var model in modelObjects)
            {
                var modelAsContainer  = model as ContainerInfo;
                var modelAsConnection = model as ConnectionInfo;
                if (modelAsContainer != null)
                {
                    ConnectionInitiator.OpenConnection(modelAsContainer);
                }
                else if (modelAsConnection != null)
                {
                    ConnectionInitiator.OpenConnection(modelAsConnection);
                }
            }
        }
Esempio n. 16
0
 private void SetContextMenuEventHandlers()
 {
     _contextMenu.Opening        += (sender, args) => _contextMenu.ShowHideTreeContextMenuItems(SelectedNode);
     _contextMenu.ConnectClicked += (sender, args) =>
     {
         var selectedNodeAsContainer = SelectedNode as ContainerInfo;
         if (selectedNodeAsContainer != null)
         {
             ConnectionInitiator.OpenConnection(selectedNodeAsContainer, ConnectionInfo.Force.DoNotJump);
         }
         else
         {
             ConnectionInitiator.OpenConnection(SelectedNode, ConnectionInfo.Force.DoNotJump);
         }
     };
     _contextMenu.ConnectToConsoleSessionClicked += (sender, args) =>
     {
         var selectedNodeAsContainer = SelectedNode as ContainerInfo;
         if (selectedNodeAsContainer != null)
         {
             ConnectionInitiator.OpenConnection(selectedNodeAsContainer, ConnectionInfo.Force.UseConsoleSession | ConnectionInfo.Force.DoNotJump);
         }
         else
         {
             ConnectionInitiator.OpenConnection(SelectedNode, ConnectionInfo.Force.UseConsoleSession | ConnectionInfo.Force.DoNotJump);
         }
     };
     _contextMenu.DontConnectToConsoleSessionClicked += (sender, args) =>
     {
         var selectedNodeAsContainer = SelectedNode as ContainerInfo;
         if (selectedNodeAsContainer != null)
         {
             ConnectionInitiator.OpenConnection(selectedNodeAsContainer, ConnectionInfo.Force.DontUseConsoleSession | ConnectionInfo.Force.DoNotJump);
         }
         else
         {
             ConnectionInitiator.OpenConnection(SelectedNode, ConnectionInfo.Force.DontUseConsoleSession | ConnectionInfo.Force.DoNotJump);
         }
     };
     _contextMenu.ConnectInFullscreenClicked += (sender, args) =>
     {
         var selectedNodeAsContainer = SelectedNode as ContainerInfo;
         if (selectedNodeAsContainer != null)
         {
             ConnectionInitiator.OpenConnection(selectedNodeAsContainer, ConnectionInfo.Force.Fullscreen | ConnectionInfo.Force.DoNotJump);
         }
         else
         {
             ConnectionInitiator.OpenConnection(SelectedNode, ConnectionInfo.Force.Fullscreen | ConnectionInfo.Force.DoNotJump);
         }
     };
     _contextMenu.ConnectWithNoCredentialsClick += (sender, args) =>
     {
         var selectedNodeAsContainer = SelectedNode as ContainerInfo;
         if (selectedNodeAsContainer != null)
         {
             ConnectionInitiator.OpenConnection(selectedNodeAsContainer, ConnectionInfo.Force.NoCredentials);
         }
         else
         {
             ConnectionInitiator.OpenConnection(SelectedNode, ConnectionInfo.Force.NoCredentials);
         }
     };
     _contextMenu.ChoosePanelBeforeConnectingClicked += (sender, args) =>
     {
         var selectedNodeAsContainer = SelectedNode as ContainerInfo;
         if (selectedNodeAsContainer != null)
         {
             ConnectionInitiator.OpenConnection(selectedNodeAsContainer, ConnectionInfo.Force.OverridePanel | ConnectionInfo.Force.DoNotJump);
         }
         else
         {
             ConnectionInitiator.OpenConnection(SelectedNode, ConnectionInfo.Force.OverridePanel | ConnectionInfo.Force.DoNotJump);
         }
     };
     _contextMenu.DisconnectClicked   += (sender, args) => DisconnectConnection(SelectedNode);
     _contextMenu.TransferFileClicked += (sender, args) => SshTransferFile();
     _contextMenu.DuplicateClicked    += (sender, args) => DuplicateSelectedNode();
     _contextMenu.RenameClicked       += (sender, args) => RenameSelectedNode();
     _contextMenu.DeleteClicked       += (sender, args) => DeleteSelectedNode();
     _contextMenu.ImportFileClicked   += (sender, args) =>
     {
         var selectedNodeAsContainer = SelectedNode as ContainerInfo ?? SelectedNode.Parent;
         Import.ImportFromFile(selectedNodeAsContainer, true);
     };
     _contextMenu.ImportActiveDirectoryClicked += (sender, args) => Windows.Show(WindowType.ActiveDirectoryImport);
     _contextMenu.ImportPortScanClicked        += (sender, args) => Windows.Show(WindowType.PortScan);
     _contextMenu.ExportFileClicked            += (sender, args) => Export.ExportToFile(SelectedNode, Runtime.ConnectionTreeModel);
     _contextMenu.AddConnectionClicked         += cMenTreeAddConnection_Click;
     _contextMenu.AddFolderClicked             += cMenTreeAddFolder_Click;
     _contextMenu.SortAscendingClicked         += (sender, args) => SortNodesRecursive(SelectedNode, ListSortDirection.Ascending);
     _contextMenu.SortDescendingClicked        += (sender, args) => SortNodesRecursive(SelectedNode, ListSortDirection.Descending);
     _contextMenu.MoveUpClicked       += cMenTreeMoveUp_Click;
     _contextMenu.MoveDownClicked     += cMenTreeMoveDown_Click;
     _contextMenu.ExternalToolClicked += (sender, args) => StartExternalApp((ExternalTool)((ToolStripMenuItem)sender).Tag);
 }
Esempio n. 17
0
 internal Task <CRAErrorCode> ConnectAsync(string fromVertexName, string fromEndpoint, string toVertexName, string toEndpoint, ConnectionInitiator direction)
 {
     return(Task.Factory.StartNew(
                () => { return Connect(fromVertexName, fromEndpoint, toVertexName, toEndpoint, direction); }));
 }
Esempio n. 18
0
        /// <summary>
        /// Connect one CRA vertex to another, via pre-defined endpoints. We contact the "from" vertex
        /// to initiate the creation of the link.
        /// </summary>
        /// <param name="fromVertexName">Name of the vertex from which connection is being made</param>
        /// <param name="fromEndpoint">Name of the endpoint on the fromVertex, from which connection is being made</param>
        /// <param name="toVertexName">Name of the vertex to which connection is being made</param>
        /// <param name="toEndpoint">Name of the endpoint on the toVertex, to which connection is being made</param>
        /// <param name="direction">Which vertex initiates the connection</param>
        /// <returns>Status of the Connect operation</returns>
        public CRAErrorCode Connect(string fromVertexName, string fromEndpoint, string toVertexName, string toEndpoint, ConnectionInitiator direction)
        {
            // Tell from vertex to establish connection
            // Send request to CRA instance

            // Check that vertex and endpoints are valid and existing
            if (!_vertexTableManager.ExistsVertex(fromVertexName) || !_vertexTableManager.ExistsVertex(toVertexName))
            {
                // Check for sharded vertices
                List <int> fromVertexShards, toVertexShards;

                if (!_vertexTableManager.ExistsShardedVertex(fromVertexName, out fromVertexShards))
                {
                    return(CRAErrorCode.VertexNotFound);
                }

                if (!_vertexTableManager.ExistsShardedVertex(toVertexName, out toVertexShards))
                {
                    return(CRAErrorCode.VertexNotFound);
                }

                return(ConnectSharded(fromVertexName, fromVertexShards, fromEndpoint, toVertexName, toVertexShards, toEndpoint, direction));
            }

            // Make the connection information stable
            _connectionTableManager.AddConnection(fromVertexName, fromEndpoint, toVertexName, toEndpoint);

            // We now try best-effort to tell the CRA instance of this connection
            CRAErrorCode result = CRAErrorCode.Success;

            VertexTable _row;

            try
            {
                // Get instance for source vertex
                _row = direction == ConnectionInitiator.FromSide ?
                       VertexTable.GetRowForVertex(_vertexTable, fromVertexName) :
                       VertexTable.GetRowForVertex(_vertexTable, toVertexName);
            }
            catch
            {
                Console.WriteLine("Unable to find active instance with vertex. On vertex activation, the connection should be completed automatically.");
                return(result);
            }

            try
            {
                if (_localWorker != null)
                {
                    if (_localWorker.InstanceName == _row.InstanceName)
                    {
                        return(_localWorker.Connect_InitiatorSide(fromVertexName, fromEndpoint,
                                                                  toVertexName, toEndpoint, direction == ConnectionInitiator.ToSide));
                    }
                }


                // Send request to CRA instance
                TcpClient client = null;
                // Get address and port for instance, using row with vertex = ""
                var row = VertexTable.GetRowForInstance(_vertexTable, _row.InstanceName);

                // Get a stream connection from the pool if available
                Stream stream;
                if (!TryGetSenderStreamFromPool(row.Address, row.Port.ToString(), out stream))
                {
                    client         = new TcpClient(row.Address, row.Port);
                    client.NoDelay = true;

                    stream = client.GetStream();

                    if (SecureStreamConnectionDescriptor != null)
                    {
                        stream = SecureStreamConnectionDescriptor.CreateSecureClient(stream, _row.InstanceName);
                    }
                }

                if (direction == ConnectionInitiator.FromSide)
                {
                    stream.WriteInt32((int)CRATaskMessageType.CONNECT_VERTEX_INITIATOR);
                }
                else
                {
                    stream.WriteInt32((int)CRATaskMessageType.CONNECT_VERTEX_INITIATOR_REVERSE);
                }

                stream.WriteByteArray(Encoding.UTF8.GetBytes(fromVertexName));
                stream.WriteByteArray(Encoding.UTF8.GetBytes(fromEndpoint));
                stream.WriteByteArray(Encoding.UTF8.GetBytes(toVertexName));
                stream.WriteByteArray(Encoding.UTF8.GetBytes(toEndpoint));

                result = (CRAErrorCode)stream.ReadInt32();
                if (result != 0)
                {
                    Console.WriteLine("Connection was logically established. However, the client received an error code from the connection-initiating CRA instance: " + result);
                }
                else
                {
                    // Add/Return a stream connection to the pool
                    TryAddSenderStreamToPool(row.Address, row.Port.ToString(), stream);
                }
            }
            catch
            {
                Console.WriteLine("The connection-initiating CRA instance appears to be down or could not be found. Restart it and this connection will be completed automatically");
            }
            return(result);
        }