예제 #1
0
        /// <summary>
        /// Count camera number in Cayuga system
        /// </summary>
        private int CountCameras()
        {
            try
            {
                SDKVideoManager   videoManager = SDKVideoManagerFactory.GetManager();
                SDKEntity         root         = videoManager.GetRootEntity(ConnectedInstallationID);
                Stack <SDKEntity> searchStack  = new Stack <SDKEntity>();
                searchStack.Push(root);
                List <SDKEntity> videoSources = new List <SDKEntity>();

                while (searchStack.Count > 0)
                {
                    SDKEntity currentEntity = searchStack.Pop();
                    if (videoManager.IsSubType(SDKEntityType.VideoSource, currentEntity.EntityType))
                    {
                        videoSources.Add(currentEntity);
                    }
                    foreach (long childID in currentEntity.ChildrenIDs)
                    {
                        searchStack.Push(videoManager.GetEntity(currentEntity.InstallationID, childID));
                    }
                }
                logger.Info("Camera number in the system is: " + videoSources.Count);

                return(videoSources.Count);
            }
            catch (Exception ex)
            {
                this.LogUI(ex.Message);

                logger.Error(ex.Message);

                return(-1);
            }
        }
예제 #2
0
        /// <summary>
        /// Video management events from Cayuga SDK
        /// </summary>
        private void OnvideoManager_VideoManagement(SDKEvent evt)
        {
            SDKVideoManager videoManager = SDKVideoManagerFactory.GetManager();
            var             timestamp    = evt.TimeStamp;
            var             sourceID     = evt.SourceID;
            var             entity       = videoManager.GetEntity(MainWindow.ConnectedInstallationID, sourceID);
            var             cause        = videoManager.GetEntity(MainWindow.ConnectedInstallationID, evt.CauseID);

            if (evt.EventType == SDKEventType.CMVideoSourceNotAvailable) //VideoLoss, only defined for "cable not connected"
            {
                this.SendAlarm("1", timestamp, entity.Name, "Video Loss");
                MainWindow.NotReachableCameras.Add(sourceID);
            }
            else if (evt.EventType == SDKEventType.AlarmRecordingStart)
            {
                this.SendAlarm("9", timestamp, entity.Name, "Alarm Recording Start");
            }
            else if (evt.EventType == SDKEventType.AlarmRecordingStop)
            {
                this.SendAlarm("10", timestamp, entity.Name, "Alarm Recording Stop");
            }
            else if (evt.EventType == SDKEventType.AlarmTriggered)
            {
                this.SendAlarm("7", timestamp, entity.Name, "Alarm scenario started");
            }
            else if (evt.EventType == SDKEventType.EntityStatusChanged)
            {
                if (videoManager.IsSubType(SDKEntityType.VideoSource, entity.EntityType) &&
                    entity.Status == 0 &&
                    MainWindow.NotReachableCameras.Contains(sourceID))
                {
                    this.SendAlarm("2", timestamp, entity.Name, "Video Reconnect");
                    MainWindow.NotReachableCameras.Remove(sourceID);
                }
                else if (entity.EntityType == SDKEntityType.RuntimeDM && entity.Status == 0 && DMandMDSwithFailure.Contains(sourceID)) //only when DM was offline at first
                {
                    this.SendAlarm("5", timestamp, entity.Name, "Recording Server Online (DM)");
                    MainWindow.DMandMDSwithFailure.Remove(sourceID);
                }
                else if (entity.EntityType == SDKEntityType.RuntimeMDB && entity.Status == 0 && DMandMDSwithFailure.Contains(sourceID)) //only when DM was offline at first
                {
                    this.SendAlarm("5", timestamp, entity.Name, "Recording Server Online (MDS)");
                    MainWindow.DMandMDSwithFailure.Remove(sourceID);
                }
            }
            else if (evt.EventType == SDKEventType.MDBZoneAlmostFull)
            {
                this.SendAlarm("3", timestamp, entity.Name, "MDS zone is almost full");
            }
            else if (evt.EventType == SDKEventType.REInvalidStatus || evt.EventType == SDKEventType.CMCannotStart || evt.EventType == SDKEventType.EntityDeregistered || evt.EventType == SDKEventType.MDBCannotStartMDS)
            {
                if (entity.EntityType == SDKEntityType.RuntimeDM && !DMandMDSwithFailure.Contains(sourceID))
                {
                    this.SendAlarm("6", timestamp, entity.Name, "Recording Server Offline (DM)");
                    MainWindow.DMandMDSwithFailure.Add(sourceID);
                }
                else if (entity.EntityType == SDKEntityType.RuntimeMDB && !DMandMDSwithFailure.Contains(sourceID))
                {
                    this.SendAlarm("6", timestamp, entity.Name, "Recording Server Offline (MDS)");
                    MainWindow.DMandMDSwithFailure.Add(sourceID);
                }
            }
        }
예제 #3
0
        /// (summary)
        /// Write a line to the log file.  For simplicity, assume no race conditions.
        /// Modified to also display the line in the GUI if it is running.
        /// (/summary)
        /// (param name="state")(/param)
        private void ConnectToCayuga()
        {
            try
            {
                logger.Info("Connecting to Cayuga server.");

                //Login
                SDKConnectionInfo connectionInfo = new SDKConnectionInfo();

                connectionInfo.Host     = MainWindow.hostIP;
                connectionInfo.Port     = MainWindow.hostPort;
                connectionInfo.UserName = MainWindow.username;
                connectionInfo.Password = MainWindow.password;
                connectionInfo.Profile  = MainWindow.profile;

                SDKVideoManager videoManager = SDKVideoManagerFactory.GetManager();
                MainWindow.InstallationIDResult = videoManager.Connect(connectionInfo);

                if (MainWindow.InstallationIDResult.Result == SDKErrorCode.OK)
                {
                    MainWindow.isConnectedToCayuga = true;

                    Thread startConnectorThread = new Thread(() =>
                    {
                        StartConnector();
                    });
                    startConnectorThread.Start();

                    if (Dispatcher.CheckAccess())
                    {
                        btnReconnect.IsEnabled       = false;
                        btnCheckVideoguard.IsEnabled = true;
                    }
                    else
                    {
                        Dispatcher.Invoke(() => { btnReconnect.IsEnabled = false; btnCheckVideoguard.IsEnabled = true; });
                    }

                    MainWindow.ConnectedInstallationID = MainWindow.InstallationIDResult.ReturnValue;
                    videoManager.VideoManagementEvent += OnvideoManager_VideoManagement;
                    videoManager.Disconnected         += OnDisconnectToCayugaServer;
                    videoManager.Reconnected          += OnReconnectToCayugaServer;
                    MainWindow.installationName        = videoManager.GetShortInstallationName(ConnectedInstallationID);

                    if (Dispatcher.CheckAccess())
                    {
                        labelStatusCayuga.Content    = "Connected";
                        labelStatusCayuga.Foreground = Brushes.Green;
                    }
                    else
                    {
                        Dispatcher.Invoke(() => { labelStatusCayuga.Content = "Connected"; labelStatusCayuga.Foreground = Brushes.Green; });
                    }

                    this.LogUI("Successfully connected to Cayuga server.");

                    logger.Info("Successfully connected to Cayuga server.");
                }
                else
                {
                    MainWindow.isConnectedToCayuga = false;

                    if (Dispatcher.CheckAccess())
                    {
                        labelStatusCayuga.Content    = "Not Connected";
                        labelStatusCayuga.Foreground = Brushes.Red;
                    }
                    else
                    {
                        Dispatcher.Invoke(() => { labelStatusCayuga.Content = "Not Connected"; labelStatusCayuga.Foreground = Brushes.Red; });
                    }

                    if (Dispatcher.CheckAccess())
                    {
                        btnReconnect.IsEnabled       = true;
                        btnCheckVideoguard.IsEnabled = false;
                    }
                    else
                    {
                        Dispatcher.Invoke(() => { btnReconnect.IsEnabled = true; btnCheckVideoguard.IsEnabled = false; });
                    }

                    this.LogUI("Cannot connect to Cayuga server. Problem: " + MainWindow.InstallationIDResult.Result);
                    this.LogUI("Connection problem. Check Connector configuration and if the Cayuga Server is running.");

                    logger.Warn("Cannot connect to Cayuga server. Problem: " + MainWindow.InstallationIDResult.Result);
                    logger.Warn("Connection problem. Check Connector configuration and if the Cayuga Server is running.");
                }
            }
            catch (Exception ex)
            {
                this.LogUI(ex.Message);

                logger.Error(ex.Message);
            }
        }