Beispiel #1
0
        /// <summary>
        /// 处理视频设备添加数据
        /// </summary>
        /// <param name="media">视频设备添加数据</param>
        /// <returns></returns>
        public async Task <XResponseMessage> ProcessAsync(MediaData media)
        {
            if (!_facilityCameraService.CheckCode(media.DeviceCode))
            {
                return(ResultHelper.CreateMessage("设备编码规则错误", ErrorType.InternalError));
            }
            if (!await _facilityService.ExistsWithRedisAsync(media.FacilityCode))
            {
                return(ResultHelper.CreateMessage("设施不存在", ErrorType.FacilityNotExists));
            }
            var item = await _facilityCameraService.GetFacilityCameraByIdAsny(media.DeviceCode);

            //数据库中不存在该设备(有必要吗?)
            if (item != null)
            {
                return(null);
            }
            item = new FacilityCameraDto
            {
                Serialnum         = media.DeviceCode,
                Name              = media.DeviceName,
                FacilitySerialnum = media.FacilityCode,
                Channel           = media.Channel,
                UserID            = media.User,
                UserPwd           = media.Pwd,
                IP         = media.Url,
                DataPort   = media.ContrPort,
                HttpPort   = media.MediaPort,
                Sort       = 0,
                Status     = true,
                RtspPort   = 54,
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now
            };

            try
            {
                var result = await _facilityCameraService.AddFacilityCamera(item);

                LogHelper.Info("[视频]视频{0}{1}添加{2}", item.Name, item.Serialnum, result);
                return(ResultHelper.CreateMessage($"添加视频设备{(result ? "成功" : "失败")}",
                                                  result ? ErrorType.NoError : ErrorType.InternalError));
            }
            catch (AggregateException ex)
            {
                return(ResultHelper.CreateExceptionMessage(ex, "添加视频设备失败"));
            }
        }
Beispiel #2
0
        /// <summary>
        /// 处理视频设备更新数据
        /// </summary>
        /// <param name="media">视频设备更新数据</param>
        /// <returns></returns>
        public async Task <XResponseMessage> ProcessAsync(MediaData media)
        {
            if (!_facilityCameraService.CheckCode(media.DeviceCode))
            {
                return(ResultHelper.CreateMessage("设备编码规则错误", ErrorType.InternalError));
            }
            if (!await _facilityService.ExistsAsync(media.FacilityCode))
            {
                return(ResultHelper.CreateMessage("设施不存在", ErrorType.FacilityNotExists));
            }
            var item = await _facilityCameraService.GetFacilityCameraByIdAsny(media.DeviceCode);

            //数据库中不存在该设备(有必要吗?)
            if (item == null || media.CreateTime < item.UpdateTime)
            {
                return(null);
            }
            item.Serialnum         = media.DeviceCode;
            item.Name              = media.DeviceName;
            item.FacilitySerialnum = media.FacilityCode;
            item.Channel           = media.Channel;
            item.UserID            = media.User;
            item.UserPwd           = media.Pwd;
            item.IP         = media.Url;
            item.DataPort   = media.ContrPort;
            item.HttpPort   = media.MediaPort;
            item.UpdateTime = media.CreateTime;

            try
            {
                var result = await _facilityCameraService.UpdateCamera(item);

                LogHelper.Info("[视频]视频{0}{1}更新{2}", item.Name, item.Serialnum, result);
                return(ResultHelper.CreateMessage($"更新视频设备{(result ? "成功" : "失败")}",
                                                  result ? ErrorType.NoError : ErrorType.InternalError));
            }
            catch (AggregateException ex)
            {
                return(ResultHelper.CreateExceptionMessage(ex, "更新视频设备失败"));
            }
        }
        /// <summary>
        /// 添加摄像机
        /// </summary>
        /// <param name="mediaData"></param>
        public static async Task AddCamera(MediaData mediaData)
        {
            var camera = _redis.Smember <FacilityCameraDto>("facilityCamera", DataType.Protobuf).Find(c => c.Serialnum.EqualIgnoreCase(mediaData.DeviceCode));
            var camDb  = camera != null ? camera : await _facilityCameraService.GetFacilityCameraByIdAsny(mediaData.DeviceCode);

            //FacilityCamera.FindAllWithCache().ToList().FirstOrDefault(c => c.Serialnum.Equals(mediaData.DeviceCode));
            if (camDb == null)
            {
                camDb = new FacilityCameraDto
                {
                    Serialnum         = mediaData.DeviceCode,
                    Name              = mediaData.DeviceName,
                    FacilitySerialnum = mediaData.FacilityCode,
                    IP       = mediaData.Url,
                    HttpPort = mediaData.MediaPort,
                    DataPort = mediaData.ContrPort,
                    UserID   = mediaData.User,
                    UserPwd  = mediaData.Pwd,
                    Channel  = mediaData.Channel
                };
                //await _facilityCameraService.AddFacilityCamera(camDb);
                ServiceLogger.Current.WriteDebugLog("添加设施摄像机 {0} {1}", camDb.FacilitySerialnum, camDb.IP);
            }
            else
            {
                camDb.Name = mediaData.DeviceName;
                camDb.FacilitySerialnum = mediaData.FacilityCode;
                camDb.IP       = mediaData.Url;
                camDb.HttpPort = mediaData.MediaPort;
                camDb.DataPort = mediaData.ContrPort;
                camDb.UserID   = mediaData.User;
                camDb.UserPwd  = mediaData.Pwd;
                camDb.Channel  = mediaData.Channel;
                //await _facilityCameraService.UpdateCamera(camDb);
                ServiceLogger.Current.WriteDebugLog("更新设施摄像机 {0} {1}", camDb.FacilitySerialnum, camDb.IP);
            }
            _redis.Sadd("facilityCamera", camDb, DataType.Protobuf);//加入到缓存中去
        }
Beispiel #4
0
        /// <summary>
        ///     更新设备数据
        /// </summary>
        /// <param name="update"></param>
        /// <returns></returns>
        public static async Task <XResponseMessage> ProcessDeviceUpdate(DeviceUpdateData update)
        {
            if (update == null)
            {
                throw new ArgumentNullException("update");
            }

            //更新设备
            if (update.Devices != null && update.Devices.Any())
            {
                var updateList = new List <DeviceDto>();
                var setList    = new List <DeviceExceptionSetDto>();

                //foreach (var deviceModel in update.Facility.Where(d => d != null))
                update.Devices.Where(d => d != null).ForEach(async deviceModel =>
                {
                    var devDb = await _deviceService.GetDeviceByIdAsny(deviceModel.Serialnum);
                    //if (devDb == null)
                    //{
                    devDb.Serialnum           = deviceModel.Serialnum;
                    devDb.Name                = deviceModel.Name;
                    devDb.FacilitySerialnum   = deviceModel.FacilitySerialnum;
                    devDb.DeviceTypeSerialnum = deviceModel.DeviceTypeSerialnum;
                    devDb.Unit                = deviceModel.Unit;
                    devDb.ProcessedValue      = deviceModel.ProcessedValue;
                    devDb.ShowValue           = deviceModel.ShowValue;
                    devDb.CreateTime          = devDb.UpdateTime = deviceModel.UpdateTime;
                    //devDb.Save();
                    updateList.Add(devDb);
                    var set = await _deviceExceptionSetService.GetDeviceExceptionSetByDeviceIdAsny(devDb.Serialnum) ??
                              new DeviceExceptionSetDto()
                    {
                        DeviceSerialnum = devDb.Serialnum
                    };
                    if (deviceModel.Max != null)
                    {
                        set.Max = deviceModel.Max.Value;
                    }
                    if (deviceModel.Min != null)
                    {
                        set.Min = deviceModel.Min.Value;
                    }
                    setList.Add(set);
                    //}
                });

                try
                {
                    if (updateList.Count() > 0 && updateList != null)
                    {
                        updateList.ForEach(dev =>
                        {
                            DeviceDto device = null;
                            if (_redis.Exists("device") == 1)
                            {
                                device = _redis.Smember <DeviceDto>("device", DataType.Protobuf).Find(d => d.Serialnum.EqualIgnoreCase(dev.Serialnum));
                            }
                            if (device != null)
                            {
                                _redis.Srem("device", dev, DataType.Protobuf);
                            }
                            //await _deviceService.AddDevice(dev);//保存设备
                            _redis.Sadd("device", dev, DataType.Protobuf);
                        });
                    }
                    if (setList.Count() > 0 && setList != null)
                    {
                        setList.ForEach(async set =>
                        {
                            await _deviceExceptionSetService.AddDeviceExceptionSet(set); //保存设备异常区间
                        });
                    }
                }
                catch (Exception ex)
                {
                    return(ResultHelper.CreateMessage("", ErrorType.InternalError, null, ex));
                }
            }

            //更新音视频设备
            //var cameraDb = FacilityCamera.FindAllWithCache().ToList();
            if (update.Cameras != null && update.Cameras.Any())
            {
                var cameraDb = new List <FacilityCameraDto>();
                update.Cameras.ForEach(async mediaData =>
                {
                    if (mediaData != null)
                    {
                        var cam = await _facilityCameraService.GetFacilityCameraByIdAsny(mediaData.DeviceCode);
                        if (cam != null)
                        {
                            cam.FacilitySerialnum = mediaData.FacilityCode;
                            cam.IP       = mediaData.Url;
                            cam.HttpPort = mediaData.MediaPort;
                            cam.DataPort = mediaData.ContrPort;
                            cam.UserID   = mediaData.User;
                            cam.UserPwd  = mediaData.Pwd;
                            cam.Channel  = mediaData.Channel;
                            cameraDb.Add(cam);
                        }
                    }
                });
                try
                {
                    //保存设施摄像机
                    cameraDb.ForEach(c =>
                    {
                        //await _facilityCameraService.AddFacilityCamera(c);
                        FacilityCameraDto camera = null;
                        if (_redis.Exists("facilityCamera") == 1)
                        {
                            camera = _redis.Smember <FacilityCameraDto>("facilityCamera", DataType.Protobuf).Find(fc => fc.Serialnum.EqualIgnoreCase(c.Serialnum));
                        }
                        if (camera != null)
                        {
                            _redis.Srem("facilityCamera", camera, DataType.Protobuf);
                        }
                        _redis.Sadd("facilityCamera", camera, DataType.Protobuf);
                    });
                }
                catch (Exception ex)
                {
                    return(ResultHelper.CreateMessage("", ErrorType.InternalError, null, ex));
                }
            }

            return(null);
        }
Beispiel #5
0
 public async Task <FacilityCameraDto> ProcessAsync(string MediaCode)
 {
     return(await _facilityCameraService.GetFacilityCameraByIdAsny(MediaCode));
 }