Exemplo n.º 1
0
        /// <summary>
        /// Update log.
        /// </summary>
        /// <param name="message"> received message</param>
        public void UpdateByNotification(string message)
        {
            try
            {
                // Wrap given message in Json.
                ConfigurationRecieveEventArgs configurationNotify =
                    JsonConvert.DeserializeObject <ConfigurationRecieveEventArgs>(message);

                // Update log according to message type.
                switch ((ConfigurationEnum)configurationNotify.ConfigurationID)
                {
                case ConfigurationEnum.LogHistory:
                    SetLogHistory(configurationNotify.Args);
                    break;

                case ConfigurationEnum.NewLogMessageConfiguraton:
                    AddLogMessage(configurationNotify.Args);
                    break;

                default:
                    break;
                }
                notify?.Invoke();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Execute command.
        /// </summary>
        /// <param name="args"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public string Execute(string[] args, out bool result)
        {
            //Get handler to remove from args.
            string removeHandler = args[0];

            //Remove wanted handler.
            result = m_imageServer.RemoveHandler(removeHandler);
            string resultString;

            //Check result and create result string accordingly.
            if (result)
            {
                resultString = "Handler " + removeHandler + " removed";
            }
            else
            {
                resultString = "Handler " + removeHandler + " can't be removed. Check log.";
            }
            //Create result command.
            ConfigurationRecieveEventArgs command =
                new ConfigurationRecieveEventArgs((int)ConfigurationEnum.RemoveHandler, args);
            //Serialize it.
            string output = JsonConvert.SerializeObject(command);

            //Invoke with result command.
            //m_handleGui.InvokeEvent(command);
            return(output);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Update settings model by given message.
        /// </summary>
        /// <param name="message"></param>
        public void UpdateByNotification(string message)
        {
            try
            {
                //Deserialize message.
                ConfigurationRecieveEventArgs configurationNotify =
                    JsonConvert.DeserializeObject <ConfigurationRecieveEventArgs>(message);
                //Set by given enum ID.
                switch ((ConfigurationEnum)configurationNotify.ConfigurationID)
                {
                case ConfigurationEnum.SettingsConfiguration:
                    //Set settings by arguments.
                    SetSettings(configurationNotify.Args);
                    break;

                case ConfigurationEnum.RemoveHandler:
                    //Check if wanted handler to remove is in Handlers and remove it.
                    if (Handlers.Contains(configurationNotify.Args[0]))
                    {
                        Application.Current.Dispatcher.Invoke(new Action(() =>
                                                                         { Handlers.Remove(configurationNotify.Args[0]); }));
                    }

                    break;

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Exemplo n.º 4
0
 public string Execute(string[] args, out bool result)
 {
     try
     {
         List <string> sendArgs = new List <string>();
         //Get parameters from app config
         sendArgs.Add(ConfigurationManager.AppSettings.Get("OutputDir"));
         sendArgs.Add(ConfigurationManager.AppSettings.Get("SourceName"));
         sendArgs.Add(ConfigurationManager.AppSettings.Get("LogName"));
         sendArgs.Add(ConfigurationManager.AppSettings.Get("ThumbnailSize"));
         //Split handlers by ;
         string[] handlers = HandlerListManager.GetHandlerListManager().Handlers;
         //Convert string array into list.
         for (int i = 0; i < handlers.Length; i++)
         {
             sendArgs.Add(handlers[i]);
         }
         //Create recieve command.
         ConfigurationRecieveEventArgs configurationEvent =
             new ConfigurationRecieveEventArgs((int)ConfigurationEnum.SettingsConfiguration, sendArgs.ToArray());
         //Serialize it.
         string output = JsonConvert.SerializeObject(configurationEvent);
         result = true;
         return(output);
     }
     catch (Exception)
     {
         result = false;
         return("Couldn't get settings propetries.");
     }
 }
Exemplo n.º 5
0
        public string Execute(string[] args, out bool result)
        {
            //Get log history.
            List <MessageRecievedEventArgs> logHistory = m_logging.GetLogHistory();
            //Count log history size.
            int numberOfMessages = logHistory.Count;

            //Create string array.
            string[] logHistoryArray = new string[numberOfMessages * 2];
            int      counter         = 0;

            //Put all messages into array.
            for (int i = 0; i < logHistoryArray.Length; i = i + 2, counter++)
            {
                //First place is enum number.
                logHistoryArray[i] = ((int)logHistory[counter].Status).ToString();
                //Second place is message.
                logHistoryArray[i + 1] = logHistory[counter].Message;
            }
            //Create result command.
            ConfigurationRecieveEventArgs command = new ConfigurationRecieveEventArgs((int)ConfigurationEnum.LogHistory, logHistoryArray);
            //Serialize it.
            string output = JsonConvert.SerializeObject(command);

            result = true;
            return(output);
        }
Exemplo n.º 6
0
        public string Execute(string[] args, out bool result)
        {
            //Create result command.
            ConfigurationRecieveEventArgs command =
                new ConfigurationRecieveEventArgs((int)ConfigurationEnum.Ack, args);
            //Serialize it.
            string output = JsonConvert.SerializeObject(command);

            result = true;
            return(output);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Write to log.
        /// </summary>
        /// <param name="message">Message to write.</param>
        /// <param name="type">Type of message.</param>
        public void Log(string message, MessageTypeEnum type)
        {
            logHistory.Add(new MessageRecievedEventArgs(type, message));
            MessageRecieved?.Invoke(this, new MessageRecievedEventArgs(type, message));

            string[] args = new string[2];
            args[0] = ((int)type).ToString();
            args[1] = message;
            ConfigurationRecieveEventArgs command =
                new ConfigurationRecieveEventArgs((int)ConfigurationEnum.NewLogMessageConfiguraton, args);

            NotifyClients?.Invoke(this, command);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Notify all clients about change.
 /// </summary>
 /// <param name="sender">Who wants to notify.</param>
 /// <param name="e">Parameter for notification.</param>
 public void NotifyClientsOnChange(object sender, ConfigurationRecieveEventArgs e)
 {
     try
     {
         //Serialize object in json format for sending it.
         string message = JsonConvert.SerializeObject(e);
         //Notify all clients in client list.
         foreach (TcpClient client in ClientsListenersList)
         {
             new Task(() =>
             {
                 try
                 {
                     //Get streamer.
                     NetworkStream stream = client.GetStream();
                     BinaryWriter writer  = new BinaryWriter(stream);
                     mutexForWrite.WaitOne();
                     //Write message.
                     writer.Write(message);
                     mutexForWrite.ReleaseMutex();
                 }
                 catch (Exception ex)
                 {
                     mutexForList.WaitOne();
                     ClientsListenersList.Remove(client);
                     mutexForList.ReleaseMutex();
                     Logging.Log("Removing client from list because: " + ex.Message, MessageTypeEnum.WARNING);
                 }
             }).Start();
         }
     }
     catch (Exception ex)
     {
         Logging.Log("Exception while notify all client about update: " + ex.Message, MessageTypeEnum.FAIL);
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public MainWindowModel()
        {
            //Create command to get echo from server.
            CommandRecievedEventArgs command = new CommandRecievedEventArgs((int)CommandEnum.EchoCommand, null, "");

            try
            {
                //Send echo command.
                string message = TCPClientChannel.GetTCPClientChannel().SendAndReceive(command);
                //Deserialize return object.
                ConfigurationRecieveEventArgs returnParam =
                    JsonConvert.DeserializeObject <ConfigurationRecieveEventArgs>(message);
                //Check if we get ack.
                if ((ConfigurationEnum)returnParam.ConfigurationID == ConfigurationEnum.Ack)
                {
                    IsConnected = IsConnectedEnum.Connected;
                }
            }
            catch (Exception)
            {
                //If there was exception - it means that there is no connection.
                IsConnected = IsConnectedEnum.NotConnected;
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Invokes event.
 /// </summary>
 /// <param name="message">Message to send to all clients.</param>
 public void InvokeEvent(ConfigurationRecieveEventArgs message)
 {
     NotifyClients?.Invoke(this, message);
 }