コード例 #1
0
        public ApplicationViewModel()
        {
            try
            {
                this.ConnectCommand    = new ConnectCommand(this);
                this.DisconnectCommand = new DisconnectCommand(this);

                this._currentDispatcher = Dispatcher.CurrentDispatcher;
                _clientTerminal         = new ClientTerminal(this);

                TradeSizeTypeCollection = new List <string>();

                // Create a client
                _site          = new InstanceContext(null, this);
                _site.Closed  += CommunicationObjectOnClosed;
                _site.Faulted += CommunicationObjectOnClosed;

                _client = new UpDownSignalsClient(_site);

                _heartbeatTimer           = new Timer(AcceptedDelaySeconds * 1000);
                _heartbeatTimer.Elapsed  += HeartbeatTimerElapsed;
                _heartbeatTimer.AutoReset = true;

                UpdateUI("Disconnected");

                InitializeClientTerminalUI();
            }
            catch (Exception exception)
            {
                Logger.Error(exception, OType.FullName, "ApplicationViewModel");
            }
        }
コード例 #2
0
        public void sendMsgToServer(byte[] bytes, Fleck.IWebSocketConnection clientSock, GlobalMessage msgType)
        {
            Socket value = null;

            if (msgType.Equals(GlobalMessage.PACKETERROR))
            {
                closeClient(clientSock);
                return;
            }
            else if (msgType == GlobalMessage.LOGIN)
            {
                ClientTerminal c = new ClientTerminal();
                c.Connected      += new TCPTerminal_ConnectDel(ServerConnected);
                c.MessageRecived += new TCPTerminal_MessageRecivedDel(ServerMessageRecived);
                c.Disconncted    += new TCPTerminal_DisconnectDel(ServerConnectionDroped);
                //clientTerminal = c;

                createSocket(c);
                value = c.m_socClient;
                toServer.Add(value, c);

                myGlobals.ClientServer.Add(clientSock, value);
                myGlobals.ServerClient.Add(value, clientSock);
                connect2Server(c);
            }
            else
            {
                value = myGlobals.ClientServer[clientSock];
            }

            //if (clientMsgProcess.messageType == clientMsgType.KEEPALIVEACK)
            //    clientHeartbeats[key].keepalive();

            toServer[value].SendMessage(bytes);
        }
コード例 #3
0
        public void AppendsSingleCharacterToString()
        {
            var terminal = new ClientTerminal();

            terminal.AppendToCurrentLine('h');

            Assert.AreEqual("h", terminal.GetCurrentLine());
        }
コード例 #4
0
        public void BufferEmptyAfterAppendingToCurrentLine()
        {
            var terminal = new ClientTerminal();

            terminal.AppendToCurrentLine("hello");

            Assert.AreEqual(0, terminal.GetBuffer().Count);
        }
コード例 #5
0
        public void AppendsTextToCurrentLine()
        {
            var terminal = new ClientTerminal();

            terminal.AppendToCurrentLine("hello");

            Assert.AreEqual("hello", terminal.GetCurrentLine());
        }
コード例 #6
0
        public void BackspaceRemovesNothingOnEmptyCurrentLine()
        {
            var terminal = new ClientTerminal();

            terminal.Backspace();

            Assert.AreEqual("", terminal.GetCurrentLine());
        }
コード例 #7
0
        public void createSocket(ClientTerminal c)
        {
            string    szIPSelected    = ServerHost2.Text;
            string    szPort          = txtPort2.Text;
            int       alPort          = Convert.ToInt16(szPort, 10);
            IPAddress remoteIPAddress = IPAddress.Parse(szIPSelected);

            c.createSocket(remoteIPAddress, alPort);
        }
コード例 #8
0
        public void WritesMessageToBuffer()
        {
            var terminal = new ClientTerminal();

            terminal.WriteLine("hello");

            Assert.AreEqual(1, terminal.GetBuffer().Count);
            Assert.AreEqual("hello", terminal.GetBuffer()[0].Message);
        }
コード例 #9
0
        public void BackspaceRemovesOneCharacterFromCurrentLine()
        {
            var terminal = new ClientTerminal();

            terminal.AppendToCurrentLine("world");
            terminal.Backspace();

            Assert.AreEqual("worl", terminal.GetCurrentLine());
        }
コード例 #10
0
        public void CurrentLineIsEmptyAfterWritingIntoBuffer()
        {
            var terminal = new ClientTerminal();

            terminal.AppendToCurrentLine("hello");
            terminal.WriteCurrentLine(TerminalStyle.Default);

            Assert.AreEqual("", terminal.GetCurrentLine());
        }
コード例 #11
0
        public void WritesCurrentLineIntoBuffer()
        {
            var terminal = new ClientTerminal();

            terminal.AppendToCurrentLine("hello");
            terminal.WriteCurrentLine(TerminalStyle.Default);

            Assert.AreEqual(1, terminal.GetBuffer().Count);
            Assert.AreEqual("hello", terminal.GetBuffer()[0].Message);
        }
コード例 #12
0
 public void connect2Server(ClientTerminal s)
 {
     try
     {
         // toSever.Connect(remoteIPAddress, alPort);
         s.Connect();
     }
     catch (SocketException se)
     {
         MessageBox.Show(se.Message);
         System.Environment.Exit(0);
     }
 }
コード例 #13
0
        public Program()
        {
            var client = new ClientWrapper();

            var formatter = new ConsoleFormatter(new ConsoleWriter());
            var terminal  = new ClientTerminal();
            var console   = new ClientConsole(terminal, formatter, client);

            client.InitializeConnection(console);

            var inputListener  = new ConsoleInputListener(console);
            var serverListener = new ServerMessageListener(client, console);

            new Thread(() => inputListener.BeginListening()).Start();
            new Thread(() => serverListener.BeginListening()).Start();
        }
コード例 #14
0
        public IClientTerminal GetClientTerminal(int ClientNumberOfTelephone)
        {
            IClientTerminal terminal = ClientTerminals.FirstOrDefault(x => x.ClientNumberOfTelephone == ClientNumberOfTelephone);

            if (terminal != null)
            {
                if (terminal.Rent == false)
                {
                    return(terminal);
                }
                else
                {
                    throw new Exception("Терминал с таким номером уже существует");
                }
            }
            else
            {
                IClientTerminal terminal1 = new ClientTerminal(ClientNumberOfTelephone, CallController);
                ClientTerminals.Add(terminal1);
                return(terminal1);
            }
        }
コード例 #15
0
        public void StartsWithEmptyBuffer()
        {
            var terminal = new ClientTerminal();

            Assert.AreEqual(0, terminal.GetBuffer().Count);
        }
コード例 #16
0
        public void StartsWithEmptyCurrentLine()
        {
            var terminal = new ClientTerminal();

            Assert.AreEqual("", terminal.GetCurrentLine());
        }