Ejemplo n.º 1
0
        public IEnumerable <object> GetCameraAdditionalInfo(NvrDto nvr)
        {
            try
            {
                var cameraInfoRequest = new AdditionalCameraInfoRequest();

                var camerasInfoCollection = ExecuteRequest <AdditionalCameraInfoResponse, IEnumerable <Object> >(nvr, cameraInfoRequest,
                                                                                                                 result =>
                {
                    var camerasInfos = result.CamerasInfoCollection;
                    return(camerasInfos);
                },
                                                                                                                 exception => _logger.Error("Failed to get camera info collection from server. Error information:\r\n{0}", exception));

                return(camerasInfoCollection.EmptyIfNull());
            }
            catch (Exception ex)
            {
                _logger.Info("NvrService GetCameraAdditionalInfo() Exception:" + ex.Message);
                string Message = "NvrService-GetCameraAdditionalInfo -- Exception = " + ex.Message;
                //InsertBrokerOperationLog.AddProcessLog(Message);
                InsertIntegrationLog.AddProcessLogIntegration(Message);//jatin
            }
            finally
            {
                ClearMemory();
            }
            return(null);
        }
Ejemplo n.º 2
0
        //TODO: review when working on alarms
        private TResult ExecuteRequest <TResponse, TResult>(NvrDto nvrDto, MessageBase request, Func <TResponse, TResult> onSuccess, Action <Exception> onError)
            where TResponse : MessageBase
        {
            var    tcs        = new TaskCompletionSource <TResult>();
            var    server     = InitializeServer(nvrDto);
            Action serverCall = () => server.SendAndGetResponseAsObservable <TResponse>(request)
                                .Subscribe <TResponse>(response =>
            {
                var result = onSuccess(response);
                tcs.TrySetResult(result);
            }, error =>
            {
                onError(error);
                tcs.TrySetResult(default(TResult));
            });

            if (server.State == ServerControllerState.Connected)
            {
                serverCall();
            }
            else
            {
                server.Connected += (s, e) => serverCall();
            }
            ClearMemory();
            return(tcs.Task.Result);
        }
Ejemplo n.º 3
0
        public IEnumerable <VideoAlarmEvent> GetVideoAlarms(NvrDto nvr, IEnumerable <Guid> sources)
        {
            try
            {
                var alarmRequest = new AlarmsEventsRequestMessageExtended
                {
                    StartDate      = DateTime.Now.ToUniversalTime().AddDays(-1),
                    EndDate        = DateTime.Now,
                    MaxTransaction = 100,
                    PosModeEnabled = false,
                    Sources        = sources,
                    SearchString   = string.Empty
                };

                var alarmsEventsResult = ExecuteRequest <AlarmsEventsResponseMessageExtended, IEnumerable <VideoAlarmEvent> >(nvr, alarmRequest,
                                                                                                                              result =>
                {
                    var alarmEvents = result.Events.Select(alarmEvent => new VideoAlarmEvent
                    {
                        AlarmId     = alarmEvent.AlarmId,
                        AlarmName   = alarmEvent.AlarmName,
                        Cameras     = alarmEvent.Cameras,
                        Date        = alarmEvent.Date,
                        Deactivated = alarmEvent.Deactivated,
                        Description = alarmEvent.Description,
                        EventId     = alarmEvent.EventId,
                        Priority    = alarmEvent.Priority
                    }).ToList();
                    return(alarmEvents);
                },
                                                                                                                              exception => _logger.Error("Failed to get video alarms for server. Error information:\r\n{0}", exception));

                return(alarmsEventsResult.EmptyIfNull());
            }
            catch (Exception ex)
            {
                _logger.Info("NvrService GetVideoAlarms() Exception:" + ex.Message);
                string Message = "NvrService-GetVideoAlarms -- Exception = " + ex.Message;
                //InsertBrokerOperationLog.AddProcessLog(Message);
                InsertIntegrationLog.AddProcessLogIntegration(Message);//jatin
            }
            finally
            {
                ClearMemory();
            }
            return(null);
        }
Ejemplo n.º 4
0
        public void AddNvr_NewNvr_AddedSuccessfully()
        {
            var controllerServiceClient = new ControllerServiceClient();
            var nvr = new NvrDto
            {
                IPAddress   = "168.63.83.237",
                Username    = "******",
                Password    = "******",
                Port        = 1518,
                Description = "Test Server",
                NvrUrl      = "http://2020-NVR/guardnvr/mobi/cameras.asp"
            };
            var nvrAsJson = Serialize(nvr);

            var result = controllerServiceClient.AddNvr(string.Empty, nvrAsJson);

            Assert.IsTrue(result);
        }
Ejemplo n.º 5
0
        // Make it service locator like
        private IServerController InitializeServer(NvrDto nvrDto)
        {
            try
            {
                var videoServerEntity = new VideoServerEntity
                {
                    Address      = nvrDto.IPAddress,
                    Id           = Guid.NewGuid(),
                    Name         = nvrDto.Description,
                    Port         = nvrDto.Port,
                    UserName     = nvrDto.Username,
                    UserPassword = nvrDto.Password,
                    UserDomain   = string.Empty
                };

                _videoServersModel.AddServer(videoServerEntity);
                var serverController = _videoServersManager.GetServer(videoServerEntity.Id);
                serverController.ServerControllerError += (s, e) =>
                {
                    _logger.Error("Server error: {0}", e.Error);
                };

                return(serverController);
            }
            catch (Exception ex)
            {
                _logger.Info("NvrService InitializeServer() Exception:" + ex.Message);
                string Message = "NvrService-InitializeServer -- Exception = " + ex.Message;
                //InsertBrokerOperationLog.AddProcessLog(Message);
                InsertIntegrationLog.AddProcessLogIntegration(Message);//jatin
            }
            finally
            {
                ClearMemory();
            }
            return(null);
        }
Ejemplo n.º 6
0
        private IEnumerable <NvrDto> GetNVRCollection()
        {
            InsertBrokerOperationLog.AddProcessLog("DeviceTimeSync Service GetInterfaceCollection(): Start");
            try
            {
                using (var context = new CentralDBEntities())
                {
                    var resultsCollection = context.NVR;

                    var result2 = resultsCollection.Select(x => x).ToList();

                    foreach (var _entity in result2)
                    {
                        NvrDto _NvrDto = new NvrDto()
                        {
                            Description  = _entity.Description,
                            InterfaceId  = int.Parse(_entity.InterfaceId.ToString()),
                            IPAddress    = _entity.IPAddress,
                            NvrId        = _entity.NvrId,
                            NvrUrl       = _entity.NvrUrl,
                            Password     = _entity.Password,
                            Port         = int.Parse(_entity.Port.ToString()),
                            Username     = _entity.Username,
                            DvrNvrTypeId = int.Parse(_entity.DvrNvrTypeId.ToString()),
                        };

                        _NvrCollection.Add(_NvrDto);
                    }
                    return(_NvrCollection);
                }
            }
            catch (Exception ex)
            {
                InsertBrokerOperationLog.AddProcessLog("DeviceTimeSync Service GetNVRCollection(): Exception:" + ex.Message);
            }
            return(null);
        }
Ejemplo n.º 7
0
        public IEnumerable <VideoAlarmEvent> GetVideoAlarms(NvrDto nvr, IEnumerable <DeviceDto> nvrDevices)
        {
            try
            {
                var devices =
                    nvrDevices.EmptyIfNull()
                    .Where(dto => dto.InterfaceId == nvr.InterfaceId)
                    .Select(device => Guid.Parse(device.CameraGUID));

                return(GetVideoAlarms(nvr, devices));
            }
            catch (Exception ex)
            {
                _logger.Info("NvrService GetVideoAlarms() Exception:" + ex.Message);
                string Message = "NvrService-GetVideoAlarms -- Exception = " + ex.Message;
                //InsertBrokerOperationLog.AddProcessLog(Message);
                InsertIntegrationLog.AddProcessLogIntegration(Message);//jatin
            }
            finally
            {
                ClearMemory();
            }
            return(null);
        }
        //TODO: this is a temporary solution, should take objects
        public IEnumerable <DeviceDto> GetCamerasByNvr(NvrDto nvr)
        {
            try
            {
                //TODO: inject service
                var nvrService = new NvrService();
                nvrService.Initialize();
                var cameras = nvrService.GetCameras(nvr);

                return(cameras);
            }
            catch (Exception ex)
            {
                _logger.Info("NvrCameraAdapterService GetCamerasByNvr() Exception:" + ex.Message);
                string Message = "NvrCameraAdapterService--- GetCamerasByNvr Exception:" + ex.Message;
                //InsertBrokerOperationLog.AddProcessLog(Message);
                InsertIntegrationLog.AddProcessLogIntegration(Message);//jatin
            }
            finally
            {
                ClearMemory();
            }
            return(null);
        }
Ejemplo n.º 9
0
        public IEnumerable <DeviceDto> GetCameras(NvrDto nvrDto)
        {
            try
            {
                // Requesting the cameras list from the server.

                /*var server = InitializeServer(nvrDto);
                 * this.camerasManager.GetCamerasAsObservable(server.ServerUniqueId).Subscribe(
                 * cameras =>
                 * {
                 *  // Looking for a camera with name specified in configuration
                 *   var camerasResult = cameras.Cameras.Select(camera =>
                 *          {
                 *              var device = new NvrCameraDto()
                 *                  {
                 *                      CameraGUID = camera.Id.ToString(),
                 *                      Description = camera.Name,
                 *                      IPAddress = camera.Address,
                 *                      Lat = camera.LocationLatitude,
                 *                      Long = camera.LocationLongitude,
                 *                      Type = "NVRCamera",
                 *                      LocationDescription = string.Empty,
                 *                      Metadata =
                 *                          string.Format("<metadata><camera-id>{0}</camera-id></metadata>", camera.Id),
                 *                      Width = camera.Width,
                 *                      Height = camera.Height,
                 *                      FPS = (int)camera.RecordingFrameRate,
                 *                      ZoneColumns = camera.Width,
                 *                      ZoneRows = camera.Height,
                 *                      UpdateRate = (decimal?)0.0001
                 *
                 *                  };
                 *              return device;
                 *          }).ToList();
                 *  var camera = cameras.Cameras.FirstOrDefault(c => c.Name == this.cameraName);
                 *  if (camera != null)
                 *  {
                 *      var source = new Source(this.server.Id, camera.Id, false) { Framerate = 25 };
                 *      //If playing video and loading thumbnails are requested during handling a response to a cameras request from the CamerasManager
                 *      // - it has to be done in separate thread in order to avoid problems with deadlock of CamerasManager.
                 *      ThreadPool.QueueUserWorkItem(_ =>
                 *      {
                 *          // Setting the source to player in order to start playing the video
                 *          this.player.Source = source;
                 *          this.player.Play();
                 *
                 *          // Setting the source to ThumbnailsSlider in order to load thumbnails for this specific camera
                 *          this.slider.Source = source;
                 *      });
                 *  }
                 *  else
                 *  {
                 *      // Such camera not found
                 *  }
                 * },
                 * error =>
                 * {
                 *  // An error occurred when receiving the cameras list
                 *   exception => _logger.Error("Failed to get cameras for server. Error information:\r\n{0}", exception));
                 *   return cameras.EmptyIfNull();
                 * });*/

                var camerasInfoRequestMessage = new AdditionalCameraInfoRequest();
                var cameras = ExecuteRequest <AdditionalCameraInfoResponse, IEnumerable <DeviceDto> >(nvrDto, camerasInfoRequestMessage,
                                                                                                      result =>
                {
                    var camerasResult = result.CamerasInfoCollection.Select(camera =>
                    {
                        var device = new NvrCameraDto()
                        {
                            CameraGUID          = camera.Id.ToString(),
                            Description         = camera.Name,
                            IPAddress           = camera.Address,
                            Lat                 = camera.LocationLatitude,
                            Long                = camera.LocationLongitude,
                            Type                = "NVRCamera",
                            IsPtz               = false,
                            IsMovable           = false,
                            LocationDescription = string.Empty,
                            Metadata            =
                                string.Format("<metadata><camera-id>{0}</camera-id></metadata>", camera.Id),
                            Width       = camera.Width,
                            Height      = camera.Height,
                            FPS         = (int)camera.RecordingFrameRate,
                            ZoneColumns = camera.Width,
                            ZoneRows    = camera.Height,
                            UpdateRate  = (decimal?)0.0001
                        };

                        return(device);
                    }).ToList();

                    return(camerasResult);
                },
                                                                                                      exception => _logger.Error("Failed to get cameras for server. Error information:\r\n{0}", exception));

                return(cameras.EmptyIfNull());
            }
            catch (Exception ex)
            {
                _logger.Info("NvrService GetCameras() Exception:" + ex.Message);
                string Message = "NvrService-GetCameras -- Exception = " + ex.Message;
                //InsertBrokerOperationLog.AddProcessLog(Message);
                InsertIntegrationLog.AddProcessLogIntegration(Message);//jatin
            }
            finally
            {
                ClearMemory();
            }
            return(null);
        }
Ejemplo n.º 10
0
        //PTZ Handoff
        public void PTZHandoff(string nNvrId, string srePresetNum, string strCamGuid)//For Quadrox only
        {
            try
            {
                InsertIntegrationLog.AddProcessLogIntegration("PTZHandoff nNvrId:" + nNvrId + "--!--PresetNum:" + srePresetNum + "--!--CamGuid:" + strCamGuid);
                NvrDto result     = null;
                int    nPresetNum = Int32.Parse(srePresetNum);

                if (nPresetNum != 0)
                {
                    nPresetNum = nPresetNum - 1;
                }

                if (_nvrService != null)
                {
                    try
                    {
                        int _nNvrId = Int32.Parse(nNvrId);

                        using (var ctx = new CentralDBEntities())
                        {
                            var resultDb = (from nvr in ctx.NVR
                                            where nvr.NvrId == _nNvrId
                                            select nvr).First();
                            if (resultDb != null)
                            {
                                result = new NvrDto()
                                {
                                    Description = resultDb.Description,
                                    InterfaceId = int.Parse(resultDb.InterfaceId.ToString()),
                                    IPAddress   = resultDb.IPAddress,
                                    NvrId       = resultDb.NvrId,
                                    NvrUrl      = resultDb.NvrUrl,
                                    Password    = resultDb.Password,
                                    Port        = int.Parse(resultDb.Port.ToString()),
                                    Username    = resultDb.Username
                                };
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        InsertIntegrationLog.AddProcessLogIntegration("PTZHandoff get nvr details Exception :" + strCamGuid);
                    }

                    if (result != null)
                    {
                        NvrDto _nvr = result;

                        QL.Communication.Server.IServerController server;
                        _nvrService.AddServer(
                            _nvr.IPAddress,
                            _nvr.Port,
                            _nvr.Username,
                            _nvr.Password,
                            ""
                            );   //2020IMAGING

                        if (_nvrService.GetServerController().State == QL.Communication.Server.ServerControllerState.Connected)
                        {
                            InsertIntegrationLog.AddProcessLogIntegration("PTZHandoff  inside if :");

                            QL.Communication.Server.VideoServerEntity serverEntity = _nvrService.GetServer(_nvr.IPAddress);//nvr ipaddress

                            if (_nvrService.GetServerManager().TryGetServer(serverEntity.Id, out server))
                            {
                                var request = new QL.Communication.Messaging.Messages.PtzGoToPresetRequest
                                {
                                    SourceId     = new Guid(strCamGuid),//PTX Camera Guid
                                    PresetNumber = (byte)nPresetNum
                                };

                                server.SendAndGetResponseAsObservable <QL.Communication.Messaging.Messages.EmptyMessage>(request).Subscribe(
                                    ok =>
                                {
                                    InsertIntegrationLog.AddProcessLogIntegration("PTZHandoff  ok :");
                                },
                                    error =>
                                {
                                    InsertIntegrationLog.AddProcessLogIntegration("PTZHandoff error :" + error);
                                });
                            }
                        }
                        else
                        {
                            InsertIntegrationLog.AddProcessLogIntegration("PTZHandoff  inside else :");

                            _nvrService.GetServerController().Connected += (sender, args) =>
                            {
                                QL.Communication.Server.VideoServerEntity serverEntity = _nvrService.GetServer(_nvr.IPAddress);//nvr ipaddress

                                InsertIntegrationLog.AddProcessLogIntegration("PTZHandoff  serverEntity.Id :" + serverEntity.Id);

                                if (_nvrService.GetServerManager().TryGetServer(serverEntity.Id, out server))
                                {
                                    var request = new QL.Communication.Messaging.Messages.PtzGoToPresetRequest
                                    {
                                        SourceId     = new Guid(strCamGuid), //PTX Camera Guid
                                        PresetNumber = (byte)nPresetNum      //_associatedPtzDev.PresetNumber //amit 23 May 16
                                    };
                                    server.SendAndGetResponseAsObservable <QL.Communication.Messaging.Messages.EmptyMessage>(request).Subscribe(
                                        ok =>
                                    {
                                        InsertIntegrationLog.AddProcessLogIntegration("PTZHandoff else ok :");
                                    },
                                        error =>
                                    {
                                        InsertIntegrationLog.AddProcessLogIntegration("PTZHandoff else error :" + error);
                                    });
                                }
                            };
                        }
                    }
                    //
                }
            }
            catch (Exception ex)
            {
                InsertIntegrationLog.AddProcessLogIntegration("PTZHandoff Main catch Exception :" + ex.Message);
                // LogManager.GetCurrentClassLogger().Error(ex.Message);
            }
        }