Ejemplo n.º 1
0
        /**********************************************************/

        /// <summary>
        /// force the VEN to reregister
        /// </summary>
        public void register()
        {
            Thread thread = new Thread(delegate()
            {
                try
                {
                    lock (m_ven)
                    {
                        if (!handleRegistration(true))
                        {
                            return;
                        }

                        OadrPoll poll = doPoll();

                        // continually process messages in the remote queue until the queue
                        // is empty
                        while (!poll.responseTypeIs(typeof(oadrResponseType)))
                        {
                            poll = doPoll();
                        }
                    }
                }
                catch (Exception ex)
                {
                    m_callbacks.processException(ex);
                }
                finally
                {
                    updateStatus(STATUS_IDLE);
                }
            });

            thread.Start();
        }
        /**********************************************************************************/


        private void execute()
        {
            OadrPoll oadrPoll = null;

            while (m_running)
            {
                try
                {
                    updateStatus(STATUS_POLLING);

                    if (handleRegistration())
                    {
                        oadrPoll = doPoll();
                        Logger.logMessage(oadrPoll.ToString() + "\n", "VenWrapper.log");
                    }
                }
                catch (Exception ex)
                {
                    m_callbacks.processException(ex);
                }

                try
                {
                    handleEventStatusChanges();
                }
                catch (Exception ex)
                {
                    m_callbacks.processException(ex);
                }

                try
                {
                    // only sleep if the last oadrpoll was an OadrResponse or an error occured
                    if (oadrPoll == null || oadrPoll.response == null || oadrPoll.responseTypeIs(typeof(oadrResponseType)) || oadrPoll.eiResponseCode != 200)
                    {
                        updateStatus(STATUS_IDLE);

                        Thread.Sleep(m_timeout);
                    }
                    else
                    {
                        Thread.Sleep(1000);
                    }
                }
                catch (ThreadInterruptedException)
                {
                }
                catch (Exception ex)
                {
                    m_callbacks.processException(ex);
                }
            }
        }
        /**********************************************************************************/

        private OadrPoll doPoll()
        {
            OadrPoll oadrPoll = null;

            lock (m_ven) { oadrPoll = m_ven.poll(); }

            m_callbacks.processPoll(oadrPoll);

            if (oadrPoll == null)
            {
                return(null);
            }

            m_serverOffsetSeconds = oadrPoll.serverOffset;

            if (oadrPoll.responseTypeIs(typeof(oadrDistributeEventType)))
            {
                processDistributeEvent(oadrPoll.getDistributeEventResponse());
            }

            else if (oadrPoll.responseTypeIs(typeof(oadrRegisterReportType)))
            {
                processRegisterReport(oadrPoll.getRegisterReportResponse());
            }

            else if (oadrPoll.responseTypeIs(typeof(oadrCreateReportType)))
            {
                processCreateReport(oadrPoll.getCreateReportResponse());
            }

            else if (oadrPoll.responseTypeIs(typeof(oadrCancelReportType)))
            {
                processCancelReport(oadrPoll.getCancelReportResponse());
            }

            else if (oadrPoll.responseTypeIs(typeof(oadrCancelPartyRegistrationType)))
            {
                processCancelRegistration(oadrPoll.getCancelPartyRegistrationResponse());
            }

            else if (oadrPoll.responseTypeIs(typeof(oadrRequestReregistrationType)))
            {
                handleRegistration(true);
            }

            return(oadrPoll);
        }
        public void N1_0020_TH_VTN_1()
        {
            VEN2b ven = new VEN2b(new HttpWebRequestWrapper(false, System.Net.SecurityProtocolType.Tls12), TestProperties.vtnURL, TestProperties.venName, TestProperties.venID, TestProperties.venPassword);

            // register
            CreatePartyRegistration createPartyRegistration = ven.createPartyRegistration(RandomHex.instance().generateRandomHex(10), oadrProfileType.Item20b, oadrTransportType.simpleHttp, "", false, false, true);

            Assert.IsTrue(createPartyRegistration.response != null);

            Console.Out.WriteLine(createPartyRegistration.responseBody);

            // POLL
            OadrPoll oadrPoll = ven.poll();

            Assert.IsNotNull(oadrPoll.response);

            Console.Out.WriteLine(oadrPoll.responseBody);

            // First request is registerReport
            Assert.IsTrue(oadrPoll.responseTypeIs(typeof(oadrRegisterReportType)));

            oadrRegisterReportType registerReportType = oadrPoll.getRegisterReportResponse();

            RegisteredReport registeredReport = ven.registeredReport(registerReportType.requestID, "200", "OK");

            Assert.IsNotNull(registeredReport.response);
            Assert.AreEqual(registeredReport.response.eiResponse.responseCode, "200");

            // register our own report
            ReportDescription reportDescription = ReportHelper.generateReportDescription();

            RegisterReport registerReport = ven.registerReport(RandomHex.instance().generateRandomHex(10), reportDescription);

            Assert.IsNotNull(registerReport.response);

            Assert.AreEqual("200", registerReport.response.eiResponse.responseCode);

            Assert.AreEqual(registerReport.request.requestID, registerReport.response.eiResponse.requestID);
        }
Ejemplo n.º 5
0
        public void R1_3010_TH_VTN_1()
        {
            VEN2b ven = new VEN2b(new HttpWebRequestWrapper(false, System.Net.SecurityProtocolType.Tls12), TestProperties.vtnURL, TestProperties.venName, "", TestProperties.venPassword);

            QueryRegistration queryRegistration = ven.queryRegistration();

            OadrPoll poll = ven.poll();

            poll.responseTypeIs(typeof(oadrCreateReportType));

            oadrCreateReportType createReport = poll.getCreateReportResponse();

            Console.Out.WriteLine(poll.responseBody);

            ReportDescription reportDescription = new ReportDescription();

            reportDescription.addReport(createReport.oadrReportRequest[0].reportSpecifier.reportSpecifierID, ReportName.TELEMETRY_STATUS, 0, DurationModifier.MINUTES);

            DateTime dtstart = DateTime.UtcNow;

            reportDescription.addIntervalResourceStatus(createReport.oadrReportRequest[0].reportSpecifier.reportSpecifierID, dtstart,
                                                        0, DurationModifier.SECONDS, "rid", 1, (float)1.0, DataQuality.qualityGoodNonSpecific, true, false, (float)1.0, (float)1.0, (float)1.0, (float)1.0,
                                                        (float)1.0, (float)1.0, (float)1.0, (float)1.0, (float)1.0, (float)1.0, (float)1.0, (float)1.0, (float)1.0, (float)1.0,
                                                        (float)1.0, (float)1.0);

            CreatedReport createdReport = ven.createdReport(createReport.requestID, 200, "OK");

            Assert.IsNotNull(createdReport.response);

            List <string> reportSpecifierIDs = new List <string>();

            reportSpecifierIDs.Add(createReport.oadrReportRequest[0].reportSpecifier.reportSpecifierID);

            UpdateReport updateReport = ven.updateReport(createReport.requestID, reportDescription, reportSpecifierIDs, dtstart);

            Assert.IsNotNull(updateReport.response);
        }
Ejemplo n.º 6
0
        public void R1_3020_TH_VTN_1()
        {
            VEN2b ven = new VEN2b(new HttpWebRequestWrapper(false, System.Net.SecurityProtocolType.Tls12), TestProperties.vtnURL, TestProperties.venName, TestProperties.venID, TestProperties.venPassword);

            OadrPoll poll = ven.poll();

            poll.responseTypeIs(typeof(oadrCreateReportType));

            oadrCreateReportType createReport = poll.getCreateReportResponse();

            Console.Out.WriteLine(poll.responseBody);

            ReportDescription reportDescription = new ReportDescription();

            reportDescription.addReport(createReport.oadrReportRequest[0].reportSpecifier.reportSpecifierID, ReportName.TELEMETRY_STATUS, 0, DurationModifier.MINUTES);


            CreatedReport createdReport = ven.createdReport(createReport.requestID, 200, "OK");

            Assert.IsNotNull(createdReport.response);

            List <string> reportSpecifierIDs = new List <string>();

            int sleepTime = (int)(createReport.oadrReportRequest[0].reportSpecifier.reportInterval.properties.dtstart.datetime - DateTime.UtcNow).TotalSeconds;

            if (sleepTime > 0)
            {
                System.Threading.Thread.Sleep(sleepTime * 1000);
            }

            reportSpecifierIDs.Add(createReport.oadrReportRequest[0].reportSpecifier.reportSpecifierID);

            DateTime endTime = createReport.oadrReportRequest[0].reportSpecifier.reportInterval.properties.dtstart.datetime +
                               System.Xml.XmlConvert.ToTimeSpan(createReport.oadrReportRequest[0].reportSpecifier.reportInterval.properties.duration.duration);

            // convert ISO8601 duration to timespan
            // http://stackoverflow.com/questions/62804/how-to-convert-iso-8601-duration-to-timespan-in-vb-net
            // http://msdn.microsoft.com/en-us/library/system.xml.xmlconvert.totimespan.aspx
            int sleepDelay = (int)System.Xml.XmlConvert.ToTimeSpan(createReport.oadrReportRequest[0].reportSpecifier.reportBackDuration.duration).TotalSeconds;

            // the test should continue until the end time has passed, but the test set exits after it receives 2 updates
            // while (DateTime.Now < endTime)
            for (int count = 0; count < 2; count++)
            {
                DateTime dtstart = DateTime.UtcNow;

                reportDescription.addIntervalResourceStatus(createReport.oadrReportRequest[0].reportSpecifier.reportSpecifierID, dtstart,
                                                            0, DurationModifier.SECONDS, "rid", 1, (float)1.0, DataQuality.qualityGoodNonSpecific, true, false, (float)1.0, (float)1.0, (float)1.0, (float)1.0,
                                                            (float)1.0, (float)1.0, (float)1.0, (float)1.0, (float)1.0, (float)1.0, (float)1.0, (float)1.0, (float)1.0, (float)1.0,
                                                            (float)1.0, (float)1.0);

                UpdateReport updateReport = ven.updateReport(createReport.requestID, reportDescription, reportSpecifierIDs, dtstart);

                Assert.IsNotNull(updateReport.response);

                if (count == 0)
                {
                    System.Threading.Thread.Sleep(sleepDelay * 1000);
                }
            }
        }