Ejemplo n.º 1
0
        /// <summary>
        /// Initializes (and returns) event service address (using GetCapabilities method).
        /// </summary>
        /// <returns></returns>
        protected string GetEventServiceAddress()
        {
            string address = string.Empty;

            RunStep(() =>
            {
                HttpTransport.HttpBinding binding =
                    (HttpTransport.HttpBinding)CreateBinding(true,
                                                             new IChannelController[] { new SoapValidator(DeviceManagementSchemasSet.GetInstance()) });

                DeviceClient device = new DeviceClient(binding, new EndpointAddress(_cameraAddress));
                AddSecurityBehaviour(device.Endpoint);
                Capabilities capabilities = device.GetCapabilities(new CapabilityCategory[] { CapabilityCategory.Events });
                DoRequestDelay();

                if (capabilities.Events != null)
                {
                    address = capabilities.Events.XAddr;
                }
                if (string.IsNullOrEmpty(address))
                {
                    throw new DutPropertiesException("Event capabilities not found");
                }
                Uri uri;
                if (!Uri.TryCreate(address, UriKind.Absolute, out uri))
                {
                    throw new AssertException(string.Format("Event service address [{0}] is invalid", address));
                }
            }, "Get Event service address");
            _eventServiceAddress = address;
            return(address);
        }
Ejemplo n.º 2
0
        void SendBrokenMessage()
        {
            MessageSpoiler behaviour = new MessageSpoiler();

            Dictionary <string, string> namespaces = new Dictionary <string, string>();

            namespaces.Add("s", "http://www.w3.org/2003/05/soap-envelope");
            namespaces.Add("onvif", "http://www.onvif.org/ver10/device/wsdl");

            Dictionary <string, string> replacements = new Dictionary <string, string>();

            replacements.Add("/s:Envelope/s:Body/onvif:GetCapabilities/onvif:Category", "XYZ");

            behaviour.Namespaces     = namespaces;
            behaviour.NodesToReplace = replacements;

            try
            {
                DeviceClient client = new DeviceClient(new HttpBinding(new IChannelController[] { _listener, behaviour }),
                                                       new EndpointAddress(tbAddress.Text));

                client.InnerChannel.OperationTimeout = new TimeSpan(0, 0, 0, 0, int.Parse(tbTimeout.Text));

                client.GetCapabilities(new CapabilityCategory[] { CapabilityCategory.All });
            }
            catch (Exception exc)
            {
                BeginInvoke(new Action(() => { ReportError(exc); }));
            }
            finally
            {
                StopAnimation();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns DUT's imaging service address
        /// </summary>
        /// <returns>Imaging service url</returns>
        protected string GetImagingServiceAdderss()
        {
            string address = string.Empty;

            RunStep(() =>
            {
                Capabilities capabilities =
                    DeviceClient.GetCapabilities(
                        new CapabilityCategory[]
                {
                    CapabilityCategory.Imaging
                });

                DoRequestDelay();

                if (capabilities.Imaging != null)
                {
                    address = capabilities.Imaging.XAddr;
                    LogStepEvent(address);
                }
                if (string.IsNullOrEmpty(address))
                {
                    throw new AssertException("Imaging capabilities not found");
                }
            }, "Get imaging service address");
            return(address);
        }
Ejemplo n.º 4
0
        public static Capabilities GetCapabilities(BaseOnvifTest test, DeviceClient client, CapabilityCategory[] categories)
        {
            Capabilities capabilities = null;

            RunStep(test, () => { capabilities = client.GetCapabilities(categories); }, "Get capabilities");
            DoRequestDelay(test);
            return(capabilities);
        }
Ejemplo n.º 5
0
        protected Capabilities GetCapabilities(CapabilityCategory[] categories, string stepName)
        {
            Capabilities capabilities = null;

            RunStep(() => { capabilities = DeviceClient.GetCapabilities(categories); }, stepName);
            DoRequestDelay();
            return(capabilities);
        }
Ejemplo n.º 6
0
        public static string GetServiceAddress(this DeviceClient device,
                                               CapabilityCategory category,
                                               Func <Capabilities, string> addressSelector)
        {
            string       address      = string.Empty;
            Capabilities capabilities = device.GetCapabilities(new CapabilityCategory[] { category });

            return(addressSelector(capabilities));
        }
Ejemplo n.º 7
0
        internal DeviceService(Camera camera, string serviceUrl) : base(camera)
        {
            deviceClient = new DeviceClient(ServiceFactory.CreateServiceBinding(), ServiceFactory.CreateEndpoint(serviceUrl));
            deviceClient.Endpoint.Behaviors.Add(camera.PasswordDigestBehavior);
            deviceClient.ClientCredentials.UserName.UserName = camera.PasswordDigestBehavior.Username;
            deviceClient.ClientCredentials.UserName.Password = camera.PasswordDigestBehavior.Password;

            // load capabilities for the service
            var capabilities = deviceClient.GetCapabilities(new CapabilityCategory[] { CapabilityCategory.Device });
            // TODO: parse capabilities
        }
Ejemplo n.º 8
0
        public static void MuestraInfo(string uri)
        {
            System.DateTime UTCTime = System.DateTime.UtcNow;

            Console.Write(string.Format("Client UTC Time: {0}", UTCTime.ToString("HH:mm:ss")));

            HttpTransportBindingElement httpTransport = new HttpTransportBindingElement();
            var httpTransportBinding = new HttpTransportBindingElement {
                AuthenticationScheme = AuthenticationSchemes.Digest
            };
            var textMessageEncodingBinding = new TextMessageEncodingBindingElement {
                MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None)
            };
            var customBinding = new CustomBinding(textMessageEncodingBinding, httpTransportBinding);
            TextMessageEncodingBindingElement textMessageEncoding = new TextMessageEncodingBindingElement(MessageVersion.Soap12, Encoding.UTF8);

            EndpointAddress         serviceAddress = new EndpointAddress(uri);
            ChannelFactory <Device> channelFactory = new ChannelFactory <Device>(customBinding, serviceAddress);

            var passwordDigestBehavior = new PasswordDigestBehavior("julian", "julian");

            channelFactory.Endpoint.Behaviors.Remove(typeof(ClientCredentials));
            channelFactory.Endpoint.Behaviors.Add(passwordDigestBehavior);

            var deviceClient = new DeviceClient(customBinding, serviceAddress);

            deviceClient.Endpoint.Behaviors.Add(passwordDigestBehavior);

            var unitTime = deviceClient.GetSystemDateAndTime();

            Console.Write((string.Format(" Camera UTC Time: {0}:{1}:{2}", unitTime.UTCDateTime.Time.Hour, unitTime.UTCDateTime.Time.Minute, unitTime.UTCDateTime.Time.Second)));

            ServiceReference1.CapabilityCategory[] cc = new ServiceReference1.CapabilityCategory[100];
            deviceClient.GetCapabilities(cc);

            Console.Write(" GetHostname: " + deviceClient.GetHostname().Name);
            Console.Write(" GetWsdlUrl: " + deviceClient.GetWsdlUrl());


            string model, firmwareVersion, serialNumber, hardwareId;

            deviceClient.GetDeviceInformation(out model, out firmwareVersion, out serialNumber, out hardwareId);
            Console.Write(" Model: " + model);
            Console.Write(" firmwareVersion: " + firmwareVersion);
            Console.Write(" serialNumber: " + serialNumber);
            Console.WriteLine("hardwareId: " + hardwareId + "\n\n");
        }
        public static Capabilities GetCapabilities(Structures set)
        {
            var messageElement = new TextMessageEncodingBindingElement();

            messageElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None);
            HttpTransportBindingElement httpBinding = new HttpTransportBindingElement();

            httpBinding.AuthenticationScheme = AuthenticationSchemes.Basic;
            CustomBinding   bind         = new CustomBinding(messageElement, httpBinding);
            EndpointAddress mediaAddress = new EndpointAddress(set.GetONVIF + "/onvif/Device");
            DeviceClient    client       = new DeviceClient(bind, mediaAddress);

            client.ClientCredentials.UserName.UserName = set.Login;
            client.ClientCredentials.UserName.Password = set.Password;

            var t = client.GetCapabilities(new CapabilityCategory[] { CapabilityCategory.All });

            return(t);
        }
Ejemplo n.º 10
0
        public static void MuestraInfoTest(string uri)
        {
            System.DateTime UTCTime = System.DateTime.UtcNow;

            Console.Write(string.Format("Client UTC Time: {0}", UTCTime.ToString("HH:mm:ss")));

            HttpTransportBindingElement httpTransport = new HttpTransportBindingElement();
            var httpTransportBinding = new HttpTransportBindingElement {
                AuthenticationScheme = AuthenticationSchemes.Anonymous
            };
            var textMessageEncodingBinding = new TextMessageEncodingBindingElement {
                MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None)
            };
            var customBinding = new CustomBinding(textMessageEncodingBinding, httpTransportBinding);

            EndpointAddress serviceAddress = new EndpointAddress(uri);

            var deviceClient = new DeviceClient(customBinding, serviceAddress);

            Console.Write(" GetHostname: " + deviceClient.GetHostname().Name);
            var unitTime = deviceClient.GetSystemDateAndTime();

            Console.Write((string.Format(" Camera UTC Time: {0}:{1}:{2}", unitTime.UTCDateTime.Time.Hour, unitTime.UTCDateTime.Time.Minute, unitTime.UTCDateTime.Time.Second)));

            CapabilityCategory[] cc = new CapabilityCategory[100];
            deviceClient.GetCapabilities(cc);

            Console.Write(" GetHostname: " + deviceClient.GetHostname().Name);
            Console.Write(" GetWsdlUrl: " + deviceClient.GetWsdlUrl());


            string model, firmwareVersion, serialNumber, hardwareId;

            deviceClient.GetDeviceInformation(out model, out firmwareVersion, out serialNumber, out hardwareId);
            Console.Write(" Model: " + model);
            Console.Write(" firmwareVersion: " + firmwareVersion);
            Console.Write(" serialNumber: " + serialNumber);
            Console.WriteLine("hardwareId: " + hardwareId + "\n\n");
        }
Ejemplo n.º 11
0
        private void GetServices(DeviceClient client)
        {
            // GetCapabilities is now deprecated (as of v2.1) - replaced by GetServices (Older devices may still use)
            OnvifDeviceManagementServiceReference.Capabilities capabilities = client.GetCapabilities(new CapabilityCategory[] { CapabilityCategory.All });

            if (capabilities.Analytics != null)
            {
                lbxCapabilities.Items.Add("Analytics");
            }
            if (capabilities.Events != null)
            {
                lbxCapabilities.Items.Add("Events");
            }
            if (capabilities.Extension != null)
            {
                lbxCapabilities.Items.Add("Extension");
            }
            if (capabilities.Imaging != null)
            {
                lbxCapabilities.Items.Add("Imaging");
            }
            if (capabilities.Media != null)
            {
                lbxCapabilities.Items.Add("Media");
            }
            if (capabilities.PTZ != null)
            {
                lbxCapabilities.Items.Add("PTZ");
            }

            lbxCapabilities.Items.Add("");
            ServiceUris.Clear();

            Service[] svc = null;
            try
            {
                svc = client.GetServices(IncludeCapability: true);
            }
            catch
            {
                // Bosch Autodome 800 response can't be deserialized if IncludeCapability enabled
                // Ignore and try with IncludeCapability disabled
            }

            // Try with IncludeCapability disabled
            if (svc == null)
            {
                svc = client.GetServices(IncludeCapability: false); // Bosch Autodome 800 response can't be deserialized if IncludeCapability enabled
            }

            foreach (Service s in svc)
            {
                Console.WriteLine(s.XAddr + " " + " " + s.Namespace);  // Not present on Axis + s.Capabilities.NamespaceURI);
                lbxCapabilities.Items.Add(string.Format("{0}", s.Namespace));
                ServiceUris.Add(s.Namespace, s.XAddr);

                if (s.Capabilities != null)
                {
                    foreach (System.Xml.XmlNode x in s.Capabilities)
                    {
                        Console.WriteLine(string.Format("\t{0}", x.LocalName));
                        lbxCapabilities.Items.Add(string.Format("    {0}", x.LocalName));
                        if (x.Attributes.Count > 0)
                        {
                            foreach (System.Xml.XmlNode a in x.Attributes)
                            {
                                Console.WriteLine(string.Format("\t\t{0} = {1}", a.Name, a.Value));
                                lbxCapabilities.Items.Add(string.Format("        {0} = {1}", a.Name, a.Value));
                            }
                        }
                    }
                }
            }

            //DeviceServiceCapabilities dsc = client.GetServiceCapabilities();
        }
Ejemplo n.º 12
0
        public void GuaranteedNumberOfEncodersAndEncodingConfigurationOptionsConsistency()
        {
            RunTest(() =>
            {
                int?maxProfilesFromDevice = null;
                int?maxProfilesFromMedia  = null;

                if (Features.Contains(Feature.GetCapabilities))
                {
                    //3.	If GetCapabilities supported by the DUT, ONVIF Client will invoke GetCapabilitiesRequest message (Category = ‘Media’) to get MaximumNumberOfProfiles capability. Otherwise skip steps 3-4 and go to the step 5.
                    //4.	Verify the GetCapabilitiesResponse message from the DUT.

                    DeviceClient device = GetDeviceClient();

                    BeginStep("Get Media service capabilities from Device service");
                    Capabilities capabilities = device.GetCapabilities(new CapabilityCategory[] { CapabilityCategory.Media });
                    StepPassed();

                    Assert(capabilities != null && capabilities.Media != null, "Media capabilities were not received", "Check that the DUT returned Media capabilities");

                    if (capabilities.Media.Extension != null && capabilities.Media.Extension.ProfileCapabilities != null)
                    {
                        maxProfilesFromDevice = capabilities.Media.Extension.ProfileCapabilities.MaximumNumberOfProfiles;
                    }
                }

                if (Features.Contains(Feature.GetServices))
                {
                    //5.	If GetServices supported by the DUT, ONVIF Client will invoke GetServiceCapabilitiesRequest message to get MaximumNumberOfProfiles capability. Otherwise skip steps 5-6 and go to the step 7.
                    //6.	Verify the GetServiceCapabilitiesResponse message from the DUT.

                    MediaServiceCapabilities capabilities = GetServiceCapabilities();

                    Assert(capabilities != null, "Media service capabilities were not received", "Check that the DUT returned Media service capabilities");

                    if (capabilities.ProfileCapabilities != null)
                    {
                        if (capabilities.ProfileCapabilities.MaximumNumberOfProfilesSpecified)
                        {
                            maxProfilesFromMedia = capabilities.ProfileCapabilities.MaximumNumberOfProfiles;
                        }
                    }
                }

                string reason;
                //7.	ONVIF Client will invoke GetVideoEncoderConfigurationsRequest message to retrieve all DUT video encoder configurations.
                //8.	Verify the GetVideoSourceConfigurationsResponse message from the DUT.
                VideoEncoderConfiguration[] encoderConfigurations = GetVideoEncoderConfigurations();
                Assert(ValidateVideoEncoderConfigs(encoderConfigurations, out reason), reason, Resources.StepValidatingVideoEncoderConfigs_Title);

                //9.	ONVIF Client will invoke GetVideoSourceConfigurationsRequest message to retrieve all DUT video source configurations.
                //10.	Verify the GetVideoSourceConfigurationsResponse message from the DUT.
                VideoSourceConfiguration[] configs = GetVideoSourceConfigurations();

                Assert(ValidateVideoSourceConfigs(configs, out reason), reason, Resources.StepValidatingVideoSourceConfigs_Title);

                bool jpegPresent = false;
                bool mpegPresent = false;
                bool h264Present = false;

                bool jpegNotSupported = true;
                bool mpegNotSupported = true;
                bool h264NotSupported = true;

                foreach (VideoSourceConfiguration config in configs)
                {
                    string configToken = config.token;
                    int?jpeg;
                    int?mpeg;
                    int?h264;

                    //11.	ONVIF Client will invoke GetGuaranteedNumberOfVideoEncoderInstancesRequest message
                    // (ConfigurationToken = “Token1”, where “Token1” is a first video source configuration
                    // token from GetVideoSourceConfigurationsResponse message) to retrieve guaranteed number
                    // of video encoder instances per first video source configuration.
                    //12.	Verify the GetGuaranteedNumberOfVideoEncoderInstancesResponse message from the DUT.
                    int totalNumber = GetGuaranteedNumberOfVideoEncoderInstances(configToken, out jpeg, out h264, out mpeg);

                    //11.	Verify that GetGuaranteedNumberOfVideoEncoderInstancesResponse.TotalNumber less
                    // or equal to total number of VideoEncoderConfigurations.

                    Assert(totalNumber <= encoderConfigurations.Length,
                           "Guaranteed total number of video encoder instances is greater than total number of video encoder configurations",
                           "Compare guaranteed total number of video encoder instances and total number of video encoder configurations");

                    //13.	Verify that GetGuaranteedNumberOfVideoEncoderInstancesResponse.TotalNumber less
                    // or equal to total number of VideoEncoderConfigurations.
                    //14.	If GetCapabilities supported by the DUT, Verify that
                    // GetGuaranteedNumberOfVideoEncoderInstancesResponse.TotalNumber less or equal to total
                    // number of GetCapabilitiesResponse.Media.Extension.ProfileCapabilities.MaximumNumberOfProfiles
                    // if specified.
                    //15.	If GetServices supported by the DUT, Verify that GetGuaranteedNumberOfVideoEncoderInstancesResponse.TotalNumber
                    // less or equal to total number of GetServiceCapabilitiesResponse.Capabilities.ProfileCapabilities.MaximumNumberOfProfiles
                    // if specified.

                    if (maxProfilesFromDevice.HasValue)
                    {
                        Assert(totalNumber <= maxProfilesFromDevice,
                               "Guaranteed total number of video encoder instances is greater than max number of profiles as defined in Device capabilities",
                               "Compare guaranteed total number of video encoder instances and maximum number of profiles");
                    }

                    if (maxProfilesFromMedia.HasValue)
                    {
                        Assert(totalNumber <= maxProfilesFromMedia,
                               "Guaranteed total number of video encoder instances is greater than max number of profiles as defined in Media service capabilities",
                               "Compare guaranteed total number of video encoder instances and maximum number of profiles");
                    }

                    // positive value: supported;
                    if (jpeg.HasValue)
                    {
                        if (jpeg.Value > 0)
                        {
                            jpegPresent      = true;
                            jpegNotSupported = false;
                        }
                    }
                    else
                    {
                        jpegNotSupported = false;
                    }
                    if (mpeg.HasValue)
                    {
                        if (mpeg.Value > 0)
                        {
                            mpegPresent      = true;
                            mpegNotSupported = false;
                        }
                    }
                    else
                    {
                        mpegNotSupported = false;
                    }
                    if (h264.HasValue)
                    {
                        if (h264.Value > 0)
                        {
                            h264Present      = true;
                            h264NotSupported = false;
                        }
                    }
                    else
                    {
                        h264NotSupported = false;
                    }
                }
                //16.	Repeat steps 11-15 to retrieve guaranteed number of video encoder instances for all video source configuration

                //17.	ONVIF Client will invoke GetVideoEncoderConfigurationOptionsRequest message (no ConfigurationToken, no ProfileToken) to retrieve general video encoder options for the DUT.
                //18.	Verify the GetVideoEncoderConfigurationOptionsResponse message from the DUT.
                VideoEncoderConfigurationOptions options = GetVideoEncoderConfigurationOptions(null, null);

                //19.	Verify that GetVideoEncoderConfigurationOptionsResponse contains Options.JPEG,
                // if there is at least one GetGuaranteedNumberOfVideoEncoderInstancesResponse
                // with JPEG element having value greater than 0.
                //20.	Verify that GetVideoEncoderConfigurationOptionsResponse contains Options.MPEG4,
                // if there is at least one GetGuaranteedNumberOfVideoEncoderInstancesResponse with
                // MPEG4 element having value greater than 0.
                //21.	Verify that GetVideoEncoderConfigurationOptionsResponse contains Options.H264,
                // if there is at least one GetGuaranteedNumberOfVideoEncoderInstancesResponse with H264
                // element having value greater than 0.
                //22.	Verify that GetVideoEncoderConfigurationOptionsResponse does not contain Options.JPEG,
                // if there are no GetGuaranteedNumberOfVideoEncoderInstancesResponses with skipped JPEG element
                // or with JPEG element having value greater than 0.
                //23.	Verify that GetVideoEncoderConfigurationOptionsResponse does not contain Options.MPEG4,
                // if there are no GetGuaranteedNumberOfVideoEncoderInstancesResponses with skipped MPEG4
                // element or with MPEG4 element having value greater than 0.
                //24.	Verify that GetVideoEncoderConfigurationOptionsResponse does not contain Options.H264,
                // if there are no GetGuaranteedNumberOfVideoEncoderInstancesResponses with skipped H264
                // element or with H264 element having value greater than 0.

                Action <bool, bool, object, string> encoderCheck =
                    new Action <bool, bool, object, string>(
                        (found, notSupported, settings, name) =>
                {
                    if (found)
                    {
                        Assert(settings != null,
                               string.Format("{0} options not found, while GetGuaranteedNumberOfVideoEncoderInstances returns positive value for at least one configuration", name),
                               string.Format("Check that {0} options are present", name));
                    }
                    if (notSupported)
                    {
                        Assert(settings == null,
                               string.Format("{0} options are not empty, while GetGuaranteedNumberOfVideoEncoderInstances returns 0 for all configurations", name),
                               string.Format("Check that {0} options are not present", name));
                    }
                });

                encoderCheck(jpegPresent, jpegNotSupported, options.JPEG, "JPEG");
                encoderCheck(mpegPresent, mpegNotSupported, options.MPEG4, "MPEG4");
                encoderCheck(h264Present, h264NotSupported, options.H264, "H264");
            });
        }