Exemplo n.º 1
0
        /// <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.SettingsView.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();
        }