Ejemplo n.º 1
0
        protected override void OnOpen()
        {
            try
            {
                string deviceSerial = this.Context.Headers.GetValues("device-serial").FirstOrDefault();

                DeviceModel objDevice = DevicePool.GetDevice(deviceSerial);
                if (objDevice == null)
                {
                    using (var ctx = new DeviceMgmtEntities())
                    {
                        objDevice = ctx.Devices.Where(d => d.DeviceSerialNr.Equals(deviceSerial)).Select(dvc => new DeviceModel()
                        {
                            DeviceID = dvc.ID, DeviceDescription = dvc.Description, DeviceName = dvc.Name, DeviceSerialNumber = dvc.DeviceSerialNr, DeviceType = dvc.DeviceType, SessionId = this.ID
                        }).FirstOrDefault();
                    }
                    DevicePool.AddDevice(objDevice);
                }
                else
                {
                    DevicePool.UpdateDeviceSession(objDevice.DeviceSerialNumber, this.ID);
                }
            }
            catch
            {
                //Logs goes here...
            }
        }
 public JsonResult Control(DeviceActionModel model)
 {
     try
     {
         var device = DevicePool.GetDevice(model.DeviceSerial);
         MvcApplication.objWsServer.WebSocketServices["/"].Sessions.SendTo(new JavaScriptSerializer().Serialize(model), device.SessionId);
         return(Json(true));
     }
     catch
     {
         return(Json(false));
     }
 }