Esempio n. 1
0
        public EndpointReferenceType CreatePullPointSubscription(Events.FilterType Filter,
                                                                 [System.Xml.Serialization.XmlElementAttribute(IsNullable = true)] string InitialTerminationTime,
                                                                 CreatePullPointSubscriptionSubscriptionPolicy SubscriptionPolicy,
                                                                 [System.Xml.Serialization.XmlAnyElementAttribute()] ref System.Xml.XmlElement[] Any,
                                                                 [System.Xml.Serialization.XmlElementAttribute(Namespace = "http://docs.oasis-open.org/wsn/b-2")] out System.DateTime CurrentTime, [System.Xml.Serialization.XmlElementAttribute(Namespace = "http://docs.oasis-open.org/wsn/b-2", IsNullable = true)] out System.Nullable <System.DateTime> TerminationTime)
        {
            //SoapFaultSubCode subCode =
            //    new SoapFaultSubCode(new XmlQualifiedName("ResourseUnknown1", "http://www.onvif.org/ver10/error"));

            //SoapException exception = new SoapException("Invalid Argument",
            //                                            new XmlQualifiedName("Sender",
            //                                                                 "http://www.w3.org/2003/05/soap-envelope"),
            //                                            subCode);
            //throw exception;


            Application["consumer"] = "http://127.0.0.1:8080";

            Events.EndpointReferenceType endpointReferenceType = new Events.EndpointReferenceType();

            endpointReferenceType.Address       = new Events.AttributedURIType();
            endpointReferenceType.Address.Value = string.Format("http://{0}/Events/PullPointServiceFake.asmx?param=value", HttpContext.Current.Request.Url.Authority);
            //endpointReferenceType.Address.Value = string.Format("http://{0}/Events/PullPointWcfService.svc?param=value", HttpContext.Current.Request.Url.Host);

            CurrentTime     = System.DateTime.Now;
            TerminationTime = CurrentTime.AddSeconds(60);

            if (actionHeader == null)
            {
                actionHeader = new ActionHeader();
            }
            actionHeader.Value = "http://www.onvif.org/ver10/events/wsdl/EventPortType/CreatePullPointSubscriptionResponse";

            return(endpointReferenceType);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Filter"></param>
        /// <param name="InitialTerminationTime"></param>
        /// <param name="SubscriptionPolicy"></param>
        /// <param name="Any"></param>
        /// <param name="CurrentTime"></param>
        /// <param name="TerminationTime"></param>
        /// <returns></returns>
        /// <remarks>As this method uses EventPortType client, the client can be created without additional data.</remarks>
        protected EndpointReferenceType CreatePullPointSubscription(
            FilterType Filter,
            string InitialTerminationTime,
            CreatePullPointSubscriptionSubscriptionPolicy SubscriptionPolicy,
            ref XmlElement[] Any,
            out DateTime CurrentTime,
            out System.Nullable <System.DateTime> TerminationTime)
        {
            EnsureEventPortTypeClientCreated();

            EndpointReferenceType result = null;

            System.Xml.XmlElement[] anyCopy         = Any;
            System.DateTime         currentTimeCopy = DateTime.MinValue;
            DateTime?terminationTimeCopy            = DateTime.MinValue;

            RunStep(() =>
            {
                result = _eventPortTypeClient.CreatePullPointSubscription(
                    Filter,
                    InitialTerminationTime,
                    SubscriptionPolicy,
                    ref anyCopy,
                    out currentTimeCopy,
                    out terminationTimeCopy);
            }, "Create Pull Point Subsciption");

            CurrentTime     = currentTimeCopy;
            TerminationTime = terminationTimeCopy;

            return(result);
        }
Esempio n. 3
0
        protected EndpointReferenceType CreatePullPointSubscriptionSafe(
            FilterType Filter,
            string InitialTerminationTime,
            CreatePullPointSubscriptionSubscriptionPolicy SubscriptionPolicy,
            ref XmlElement[] Any,
            out DateTime CurrentTime,
            out System.Nullable <System.DateTime> TerminationTime,
            ref int terminationTime)
        {
            try
            {
                return(CreatePullPointSubscription(Filter,
                                                   InitialTerminationTime,
                                                   SubscriptionPolicy,
                                                   ref Any,
                                                   out CurrentTime,
                                                   out TerminationTime));
            }
            catch (FaultException exc)
            {
                FaultException <UnacceptableInitialTerminationTimeFaultType> invalidTerminationTimeFault =
                    exc as FaultException <UnacceptableInitialTerminationTimeFaultType>;

                if (invalidTerminationTimeFault != null)
                {
                    LogStepEvent(string.Format("Exception of type FaultException<UnacceptableInitialTerminationTimeFaultType> received. Try to subscribe with new parameters"));
                    StepPassed();

                    string duration = string.Empty;
                    terminationTime = GetRecommendedDuration <UnacceptableInitialTerminationTimeFaultType>(invalidTerminationTimeFault, out duration);

                    return(CreatePullPointSubscription(Filter,
                                                       duration,
                                                       SubscriptionPolicy,
                                                       ref Any,
                                                       out CurrentTime,
                                                       out TerminationTime));
                }
                else
                {
                    StepPassed();
                    TerminationTime = null;
                    CurrentTime     = DateTime.MinValue;
                    return(null);
                    //throw;
                }
            }
        }
Esempio n. 4
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);
            }
        }
        public override EndpointReferenceType CreatePullPointSubscription(FilterType Filter, [System.Xml.Serialization.XmlElementAttribute(IsNullable = true)] string InitialTerminationTime, CreatePullPointSubscriptionSubscriptionPolicy SubscriptionPolicy, [System.Xml.Serialization.XmlAnyElementAttribute()] ref System.Xml.XmlElement[] Any, [System.Xml.Serialization.XmlElementAttribute(Namespace = "http://docs.oasis-open.org/wsn/b-2")] out System.DateTime CurrentTime, [System.Xml.Serialization.XmlElementAttribute(Namespace = "http://docs.oasis-open.org/wsn/b-2", IsNullable = true)] out System.Nullable <System.DateTime> TerminationTime)
        {
            SoapHeaderProcessing(unknownHeaders);

            ConfStorageLoad();
            EventServerLoad();

            EndpointReferenceType res = new EndpointReferenceType();

            DateTime terminationTime;
            bool     nullInitialTerminationTime = false;

            if (InitialTerminationTime == null)
            {
                InitialTerminationTime     = "PT10S";
                nullInitialTerminationTime = true;
            }

            try
            {
                TimeSpan timeSpan = System.Xml.XmlConvert.ToTimeSpan(InitialTerminationTime);
                terminationTime = DateTime.UtcNow.Add(timeSpan.Add(new TimeSpan(0, 0, 1)));
            }
            catch (Exception)
            {
                try
                {
                    terminationTime = System.Xml.XmlConvert.ToDateTime(InitialTerminationTime, XmlDateTimeSerializationMode.Utc);
                }
                catch (Exception)
                {
                    throw FaultLib.GetSoapException(FaultType.General, "Wrong Initial Termination Time.");
                }
            }

            string     rawRequest    = RequestListener.Take();
            XmlElement filterElement = Utils.GetFilterElements(rawRequest, true);

            int subscriptionKey = EventServer.AddSubscribtion(null, Filter, filterElement, terminationTime, nullInitialTerminationTime);

            CurrentTime     = DateTime.UtcNow;
            TerminationTime = terminationTime;

            res.ReferenceParameters = new ReferenceParametersType();
            res.Address             = new AttributedURIType();
            string hostAndPort = HttpContext.Current.Request.Url.Authority;

            res.Address.Value           = "http://" + hostAndPort + "/ServiceEvents10/PullpointSubscriptionService.asmx";
            res.ReferenceParameters.Any = new System.Xml.XmlElement[1];

            NameTable           nt    = new NameTable();
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);

            nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
            nsmgr.AddNamespace("dut", "http://dut");
            nsmgr.AddNamespace("tdc", "http://www.onvif.org/ver10/doorcontrol/wsdl");

            XmlDocument referenceParameters = new XmlDocument(nt);

            res.ReferenceParameters.Any[0]          = referenceParameters.CreateElement("dut", "id", "http://dut");
            res.ReferenceParameters.Any[0].InnerXml = subscriptionKey.ToString();



            EventServerSave();
            ConfStorageSave();

            actionHeader.actionValue = "http://www.onvif.org/ver10/events/wsdl/EventPortType/CreatePullPointSubscriptionResponse";
            EventServer.SynchronizationPoint(subscriptionKey);
            return(res);
        }
Esempio n. 6
0
        public static EndpointReferenceType CreatePullPointSubscription(this IEventService s, FilterType Filter, string InitialTerminationTime, CreatePullPointSubscriptionSubscriptionPolicy SubscriptionPolicy, ref System.Xml.XmlElement[] Any, out System.DateTime CurrentTime, out DateTime?TerminationTime)
        {
            s.InitializeGuard();

            EndpointReferenceType r = null;

            XmlElement[]    localAny             = Any;
            System.DateTime localCurrentTime     = System.DateTime.MinValue;
            System.DateTime?localTerminationTime = null;

            s.Test.RunStep(() => r = s.ServiceClient.Port.CreatePullPointSubscription(Filter, InitialTerminationTime, SubscriptionPolicy, ref localAny, out localCurrentTime, out localTerminationTime), "Get Service Capabilities(Event)");
            CurrentTime            = localCurrentTime;
            TerminationTime        = localTerminationTime;

            return(r);
        }
Esempio n. 7
0
        internal StepType CreatePullPointSubscriptionTest(out EndpointReferenceType target, out System.DateTime CurrentTime, out System.DateTime?TerminationTime, out SoapException ex, out int timeOut, FilterType Filter, string InitialTerminationTime, CreatePullPointSubscriptionSubscriptionPolicy SubscriptionPolicy, XmlElement[] Any)
        {
            StepType res = StepType.None;

            target  = new EndpointReferenceType();
            timeOut = 0;
            ex      = null;
            bool   passed     = true;
            string logMessage = "";

            CurrentTime     = System.DateTime.UtcNow;
            TerminationTime = CurrentTime.AddSeconds(10);

            //Get step list for command
            XmlNodeList m_testList = m_TestCommon.GetStepsForCommand("CreatePullPointSubscription");

            if (m_testList != null)
            {
                //Get current step
                XmlNode test = m_testList[m_commandCount[CreatePullPointSubscription]];

                #region Analyze request

                //InitialTerminationTime
                CommonCompare.StringCompare("RequestParameters/InitialTerminationTime", "InitialTerminationTime", InitialTerminationTime, ref logMessage, ref passed, test);

                //Filter
                if (Filter != null)
                {
                    if (test.SelectSingleNode("RequestParameters/Filter") != null)
                    {
                        if (test.SelectSingleNode("RequestParameters/Filter[@nocomp=\"true\"]") == null)
                        {
                            string XMLString = "";
                            foreach (XmlElement i in Filter.Any)
                            {
                                XMLString = XMLString + i.OuterXml;
                            }
                            CommonCompare.StringCompare("RequestParameters/Filter", "Filter", XMLString, ref logMessage, ref passed, test);
                        }
                    }
                    else
                    {
                        passed     = false;
                        logMessage = logMessage + "Unexpected Filter.";
                    }
                }
                else
                {
                    if (test.SelectSingleNode("RequestParameters/Filter") != null)
                    {
                        passed     = false;
                        logMessage = logMessage + "No Filter.";
                    }
                }

                #endregion //Analyze request

                //Generate response
                int    useRealAddress = 0;
                object targetObj;
                res    = m_TestCommon.GenerateResponseStepTypeNotVoidSpecial(test, out targetObj, out ex, out timeOut, typeof(EndpointReferenceType), out useRealAddress);
                target = (EndpointReferenceType)targetObj;

                //Get real path to service
                if (useRealAddress != 0)
                {
                    if (target.Address != null)
                    {
                        switch (useRealAddress)
                        {
                        case 1:
                            target.Address.Value = m_TestCommon.SubscriptionManagerServiceUri;
                            break;

                        case 2:
                            target.Address.Value = m_TestCommon.PullpointSubscriptionServiceUri;
                            break;

                        case 3:
                            target.Address.Value = m_TestCommon.PullpointSubscriptionService2Uri;
                            break;
                        }
                    }
                }

                #region Serialization Temp
                //Events.EndpointReferenceType dsr = new Events.EndpointReferenceType();
                //dsr.Address = new Events.AttributedURIType();
                //dsr.Address.Value = "http://192.168.10.203/onvif/event";
                //dsr.Metadata = new Events.MetadataType();
                //dsr.ReferenceParameters = new Events.ReferenceParametersType();
                //XmlSerializer serializer1 = new XmlSerializer(typeof(Events.EndpointReferenceType));
                //TextWriter textWriter = new StreamWriter("c:\\2.txt");
                //serializer1.Serialize(textWriter, dsr);
                #endregion //Serialization Temp

                if (res == StepType.Normal)
                {
                    //CurrentTime
                    string CurrentTimeType = test.SelectSingleNode("ResponseParametersAdditional/CurrentTime/@type").InnerText;
                    switch (CurrentTimeType)
                    {
                    case "now":
                    {
                        CurrentTime = System.DateTime.UtcNow;
                        break;
                    }

                    case "value":
                    {
                        CurrentTime = Convert.ToDateTime(test.SelectSingleNode("ResponseParametersAdditional/CurrentTime").InnerText);
                        break;
                    }

                    case "nowDiff":
                    {
                        int timeDiff = Convert.ToInt32(test.SelectSingleNode("ResponseParametersAdditional/CurrentTime").InnerText);
                        CurrentTime = System.DateTime.UtcNow.AddSeconds(timeDiff);
                        break;
                    }
                    }

                    //TerminationTime
                    if (test.SelectNodes("ResponseParametersAdditional/TerminationTime[@nil=\"true\"]").Count != 0)
                    {
                        TerminationTime = null;
                    }
                    else
                    {
                        if (test.SelectNodes("ResponseParametersAdditional/TerminationTime[@differance=\"true\"]").Count != 0)
                        {
                            int timeDiff = Convert.ToInt32(test.SelectSingleNode("ResponseParametersAdditional/TerminationTime").InnerText);
                            TerminationTime = CurrentTime.AddSeconds(timeDiff);
                        }
                        else
                        {
                            TerminationTime = Convert.ToDateTime(test.SelectSingleNode("ResponseParametersAdditional/TerminationTime").InnerText);
                        }
                    }
                }

                //Log message
                m_TestCommon.writeToLog(test, logMessage, passed);

                Increment(m_testList.Count, CreatePullPointSubscription);
            }
            else
            {
                timeOut = 0;
                target  = null;
                ex      = null;
                res     = StepType.None;
            }
            return(res);
        }