예제 #1
0
        public void QueryRecordings()
        {
            DiscoveredDevices         devices      = ContextController.GetDiscoveredDevices();
            string                    address      = devices != null ? devices.ServiceAddress : string.Empty;
            DeviceEnvironment         env          = ContextController.GetDeviceEnvironment();
            ManagementServiceProvider deviceClient = new ManagementServiceProvider(address, env.Timeouts.Message);

            ReportOperationStarted();
            Thread thread = new Thread(new ThreadStart(new Action(() =>
            {
                try
                {
                    DeviceServicesInfo info         = deviceClient.GetCapabilitiesDefineSecurity(new Onvif.CapabilityCategory[] { Onvif.CapabilityCategory.All });
                    Onvif.Capabilities capabilities = info.Capabilities;

                    string recordingControlAddress = string.Empty;

                    if (capabilities != null)
                    {
                        if (capabilities.Extension != null)
                        {
                            if (capabilities.Extension.Recording != null)
                            {
                                recordingControlAddress = capabilities.Extension.Recording.XAddr;
                            }
                        }
                    }

                    if (string.IsNullOrEmpty(recordingControlAddress))
                    {
                        if (info.Services != null)
                        {
                            Onvif.Service service = Tests.Common.CommonUtils.Extensions.FindService(
                                info.Services, OnvifService.RECORIDING);
                            if (service != null)
                            {
                                recordingControlAddress = service.XAddr;
                            }
                        }
                        else
                        {
                            throw new Exception("Unable to get service address");
                        }
                    }
                    if (string.IsNullOrEmpty(recordingControlAddress))
                    {
                        throw new Exception("Device does not support Recording service");
                    }

                    RecordingServiceProvider client =
                        new RecordingServiceProvider(recordingControlAddress, env.Timeouts.Message);
                    client.Security = deviceClient.Security;
                    List <Onvif.GetRecordingsResponseItem> recordings = client.GetRecordings();
                    List <string> tokens = recordings.Select(R => R.RecordingToken).ToList();
                    if ((tokens != null) && (tokens.Count > 0))
                    {
                        View.SettingsView.SetRecordings(tokens);
                    }
                    else
                    {
                        throw new Exception("No Recordings returned by device");
                    }
                }
                catch (System.Exception ex)
                {
                    View.ShowError(ex);
                }
                finally
                {
                    ReportOperationCompleted();
                }
            })));

            thread.CurrentUICulture = System.Globalization.CultureInfo.InvariantCulture;
            thread.Start();
        }
예제 #2
0
        public void QueryEventTopics()
        {
            DiscoveredDevices         devices      = ContextController.GetDiscoveredDevices();
            string                    address      = devices != null ? devices.ServiceAddress : string.Empty;
            DeviceEnvironment         env          = ContextController.GetDeviceEnvironment();
            ManagementServiceProvider deviceClient = new ManagementServiceProvider(address, env.Timeouts.Message);

            ReportOperationStarted();
            Thread thread = new Thread(new ThreadStart(new Action(() =>
            {
                try
                {
                    DeviceServicesInfo info         = deviceClient.GetCapabilitiesDefineSecurity(new Onvif.CapabilityCategory[] { Onvif.CapabilityCategory.Events });
                    Onvif.Capabilities capabilities = info.Capabilities;

                    string eventAddress = string.Empty;

                    if (capabilities != null)
                    {
                        if (capabilities.Events != null)
                        {
                            eventAddress = capabilities.Events.XAddr;
                        }
                        else
                        {
                            throw new Exception("Device does not support Events service");
                        }
                    }
                    else
                    {
                        if (info.Services != null)
                        {
                            Onvif.Service eventsService = Tests.Common.CommonUtils.Extensions.FindService(
                                info.Services, OnvifService.EVENTS);
                            if (eventsService != null)
                            {
                                eventAddress = eventsService.XAddr;
                            }
                            else
                            {
                                throw new Exception("Device does not support Events service");
                            }
                        }
                        else
                        {
                            throw new Exception("Unable to get service address");
                        }
                    }

                    EventsServiceProvider client = new EventsServiceProvider(eventAddress, env.Timeouts.Message);
                    client.Security = deviceClient.Security;
                    List <EventsTopicInfo> infos = client.GetTopics();
                    if ((infos != null) && (infos.Count > 0))
                    {
                        View.SettingsView.SetEventsTopic(infos);
                    }
                    else
                    {
                        throw new Exception("No Event Topics returned by device");
                    }
                }
                catch (System.Exception ex)
                {
                    View.ShowError(ex);
                }
                finally
                {
                    ReportOperationCompleted();
                }
            })));

            thread.CurrentUICulture = System.Globalization.CultureInfo.InvariantCulture;
            thread.Start();
        }
예제 #3
0
        public void QueryVideoSources()
        {
            DiscoveredDevices         devices      = ContextController.GetDiscoveredDevices();
            string                    address      = devices != null ? devices.ServiceAddress : string.Empty;
            DeviceEnvironment         env          = ContextController.GetDeviceEnvironment();
            ManagementServiceProvider deviceClient = new ManagementServiceProvider(address, env.Timeouts.Message);

            ReportOperationStarted();
            Thread thread = new Thread(new ThreadStart(new Action(() =>
            {
                try
                {
                    DeviceServicesInfo info         = deviceClient.GetCapabilitiesDefineSecurity(new Onvif.CapabilityCategory[] { Onvif.CapabilityCategory.Media });
                    Onvif.Capabilities capabilities = info.Capabilities;

                    string mediaAddress = string.Empty;

                    if (capabilities != null)
                    {
                        if (capabilities.Media != null)
                        {
                            mediaAddress = capabilities.Media.XAddr;
                        }
                        else
                        {
                            throw new Exception("Device does not support Media service");
                        }
                    }
                    else
                    {
                        if (info.Services != null)
                        {
                            Onvif.Service mediaService = Tests.Common.CommonUtils.Extensions.FindService(
                                info.Services, OnvifService.MEDIA);
                            if (mediaService != null)
                            {
                                mediaAddress = mediaService.XAddr;
                            }
                            else
                            {
                                throw new Exception("Device does not support Media service");
                            }
                        }
                        else
                        {
                            throw new Exception("Unable to get service address");
                        }
                    }

                    MediaServiceProvider client = new MediaServiceProvider(mediaAddress, env.Timeouts.Message);
                    client.Security             = deviceClient.Security;
                    Onvif.VideoSource[] sources = client.GetVideoSources();
                    if ((sources != null) && (sources.Length > 0))
                    {
                        View.SettingsView.SetVideoSources(sources);
                    }
                    else
                    {
                        throw new Exception("No Video Sources returned by device");
                    }
                }
                catch (System.Exception ex)
                {
                    View.ShowError(ex);
                }
                finally
                {
                    ReportOperationCompleted();
                }
            })));

            thread.CurrentUICulture = System.Globalization.CultureInfo.InvariantCulture;
            thread.Start();
        }
        /// <summary>
        /// Queries PTZ nodes
        /// </summary>
        public void GetPTZNodes()
        {
            DiscoveredDevices         devices      = ContextController.GetDiscoveredDevices();
            string                    address      = devices != null ? devices.ServiceAddress : string.Empty;
            DeviceEnvironment         env          = ContextController.GetDeviceEnvironment();
            ManagementServiceProvider deviceClient = new ManagementServiceProvider(address, env.Timeouts.Message);

            ReportOperationStarted();
            Thread thread = new Thread(new ThreadStart(new Action(() =>
            {
                try
                {
                    DeviceServicesInfo info         = deviceClient.GetCapabilitiesDefineSecurity(new Onvif.CapabilityCategory[] { Onvif.CapabilityCategory.PTZ });
                    Onvif.Capabilities capabilities = info.Capabilities;

                    string ptzAddress = string.Empty;

                    if (capabilities != null)
                    {
                        if (capabilities.PTZ != null)
                        {
                            ptzAddress = capabilities.PTZ.XAddr;
                        }
                        else
                        {
                            throw new Exception("Device does not support PTZ service");
                        }
                    }
                    else
                    {
                        if (info.Services != null)
                        {
                            Onvif.Service ptzService = Tests.Common.CommonUtils.Extensions.FindService(
                                info.Services, OnvifService.PTZ);
                            if (ptzService != null)
                            {
                                ptzAddress = ptzService.XAddr;
                            }
                            else
                            {
                                throw new Exception("Device does not support PTZ service");
                            }
                        }
                        else
                        {
                            throw new Exception("Unable to get service address");
                        }
                    }

                    PTZServiceProvider ptzClient = new PTZServiceProvider(ptzAddress, env.Timeouts.Message);

                    ptzClient.Security    = deviceClient.Security;
                    Onvif.PTZNode[] nodes = ptzClient.GetNodes();
                    if ((nodes != null) && (nodes.Length > 0))
                    {
                        View.SetPTZNodes(nodes);
                    }
                    else
                    {
                        throw new Exception("No PTZ nodes returned by device");
                    }
                }
                catch (System.Exception ex)
                {
                    View.ShowError(ex);
                }
                finally
                {
                    ReportOperationCompleted();
                }
            })));

            thread.CurrentUICulture = System.Globalization.CultureInfo.InvariantCulture;
            thread.Start();
        }