Beispiel #1
0
 /// <summary>
 /// Handles capabilities received event
 /// </summary>
 /// <param name="capabilities">Received capabilities</param>
 void OnCapabilitiesReceived(Onvif.Capabilities capabilities)
 {
     if (capabilities.Media != null)
     {
         View.MediaAddress = capabilities.Media.XAddr;
     }
 }
 /// <summary>
 /// Handles capabilities received event
 /// </summary>
 /// <param name="capabilities">Received capabilities</param>
 void OnCapabilitiesReceived(Onvif.Capabilities capabilities)
 {
     View.PTZAddress   = string.Empty;
     View.MediaAddress = string.Empty;
     if (capabilities.PTZ != null)
     {
         View.PTZAddress = capabilities.PTZ.XAddr;
     }
     if (capabilities.Media != null)
     {
         View.MediaAddress = capabilities.Media.XAddr;
     }
 }
        /// <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
                {
                    Onvif.Capabilities capabilities = deviceClient.GetCapabilitiesSync(new Onvif.CapabilityCategory[] { Onvif.CapabilityCategory.PTZ });
                    if (capabilities.PTZ != null)
                    {
                        string ptzAddress            = capabilities.PTZ.XAddr;
                        PTZServiceProvider ptzClient = new PTZServiceProvider(ptzAddress, env.Timeouts.Message);
                        Onvif.PTZNode[] nodes        = ptzClient.GetNodes();
                        if ((nodes != null) && (nodes.Length > 0))
                        {
                            View.SetPTZNodes(nodes);
                        }
                        else
                        {
                            throw new Exception("No PTZ nodes returned by device");
                        }
                    }
                    else
                    {
                        throw new Exception("Device does not support PTZ service");
                    }
                }
                catch (System.Exception ex)
                {
                    View.ShowError(ex);
                }
                finally
                {
                    ReportOperationCompleted();
                }
            })));

            thread.CurrentUICulture = System.Globalization.CultureInfo.InvariantCulture;
            thread.Start();
        }
Beispiel #4
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();
        }
Beispiel #5
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();
        }
Beispiel #6
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();
        }
Beispiel #7
0
        protected TestTool.Proxies.Onvif.Capabilities GetCapabilities(CapabilityCategory[] categories, string stepName)
        {
            TestTool.Proxies.Onvif.Capabilities capabilities = null;

            bool retry = false;

            BeginStep("GetCapabilities (no credentials supplied)");
            try
            {
                capabilities = Client.GetCapabilities(categories);
            }
            catch (HttpTransport.Interfaces.Exceptions.AccessDeniedException exc)
            {
                // digest authorization required
                _credentialsProvider.Security = Security.Digest;
                LogStepEvent("DUT requires Digest authentication");
                LogStepEvent("Warning: GetCapabilities should not require authentication");
                retry = true;
            }
            catch (FaultException exc)
            {
                LogFault(exc);
                if (IsAccessDeniedFault(exc))
                {
                    // WS-username quthentication required
                    _credentialsProvider.Security = Security.WS;
                    LogStepEvent("DUT requires WS-UsernameToken authentication");
                    LogStepEvent("Warning: GetCapabilities should not require authentication");
                    retry = true;
                }
            }
            catch (Exception exc)
            {
                RethrowIfStop(exc);
                LogStepEvent(string.Format("GetCapabilities failed ({0})", exc.Message));
            }
            StepPassed();
            DoRequestDelay();

            // suppress any exceptions. Return null, if somethig goes wrong.
            if (retry)
            {
                BeginStep("Get Capabilities");
                try
                {
                    capabilities = Client.GetCapabilities(categories);
                }
                catch (FaultException exc)
                {
                    LogFault(exc);
                    LogStepEvent(string.Format("GetCapabilities failed ({0})", exc.Message));
                }
                catch (Exception exc)
                {
                    RethrowIfStop(exc);
                    LogStepEvent(string.Format("GetCapabilities failed ({0})", exc.Message));
                }

                StepPassed();
                DoRequestDelay();
            }

            return(capabilities);
        }