コード例 #1
0
 private void OnDeviceStateChanged(DeviceStateChanged msg)
 {
     _deviceStateDto                = msg.DeviceStateDto;
     _deviceState                   = msg.DeviceStateDto.CurrentState;
     _deviceStateEventTimeStamp     = msg.DeviceStateDto.TimeStamp;
     _deviceStateProcessedTimeStamp = DateTime.UtcNow;
 }
コード例 #2
0
        public ActionResult <DeviceStateDto> AddDeviceState(DeviceStateDto deviceStateDto)
        {
            var deviceStateModel = _mapper.Map <DeviceState>(deviceStateDto);

            _repository.AddDeviceState(deviceStateModel);

            var newDeviceStateDto = _mapper.Map <DeviceStateDto>(deviceStateModel);

            return(CreatedAtRoute(nameof(GetDeviceBySerialNumber), new { serial_number = newDeviceStateDto.device_serial_number },
                                  newDeviceStateDto));
        }
コード例 #3
0
 public GetDeviceStatusReceived(DeviceStateDto deviceState)
 {
     DeviceState = deviceState;
 }
 public DeviceStateChanged(DeviceStateDto deviceStateDto)
 {
     DeviceStateDto = deviceStateDto;
 }
コード例 #5
0
 public SetDeviceStatusReceived(DeviceStateDto deviceStateDto)
 {
     DeviceStateDto   = deviceStateDto;
     UnexistingDevice = false;
 }
コード例 #6
0
        /// <summary>
        ///  获取设备状态
        /// </summary>
        /// <param name="deviceIdList">Device.DeviceId</param>
        /// <param name="deviceResponseFlag">ref 集合对象</param>
        /// <returns></returns>
        public ResponseBaseDto GetServerDeviceState(int[] deviceIdList, string customerToken, ref List <DeviceResponse> deviceResponseFlag)
        {
            ResponseBaseDto    dto = new ResponseBaseDto();
            UserTokenCache     utc = UserTokenCache.GetInstance();
            TokenCacheProperty tcp = new TokenCacheProperty();

            try
            {
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.ServerNoToken;
                    dto.Message = "用户token已失效";
                }
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                if (dto.Code != 0)
                {
                    return(dto);
                }
                else
                {
                    IList <DeviceTokenDto> deviceTokenDtoFlag = new List <DeviceTokenDto>();
                    for (int i = 0; i < deviceIdList.Length; i++)
                    {
                        //缓存里是否有这个设备
                        DeviceResponse deviceResponse = deviceCache.FindByDeviceKey(GetDeivceKey(deviceIdList[i]));
                        if (deviceResponse != null)
                        {
                            deviceResponseFlag.Add(deviceResponse);
                        }
                        else
                        {
                            DeviceTokenDto deviceTokenDto = new DeviceTokenDto();
                            //服务器的设备ID
                            IList <Device> dFlag =
                                deviceServer.SelectDeviceByDeviceId(new Device()
                            {
                                DeviceId = deviceIdList[i]
                            });
                            if (dFlag != null && dFlag.Count != 0)
                            {
                                deviceTokenDto.ID = dFlag[0].BPServerDeviceId;
                                deviceTokenDtoFlag.Add(deviceTokenDto);
                            }
                        }
                    }
                    try
                    {
                        Bsr.ServiceProxy.Utils.ServiceFactory serviceFactory = new ServiceProxy.Utils.ServiceFactory();
                        string seviceAddr = bllHelper.GetServerModelStr();
                        IDictionary <int, DeviceStateDto> deviceState = null;
                        serviceFactory.GetProxy <IDevice>(new Uri(seviceAddr)).Use(
                            p =>
                        {
                            deviceState = p.RefreshDevices(deviceTokenDtoFlag);
                        }
                            );
                        for (int i = 0; i < deviceTokenDtoFlag.Count; i++)
                        {
                            DeviceStateDto dsDto        = deviceState[(deviceTokenDtoFlag[i].ID)];
                            IList <Device> dbDeviceFlag =
                                deviceServer.SelectDeviceByBPServerDeviceId(new Device()
                            {
                                BPServerDeviceId = deviceTokenDtoFlag[i].ID
                            });
                            if (dbDeviceFlag != null && dbDeviceFlag.Count == 1)
                            {
                                Device         device         = dbDeviceFlag[i];
                                DeviceResponse deviceResponse = new DeviceResponse();
                                deviceResponse.DeviceId = device.DeviceId;
                                if (dsDto.IsOnline == true)
                                {
                                    deviceResponse.BPServerDeviceState = 1;
                                }
                                else
                                {
                                    deviceResponse.BPServerDeviceState = 0;
                                }
                                //数据放入缓存
                                DateTime dt = DateTime.Now.AddSeconds(300);//失效时间定义为5分钟
                                deviceCache.AddDeviceCache(GetDeivceKey(dbDeviceFlag[0].DeviceId), deviceResponse, dt);
                                deviceResponseFlag.Add(deviceResponse);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        dto.Code    = (int)CodeEnum.ApplicationErr;
                        dto.Message = "服务未开启";
                        myLog.WarnFormat("GetServerGetDeviceState方法异常,BP4Server服务未开启!", ex);
                    }

                    dto.Code    = (int)CodeEnum.Success;
                    dto.Message = "设备状态已获取完成";
                }/*end if(utc.IsValid(customerToken) == false)*/
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常,请刷新页面后继续";
                myLog.ErrorFormat("GetServerGetDeviceState方法异常,设备Id{0}", ex, deviceIdList.ToString());
            }
            return(dto);
        }