Example #1
0
        public override void OnOpen()
        {
            MessageManager manager = new MessageManager();

            base.OnOpen();
            try
            {
                string           deviceSerial     = this.WebSocketContext.Headers.GetValues("device-serial").FirstOrDefault();
                WebSocketHandler objDeviceSession = DeviceSessionPool.GetDeviceSession(deviceSerial);
                manager.PushMessage("OnOpen_1", deviceSerial);
                if (objDeviceSession == null)
                {
                    DeviceManager objDeviceManager = new DeviceManager();
                    if (objDeviceManager.IsDeviceExists(deviceSerial))
                    {
                        DeviceSessionPool.AddDeviceSession(deviceSerial, this);
                    }
                }
                else
                {
                    DeviceSessionPool.UpdateDeviceSession(deviceSerial, this);
                }
            }
            catch (Exception ex)
            {
                manager.PushMessage("OnOpen_exception", ex.Message);
                base.Send("You are not connected. " + ex.Message);
            }
        }
Example #2
0
 public HttpResponseMessage Control(DeviceAction deviceAction)
 {
     try
     {
         var deviceSession = DeviceSessionPool.GetDeviceSession(deviceAction.DeviceSerial);
         deviceSession.Send((new JavaScriptSerializer().Serialize(deviceAction)));
         return(Request.CreateResponse(HttpStatusCode.OK, true));
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.OK, false));
     }
 }
Example #3
0
 public HttpResponseMessage ResetWifi(DeviceAction deviceAction)
 {
     try
     {
         deviceAction.Action = "RESET";
         var deviceSession = DeviceSessionPool.GetDeviceSession(deviceAction.DeviceSerial);
         deviceSession.Send((new JavaScriptSerializer().Serialize(deviceAction)));
         return(Request.CreateResponse(HttpStatusCode.OK, true));
     }
     catch
     {
         return(Request.CreateResponse(HttpStatusCode.OK, false));
     }
 }
Example #4
0
 public HttpResponseMessage IsOnline(string deviceSerial)
 {
     try
     {
         if (DeviceSessionPool.GetDeviceSession(deviceSerial) == null)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, false));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.OK, true));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
Example #5
0
        public HttpResponseMessage CheckStatus(string deviceSerial)
        {
            try
            {
                var deviceAction = new DeviceAction
                {
                    Action       = "STATUS",
                    DeviceSerial = deviceSerial
                };

                var deviceSession = DeviceSessionPool.GetDeviceSession(deviceSerial);
                deviceSession.Send((new JavaScriptSerializer().Serialize(deviceAction)));
                return(Request.CreateResponse(HttpStatusCode.OK, DeviceSessionPool.deviceStatus[deviceSerial]));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }