Exemplo n.º 1
0
        /// <summary>
        /// Messages from server.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="CommandEventArgs" /> instance containing the event data.</param>
        public void MessageFromServer(object sender, CommandEventArgs args)
        {
            CommandEnum commandID = args.CommandID;

            if (commandID == CommandEnum.GetAllLogsCommand)
            {
                GUIClient client  = (GUIClient)sender;
                string    message = args.CommandArgs[0];
                var       obj     = Newtonsoft.Json.JsonConvert.DeserializeObject <List <MessageRecievedEventArgs> >(message);
                List <MessageRecievedEventArgs> logs = (List <MessageRecievedEventArgs>)obj;
                logs.Reverse();
                foreach (MessageRecievedEventArgs log in (List <MessageRecievedEventArgs>)obj)
                {
                    ReceivedLog?.Invoke(this, log);
                }
                //for (int i = logs.Count - 1; i >= 0; i++) {  ReceivedLog?.Invoke(this, logs[i]); }
            }
            else if (commandID == CommandEnum.LogCommand)
            {
                GUIClient client  = (GUIClient)sender;
                string    message = args.CommandArgs[0];
                var       obj     = Newtonsoft.Json.JsonConvert.DeserializeObject <MessageRecievedEventArgs>(args.CommandArgs[0]);
                //string log = message.Substring(1);
                // string log = message;
                // MessageRecievedEventArgs logInfo = ParseLogFromString(log);
                MessageRecievedEventArgs logInfo = (MessageRecievedEventArgs)obj;
                ReceivedLog?.Invoke(this, logInfo);
            }
        }
        public void MessageFromServer(object sender, CommandEventArgs args)
        {
            CommandEnum commandID = args.CommandID;

            if (commandID == CommandEnum.GetAllLogsCommand)
            {
                Client client  = (Client)sender;
                string message = args.CommandArgs[0];
                var    obj     = Newtonsoft.Json.JsonConvert.DeserializeObject <List <MessageRecievedEventArgs> >(message);
                List <MessageRecievedEventArgs> logs = (List <MessageRecievedEventArgs>)obj;
                logs.Reverse();
                foreach (MessageRecievedEventArgs log in (List <MessageRecievedEventArgs>)obj)
                {
                    ReceivedLog?.Invoke(this, log);
                }
            }
            else if (commandID == CommandEnum.LogCommand)
            {
                Client client  = (Client)sender;
                string message = args.CommandArgs[0];
                var    obj     = Newtonsoft.Json.JsonConvert.DeserializeObject <MessageRecievedEventArgs>(args.CommandArgs[0]);

                MessageRecievedEventArgs SpecificLogView = (MessageRecievedEventArgs)obj;
                ReceivedLog?.Invoke(this, SpecificLogView);
            }
        }
 public static void HandleMessage(MqttApplicationMessageReceivedEventArgs args)
 {
     if (args.ApplicationMessage.Topic.StartsWith(Topics.PING.Split('/')[0], StringComparison.Ordinal))
     {
         var client = new Client
         {
             Name = args.ApplicationMessage.ConvertPayloadToString(),
             Id   = args.ApplicationMessage.Topic.Split('/')[1]
         };
         ClientConnected?.Invoke(client);
     }
     else if (args.ApplicationMessage.Topic.StartsWith(Topics.Log.Split('/')[0], StringComparison.Ordinal))
     {
         var json     = args.ApplicationMessage.ConvertPayloadToString();
         var logEvent = Serializer.DeserializeJson <LogEvent>(json);
         ReceivedLog?.Invoke(args.ApplicationMessage.Topic.Split('/')[1], logEvent);
     }
 }