/// <summary>
        /// Resolves address and reads the <see cref="DomainModel"/> record as an asynchronous operation.
        /// </summary>
        /// <param name="modelUri">The model URI.</param>
        /// <param name="rootZoneUrl">The root zone URL where the resolving process shall start.</param>
        /// <param name="log"><see cref="Action{T1, T2, T3}"/> encapsulating tracing functionality .</param>
        /// <returns>Task{DomainModel}.</returns>
        /// <exception cref="InvalidOperationException">Too many iteration in the resolving process.</exception>
        public async Task <DomainModel> ResolveDomainModelAsync(Uri modelUri, Uri rootZoneUrl, Action <string, TraceEventType, Priority> log)
        {
            log($"Starting resolving address of the domain model descriptor for the model Uri {modelUri}", TraceEventType.Verbose, Priority.Low);
            DomainDescriptor _lastDomainDescriptor = new DomainDescriptor()
            {
                NextStepRecordType = RecordType.DomainDescriptor
            };
            Uri _nextUri   = rootZoneUrl;
            int _iteration = 0;

            do
            {
                _iteration++;
                log($"Resolving address iteration {_iteration} address: {_nextUri}", TraceEventType.Verbose, Priority.Low);
                if (_iteration > 16)
                {
                    throw new InvalidOperationException("Too many iteration in the resolving process.");
                }
                _lastDomainDescriptor = await GetHTTPResponseAsync <DomainDescriptor>(_nextUri, log);

                _nextUri = _lastDomainDescriptor.ResolveUri(modelUri);
            } while (_lastDomainDescriptor.NextStepRecordType == RecordType.DomainDescriptor);
            log($"Reading DomainModel at: {_nextUri}", TraceEventType.Verbose, Priority.Low);
            Task <DomainModel> _DomainModelTask = GetHTTPResponseAsync <DomainModel>(_nextUri, log);
            DomainModel        _model           = await _DomainModelTask;

            _model.UniversalDiscoveryServiceLocator = _nextUri.ToString();
            log($"Successfuly received and decoded the requested DomainModel record: {_nextUri}", TraceEventType.Verbose, Priority.Low);
            return(_model);
        }
예제 #2
0
        public void GetRootDomainDescriptorTest()
        {
            DomainDescriptor _rootDomainDescriptor = DomainDescriptorFactory.GetRootDomainDescriptor();
            Uri    _resolution            = _rootDomainDescriptor.ResolveUri(m_ModelUri);
            string m_ExpectedFirsRoundUrl = "https://raw.githubusercontent.com/mpostol/OPC-UA-OOI/master/DataDiscovery/Tests/DiscoveryServices.UnitTest/TestData/root.zone/commsvr.com/DomainDescriptor.xml";

            Assert.AreEqual <string>(m_ExpectedFirsRoundUrl, _resolution.ToString());
            string   _fn = "RootDomainDescriptor.xml";
            FileInfo _fi = new FileInfo($@"TestData\{_fn}");

            using (Stream _outputStream = _fi.Create())
            {
                XmlSerializer _serializer = new XmlSerializer(typeof(DomainDescriptor));
                _serializer.Serialize(_outputStream, _rootDomainDescriptor);
            }
            _fi.Refresh();
            Assert.IsTrue(_fi.Exists);
            Assert.IsTrue(_fi.Length > 0);
            DomainDescriptor _tc;

            using (Stream _descriptionStream = _fi.OpenRead())
            {
                XmlSerializer _serializer = new XmlSerializer(typeof(DomainDescriptor));
                _tc = (DomainDescriptor)_serializer.Deserialize(_descriptionStream);
                Assert.IsNotNull(_tc);
            }
            Assert.IsTrue(_tc.Description.Contains("Starting point"));
            Assert.AreEqual <RecordType>(RecordType.DomainDescriptor, _tc.NextStepRecordType);
            Assert.AreEqual <string>(@"https://raw.githubusercontent.com/mpostol/OPC-UA-OOI/master/DataDiscovery/Tests/DiscoveryServices.UnitTest/TestData/root.zone/#authority#/DomainDescriptor.xml", _tc.UrlPattern);
            _resolution = _tc.ResolveUri(m_ModelUri);
            Assert.AreEqual <string>(m_ExpectedFirsRoundUrl, _resolution.ToString());
        }