/// <summary>
 /// constructor
 /// </summary>
 public LogsModel()
 {
     commChannel = TcpClientChannel.GetInstance();
     commChannel.MessageReceived += ReadRecivedMessage;
     this.Logs = new ObservableCollection <MessageRecievedEventArgs>();
     Thread.Sleep(1000);
     this.GetLogs();
 }
        /// <summary>
        /// constructor
        /// </summary>
        public SettingsModel()
        {
            commChannel = TcpClientChannel.GetInstance();
            commChannel.MessageReceived += ReadRecivedMessage;

            this.GetConfig();
            Thread.Sleep(1000);
        }
Beispiel #3
0
        /// <summary>
        /// the constructor.
        /// </summary>
        private ModelCommunication()
        {
            ///getting a tcpClient instance.
            client = TcpClientChannel.GetInstance();
            //if not already connected then connect.
            if (!TcpClientChannel.connected)
            {
                try
                {
                    //connecting to the server and setting the connected boolean to true.
                    TcpClientChannel.Connect(8000);
                    connected = true;
                }
                catch (Exception)
                {
                    //connection failed.
                    connected = false;
                }
            }
            //If we connected we will continue
            if (TcpClientChannel.connected)
            {
                try
                {
                    Task t = new Task(() =>
                    {
                        //Receiving messages.
                        while (true)
                        {
                            MessageToClient message;
                            //getting all things that relate to the message.
                            try
                            {
                                message = client.recieveMessage();
                            } catch (Exception)
                            {
                                connected = false;
                                return;
                            }
                            int id          = message.TypeMessage;
                            string content  = message.Content;
                            bool allClients = message.AllClients;
                            //Check to who transfer the message
                            if (id == (int)SendClientEnum.AddLog)
                            {
                                AddLog?.Invoke(this, content);
                            }
                            if (id == (int)SendClientEnum.RemoveHandler)
                            {
                                RemoveHandler?.Invoke(allClients, content);
                            }

                            if (id == (int)SendClientEnum.GetConfig)
                            {
                                GetConfig?.Invoke(this, content);
                            }

                            if (id == (int)SendClientEnum.GetLogs)
                            {
                                GetLogs?.Invoke(this, content);
                            }
                        }
                    });
                    t.Start();
                }
                catch (Exception) {
                    connected = false;
                }
            }
        }
Beispiel #4
0
 /// <summary>
 /// constructor for the class
 /// </summary>
 public MainWindowViewModel()
 {
     this.commChannel = TcpClientChannel.GetInstance();
     IsConnected      = this.commChannel.IsConnected;
 }