Esempio n. 1
0
        public void SocketLoop()
        {
            // Socket loop
            var quitTask       = Task.Run(() => { QuitEvent.WaitOne(); });
            var running        = true;
            var currentMessage = new PilightMessage();

            while (running)
            {
                var lineTask = Client.ReadLine();

                if (0 == Task.WaitAny(quitTask, lineTask))
                {
                    running = false;
                }
                else
                {
                    // line from socket
                    var line = lineTask.Result;

                    currentMessage.AddMessageLine(line);
                    if (currentMessage.IsComplete)
                    {
                        MessageReceived?.Invoke(currentMessage);
                        currentMessage = new PilightMessage();
                    }
                }
            }
        }
        public virtual async Task OnMessage(PilightMessage msg)
        {
            try
            {
                var json = JsonConvert.DeserializeObject <PilightJsonObject>(msg.Message);

                // Default implementation does nothing except log
                Console.WriteLine("Message from Pilight: {0}", msg.Message);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Exception parsing pilight message: {0} {1}", ex.GetType().Name, ex.Message);
            }
        }