Пример #1
0
        // =================================================================
        //              UI Events
        // =================================================================

        private void ButtonConnect_Click(object sender, EventArgs e)
        {
            var sd = ServersConfig.GetInstance().GetSelected();

            if (sd == null)
            {
                return;
            }
            if (rm == null)
            {
                RemoteManager rmm = RemoteManager.GetInstance();
                rm = rmm.Connect(sd);

                if (rm.IsConnected())
                {
                    st = rm.GetStream();
                    ButtonConnect.Text = "Disconnect";
                }
                return;
            }

            if (rm.IsConnected())
            {
                rm.Disconnect();
                rm = null;
                st = null;
                ButtonConnect.Text = "Connect";
            }
        }
Пример #2
0
        public void DisconnectServer(RomoteType type)
        {
            IRemote remote = Get(type);

            if (null != remote)
            {
                remote.Disconnect();
            }
        }
Пример #3
0
        private void OnConnect(IAsyncResult result)
        {
            TcpClient    client = serverSocket.EndAcceptTcpClient(result);
            StreamReader reader = new StreamReader(client.GetStream());
            string       type   = reader.ReadLine();
            IRemote      remote = null;

            RemoteConnectEventArgs args = new RemoteConnectEventArgs();

            OnRemoteConnect.Call(type, args);

            if (args.Canceled)
            {
                client.Close();
                reader.Close();

                if (!Server.ShuttingDown)
                {
                    serverSocket.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null);
                }

                return;
            }

            try {
                remote = (IRemote)Activator.CreateInstance(args.Assembly.GetType(type), client);
                ThreadPool.QueueUserWorkItem(new WaitCallback(remote.Run));
            }
            catch (Exception e) {
                Logger.LogError(e);
                if (remote != null)
                {
                    remote.Disconnect("Caused Error");
                }
            }
            if (!Server.ShuttingDown)
            {
                serverSocket.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null);
            }
        }