Example #1
0
        //Helpers
        private static void ValidateAndExportModelPreparation(out UANodeSet _ns, out IAddressSpaceContext _as)
        {
            _ns = TestData.CreateNodeSetModel();
            List <TraceMessage> _trace = new List <TraceMessage>();
            int _diagnosticCounter     = 0;

            Assert.AreEqual <int>(0, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            Assert.IsTrue(_ns.NamespaceUris.Length >= 1, "Wrong test data - NamespaceUris must contain more then 2 items");
            _as = new AddressSpaceContext(x => { Helpers.TraceHelper.TraceDiagnostic(x, _trace, ref _diagnosticCounter); });
            Assert.IsNotNull(_as);
            Assert.AreEqual <int>(0, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            _as.ImportUANodeSet(_ns);
            Assert.AreEqual <int>(0, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
        }
Example #2
0
        public void UndefinedHasSubtypeTestMethod()
        {
            FileInfo _testDataFileInfo = new FileInfo(@"ModelsWithErrors\UndefinedHasSubtype.xml");

            Assert.IsTrue(_testDataFileInfo.Exists);
            using (Logger _log = new Logger())
            {
                IAddressSpaceContext _as = _log.GetInstance();
                _as.ImportUANodeSet(_testDataFileInfo);
                Assert.AreEqual <int>(0, _log.TraceList.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
                _as.ValidateAndExportModel(m_NameSpace);
                Assert.AreEqual <int>(1, _log.TraceList.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
                Assert.AreEqual <int>(1, _log.TraceList.Where <TraceMessage>(x => x.BuildError.Identifier == "P3-0710000001").Count <TraceMessage>());
            }
        }
Example #3
0
        public void WrongReference2PropertyTestMethod()
        {
            FileInfo _testDataFileInfo = new FileInfo(@"ModelsWithErrors\WrongReference2Property.xml");

            Assert.IsTrue(_testDataFileInfo.Exists);
            using (Logger _log = new Logger())
            {
                IAddressSpaceContext _as = _log.GetInstance();
                Assert.IsNotNull(_as);
                _as.ImportUANodeSet(_testDataFileInfo);
                Assert.AreEqual <int>(0, _log.TraceList.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
                _as.ValidateAndExportModel(m_NameSpace);
                Assert.AreEqual <int>(2, _log.TraceList.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            }
        }
        public void WrongNodeId()
        {
            FileInfo _testDataFileInfo = new FileInfo(@"ModelsWithErrors\WrongNodeId.xml");

            Assert.IsTrue(_testDataFileInfo.Exists);
            using (Logger _log = new Logger())
            {
                IAddressSpaceContext _as = _log.GetInstance();
                _as.ImportUANodeSet(_testDataFileInfo);
                Assert.AreEqual <int>(0, _log._trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
                _as.ValidateAndExportModel(m_NameSpace);
                Assert.AreEqual <int>(3, _log._trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
                Assert.AreEqual <int>(3, _log._trace.Where <TraceMessage>(x => x.BuildError.Identifier == "P3-0502020001").Count <TraceMessage>());
            }
        }
Example #5
0
        /// <summary>
        /// Creates new instance of the <see cref="OPCFModelDesign" />.
        /// </summary>
        /// <param name="filePath">The path of the UANodeSet file.</param>
        /// <param name="trace">A delegate to trace the import progress.</param>
        /// <returns>An object of <see cref="OPCFModelDesign"/>.</returns>
        /// <exception cref="FileNotFoundException">The imported file does not exist</exception>
        public static OPCFModelDesign Import(FileInfo filePath, Action <TraceMessage> trace)
        {
            if (!filePath.Exists)
            {
                throw new FileNotFoundException("The imported file does not exist", filePath.FullName);
            }
            IAddressSpaceContext _as       = AddressSpaceFactory.AddressSpace;
            IModelDesignExport   _exporter = ModelDesignExportAPI.GetModelDesignExport();

            _as.InformationModelFactory = _exporter.GetFactory();
            Uri uriToBeExported = _as.ImportUANodeSet(filePath);

            //TODO AddressSpacePrototyping - IMNamespace must be required in case of export #584
            _as.ValidateAndExportModel(uriToBeExported);
            return(_exporter.ExportToObject());
        }
Example #6
0
        public void UndefinedHasTypeDefinitionTestMethod()
        {
            FileInfo _testDataFileInfo = new FileInfo(@"ModelsWithErrors\UndefinedHasTypeDefinition.xml");

            Assert.IsTrue(_testDataFileInfo.Exists);
            using (Logger _log = new Logger())
            {
                IAddressSpaceContext _as = _log.GetInstance();
                _as.ImportUANodeSet(_testDataFileInfo);
                Assert.AreEqual <int>(0, _log.TraceList.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
                _as.ValidateAndExportModel(m_NameSpace);
                //TODO Recognize problems with P3.7.13 HasTypeDefinition ReferenceType #39
                Assert.Inconclusive("Instances are not imported - the error is not recognized.");
                Assert.AreEqual <int>(1, _log.TraceList.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
                Assert.AreEqual <int>(1, _log.TraceList.Where <TraceMessage>(x => x.BuildError.Identifier == "P3-0713000000").Count <TraceMessage>());
            }
        }
        /// <summary>
        /// Creates new instance of the <see cref="ModelDesign.ModelDesign" />.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <param name="traceEvent">The trace event.</param>
        /// <returns>An object of <see cref="ModelDesign.ModelDesign"/>.</returns>
        /// <exception cref="System.IO.FileNotFoundException">The imported file does not exist</exception>
        public static ModelDesign CreateInstance(FileInfo filePath, Action <TraceMessage> traceEvent)
        {
            if (!filePath.Exists)
            {
                throw new FileNotFoundException("The imported file does not exist", filePath.FullName);
            }
            traceEvent(TraceMessage.DiagnosticTraceMessage("Entering AddressSpaceContextService.CreateInstance"));
            IBuildErrorsHandling _log = BuildErrorsHandling.Log;

            _log.TraceEventAction += traceEvent;
            IAddressSpaceContext _as      = AddressSpaceFactory.AddressSpace;
            ModelFactory         _factory = new ModelFactory(traceEvent);

            _as.InformationModelFactory = _factory;
            _as.ImportUANodeSet(filePath);
            _as.ValidateAndExportModel();
            return(_factory.Export());
        }
Example #8
0
        public void NotSupportedFeature()
        {
            FileInfo _testDataFileInfo = new FileInfo(@"ModelsWithErrors\NotSupportedFeature.xml");

            Assert.IsTrue(_testDataFileInfo.Exists);
            using (Logger _log = new Logger())
            {
                IAddressSpaceContext _as = _log.GetInstance();
                Assert.IsNotNull(_as);
                Assert.IsNotNull(_as);
                _as.ImportUANodeSet(_testDataFileInfo);
                Assert.AreEqual <int>(0, _log.TraceList.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
                _as.ValidateAndExportModel(m_NameSpace);
                Assert.AreEqual <int>(1, _log.TraceList.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
                Assert.AreEqual <int>(1, _log.TraceList.Where <TraceMessage>(x => x.BuildError.Identifier == "P0-0001010000").Count <TraceMessage>());
                BuildErrorsHandling.Log.TraceEventAction -= _message => _log.TraceList.Add(_message);
            }
        }
Example #9
0
        private static void Do(Options options)
        {
            PrintLogo(options);
            BuildErrorsHandling.Log.TraceEventAction += z => Console.WriteLine(z.ToString());
            IAddressSpaceContext _as       = AddressSpaceFactory.AddressSpace; //Creates Address Space infrastructure exposed to the API clients using default messages handler.
            ModelDesignExport    _exporter = new ModelDesignExport();          //creates new instance of the ModelDesignExport class that captures functionality supporting export functionality of the OPC UA Information Model represented
                                                                               //by an xml file compliant with UAModelDesign schema.
            bool _exportModel = false;

            if (!string.IsNullOrEmpty(options.ModelDesignFileName))
            {
                _as.InformationModelFactory = _exporter.GetFactory(options.ModelDesignFileName, BuildErrorsHandling.Log.TraceEvent); //Sets the information model factory, which can be used to export a part of the OPC UA Address Space.
                _exportModel = true;
            }
            if (options.Filenames == null)
            {
                throw new ArgumentOutOfRangeException($"{nameof(options.Filenames)}", "List of input files to convert i incorrect. At least one file UANodeSet must be entered.");
            }
            foreach (string _path in options.Filenames)
            {
                FileInfo _fileToRead = new FileInfo(_path);
                if (!_fileToRead.Exists)
                {
                    throw new FileNotFoundException(string.Format($"FileNotFoundException - the file {_path} doesn't exist.", _fileToRead.FullName));
                }
                _as.ImportUANodeSet(_fileToRead); //Imports a part of the OPC UA Address Space contained in the file compliant with the `UANodeSet` schema.
            }
            if (string.IsNullOrEmpty(options.IMNamespace))
            {
                _as.ValidateAndExportModel();
            }
            else
            {
                _as.ValidateAndExportModel(options.IMNamespace); //Validates and exports the selected model.
            }
            if (_exportModel)
            {
                _exporter.ExportToXMLFile(options.Stylesheet); //Serializes the already generated model and writes the XML document to a file.
            }
        }
 //Helpers
 private static void ValidateAndExportModelPreparation(out UANodeSet _ns, out IAddressSpaceContext _as)
 {
     _ns = TestData.CreateNodeSetModel();
       List<TraceMessage> _trace = new List<TraceMessage>();
       int _diagnosticCounter = 0;
       Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
       Assert.IsTrue(_ns.NamespaceUris.Length >= 1, "Wrong test data - NamespaceUris must contain more then 2 items");
       _as = new AddressSpaceContext(x => { Helpers.TraceHelper.TraceDiagnostic(x, _trace, ref _diagnosticCounter); });
       Assert.IsNotNull(_as);
       Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
       _as.ImportUANodeSet(_ns);
       Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
 }