Пример #1
0
        private static void EventFiredHandler(object sender, EventFiredEventArgs e)
        {
            string       sourceName = "Name-not-found";
            SearchResult result;
            List <Item>  anyItem = Configuration.Instance.GetItemsBySearch(e.SourceId.ToString(), 10, 5, out result);

            if (anyItem.Count == 1)
            {
                sourceName = anyItem[0].Name;
            }

            Console.WriteLine("{0} - Event {1} fired from source {2}",
                              e.Time.ToLocalTime(), KnownStatusEvents.GetEventName(e.EventId), sourceName);
            foreach (Guid id in e.DeviceIds)
            {
                String cameraName = "";
                Item   camera;
                if (_cameras.TryGetValue(id, out camera))
                {
                    cameraName = camera.Name;
                }
                Console.WriteLine(" --- > " + id + "  - " + cameraName);
            }
            foreach (string k in e.Metadata.Keys)
            {
                Console.WriteLine(" --- > Metadata: " + k + " = " + e.Metadata[k]);
            }
        }
Пример #2
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)
        {
            string server = "http://localhost";

            if (args.Length > 0)
            {
                server = args[0];
            }

            var recordingServer   = GetRecordingServer(server);
            var recordingServerId = recordingServer.FQID;

            // Find all cameras connected to the Recording Server
            List <Item> allItems = recordingServer.GetChildren();

            _cameras = FindAllCameras(allItems, recordingServerId.ServerId.Id).ToDictionary(item => item.FQID.ObjectId);
            ISet <Guid> subsribedCameras = new HashSet <Guid>(_cameras.Keys);

            SearchResult result;
            List <Item>  allUserDefinedEvents = Configuration.Instance.GetItemsBySearch(Kind.TriggerEvent.ToString(), 10, 5, out result);

            List <Item> allHardware = Configuration.Instance.GetItemsBySearch(Kind.Hardware.ToString(), 10, 5, out result);

            foreach (var h in allHardware)
            {
                if (h.FQID.FolderType == FolderType.No)
                {
                    _hardware.Add(h.FQID.ObjectId, h);
                }
            }
            // Subscribe to a set of known events
            ISet <Guid> subscribedEvents = new HashSet <Guid>(KnownStatusEvents.GetAllEvents());

            foreach (Item udevent in allUserDefinedEvents)
            {
                subscribedEvents.Add(udevent.FQID.ObjectId);
            }

            ISet <Guid> subsribedHardware = new HashSet <Guid>();

            foreach (var hw in _hardware.Values)
            {
                subsribedHardware.Add(hw.FQID.ObjectId);
            }
            // Start the Status session with the Recording Server. The StatusSession class does more than just act as a proxy,
            // as it also handles reconnects and dropped sessions. The Dispose method is used to stop the session with the
            // Recording Server, so it should be called when the session is finished either explicitly or in a using-statement.
            Console.WriteLine("Press a key to terminate the sample");
            using (var statusApi = new StatusSession(recordingServer))
            {
                // Lets get hold of all events, including the dynamic ones defined by drivers
                foreach (var ev in statusApi.GetAllStatusEventMessages())
                {
                    subscribedEvents.Add(ev.Id);
                }
                // Listen for changes to the connection state
                statusApi.ConnectionStateChanged += ConnectionStateChangedHandler;

                // Listen to changes to the states of cameras
                statusApi.CameraStateChanged   += CameraStateChangedHandler;
                statusApi.HardwareStateChanged += StatusApi_HardwareStateChanged;
                //statusApi.InputDeviceStateChanged += ...
                //statusApi.MicrophoneStateChanged += ...

                // Listen to events
                statusApi.EventFired += EventFiredHandler;

                // Start the session with the Recording Server
                statusApi.StartSession();

                // Subscribe to events
                statusApi.SetSubscribedEvents(subscribedEvents);

                // Subscribe to camera found
                statusApi.SetSubscribedDevicesForStateChanges(subsribedCameras);

                // Alternatively, it is possible to subscribe to all devices of a specific kind.
                //statusApi.AddSubscriptionsToDevicesOfKind(Kind.Camera);

                // Subscribe to all hardware
                statusApi.SetSubscribedHardwareForStateChanges(subsribedHardware);

                // Wait for events to arrive and stop the program when the user presses a key.
                Console.ReadKey();

                statusApi.EventFired             -= EventFiredHandler;
                statusApi.CameraStateChanged     -= CameraStateChangedHandler;
                statusApi.ConnectionStateChanged -= ConnectionStateChangedHandler;
            }

            Console.WriteLine("Terminating main normally...");
        }
Пример #3
0
 private static void EventFiredHandler(object sender, EventFiredEventArgs e)
 {
     Console.WriteLine(@"{0} - Event {1} fired from source {2}", e.Time.ToLocalTime(), KnownStatusEvents.GetEventName(e.EventId), e.SourceId);
 }