Exemplo n.º 1
0
        private void OpenConnection(ConnectionInfo connectionInfo, ConnectionInfo.Force force, Form conForm)
        {
            try
            {
                if (connectionInfo.Hostname == "" && connectionInfo.Protocol != ProtocolType.IntApp)
                {
                    Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg,
                                                        Language.strConnectionOpenFailedNoHostname);
                    return;
                }

                StartPreConnectionExternalApp(connectionInfo);

                if (!force.HasFlag(ConnectionInfo.Force.DoNotJump))
                {
                    if (SwitchToOpenConnection(connectionInfo))
                    {
                        return;
                    }
                }

                var protocolFactory = new ProtocolFactory();
                var newProtocol     = protocolFactory.CreateProtocol(connectionInfo);

                var connectionPanel = SetConnectionPanel(connectionInfo, force);
                if (string.IsNullOrEmpty(connectionPanel))
                {
                    return;
                }
                var connectionForm      = SetConnectionForm(conForm, connectionPanel);
                var 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);
                _activeConnections.Add(connectionInfo.ConstantID);
                FrmMain.Default.SelectedConnection = connectionInfo;
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddExceptionStackTrace(Language.strConnectionOpenFailed, ex);
            }
        }
        private void _server_DataReceived(object sender, Message e)
        {
            Console.WriteLine("Packet Weight : " + e.Data.Count() + " bytes");
            Thread thread = new Thread(delegate()
            {
                var tmp    = SimpleTcpAdapter.Convert(e.TcpClient);
                var packet = new BasicPacket();
                if (!packet.Parse(e.Data))
                {
                    var packets = SplitPacket(e.Data);
                    foreach (var pk in packets)
                    {
                        Thread.Sleep(500);
                        Thread t = new Thread(delegate()
                        {
                            var pack = new BasicPacket();
                            if (!pack.Parse(pk))
                            {
                                return;
                            }
                            var ptc = ProtocolFactory.CreateProtocol(pack.Opcode);
                            if (!ptc.Parse(Encoding.Unicode.GetString(pack.Data)))
                            {
                                return;
                            }
                            var handling  = HandleFactory.CreateHandle(pack.Opcode);
                            string toview = handling.Handling(ptc, tmp);
                            if (OnNewMessage != null)
                            {
                                OnNewMessage.Invoke(tmp, toview);
                            }
                        });
                        t.Start();
                    }

                    return;
                }
                var protocol = ProtocolFactory.CreateProtocol(packet.Opcode);
                if (!protocol.Parse(Encoding.Unicode.GetString(packet.Data)))
                {
                    return;
                }
                var handle    = HandleFactory.CreateHandle(packet.Opcode);
                string toView = handle.Handling(protocol, tmp);
                if (OnNewMessage != null)
                {
                    OnNewMessage.Invoke(tmp, toView);
                }
            });

            thread.Priority = ThreadPriority.Highest;
            thread.Start();
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        public static void OpenConnection(ConnectionInfo connectionInfo, ConnectionInfo.Force force, Form conForm)
        {
            try
            {
                if (connectionInfo.Hostname == "" && connectionInfo.Protocol != ProtocolType.IntApp)
                {
                    Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, Language.strConnectionOpenFailedNoHostname);
                    return;
                }

                StartPreConnectionExternalApp(connectionInfo);

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

                var protocolFactory = new ProtocolFactory();
                var newProtocol     = protocolFactory.CreateProtocol(connectionInfo);

                var connectionPanel     = SetConnectionPanel(connectionInfo, force);
                var connectionForm      = SetConnectionForm(conForm, connectionPanel);
                var 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);
                frmMain.Default.SelectedConnection = connectionInfo;
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.strConnectionOpenFailed + Environment.NewLine + ex.Message);
            }
        }
        private void Receive(byte[] data)
        {
            StreamPacket packet = new StreamPacket();

            if (!packet.Parse(data))
            {
                return;
            }
            var protocol = ProtocolFactory.CreateProtocol(packet.Opcode);

            if (!protocol.Parse(packet.Data))
            {
                return;
            }
            if (NewDataReceive != null)
            {
                NewDataReceive.Invoke(protocol, packet.Opcode);
            }
        }
Exemplo n.º 6
0
        private void _client_DataReceived(object sender, Message e)
        {
            var packet = new BasicPacket();

            if (!packet.Parse(e.Data))
            {
                return;
            }
            var protocol = ProtocolFactory.CreateProtocol(packet.Opcode);

            if (!protocol.Parse(Encoding.Unicode.GetString(packet.Data)))
            {
                return;
            }

            if (OnNewRecieve != null)
            {
                OnNewRecieve.Invoke(packet.Opcode, protocol);
            }
        }
Exemplo n.º 7
0
        public void NewRecieve(byte[] data, EndPoint endpoint)
        {
            StreamPacket packet = new StreamPacket();

            if (!packet.Parse(data))
            {
                return;
            }
            var protocol = ProtocolFactory.CreateProtocol(packet.Opcode);

            if (!protocol.Parse(packet.Data))
            {
                return;
            }
            var handle = HandleFactory.CreateHandle(packet.Opcode);
            var toview = handle.Handling(protocol, endpoint, UDPSocketAdapter.Convert(_socket));

            if (OnReceive != null)
            {
                OnReceive.Invoke(toview);
            }
        }