/// <summary> /// Validates and exports the selected model for the default namespace at index 1 if defined or standard OPC UA. /// </summary> void IAddressSpaceContext.ValidateAndExportModel() { int _nsi = Math.Max(m_NamespaceTable.Count - 1, 0); string _namespace = m_NamespaceTable.GetString((uint)_nsi); m_TraceEvent(TraceMessage.DiagnosticTraceMessage(String.Format("Entering AddressSpaceContext.ValidateAndExportModel - starting for the {0} namespace.", _namespace))); ValidateAndExportModel(_nsi); }
private static void Update(IDataTypeFactory nodeDesign, UADataType nodeSet, IUAModelContext modelContext, Action <TraceMessage> traceEvent) { nodeSet.Definition.GetParameters(nodeDesign.NewDefinition(), modelContext, traceEvent); nodeDesign.DataTypePurpose = nodeSet.Purpose.ConvertToDataTypePurpose(); if (nodeSet.Purpose != XML.DataTypePurpose.Normal) { traceEvent(TraceMessage.DiagnosticTraceMessage($"DataTypePurpose value {nodeSet.Purpose } is not supported by the tool")); } }
private void Update(IDataTypeFactory nodeDesign, UADataType nodeSet) { nodeSet.Definition.GetParameters(nodeDesign.NewDefinition(), AS, Log.TraceEvent); nodeDesign.DataTypePurpose = nodeSet.Purpose.ConvertToDataTypePurpose(); if (nodeSet.Purpose != XML.DataTypePurpose.Normal) { Log.TraceEvent(TraceMessage.DiagnosticTraceMessage($"DataTypePurpose value {nodeSet.Purpose } is not supported by the tool")); } }
/// <summary> /// Imports a part of the OPC UA Address Space contained in the <see cref="UANodeSet" /> object model. /// </summary> /// <param name="model">The model to be imported.</param> /// <exception cref="System.ArgumentNullException">model;the model cannot be null</exception> void IAddressSpaceContext.ImportUANodeSet(UANodeSet model) { m_TraceEvent(TraceMessage.DiagnosticTraceMessage("Entering AddressSpaceContextService.ImportUANodeSet - importing from object model.")); if (model == null) { throw new ArgumentNullException("model", "the model cannot be null"); } ImportNodeSet(model); }
private void ValidateAndExportModel(int nameSpaceIndex) { IEnumerable <UANodeContext> _stubs = from _key in m_NodesDictionary.Values where _key.NodeIdContext.NamespaceIndex == nameSpaceIndex select _key; //TODO ValidateAndExportModel shall export also instances #40 List <UANodeContext> _nodes = (from _node in _stubs where _node.UANode != null && (_node.UANode is UAType) select _node).ToList(); m_TraceEvent(TraceMessage.DiagnosticTraceMessage(String.Format("AddressSpaceContext.ValidateAndExportModel - selected {0} nodes to be added to the model.", _nodes.Count))); Validator.ValidateExportModel(_nodes, InformationModelFactory, this, m_TraceEvent); }
/// <summary> /// Initializes a new instance of the <see cref="AddressSpaceContext" /> class. /// </summary> /// <param name="traceEvent">Encapsulates an action to trace the progress and validation issues.</param> /// <exception cref="System.ArgumentNullException">traceEvent - cannot be null.</exception> public AddressSpaceContext(Action <TraceMessage> traceEvent) { m_TraceEvent = traceEvent ?? throw new ArgumentNullException("traceEvent"); m_NamespaceTable = new NamespaceTable(); m_TraceEvent(TraceMessage.DiagnosticTraceMessage("Entering AddressSpaceContext creator - starting creation the OPC UA Address Space.")); UANodeSet _standard = UANodeSet.ReadUADefinedTypes(); m_TraceEvent(TraceMessage.DiagnosticTraceMessage("Address Space - the OPC UA defined has been uploaded.")); ImportNodeSet(_standard); m_TraceEvent(TraceMessage.DiagnosticTraceMessage("Address Space - has bee created successfully.")); }
/// <summary> /// Validates and exports the selected model. /// </summary> /// <param name="targetNamespace">The target namespace of the validated model.</param> /// <exception cref="System.ArgumentOutOfRangeException">targetNamespace;Cannot find this namespace</exception> void IAddressSpaceContext.ValidateAndExportModel(string targetNamespace) { m_TraceEvent(TraceMessage.DiagnosticTraceMessage(string.Format("Entering IAddressSpaceContext.ValidateAndExportModel - starting for the {0} namespace.", targetNamespace))); int _nsIndex = m_NamespaceTable.GetIndex(targetNamespace); if (_nsIndex == -1) { throw new ArgumentOutOfRangeException("targetNamespace", "Cannot find this namespace"); } ValidateAndExportModel(_nsIndex); }
private static FactoryType CreateNode <FactoryType, NodeSetType> ( Func <FactoryType> createNode, IUANodeBase nodeContext, Action <FactoryType, NodeSetType> updateNode, Action <FactoryType, NodeSetType, IUANodeBase, Action <TraceMessage> > updateBase, Action <TraceMessage> traceEvent ) where FactoryType : INodeFactory where NodeSetType : UANode { FactoryType _nodeFactory = createNode(); nodeContext.CalculateNodeReferences(_nodeFactory); NodeSetType _nodeSet = (NodeSetType)nodeContext.UANode; XmlQualifiedName _browseName = nodeContext.ExportNodeBrowseName(); string _symbolicName; if (string.IsNullOrEmpty(_nodeSet.SymbolicName)) { _symbolicName = _browseName.Name.ValidateIdentifier(traceEvent); //TODO IsValidLanguageIndependentIdentifier is not supported by the .NET standard #340 } else { _symbolicName = _nodeSet.SymbolicName.ValidateIdentifier(traceEvent); //TODO IsValidLanguageIndependentIdentifier is not supported by the .NET standard #340 } _nodeFactory.BrowseName = _browseName.Name.ExportString(_symbolicName); _nodeSet.Description.ExportLocalizedTextArray(_nodeFactory.AddDescription); _nodeSet.DisplayName.Truncate(512, traceEvent).ExportLocalizedTextArray(_nodeFactory.AddDisplayName); _nodeFactory.SymbolicName = new XmlQualifiedName(_symbolicName, _browseName.Namespace); Action <uint, string> _doReport = (x, y) => { traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongWriteMaskValue, string.Format("The current value is {0:x} of the node type {1}.", x, y))); }; _nodeFactory.WriteAccess = _nodeSet is UAVariable?_nodeSet.WriteMask.Validate(0x200000, x => _doReport(x, _nodeSet.GetType().Name)) : _nodeSet.WriteMask.Validate(0x400000, x => _doReport(x, _nodeSet.GetType().Name)); _nodeFactory.AccessRestrictions = ConvertToAccessRestrictions(_nodeSet.AccessRestrictions, _nodeSet.GetType().Name, traceEvent); _nodeFactory.Category = _nodeSet.Category; if (_nodeSet.RolePermissions != null) { traceEvent(TraceMessage.DiagnosticTraceMessage("RolePermissions is not supported. You must fix it manually.")); } if (!string.IsNullOrEmpty(_nodeSet.Documentation)) { traceEvent(TraceMessage.DiagnosticTraceMessage("Documentation is not supported. You must fix it manually.")); } updateBase(_nodeFactory, _nodeSet, nodeContext, traceEvent); updateNode(_nodeFactory, _nodeSet); return(_nodeFactory); }
/// <summary> /// Imports a part of the OPC UA Address Space contained in the file <see cref="FileInfo" />. /// </summary> /// <param name="model">The model to be imported.</param> /// <exception cref="System.IO.FileNotFoundException">The imported file does not exist</exception> void IAddressSpaceContext.ImportUANodeSet(FileInfo model) { m_TraceEvent(TraceMessage.DiagnosticTraceMessage("Entering AddressSpaceContextService.ImportUANodeSet - importing form file")); if (model == null) { throw new ArgumentNullException("model", "the model cannot be null"); } if (!model.Exists) { throw new FileNotFoundException("The imported file does not exist", model.FullName); } UANodeSet _nodeSet = UANodeSet.ReadModellFile(model); ImportNodeSet(_nodeSet); }
/// <summary> /// Initializes a new instance of the <see cref="AddressSpaceContext" /> class. /// </summary> /// <param name="traceEvent">Encapsulates an action to trace the progress and validation issues.</param> /// <exception cref="System.ArgumentNullException">traceEvent - cannot be null.</exception> public AddressSpaceContext(Action <TraceMessage> traceEvent) { if (traceEvent == null) { throw new ArgumentNullException("traceEvent"); } m_NamespaceTable = new NamespaceTable(traceEvent); m_TraceEvent = x => { }; traceEvent(TraceMessage.DiagnosticTraceMessage("Entering AddressSpaceContext creator - starting address space validation.")); UANodeSet _standard = UANodeSet.ReadUADefinedTypes(); Debug.Assert(_standard != null); traceEvent(TraceMessage.DiagnosticTraceMessage("AddressSpaceContext - uploading the OPC UA defined types.")); ImportNodeSet(_standard); m_TraceEvent = traceEvent; m_TraceEvent(TraceMessage.DiagnosticTraceMessage("AddressSpaceContext - has bee created successfully.")); }
/// <summary> /// Validates the selected nodes <paramref name="nodesCollection"/> and export it using <paramref name="exportModelFactory"/>. /// </summary> /// <param name="nodesCollection">The items <see cref="IEnumerable{IUANodeBase}" /> 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 <IUANodeBase> nodesCollection, IModelFactory exportModelFactory, IAddressSpaceValidationContext addressSpaceContext, Action <TraceMessage> traceEvent) { traceEvent(TraceMessage.DiagnosticTraceMessage(string.Format("Entering Validator.ValidateExportModel - starting creation of the ModelDesign for {0} nodes.", nodesCollection.Count <IUANodeBase>()))); List <BuildError> _errors = new List <BuildError>(); //TODO should be added to the model; foreach (IModelTableEntry _ns in addressSpaceContext.ExportNamespaceTable) { string _publicationDate = _ns.PublicationDate.HasValue ? _ns.PublicationDate.Value.ToShortDateString() : DateTime.UtcNow.ToShortDateString(); string _version = _ns.Version; exportModelFactory.CreateNamespace(_ns.ModelUri, _publicationDate, _version); } string _msg = null; int _nc = 0; foreach (IUANodeBase _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)); }
/// <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)); }
private void ImportUANode(UANode node, UAModelContext modelContext, Action <TraceMessage> traceEvent) { try { if (node == null) { m_TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NodeCannotBeNull, "At Importing UANode.")); } NodeId nodeId = modelContext.ImportNodeId(node.NodeId, false, m_TraceEvent); UANodeContext _newNode = null; string nodeIdKey = nodeId.ToString(); if (!m_NodesDictionary.TryGetValue(nodeIdKey, out _newNode)) { _newNode = new UANodeContext(this, modelContext, nodeId); _newNode.Update(node, traceEvent); m_NodesDictionary.Add(nodeIdKey, _newNode); } else { if (_newNode.UANode != null) { m_TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NodeIdDuplicated, String.Format("The {0} is already defined.", node.NodeId.ToString()))); } _newNode.Update(node, traceEvent); } foreach (Reference _rf in node.References) { UAReferenceContext _rs = UAReferenceContext.NewReferenceStub(_rf, this, modelContext, _newNode, m_TraceEvent); if (!m_References.ContainsKey(_rs.Key)) { m_References.Add(_rs.Key, _rs); } } } catch (Exception _ex) { string _msg = String.Format("ImportUANode {1} is interrupted by exception {0}", _ex.Message, node.NodeId); m_TraceEvent(TraceMessage.DiagnosticTraceMessage(_msg)); } }
//methods private void ImportNodeSet(UANodeSet model) { if (model.ServerUris != null) { m_TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NotSupportedFeature, "ServerUris is omitted during the import")); } if (model.Extensions != null) { m_TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NotSupportedFeature, "Extensions is omitted during the import")); } string _namespace = model.NamespaceUris == null?m_NamespaceTable.GetString(0) : model.NamespaceUris[0]; m_TraceEvent(TraceMessage.DiagnosticTraceMessage(String.Format("Entering AddressSpaceContext.ImportNodeSet - starting import {0}.", _namespace))); UAModelContext _modelContext = new UAModelContext(model.Aliases, model.NamespaceUris, this); m_TraceEvent(TraceMessage.DiagnosticTraceMessage("AddressSpaceContext.ImportNodeSet - context for imported model is created and starting import nodes.")); foreach (UANode _nd in model.Items) { this.ImportUANode(_nd, _modelContext, m_TraceEvent); } m_TraceEvent(TraceMessage.DiagnosticTraceMessage(String.Format("Finishing AddressSpaceContext.ImportNodeSet - imported {0} nodes.", model.Items.Length))); }