Ejemplo n.º 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");
            }
        }
Ejemplo n.º 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);
        }
        public void AppendsSingleCharacterToString()
        {
            var terminal = new ClientTerminal();

            terminal.AppendToCurrentLine('h');

            Assert.AreEqual("h", terminal.GetCurrentLine());
        }
        public void BufferEmptyAfterAppendingToCurrentLine()
        {
            var terminal = new ClientTerminal();

            terminal.AppendToCurrentLine("hello");

            Assert.AreEqual(0, terminal.GetBuffer().Count);
        }
        public void AppendsTextToCurrentLine()
        {
            var terminal = new ClientTerminal();

            terminal.AppendToCurrentLine("hello");

            Assert.AreEqual("hello", terminal.GetCurrentLine());
        }
        public void BackspaceRemovesNothingOnEmptyCurrentLine()
        {
            var terminal = new ClientTerminal();

            terminal.Backspace();

            Assert.AreEqual("", terminal.GetCurrentLine());
        }
Ejemplo n.º 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);
        }
        public void WritesMessageToBuffer()
        {
            var terminal = new ClientTerminal();

            terminal.WriteLine("hello");

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

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

            Assert.AreEqual("worl", terminal.GetCurrentLine());
        }
        public void CurrentLineIsEmptyAfterWritingIntoBuffer()
        {
            var terminal = new ClientTerminal();

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

            Assert.AreEqual("", terminal.GetCurrentLine());
        }
        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);
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
            }
        }
        public void StartsWithEmptyBuffer()
        {
            var terminal = new ClientTerminal();

            Assert.AreEqual(0, terminal.GetBuffer().Count);
        }
        public void StartsWithEmptyCurrentLine()
        {
            var terminal = new ClientTerminal();

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