Esempio n. 1
0
        private static void OpenConnectionFinal(ConnectionInfo ConnectionInfo, ConnectionInfo.Force Force, Form ConForm)
        {
            try
            {
                if (ConnectionInfo.Hostname == "" && ConnectionInfo.Protocol != ProtocolType.IntApp)
                {
                    MessageCollector.AddMessage(MessageClass.WarningMsg, Language.strConnectionOpenFailedNoHostname);
                    return;
                }

                StartPreConnectionExternalApp(ConnectionInfo);

                if ((Force & ConnectionInfo.Force.DoNotJump) != ConnectionInfo.Force.DoNotJump)
                {
                    if (SwitchToOpenConnection(ConnectionInfo))
                    {
                        return;
                    }
                }

                ProtocolFactory protocolFactory = new ProtocolFactory();
                ProtocolBase    newProtocol     = protocolFactory.CreateProtocol(ConnectionInfo);

                string  connectionPanel     = SetConnectionPanel(ConnectionInfo, Force);
                Form    connectionForm      = SetConnectionForm(ConForm, connectionPanel);
                Control connectionContainer = SetConnectionContainer(ConnectionInfo, connectionForm);
                SetConnectionFormEventHandlers(newProtocol, connectionForm);
                SetConnectionEventHandlers(newProtocol);
                BuildConnectionInterfaceController(ConnectionInfo, newProtocol, connectionContainer);

                newProtocol.Force = Force;

                if (newProtocol.Initialize() == false)
                {
                    newProtocol.Close();
                    return;
                }

                if (newProtocol.Connect() == false)
                {
                    newProtocol.Close();
                    return;
                }

                ConnectionInfo.OpenConnections.Add(newProtocol);
                SetTreeNodeImages(ConnectionInfo);
                frmMain.Default.SelectedConnection = ConnectionInfo;
            }
            catch (Exception ex)
            {
                MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.strConnectionOpenFailed + Environment.NewLine + ex.Message);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates then initializes the protocol.
        /// </summary>
        /// <param name="protocolId">A UInt16 that specifies the unique protocol
        /// identifier.</param>
        /// <param name="userData">An object that may be used client applications to pass
        /// objects or data to client side protocol implementations.</param>
        /// <returns>A ProtocolBase that implements the protocol layer.</returns>
        public ProtocolBase Initialize(ushort protocolId, object userData = null)
        {
            ProtocolBase p = null;

            lock (protocolImplementations)
            {
                if (!protocolImplementations.ContainsKey(protocolId))
                {
                    if (!protocolConfigurations.ContainsKey(protocolId))
                    {
                        throw new Exception(string.Format(ErrorTypes.INVALID_PROTOCOL, protocolId));
                    }

                    ProtocolConfiguration pc = protocolConfigurations[protocolId];
                    p = pc.CreateInstance();
                    if (p == null)
                    {
                        throw new Exception(string.Format(ErrorTypes.CLASS_NOT_FOUND, pc));
                    }

                    protocolImplementations.Add(protocolId, p);

                    Log(Level.Debug, string.Format("Initializing protocol {0}...", protocolId));
                    if (userData == null)
                    {
                        userData = this.userData;
                    }
                    p.Initialize(this, pc, userData);
                    LastActivityAt = DateTime.Now;
                }
                else
                {
                    p = protocolImplementations[protocolId];
                }
            }
            return(p);
        }