Beispiel #1
0
 private void OnSocketMessage(object sender, MessageEventArgs e)
 {
     lock (this)
     {
         JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
         if (e.Type == Opcode.Text)
         {
             String json = e.Data.ToString();
             if (json.StartsWith("{\"DataInfo\":"))
             {
                 NavicoJson.IncomingDataInfo info = javaScriptSerializer.Deserialize <NavicoJson.IncomingDataInfo>(json);
                 if (info.IsValid())
                 {
                     HandleMessage(info);
                 }
             }
             else if (json.StartsWith("{\"DeviceList\":"))
             {
                 NavicoJson.IncomingDeviceList deviceList = javaScriptSerializer.Deserialize <NavicoJson.IncomingDeviceList> (json);
                 if (deviceList.IsValid())
                 {
                     HandleMessage(deviceList);
                 }
             }
             else
             {
                 NavicoJson.IncomingData data = javaScriptSerializer.Deserialize <NavicoJson.IncomingData> (json);
                 if (data.IsValid())
                 {
                     HandleMessage(data);
                 }
                 else
                 {
                     NavicoJson.DList dl = javaScriptSerializer.Deserialize <NavicoJson.DList> (json);
                     if (dl.IsValid())
                     {
                         HandleMessage(dl);
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
        internal void HandleMessage(NavicoJson.IncomingData data)
        {
            if (Logging)
            {
                foreach (NavicoJson.IncomingData.DataItem item in data.Data)
                {
                    m_CurrentMessage.AddData(item);  //.id, item.ToString());
                }

                if (m_UseUserTimer == false)
                {
                    HandleDecodedMessage();
                }

                if (ValidMessageReceived != null)
                {
                    ValidMessageReceived(this, new EventArgs());
                }
            }
        }