コード例 #1
0
        // sends data
        void socketServer_CommandHandler(WebSocketSession session, WebSocketCommandInfo commandInfo)
        {
            int?        value = (int.Parse(commandInfo.Data.ToString()));
            ThermoTemps temp  = commService.GetTemperatures(value);

            System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            string sJSON = oSerializer.Serialize(temp);

            SendToAll(session.Cookies["name"] + ": " + sJSON);

            // SendToAll(session.Cookies["name"] + ": " + commService.ReverseCommunication(commandInfo.Data));
        }
コード例 #2
0
        void OnSecureSocketPushTimerCallback(object state)
        {
            lock (m_SessionSyncRoot)
            {
                // SendToAll("Push data from SecureWebSocket. Current Time: " + DateTime.Now);

                ThermoTemps temp = commService.GetTemperatures(null);
                System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                string sJSON = oSerializer.Serialize(temp);

                SendToAll("Computer Update: " + sJSON);
            }
        }
コード例 #3
0
        public ThermoTemps GetTemperatures(int?fan = null)
        {
            Random      rnd          = new Random();
            ThermoTemps temperatures = new ThermoTemps();

            // determine if fan temp past in
            if (fan != null)
            {
                temperatures.Fan = (int)fan;
            }
            else
            {
                temperatures.Fan = rnd.Next(-20, 20);
            }

            temperatures.CoolingVent = rnd.Next(-20, 20);
            temperatures.Freezer     = rnd.Next(-20, 20);
            temperatures.Fridge      = rnd.Next(-20, 20);
            temperatures.IceMaker    = rnd.Next(-20, 20);

            return(temperatures);
        }
コード例 #4
0
        public void UpdateText(string result)
        {
            try
            {
                string      jsonString        = result.Substring(result.IndexOf('{'));
                ThermoTemps myDeserializedObj = new ThermoTemps();

                DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(ThermoTemps));
                MemoryStream memoryStream = new MemoryStream(Encoding.Unicode.GetBytes(jsonString));
                myDeserializedObj = (ThermoTemps)dataContractJsonSerializer.ReadObject(memoryStream);
                ThermoCollection.Add(myDeserializedObj);

                this.radialBarCoolVent.Value = myDeserializedObj.CoolingVent; // set the needle
                this.radialBarFan.Value      = myDeserializedObj.Fan;         // set the needle
                this.radialBarFreezer.Value  = myDeserializedObj.Freezer;     // set the needle
                this.radialBarFridge.Value   = myDeserializedObj.Fridge;      // set the needle
                this.radialBarIceMaker.Value = myDeserializedObj.IceMaker;    // set the needle
            }
            catch (Exception ex) { }

            mytextblock.Text += result + Environment.NewLine;
        }