Ejemplo n.º 1
0
        // Take name of XPCO Management Server from command line or use a hardcoded default.
        // This is the only value you must change to modify this to run on your site.

        static void Main(string[] args)
        {
            VideoOS.Platform.SDK.Environment.Initialize();

            string hostManagementService = "http://localhost";

            if (args.GetLength(0) > 0)
            {
                hostManagementService = args[0];
            }
            if (hostManagementService.StartsWith("http://") == false)
            {
                hostManagementService = "http://" + hostManagementService;
            }

            Uri uri = new UriBuilder(hostManagementService).Uri;

            VideoOS.Platform.SDK.Environment.AddServer(uri, CredentialCache.DefaultNetworkCredentials);
            try
            {
                VideoOS.Platform.SDK.Environment.Login(uri, IntegrationId, IntegrationName, Version, ManufacturerName);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Could not logon to management server: " + ex.Message);
                Console.WriteLine("");
                Console.WriteLine("Press any key");
                Console.ReadKey();
                return;
            }

            if (EnvironmentManager.Instance.CurrentSite.ServerId.ServerType != ServerId.CorporateManagementServerType)
            {
                Console.WriteLine("{0} is not an XProtect Corporate Management Server", hostManagementService);
                Console.WriteLine("");
                Console.WriteLine("Press any key");
                Console.ReadKey();
                return;
            }

            VideoOS.Platform.Login.LoginSettings loginSettings =
                VideoOS.Platform.Login.LoginSettingsCache.GetLoginSettings(hostManagementService);
            Console.WriteLine("... Token=" + loginSettings.Token);

            // Limit this to 1 recording server. Here I select the last one.
            // If there are XPE servers acting as recording servers, you must filter them away by having an explicit list
            // With XPE, you don't use the Status API, but the Central API". See the sample "CentralDemo".

            Item        serverItem  = Configuration.Instance.GetItem(EnvironmentManager.Instance.CurrentSite);
            List <Item> serverItems = serverItem.GetChildren();
            Item        recorder    = null;

            foreach (Item item in serverItems)
            {
                if (item.FQID.Kind == Kind.Server && item.FQID.ServerId.ServerType == ServerId.CorporateRecordingServerType)
                {
                    recorder = item;
                }
            }
            List <Item> allItems = recorder.GetChildren();

            //string hostRecorderService = recorder.Properties["Address"];
            VideoOS.Platform.SDK.Proxy.Status2.RecorderStatusService2 client = new VideoOS.Platform.SDK.Proxy.Status2.RecorderStatusService2(recorder.FQID.ServerId.Uri);

            // Start a status session with a recording server
            Guid sessionId = client.StartStatusSession(loginSettings.Token);

            // Set up to subscribe to all the user defined events on that recording server
            List <Guid> subscribeTheseEventIds  = new List <Guid>();
            List <Guid> subscribeTheseDeviceIds = new List <Guid>();

            List <Item> allEvents = FindAllEvents(allItems, serverItem.FQID.ObjectId);

            foreach (Item item in allEvents)
            {
                subscribeTheseEventIds.Add(item.FQID.ObjectId);
                subscribeTheseDeviceIds.Add(item.FQID.ObjectId);
            }
            allEvents = FindAllEvents(serverItems, serverItem.FQID.ObjectId);
            foreach (Item item in allEvents)
            {
                subscribeTheseEventIds.Add(item.FQID.ObjectId);
                subscribeTheseDeviceIds.Add(item.FQID.ObjectId);
            }

            // Set up to subscribe to almost all built-in events
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.ArchiveDiskAvailable);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.ArchiveDiskUnavailable);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.CommunicationError);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.CommunicationStarted);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.CommunicationStopped);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.DatabaseDiskAvailable);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.DatabaseDiskFull);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.DatabaseDiskUnavailable);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.DatabaseRepair);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.DeviceSettingsChanged);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.DeviceSettingsChangedError);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.FeedOverflowStarted);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.FeedOverflowStopped);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.HardwareSettingsChanged);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.HardwareSettingsChangedError);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.InputActivated);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.InputChanged);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.InputDeactivated);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.LiveClientFeedRequested);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.LiveClientFeedTerminated);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.MotionStarted);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.MotionStopped);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.OutputActivated);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.OutputChanged);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.OutputDeactivated);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.PTZManualSessionStarted);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.PTZManualSessionStopped);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.RecordingStarted);
            subscribeTheseEventIds.Add(BuiltInEventTypes.EventIDs.RecordingStopped);

            Guid[] eventArray = new Guid[subscribeTheseEventIds.Count];
            subscribeTheseEventIds.CopyTo(eventArray);

            // Now, do the actual event subscription
            // Every time an event occurs, you will be informed next time you query the status
            client.SubscribeEventStatus(loginSettings.Token, sessionId, eventArray);

            // Subscribe to configuration changes
            // Every time a change occurs, you will be informed next time you query the status
            client.SubscribeConfigurationStatus(loginSettings.Token, sessionId, true);

            // Set up to subscribe to device descriptions
            // First time you query the status, you will get information on all devices subsribed to
            // Subsequent queries will return changed values only
            // You may subscribe to a device once again to force information to be returned on that device
            Dictionary <Guid, Item> allCameras = new Dictionary <Guid, Item>();

            FindAllCameras(allItems, recorder.FQID.ServerId.Id, allCameras);
            foreach (Item item in allCameras.Values)
            {
                subscribeTheseDeviceIds.Add(item.FQID.ObjectId);
            }

            // Now, do the actual device subscription
            client.SubscribeDeviceStatus(loginSettings.Token, sessionId, subscribeTheseDeviceIds.ToArray());

            // Now we are ready to enter a loop querying for status information with 2 seconds sleep after each
            int count = 30;
            int intr  = 2000;

            while (count > 0)
            {
                count--;

                Status stats = client.GetStatus(loginSettings.Token, sessionId, 5000);

                foreach (EventStatus eStat in stats.EventStatusArray)
                {
                    Console.WriteLine(eStat.Time.ToLocalTime().ToString() + " Event " + eStat.EventId.ToString() + " guid " +
                                      eStat.EventId.ToString() +
                                      " Source " + eStat.SourceId.ToString());
                    if (eStat.Metadata != null)
                    {
                        foreach (KeyValue keyValue in eStat.Metadata)
                        {
                            Console.WriteLine("    ---> Metadata:  " + keyValue.Key + " = " + keyValue.Value);
                        }
                    }
                }
                if (stats.ConfigurationChangedStatus != null)
                {
                    ConfigurationChangedStatus eStat = stats.ConfigurationChangedStatus;
                    Console.WriteLine(eStat.Time.ToLocalTime().ToString() + " Configuration change ");
                }

                foreach (SpeakerDeviceStatus eStat in stats.SpeakerDeviceStatusArray)
                {
                    Console.WriteLine(eStat.Time.ToLocalTime().ToString() + " Speaker " + eStat.DeviceId.ToString() +
                                      " Started " + eStat.Started.ToString());
                }

                foreach (OutputDeviceStatus eStat in stats.OutputDeviceStatusArray)
                {
                    Console.WriteLine(eStat.Time.ToLocalTime().ToString() + " Output " + eStat.DeviceId.ToString() +
                                      " Started " + eStat.Started.ToString() +
                                      " State " + eStat.State.ToString());
                }

                foreach (CameraDeviceStatus eStat in stats.CameraDeviceStatusArray)
                {
                    Console.WriteLine(eStat.Time.ToLocalTime().ToString() + " Camera " + allCameras[eStat.DeviceId].Name +
                                      " Started " + eStat.Started.ToString() +
                                      " Recording " + eStat.Recording.ToString());
                }

                foreach (MicrophoneDeviceStatus eStat in stats.MicrophoneDeviceStatusArray)
                {
                    Console.WriteLine(eStat.Time.ToLocalTime().ToString() + " Microphone " + eStat.DeviceId.ToString() +
                                      " Started " + eStat.Started.ToString() +
                                      " Error " + eStat.Error.ToString());
                }

                foreach (InputDeviceStatus eStat in stats.InputDeviceStatusArray)
                {
                    Console.WriteLine(eStat.Time.ToLocalTime().ToString() + " Input " + eStat.DeviceId.ToString() +
                                      " Started " + eStat.Started.ToString());
                }

                Console.WriteLine("{0} queries remaining", count);
                Thread.Sleep(intr);
            }
            Console.WriteLine("");
            Console.WriteLine("Press any key");
            Console.ReadKey();

            // Stop the status session.
            client.StopStatusSession(loginSettings.Token, sessionId);

            // The token will time out automatically a little later.
            VideoOS.Platform.SDK.Environment.RemoveAllServers();
        }
Ejemplo n.º 2
0
        static Item GetRecordingServer(string hostname)
        {
            VideoOS.Platform.SDK.Environment.Initialize();

            string hostManagementService = hostname;

            if (hostManagementService.StartsWith("http://") == false)
            {
                hostManagementService = "http://" + hostManagementService;
            }

            Uri uri = new UriBuilder(hostManagementService).Uri;

            VideoOS.Platform.SDK.Environment.AddServer(uri, CredentialCache.DefaultNetworkCredentials);

            // If you need different credentials than the user that runs the sample, please comment out the line above and
            // uncomment the line below and set the appropriate username and password.
            //VideoOS.Platform.SDK.Environment.AddServer(uri, new NetworkCredential("username", "password"));

            try
            {
                VideoOS.Platform.SDK.Environment.Login(uri, IntegrationId, IntegrationName, Version, ManufacturerName);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Could not logon to management server: " + ex.Message);
                Console.WriteLine("");
                Console.WriteLine("Press any key");
                Console.ReadKey();
                throw new ApplicationException("Cannot connect");
            }

            if (EnvironmentManager.Instance.CurrentSite.ServerId.ServerType != ServerId.CorporateManagementServerType)
            {
                Console.WriteLine("{0} is not an XProtect Corporate Management Server", hostManagementService);
                Console.WriteLine("");
                Console.WriteLine("Press any key");
                Console.ReadKey();
                throw new ApplicationException("Wrong servertype");
            }

            VideoOS.Platform.Login.LoginSettings loginSettings =
                VideoOS.Platform.Login.LoginSettingsCache.GetLoginSettings(hostManagementService);
            Console.WriteLine("... Token=" + loginSettings.Token);

            // Limit this to 1 recording server. Here I select the last one.
            // If there are XPE servers acting as recording servers, you must filter them away by having an explicit list
            // With XPE, you don't use the Status API, but the Central API". See the sample "CentralDemo".
            Item        serverItem  = Configuration.Instance.GetItem(EnvironmentManager.Instance.CurrentSite);
            List <Item> serverItems = serverItem.GetChildren();
            Item        recorder    = null;

            foreach (Item item in serverItems)
            {
                if (item.FQID.Kind == Kind.Server && item.FQID.ServerId.ServerType == ServerId.CorporateRecordingServerType)
                {
                    recorder = item;
                }
            }

            return(recorder);
        }