Esempio n. 1
0
        public void Run(ILogger _logger)
        {
            var client = new EventPortTypeClient();

            // Bypass invalid SSL certificate
            client.ClientCredentials.ServiceCertificate.SslCertificateAuthentication =
                new X509ServiceCertificateAuthentication()
            {
                CertificateValidationMode = X509CertificateValidationMode.None,
                RevocationMode            = X509RevocationMode.NoCheck
            };

            HeaderType hd = new HeaderType();

            hd.ClientTimeZoneID = "Asia/Ho_Chi_Minh";
            hd.Identity         = "91";
            var eventName = "CFCScoring";
            var itemTypes = GenerateItemTypes();
            var request   = new EventRequest(hd, itemTypes, eventName);

            _logger.LogInformation($"CheckScoring - Request: {ConvertToXML(request)}");

            EventResponse response = null;

            try
            {
                response = client.EventAsync(request).Result;
                _logger.LogInformation($"CheckScoring - Response: {JsonConvert.SerializeObject(response)}");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected Proxies.Event.EventServiceCapabilities GetEventCapabilities()
        {
            EventPortTypeClient client = EventClient;

            Proxies.Event.EventServiceCapabilities eventServiceCapabilities = null;
            RunStep(() => { eventServiceCapabilities = client.GetServiceCapabilities(); }, "Get Service Capabilities");
            return(eventServiceCapabilities);
        }
Esempio n. 3
0
        public OnVif1Events(OnVifDevice onVifDevice) : base(onVifDevice)
        {
            //   m_ErrorMessage = "";
            m_PullPointResponse = null;
            //   m_onVifDevice = onVifDevice;
            m_EventPropertiesResponse = null;
            m_EventPortTypeClient     = null;

            m_PullPointSubscriptionClient = null;
            m_SubscriptionManagerClient   = null;
            //       m_initialised = false;
            m_subscriptionTerminationTime = TimeSpan.FromSeconds(20);
        }
        /*[Test(Name = "EVENT SERVICE CAPABILITIES",
         *  Order = "05.01.01",
         *  Id = "5-1-1",
         *  Category = Category.EVENT,
         *  Path = PATH,
         *  Version = 2.1,
         *  RequirementLevel = RequirementLevel.Must,
         *  RequiredFeatures = new Feature[] { Feature.GetServices },
         *  FunctionalityUnderTest = new Functionality[] { Functionality.GetEventsServiceCapabilities })]
         */public void DeviceServiceCapabilitiesTest()
        {
            RunTest(() =>
            {
                // Initialize client
                EventPortTypeClient client = EventClient;

                Proxies.Event.EventServiceCapabilities eventServiceCapabilities = GetEventCapabilities();
            },
                    () =>
            {
                CloseEventClient();
            });
        }
Esempio n. 5
0
        /// <summary>
        /// Subscribes to all events provided by the device and directs to :8080/subscription-1 Http listener
        /// </summary>
        /// <param name="uri">XAddr URI for Onvif events</param>
        /// <param name="username">User</param>
        /// <param name="password">Password</param>
        public void Subscribe(string uri, double deviceTimeOffset, string username, string password)
        {
            EventPortTypeClient eptc = OnvifServices.GetEventClient(uri, deviceTimeOffset, username, password);

            string localIP = GetLocalIp();

            // Producer client
            NotificationProducerClient npc = OnvifServices.GetNotificationProducerClient(uri, deviceTimeOffset, username, password); // ip, port, username, password);

            npc.Endpoint.Address = eptc.Endpoint.Address;

            Subscribe s = new Subscribe();
            // Consumer reference tells the device where to Post messages back to (the client)
            EndpointReferenceType clientEndpoint = new EndpointReferenceType()
            {
                Address = new AttributedURIType()
                {
                    Value = string.Format("http://{0}:8080/subscription-1", localIP)
                }
            };

            s.ConsumerReference      = clientEndpoint;
            s.InitialTerminationTime = "PT60S";

            try
            {
                SubscribeResponse sr = npc.Subscribe(s);

                // Store the subscription URI for use in Renew
                SubRenewUri = sr.SubscriptionReference.Address.Value;

                // Start timer to periodically check if a Renew request needs to be issued
                // Use PC time for timer in case camera time doesn't match PC time
                // This works fine because the renew command issues a relative time (i.e. PT60S) so PC/Camera mismatch doesn't matter
                SubTermTime = System.DateTime.UtcNow.AddSeconds(50); // sr.TerminationTime;
                SubRenewTimer.Start();
                SubRenewTimer.Interval = 1000;
                SubRenewTimer.Elapsed += SubRenewTimer_Elapsed;

                OnNotification(string.Format("Initial Termination Time: {0} (Current Time: {1})", SubTermTime, System.DateTime.UtcNow));

                SubscriptionManagerClient = OnvifServices.GetSubscriptionManagerClient(SubRenewUri, deviceTimeOffset, username, password);
            }
            catch (Exception e)
            {
                OnNotification(string.Format("{0} Unable to subscribe to events on device [{1}]", System.DateTime.UtcNow, uri)); // ip));
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Creates EventPortType client (using endpoint address got via GetCapabiliites)
        /// </summary>
        /// <returns></returns>
        EventPortTypeClient CreateEventPortTypeClient()
        {
            EnsureServiceAddressNotEmpty();

            Binding binding = CreateEventServiceBinding(_eventServiceAddress);

            _eventPortTypeClient = new EventPortTypeClient(binding, new EndpointAddress(_eventServiceAddress));

            System.Net.ServicePointManager.Expect100Continue = false;

            AddSecurityBehaviour(_eventPortTypeClient.Endpoint);

            SetupTimeout(_eventPortTypeClient.InnerChannel);

            return(_eventPortTypeClient);
        }
Esempio n. 7
0
        public void pull(string ip, int port)
        {
            EventPortTypeClient eptc = OnvifServices.GetEventClient(ip, port);

            // 2. CreatePullPointSubscription
            FilterType filter = new FilterType();
            DateTime   currentTime;

            XmlElement[]         xml = null;
            DateTime?            termTime;
            List <MessageHeader> lstHeaders = new List <MessageHeader>()
            {
            };

            EndpointReferenceType ert = eptc.CreatePullPointSubscription(
                filter,
                "PT15S",
                new CreatePullPointSubscriptionSubscriptionPolicy(),
                ref xml,
                out currentTime,
                out termTime
                );

            listBox1.Items.Add(ert.Address.Value);

            if ((ert.ReferenceParameters != null) && (ert.ReferenceParameters.Any != null))
            {
                foreach (System.Xml.XmlElement oXml in ert.ReferenceParameters.Any)
                {
                    string strName  = oXml.LocalName;
                    string strNS    = oXml.NamespaceURI;
                    string strValue = oXml.InnerXml;

                    lstHeaders.Add(MessageHeader.CreateHeader(strName, strNS, strValue, true));
                }
            }

            //PullPointSubscriptionClient ppsc = OnvifServices.GetPullPointSubClient(ip, port);
            //NotificationMessageHolderType[] nmht;
            //DateTime terminationTime;
            //XmlDocument doc = new XmlDocument();
            //doc.CreateElement("test");
            //XmlElement[] pullMsgXml = { doc.CreateElement("test") };

            //ppsc.PullMessages("PT5S", 5, any, out terminationTime, out nmht);
        }
Esempio n. 8
0
        protected string[] GetEventProperties(out bool FixedTopicSet,
                                              out TopicSetType TopicSet,
                                              out string[] TopicExpressionDialect,
                                              out string[] MessageContentFilterDialect,
                                              out string[] ProducerPropertiesFilterDialect,
                                              out string[] MessageContentSchemaLocation,
                                              out XmlElement[] Any)
        {
            EventPortTypeClient client = EventClient;

            string[] response = null;

            bool         fixedTopicSetCopy = false;
            TopicSetType topicSetCopy      = null;

            string[]     topicExpressionDialectCopy          = null;
            string[]     messageContentFilterDialectCopy     = null;
            string[]     producerPropertiesFilterDialectCopy = null;
            string[]     messageContentSchemaLocationCopy    = null;
            XmlElement[] anyCopy = null;

            RunStep(() =>
            {
                response = client.GetEventProperties(out fixedTopicSetCopy,
                                                     out topicSetCopy,
                                                     out topicExpressionDialectCopy,
                                                     out messageContentFilterDialectCopy,
                                                     out producerPropertiesFilterDialectCopy,
                                                     out messageContentSchemaLocationCopy,
                                                     out anyCopy);
            },
                    "Get Event Properties");

            FixedTopicSet                   = fixedTopicSetCopy;
            TopicSet                        = topicSetCopy;
            TopicExpressionDialect          = topicExpressionDialectCopy;
            MessageContentFilterDialect     = messageContentFilterDialectCopy;
            ProducerPropertiesFilterDialect = producerPropertiesFilterDialectCopy;
            MessageContentSchemaLocation    = messageContentSchemaLocationCopy;
            Any = anyCopy;

            return(response);
        }
Esempio n. 9
0
        public void Subscribe(string ip, int port)
        {
            EventPortTypeClient eptc = OnvifServices.GetEventClient(ip, port);

            string localIP = GetLocalIp(); // "172.16.5.111";

            // Producer client
            NotificationProducerClient npc = OnvifServices.GetNotificationProducerClient(ip, port);

            npc.Endpoint.Address = eptc.Endpoint.Address;

            Subscribe s = new Subscribe();
            // Consumer reference tells the device where to Post messages back to (the client)
            EndpointReferenceType clientEndpoint = new EndpointReferenceType()
            {
                Address = new AttributedURIType()
                {
                    Value = string.Format("http://{0}:8080/subscription-1", localIP)
                }
            };

            s.ConsumerReference      = clientEndpoint;
            s.InitialTerminationTime = "PT60S";

            SubscribeResponse sr = npc.Subscribe(s);

            // Store the subscription URI for use in Renew
            SubRenewUri = sr.SubscriptionReference.Address.Value;

            // Start timer to periodically check if a Renew request needs to be issued
            // Use PC time for timer in case camera time doesn't match PC time
            // This works fine because the renew command issues a relative time (i.e. PT60S) so PC/Camera mismatch doesn't matter
            SubTermTime = DateTime.UtcNow.AddSeconds(50); // sr.TerminationTime;
            SubRenewTimer.Start();
            SubRenewTimer.Interval = 1000;
            SubRenewTimer.Tick    += SubRenewTimer_Tick;

            listBox1.Items.Add(string.Format("Initial Termination Time: {0} (Current Time: {1})", SubTermTime, DateTime.UtcNow));

            SubscriptionManagerClient = OnvifServices.GetSubscriptionManagerClient(SubRenewUri); // oAux1.Address.Value);
        }
Esempio n. 10
0
        public static EventPortTypeClient GetEventClient(string ip, int port)
        {
            EndpointAddress serviceAddress = new EndpointAddress(string.Format("http://{0}:{1}/onvif/event_service", ip, port));

            HttpTransportBindingElement httpBinding = new HttpTransportBindingElement();

            httpBinding.AuthenticationScheme = AuthenticationSchemes.Digest;

            var messageElement = new TextMessageEncodingBindingElement();

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

            EventPortTypeClient eptc = new EventPortTypeClient(bind, serviceAddress);

            //// Handles parsing SOAP messages received
            //OnvifEventBehavior behavior = new OnvifEventBehavior();
            //eptc.Endpoint.Behaviors.Add(behavior);

            return(eptc);
        }
Esempio n. 11
0
        public static EventPortTypeClient GetEventClient(string uri, double deviceTimeOffset, string username = "", string password = "")
        {
            EndpointAddress serviceAddress = new EndpointAddress(uri);

            HttpTransportBindingElement httpBinding = new HttpTransportBindingElement();

            httpBinding.AuthenticationScheme = AuthenticationSchemes.Digest;

            var messageElement = new TextMessageEncodingBindingElement();

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

            EventPortTypeClient client = new EventPortTypeClient(bind, serviceAddress);

            if (username != string.Empty)
            {
                // Handles adding of SOAP Security header containing User Token (user, nonce, pwd digest)
                PasswordDigestBehavior behavior = new PasswordDigestBehavior(username, password, deviceTimeOffset);
                client.Endpoint.Behaviors.Add(behavior);
            }

            return(client);
        }
Esempio n. 12
0
 public EventPortTypeClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
     base(EventPortTypeClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
Esempio n. 13
0
        private void button1_Click(object sender, EventArgs e)
        {
            Unsubscribe();
            listBox1.Items.Clear();
            string ip   = txtIP.Text;
            int    port = Convert.ToInt16(numPort.Value);

            EventPortTypeClient eptc = OnvifServices.GetEventClient(ip, port);

            // 1. Get Event Properties
            bool         fixedTopicSet;
            TopicSetType tst = new TopicSetType();

            string[]     topicExpDialect;
            string[]     msgContentFilter;
            string[]     producerProperties;
            string[]     msgContentSchema;
            XmlElement[] any;

            string[] result = eptc.GetEventProperties(out fixedTopicSet, out tst, out topicExpDialect, out msgContentFilter, out producerProperties, out msgContentSchema, out any);

            listBox1.Items.Add(string.Format("Result: {0}", result));
            listBox1.Items.Add(string.Format("Message Content Filter Dialect(s)"));
            foreach (string msg in msgContentFilter)
            {
                listBox1.Items.Add(string.Format("  {0}", msg));
            }

            listBox1.Items.Add("");
            listBox1.Items.Add(string.Format("Message Content Schema Location(s)"));
            foreach (string msg in msgContentSchema)
            {
                listBox1.Items.Add(string.Format("  {0}", msg));
            }

            listBox1.Items.Add("");
            listBox1.Items.Add(string.Format("Producer Properties Filter Dialect(s)"));
            foreach (string msg in producerProperties)
            {
                listBox1.Items.Add(string.Format("  {0}", msg));
            }

            listBox1.Items.Add("");
            listBox1.Items.Add(string.Format("Topic Expression Dialect(s)"));
            foreach (string msg in topicExpDialect)
            {
                listBox1.Items.Add(string.Format("  {0}", msg));
            }

            listBox1.Items.Add("");
            listBox1.Items.Add(string.Format("Topic Set item(s)"));
            foreach (XmlElement x in tst.Any)
            {
                listBox1.Items.Add("  " + x.Name);
            }

            // 2. Get capabilities
            Capabilities c = eptc.GetServiceCapabilities();

            listBox1.Items.Add("");
            listBox1.Items.Add("Capabilites");
            listBox1.Items.Add(string.Format("  MaxNotificationProducers: {0}", c.MaxNotificationProducers));
            listBox1.Items.Add(string.Format("  MaxNotificationProducersSpecified: {0}", c.MaxNotificationProducersSpecified));
            listBox1.Items.Add(string.Format("  MaxPullPoints: {0}", c.MaxPullPoints));
            listBox1.Items.Add(string.Format("  MaxPullPointsSpecified: {0}", c.MaxPullPointsSpecified));
            listBox1.Items.Add(string.Format("  PersistentNotificationStorage: {0}", c.PersistentNotificationStorage));
            listBox1.Items.Add(string.Format("  PersistentNotificationStorageSpecified: {0}", c.PersistentNotificationStorageSpecified));
            listBox1.Items.Add(string.Format("  WSPausableSubscriptionManagerInterfaceSupport: {0}", c.WSPausableSubscriptionManagerInterfaceSupport));
            listBox1.Items.Add(string.Format("  WSPausableSubscriptionManagerInterfaceSupportSpecified: {0}", c.WSPausableSubscriptionManagerInterfaceSupportSpecified));
            listBox1.Items.Add(string.Format("  WSPullPointSupport: {0}", c.WSPullPointSupport));
            listBox1.Items.Add(string.Format("  WSPullPointSupportSpecified: {0}", c.WSPullPointSupportSpecified));
            listBox1.Items.Add(string.Format("  WSSubscriptionPolicySupport: {0}", c.WSSubscriptionPolicySupport));
            listBox1.Items.Add(string.Format("  WSSubscriptionPolicySupportSpecified: {0}", c.WSSubscriptionPolicySupportSpecified));

            //3. Subscribe to notifications
            Subscribe(ip, port);

            //pull(ip, port);
            //test(ip, port);
        }
Esempio n. 14
0
        public static void ManejaEventos(string uri)
        {
            try
            {
                ServicePointManager.Expect100Continue = false;
                EndpointAddress             endPointAddress      = new EndpointAddress(uri);
                HttpTransportBindingElement httpTransportBinding = new HttpTransportBindingElement {
                    AuthenticationScheme = AuthenticationSchemes.Digest
                };
                httpTransportBinding.KeepAliveEnabled = true;
                TextMessageEncodingBindingElement textMessageEncodingBinding = new TextMessageEncodingBindingElement {
                    MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.WSAddressing10)
                };
                PasswordDigestBehavior passwordDigestBehavior = new PasswordDigestBehavior("julian", "julian");

                CustomBinding customBinding = new CustomBinding(textMessageEncodingBinding, httpTransportBinding);
                customBinding.SendTimeout = new TimeSpan(0, 0, 10);



                EventPortTypeClient ept = new EventPortTypeClient(customBinding, endPointAddress);
                ept.Endpoint.Behaviors.Add(passwordDigestBehavior);
                Console.WriteLine("Status 1 : " + ept.State.ToString());

                ept.Open();
                Console.WriteLine("Status 2 : " + ept.State.ToString());

                ept.GetType();

                ept.GetHashCode();



                FilterType filter       = new FilterType();
                string     initTermTime = null;
                CreatePullPointSubscriptionSubscriptionPolicy policy =
                    new CreatePullPointSubscriptionSubscriptionPolicy();

                XmlElement[]               elems1 = new XmlElement[10];
                System.DateTime            time1  = new System.DateTime();
                Nullable <System.DateTime> time2  = new System.DateTime();

                EndpointReferenceType endpoint = ept.CreatePullPointSubscription(filter, "PT60M", policy, ref elems1, out time1, out time2);


                System.DateTime CurrentTime = new System.DateTime();
                NotificationMessageHolderType[] NotificationMessages = new NotificationMessageHolderType[0];
                PullPointSubscriptionClient.PullMessages()

                PullPointSubscriptionClient.PullMessages("PT5M", 99, Any, out CurrentTime, out NotificationMessages);


                PullPointSubscriptionClient subbind = new PullPointSubscriptionClient(customBinding, endPointAddress);
                subbind.Endpoint.Behaviors.Add(passwordDigestBehavior);



                string          timeOut  = "PT60.000S";
                int             mesLimit = 100;
                XmlElement[]    elemns2  = new XmlElement[10];
                System.DateTime termTime = new System.DateTime();
                NotificationMessageHolderType[] messHolder =
                    new NotificationMessageHolderType[0];



                subbind.PullMessages(timeOut, mesLimit, elemns2, out termTime, out messHolder);

                for (int i = 0; i < messHolder.Length; i++)
                {
                    Console.WriteLine("parsing");
                }


                Console.WriteLine("--------- NO CATCH --------- ");
            }
            catch (Exception eee)
            {
                Console.WriteLine("manejando eventos: " + eee);
            }
        }
Esempio n. 15
0
 private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
 {
     return(EventPortTypeClient.GetEndpointAddress(EndpointConfiguration.EventPort));
 }
Esempio n. 16
0
 private static System.ServiceModel.Channels.Binding GetDefaultBinding()
 {
     return(EventPortTypeClient.GetBindingForEndpoint(EndpointConfiguration.EventPort));
 }
Esempio n. 17
0
 public EventPortTypeClient(EndpointConfiguration endpointConfiguration) :
     base(EventPortTypeClient.GetBindingForEndpoint(endpointConfiguration), EventPortTypeClient.GetEndpointAddress(endpointConfiguration))
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
Esempio n. 18
0
 public EventPortTypeClient() :
     base(EventPortTypeClient.GetDefaultBinding(), EventPortTypeClient.GetDefaultEndpointAddress())
 {
     this.Endpoint.Name = EndpointConfiguration.EventPort.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }