コード例 #1
0
ファイル: UAModelContext.cs プロジェクト: yuriik83/OPC-UA-OOI
 /// <summary>
 /// Initializes a new instance of the <see cref="UAModelContext" /> class.
 /// </summary>
 /// <param name="nodeIdAlias">The node identifier aliases table.</param>
 /// <param name="modelNamespaceUris">The model namespace uris table.</param>
 /// <param name="addressSpaceContext">The address space context.</param>
 internal UAModelContext(NodeIdAlias[] nodeIdAlias, string[] modelNamespaceUris, AddressSpaceContext addressSpaceContext)
 {
     if (nodeIdAlias == null)
     throw new ArgumentNullException("nodeIdAlias");
       if (modelNamespaceUris == null)
     modelNamespaceUris = new string[] { };
       if (addressSpaceContext == null)
     throw new ArgumentNullException("addressSpaceContext");
       AddAlias(nodeIdAlias);
       m_ModelNamespaceUris = modelNamespaceUris;
       m_AddressSpaceContext = addressSpaceContext;
 }
コード例 #2
0
 public void ObjectEventNotifierOutOfRangeTestMethod()
 {
     FileInfo _testDataFileInfo = new FileInfo(@"ModelsWithErrors\WrongEventNotifier.xml");
       Assert.IsTrue(_testDataFileInfo.Exists);
       List<TraceMessage> _trace = new List<TraceMessage>();
       int _diagnosticCounter = 0;
       IAddressSpaceContext _as = new AddressSpaceContext(z => TraceDiagnostic(z, _trace, ref _diagnosticCounter));
       Assert.IsNotNull(_as);
       _as.ImportUANodeSet(_testDataFileInfo);
       Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
       _as.ValidateAndExportModel(m_NameSpace);
       Assert.AreEqual<int>(1, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
 }
コード例 #3
0
 public void NotSupportedFeature()
 {
     FileInfo _testDataFileInfo = new FileInfo(@"ModelsWithErrors\NotSupportedFeature.xml");
       Assert.IsTrue(_testDataFileInfo.Exists);
       List<TraceMessage> _trace = new List<TraceMessage>();
       int _diagnosticCounter = 0;
       IAddressSpaceContext _as = new AddressSpaceContext(z => TraceDiagnostic(z, _trace, ref _diagnosticCounter));
       Assert.IsNotNull(_as);
       _as.ImportUANodeSet(_testDataFileInfo);
       Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
       _as.ValidateAndExportModel(m_NameSpace);
       Assert.AreEqual<int>(1, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
       Assert.AreEqual<int>(1, _trace.Where<TraceMessage>(x => x.BuildError.Identifier == "P0-0001010000").Count<TraceMessage>());
 }
コード例 #4
0
        /// <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.ModelDesign CreateInstance(FileInfo filePath, Action <OOI.TraceMessage> traceEvent)
        {
            if (!filePath.Exists)
            {
                throw new FileNotFoundException("The imported file does not exist", filePath.FullName);
            }
            traceEvent(OOI.TraceMessage.DiagnosticTraceMessage("Entering AddressSpaceContextService.CreateInstance"));
            OOI.IAddressSpaceContext _as      = new OOI.AddressSpaceContext(traceEvent);
            ModelFactory             _factory = new ModelFactory(traceEvent);

            _as.InformationModelFactory = _factory;
            _as.ImportUANodeSet(filePath);
            _as.ValidateAndExportModel();
            return(_factory.Export());
        }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UAModelContext" /> class.
 /// </summary>
 /// <param name="nodeIdAlias">The node identifier aliases table.</param>
 /// <param name="modelNamespaceUris">The model namespace uris table.</param>
 /// <param name="addressSpaceContext">The address space context.</param>
 internal UAModelContext(NodeIdAlias[] nodeIdAlias, string[] modelNamespaceUris, AddressSpaceContext addressSpaceContext)
 {
     if (nodeIdAlias == null)
     {
         throw new ArgumentNullException("nodeIdAlias");
     }
     if (modelNamespaceUris == null)
     {
         modelNamespaceUris = new string[] { }
     }
     ;
     if (addressSpaceContext == null)
     {
         throw new ArgumentNullException("addressSpaceContext");
     }
     AddAlias(nodeIdAlias);
     m_ModelNamespaceUris  = modelNamespaceUris;
     m_AddressSpaceContext = addressSpaceContext;
 }
コード例 #6
0
        internal static UAReferenceContext NewReferenceStub
            (Reference reference, AddressSpaceContext addressSpaceContext, UAModelContext modelContext, UANodeContext parentNode, Action <TraceMessage> traceEvent)
        {
            UANodeContext      targetNode = modelContext.GetOrCreateNodeContext(reference.Value, true, traceEvent);
            UAReferenceContext _stb       = new UAReferenceContext()
            {
                m_Context  = addressSpaceContext,
                ParentNode = parentNode,
                SourceNode = reference.IsForward ? parentNode : targetNode,
                ModelNode  = reference,
                TargetNode = reference.IsForward ? targetNode : parentNode,
                TypeNode   = modelContext.GetOrCreateNodeContext(reference.ReferenceType, true, traceEvent),
            };

            if (_stb.TypeNode != null && _stb.TypeNode.NodeIdContext.NamespaceIndex == 0)
            {
                _stb.ReferenceKind = _stb.GetReferenceKind(_stb.TypeNode);
            }
            return(_stb);
        }
コード例 #7
0
 internal static UAReferenceContext NewReferenceStub(Reference reference, AddressSpaceContext addressSpaceContext, UAModelContext modelContext, UANodeContext parentNode, Action<TraceMessage> traceEvent)
 {
     UANodeContext targetNode = modelContext.GetOrCreateNodeContext(reference.Value, true, traceEvent);
       UAReferenceContext _stb = new UAReferenceContext()
       {
     m_Context = addressSpaceContext,
     ParentNode = parentNode,
     SourceNode = reference.IsForward ? parentNode : targetNode,
     ModelNode = reference,
     TargetNode = reference.IsForward ? targetNode : parentNode,
     TypeNode = modelContext.GetOrCreateNodeContext(reference.ReferenceType, true, traceEvent),
       };
       if (_stb.TypeNode != null && _stb.TypeNode.NodeIdContext.NamespaceIndex == 0)
     _stb.ReferenceKind = _stb.GetReferenceKind(_stb.TypeNode);
       return _stb;
 }
コード例 #8
0
ファイル: Program.cs プロジェクト: yuriik83/OPC-UA-OOI
 internal static void ValidateFile(FileInfo _fileToRead)
 {
     IAddressSpaceContext _as = new AddressSpaceContext(z => Console.WriteLine(z.ToString()));
       _as.ImportUANodeSet(_fileToRead);
       _as.ValidateAndExportModel();
 }
コード例 #9
0
        /// <summary>
        /// Validates the selected nodes <paramref name="nodesCollection"/> and export it using <paramref name="exportModelFactory"/>.
        /// </summary>
        /// <param name="nodesCollection">The items <see cref="UANodeContext" /> imported to the Address Space <see cref="IAddressSpaceContext" />.</param>
        /// <param name="exportModelFactory">The model export factory.</param>
        /// <param name="addressSpaceContext">The Address Space context.</param>
        /// <param name="traceEvent">The trace event method encapsulation.</param>
        internal static void ValidateExportModel
            (IEnumerable <UANodeContext> nodesCollection, IModelFactory exportModelFactory, AddressSpaceContext addressSpaceContext, Action <TraceMessage> traceEvent)
        {
            traceEvent(TraceMessage.DiagnosticTraceMessage(String.Format("Entering Validator.ValidateExportModel - starting creation of the ModelDesign for {0} nodes.", nodesCollection.Count <UANodeContext>())));
            List <BuildError> _errors = new List <BuildError>(); //TODO should be added to the model;

            foreach (string _ns in addressSpaceContext.ExportNamespaceTable())
            {
                exportModelFactory.CreateNamespace(_ns);
            }
            string _msg = null;
            int    _nc  = 0;

            foreach (UANodeContext _item in nodesCollection)
            {
                try
                {
                    ValidateExportNode(_item, exportModelFactory, null, y =>
                    {
                        if (y.TraceLevel != TraceEventType.Verbose)
                        {
                            _errors.Add(y.BuildError);
                        }
                        traceEvent(y);
                    });
                    _nc++;
                }
                catch (Exception _ex)
                {
                    _msg = String.Format("Error caught while processing the node {0}. The message: {1} at {2}.", _item.UANode.NodeId, _ex.Message, _ex.StackTrace);
                    traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NonCategorized, _msg));
                }
            }
            if (_errors.Count == 0)
            {
                _msg = String.Format("Finishing Validator.ValidateExportModel - the model contains {0} nodes.", _nc);
            }
            else
            {
                _msg = String.Format("Finishing Validator.ValidateExportModel - the model contains {0} nodes and {1} errors.", _nc, _errors.Count);
            }
            traceEvent(TraceMessage.DiagnosticTraceMessage(_msg));
        }
コード例 #10
0
 public void UndefinedHasComponentTargetTestMethod()
 {
     FileInfo _testDataFileInfo = new FileInfo(@"ModelsWithErrors\UndefinedHasChildren.xml");
       Assert.IsTrue(_testDataFileInfo.Exists);
       List<TraceMessage> _trace = new List<TraceMessage>();
       int _diagnosticCounter = 0;
       IAddressSpaceContext _as = new AddressSpaceContext(z => TraceDiagnostic(z, _trace, ref _diagnosticCounter));
       Assert.IsNotNull(_as);
       _as.ImportUANodeSet(_testDataFileInfo);
       Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
       _as.ValidateAndExportModel(m_NameSpace);
       Assert.AreEqual<int>(2, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
       Assert.AreEqual<int>(1, _trace.Where<TraceMessage>(x => x.BuildError.Identifier == "P3-0707000002").Count<TraceMessage>());
       Assert.AreEqual<int>(1, _trace.Where<TraceMessage>(x => x.BuildError.Identifier == "P3-0708000000").Count<TraceMessage>());
 }
コード例 #11
0
 public void UndefinedHasTypeDefinitionTestMethod()
 {
     FileInfo _testDataFileInfo = new FileInfo(@"ModelsWithErrors\UndefinedHasTypeDefinition.xml");
       Assert.IsTrue(_testDataFileInfo.Exists);
       List<TraceMessage> _trace = new List<TraceMessage>();
       int _diagnosticCounter = 0;
       IAddressSpaceContext _as = new AddressSpaceContext(z => TraceDiagnostic(z, _trace, ref _diagnosticCounter));
       Assert.IsNotNull(_as);
       _as.ImportUANodeSet(_testDataFileInfo);
       Assert.AreEqual<int>(0, _trace.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, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
       Assert.AreEqual<int>(1, _trace.Where<TraceMessage>(x => x.BuildError.Identifier == "P3-0713000000").Count<TraceMessage>());
 }
コード例 #12
0
        public IUANodeContext GetOrCreateNodeContext(string nodeId, bool lookupAlias)
        {
            NodeId _id = ImportNodeId(nodeId, lookupAlias);

            return(AddressSpaceContext.GetOrCreateNodeContext(_id, this));
        }
コード例 #13
0
        public Parameter ExportArgument(DataSerialization.Argument argument)
        {
            XmlQualifiedName _dataType = ExportBrowseName(argument.DataType.Identifier, DataTypeIds.BaseDataType);

            return(AddressSpaceContext.ExportArgument(argument, _dataType));
        }
コード例 #14
0
 public XmlQualifiedName ExportQualifiedName(QualifiedName source)
 {
     return(new XmlQualifiedName(source.Name, AddressSpaceContext.GetNamespace(source.NamespaceIndex)));
 }
コード例 #15
0
 public void WrongFileNFormatTestMethod()
 {
     FileInfo _testDataFileInfo = new FileInfo(@"XMLModels\CorrectModels\ReferenceTest\ReferenceTest.NodeSet.xml");  //File not compliant with the schema.
       Assert.IsTrue(_testDataFileInfo.Exists);
       List<TraceMessage> _trace = new List<TraceMessage>();
       int _diagnosticCounter = 0;
       IAddressSpaceContext _as = new AddressSpaceContext(z => TraceDiagnostic(z, _trace, ref _diagnosticCounter));
       Assert.IsNotNull(_as);
       Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
       _as.ImportUANodeSet(_testDataFileInfo);
 }
コード例 #16
0
 private List<UANodeContext> ValidationUnitTest(FileInfo _testDataFileInfo, int nodes)
 {
     List<TraceMessage> _trace = new List<TraceMessage>();
       int _diagnosticCounter = 0;
       IAddressSpaceContext _as = new AddressSpaceContext(z => TraceDiagnostic(z, _trace, ref _diagnosticCounter));
       Assert.IsNotNull(_as);
       Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
       _as.ImportUANodeSet(_testDataFileInfo);
       Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
       List<UANodeContext> _nodes = ((AddressSpaceContext)_as).UTValidateAndExportModel(1);
       Assert.AreEqual<int>(nodes, ((AddressSpaceContext)_as).UTValidateAndExportModel(1).Count);
       _as.ValidateAndExportModel();
       Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
       return _nodes;
 }