Esempio n. 1
0
 internal static string ValidateIdentifier(this string name, Action <TraceMessage> reportError)
 {
     if (!System.CodeDom.Compiler.CodeGenerator.IsValidLanguageIndependentIdentifier(name))
     {
         reportError(TraceMessage.BuildErrorTraceMessage(BuildError.WrongSymbolicName, String.Format("SymbolicName: '{0}'.", name)));
     }
     return(name);
 }
Esempio n. 2
0
 /// <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);
 }
Esempio n. 3
0
 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"));
     }
 }
Esempio n. 4
0
 private static AccessRestrictions ConvertToAccessRestrictions(byte accessRestrictions, string typeName, Action <TraceMessage> traceEvent)
 {
     if (accessRestrictions > 7)
     {
         traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongAccessLevel, $"The current value is {accessRestrictions} of the node type {typeName}. Assigned max value"));
         return(AccessRestrictions.EncryptionRequired & AccessRestrictions.SessionRequired & AccessRestrictions.SigningRequired);
     }
     return((AccessRestrictions)accessRestrictions);
 }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
 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"));
     }
 }
Esempio n. 7
0
        /// <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);
        }
        /// <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."));
        }
Esempio n. 9
0
 //methods
 /// <summary>
 /// Gets or sets the name of the m browse.
 /// </summary>
 /// <value>The name of the m browse.</value>
 private void TraceErrorUndefinedBaseType(NodeId target, bool type, Action <TraceMessage> traceEvent)
 {
     if (type)
     {
         string _msg = string.Format("BaseType of Id={0} for node {1}", target, this.BrowseName);
         traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.UndefinedHasSubtypeTarget, _msg));
     }
     else
     {
         string _msg = string.Format("TypeDefinition of Id={0} for node {1}", target, this.BrowseName);
         traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.UndefinedHasTypeDefinition, _msg));
     }
 }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
 private static void Update(IVariableInstanceFactory nodeDesign, UAVariable nodeSet, IUANodeBase nodeContext, Action <TraceMessage> traceEvent)
 {
     nodeDesign.AccessLevel             = nodeSet.AccessLevel.GetAccessLevel(traceEvent);
     nodeDesign.ArrayDimensions         = nodeSet.ArrayDimensions.ExportString(string.Empty);
     nodeDesign.DataType                = nodeContext.ExportBrowseName(nodeSet.DataType, DataTypes.Number); //TODO add test case must be DataType, must not be abstract
     nodeDesign.DefaultValue            = nodeSet.Value;                                                    //TODO add test case must be of type defined by DataType
     nodeDesign.Historizing             = nodeSet.Historizing.Export(false);
     nodeDesign.MinimumSamplingInterval = nodeSet.MinimumSamplingInterval.Export(0D);
     nodeDesign.ValueRank               = nodeSet.ValueRank.GetValueRank(traceEvent);
     if (nodeSet.Translation != null)
     {
         traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NotSupportedFeature, "- the Translation element for the UAVariable"));
     }
 }
Esempio n. 12
0
 private static void Update(IReferenceTypeFactory nodeDesign, UAReferenceType nodeSet, Action <TraceMessage> traceEvent)
 {
     nodeSet.InverseName.ExportLocalizedTextArray(nodeDesign.AddInverseName);
     nodeDesign.Symmetric = nodeSet.Symmetric;
     if (nodeSet.Symmetric && (nodeSet.InverseName != null && nodeSet.InverseName.Where(x => !string.IsNullOrEmpty(x.Value)).Any()))
     {
         XML.LocalizedText _notEmpty = nodeSet.InverseName.Where(x => !string.IsNullOrEmpty(x.Value)).First();
         traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongInverseName, string.Format("If ReferenceType {0} is symmetric the InverseName {1}:{2} shall be omitted.", nodeSet.NodeIdentifier(), _notEmpty.Locale, _notEmpty.Value)));
     }
     else if (!nodeSet.Symmetric && !nodeSet.IsAbstract && (nodeSet.InverseName == null || !nodeSet.InverseName.Where(x => !string.IsNullOrEmpty(x.Value)).Any()))
     {
         traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongInverseName, string.Format("If ReferenceType {0} is not symmetric and not abstract the InverseName shall be specified.", nodeSet.NodeIdentifier())));
     }
 }
Esempio n. 13
0
        /// <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);
        }
Esempio n. 14
0
        /// <summary>
        /// Updates this instance in case the wrapped <see cref="UANode" /> is recognized in the model.
        /// </summary>
        /// <param name="node">The node <see cref="UANode" /> containing definition to be added to the model.</param>
        /// <param name="addReference">Used to add new reference to the common collection of references.</param>
        /// <exception cref="ArgumentException">node - Argument must not be null</exception>
        public void Update(UANode node, Action <UAReferenceContext> addReference)
        {
            if (node == null)
            {
                throw new ArgumentException(nameof(node), $"Argument must not be null at {nameof(Update)} ");
            }
            if (this.UANode != null)
            {
                Log.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NodeIdDuplicated, string.Format("The {0} is already defined and is removed from further processing.", node.NodeId.ToString())));
                return;
            }
            UANode          = node;
            this.BrowseName = node.BrowseName.Parse(Log.TraceEvent);
            if (QualifiedName.IsNull(this.BrowseName))
            {
                NodeId _id = NodeId.Parse(UANode.NodeId);
                this.BrowseName = new QualifiedName($"EmptyBrowseName_{_id.IdentifierPart}", _id.NamespaceIndex);
                Log.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.EmptyBrowseName, $"New identifier {this.BrowseName} is generated to proceed."));
            }
            if (node.References == null)
            {
                return;
            }
            foreach (Reference _reference in node.References)
            {
                UAReferenceContext _newReference = new UAReferenceContext(_reference, this.m_AddressSpaceContext, this);
                switch (_newReference.ReferenceKind)
                {
                case ReferenceKindEnum.Custom:
                case ReferenceKindEnum.HasComponent:
                case ReferenceKindEnum.HasProperty:
                    break;

                case ReferenceKindEnum.HasModellingRule:
                    ModelingRule = _newReference.GetModelingRule();
                    break;

                case ReferenceKindEnum.HasSubtype: //TODO Part 3 7.10 HasSubtype - add test cases #35
                    m_BaseTypeNode = _newReference.SourceNode;
                    break;

                case ReferenceKindEnum.HasTypeDefinition: //Recognize problems with P3.7.13 HasTypeDefinition ReferenceType #39
                    m_BaseTypeNode = _newReference.TargetNode;
                    break;
                }
                addReference(_newReference);
            }
        }
Esempio n. 15
0
 private void Update(IPropertyInstanceFactory propertyInstance, UAVariable nodeSet, IUANodeBase nodeContext, UAReferenceContext parentReference)
 {
     try
     {
         Update(propertyInstance, nodeSet);
         propertyInstance.ReferenceType = parentReference == null ? null : parentReference.GetReferenceTypeName();
         if (!nodeContext.IsProperty)
         {
             Log.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongReference2Property, $"Creating Property {nodeContext.BrowseName}- wrong reference type {parentReference.ReferenceKind.ToString()}"));
         }
     }
     catch (Exception _ex)
     {
         Log.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongReference2Property, string.Format("Cannot resolve the reference for Property because of error {0} at: {1}.", _ex, _ex.StackTrace)));
     }
 }
Esempio n. 16
0
 private static void Update(IVariableInstanceFactory variableInstance, UAVariable nodeSet, IUANodeBase nodeContext, UAReferenceContext parentReference, Action <TraceMessage> traceEvent)
 {
     try
     {
         Update(variableInstance, nodeSet, nodeContext, traceEvent);
         variableInstance.ReferenceType = parentReference == null ? null : parentReference.GetReferenceTypeName();
         if (nodeContext.IsProperty)
         {
             traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongReference2Variable, string.Format("Creating Variable - wrong reference type {0}", parentReference.ReferenceKind.ToString())));
         }
     }
     catch (Exception _ex)
     {
         traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongReference2Property, string.Format("Cannot resolve the reference for Variable because of error {0} at: {1}.", _ex, _ex.StackTrace)));
     }
 }
Esempio n. 17
0
        private UANodeContext TryGetUANodeContext(NodeId nodeId, Action <TraceMessage> traceEvent)
        {
            UANodeContext _ret;

            if (!m_NodesDictionary.TryGetValue(nodeId.ToString(), out _ret))
            {
                traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NodeIdNotDefined, String.Format("References to node with NodeId: {0} is omitted during the import.", nodeId)));
                return(null);
            }
            if (_ret.UANode == null)
            {
                traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NodeIdNotDefined, String.Format("NodeId: {0} is omitted during the import.", nodeId)));
                return(null);
            }
            return(_ret);
        }
Esempio n. 18
0
        /// <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>
        /// Updates this instance in case the wrapped <see cref="UANode"/> is recognized in the model.
        /// </summary>
        /// <param name="node">The node <see cref="UANode"/> containing definition to be added to the model.</param>
        /// <param name="traceEvent">A delegate <see cref="Action{TraceMessage}"/> encapsulates an action to report any errors and trace processing progress.</param>
        internal void Update(UANode node, Action <TraceMessage> traceEvent)
        {
            if (node == null)
            {
                return;
            }
            m_UAnode = node;
            QualifiedName _broseName = node.BrowseName.Parse(traceEvent);

            Debug.Assert(m_BrowseName != null);
            if (QualifiedName.IsNull(_broseName))
            {
                NodeId _id = NodeId.Parse(UANode.NodeId);
                _broseName = new QualifiedName(string.Format("EmptyBrowseName{0}", _id.IdentifierPart), _id.NamespaceIndex);
                traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.EmptyBrowseName, String.Format("New identifier {0} is generated to proceed.", _broseName)));
            }
            m_BrowseName = m_ModelContext.ImportQualifiedName(_broseName);
        }
Esempio n. 20
0
        /// <summary>
        /// Updates this instance in case the wrapped <see cref="UANode"/> is recognized in the model.
        /// </summary>
        /// <param name="node">The node <see cref="UANode"/> containing definition to be added to the model.</param>
        void IUANodeContext.Update(UANode node)
        {
            if (node == null)
            {
                return;
            }
            UANode = node;
            QualifiedName _broseName = node.BrowseName.Parse(BuildErrorsHandling.Log.TraceEvent);

            Debug.Assert(BrowseName != null);
            if (QualifiedName.IsNull(_broseName))
            {
                NodeId _id = NodeId.Parse(UANode.NodeId);
                _broseName = new QualifiedName(string.Format("EmptyBrowseName{0}", _id.IdentifierPart), _id.NamespaceIndex);
                BuildErrorsHandling.Log.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.EmptyBrowseName, string.Format("New identifier {0} is generated to proceed.", _broseName)));
            }
            BrowseName = UAModelContext.ImportQualifiedName(_broseName);
        }
Esempio n. 21
0
        /// <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));
        }
Esempio n. 22
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));
        }
        /// <summary>
        /// Builds the symbolic identifier.
        /// </summary>
        /// <param name="path">The browse path.</param>
        /// <param name="traceEvent">A delegate <see cref="Action{TraceMessage}"/> encapsulates an action to report any errors and trace processing progress.</param>
        internal void BuildSymbolicId(List <string> path, Action <TraceMessage> traceEvent)
        {
            if (this.UANode == null)
            {
                traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.DanglingReferenceTarget, ""));
                return;
            }
            IEnumerable <UAReferenceContext> _parentConnector = m_AddressSpaceContext.GetReferences2Me(this).Where <UAReferenceContext>(x => x.ChildConnector);

            Debug.Assert(_parentConnector.Count <UAReferenceContext>() <= 1);
            UAReferenceContext _connector = _parentConnector.FirstOrDefault <UAReferenceContext>();

            if (_connector != null)
            {
                _connector.BuildSymbolicId(path, traceEvent);
            }
            string _BranchName = String.IsNullOrEmpty(this.UANode.SymbolicName) ? this.m_BrowseName.Name : this.UANode.SymbolicName;

            path.Add(_BranchName);
        }
Esempio n. 24
0
        /// <summary>
        /// Builds the symbolic identifier.
        /// </summary>
        /// <param name="path">The browse path.</param>
        public void BuildSymbolicId(List <string> path)
        {
            if (this.UANode == null)
            {
                Log.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.DanglingReferenceTarget, $"The target node NodeId={this.NodeIdContext}, current path {string.Join(", ", path)}"));
                return;
            }
            IEnumerable <UAReferenceContext> _parentConnector = m_AddressSpaceContext.GetReferences2Me(this).Where <UAReferenceContext>(x => x.ChildConnector);

            Debug.Assert(_parentConnector.Count <UAReferenceContext>() <= 1); //TODO #40; ValidateAndExportModel shall export also instances #40
            UAReferenceContext _connector = _parentConnector.FirstOrDefault <UAReferenceContext>();

            if (_connector != null)
            {
                _connector.BuildSymbolicId(path);
            }
            string _BranchName = string.IsNullOrEmpty(this.UANode.SymbolicName) ? this.BrowseName.Name : this.UANode.SymbolicName;

            path.Add(_BranchName);
        }
Esempio n. 25
0
        private static FactoryType CreateNode <FactoryType, NodeSetType>
        (
            Func <FactoryType> createNode,
            UANodeContext nodeContext,
            Action <FactoryType, NodeSetType> updateNode,
            Action <FactoryType, NodeSetType, UANodeContext, Action <TraceMessage> > updateBase,
            Action <TraceMessage> traceEvent
        )
            where FactoryType : INodeFactory
            where NodeSetType : UANode
        {
            FactoryType _nodeFactory = createNode();

            nodeContext.CalculateNodeReferences(_nodeFactory, traceEvent);
            NodeSetType      _nodeSet    = (NodeSetType)nodeContext.UANode;
            XmlQualifiedName _browseName = nodeContext.ExportNodeBrowseName();
            string           _symbolicName;

            if (String.IsNullOrEmpty(_nodeSet.SymbolicName))
            {
                _symbolicName = _browseName.Name.ValidateIdentifier(traceEvent);
            }
            else
            {
                _symbolicName = _nodeSet.SymbolicName.ValidateIdentifier(traceEvent);
            }
            _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 <UInt32, 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));

            updateBase(_nodeFactory, _nodeSet, nodeContext, traceEvent);
            updateNode(_nodeFactory, _nodeSet);
            return(_nodeFactory);
        }
Esempio n. 26
0
        private ushort ImportNamespaceIndex(ushort namespaceIndex)
        {
            // nothing special required for indexes < 0.
            if (namespaceIndex == 0)
            {
                return(namespaceIndex);
            }
            // return a new value if parameter is out of range.
            string _identifier = $"NameUnknown{m_NamespaceCount++}";

            if (m_UANodeSetModel.NamespaceUris.Length > namespaceIndex - 1)
            {
                _identifier = m_UANodeSetModel.NamespaceUris[namespaceIndex - 1];
            }
            else
            {
                BuildErrorsHandling.Log.TraceEvent(
                    TraceMessage.BuildErrorTraceMessage(BuildError.UndefinedNamespaceIndex, $"ImportNamespaceIndex failed - namespace index {namespaceIndex-1} is out of the NamespaceUris index. New namespace {_identifier} is created insted."));
            }
            return(AddressSpaceContext.GetIndexOrAppend(_identifier));
        }
Esempio n. 27
0
 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));
     }
 }
Esempio n. 28
0
        //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)));
        }
Esempio n. 29
0
        internal static XML.LocalizedText[] Truncate(this XML.LocalizedText[] localizedText, int maxLength, Action <TraceMessage> reportError)
        {
            if (localizedText == null || localizedText.Length == 0)
            {
                return(null);
            }
            List <XML.LocalizedText> _ret = new List <XML.LocalizedText>();

            foreach (XML.LocalizedText _item in localizedText)
            {
                if (_item.Value.Length > maxLength)
                {
                    reportError(TraceMessage.BuildErrorTraceMessage(BuildError.WrongDisplayNameLength, string.Format
                                                                        ("The localized text starting with '{0}:{1}' of length {2} is too long.", _item.Locale, _item.Value.Substring(0, 20), _item.Value.Length)));
                    XML.LocalizedText _localizedText = new XML.LocalizedText()
                    {
                        Locale = _item.Locale,
                        Value  = _item.Value.Substring(0, maxLength)
                    };
                }
            }
            return(localizedText);
        }
 private void TraceDiagnostic(TraceMessage msg, List<TraceMessage> errors, ref int diagnosticCounter)
 {
     Console.WriteLine(msg.ToString());
       if (msg.BuildError.Focus == Focus.Diagnostic)
       {
     diagnosticCounter++;
       }
       else
     errors.Add(msg);
 }
Esempio n. 31
0
        /// <summary>
        /// Validates <paramref name="nodeContext"/> and exports it using an object of <see cref="IModelFactory"/>  type.
        /// </summary>
        /// <param name="nodeContext">The node context to be validated and exported.</param>
        /// <param name="exportFactory">A model export factory.</param>
        /// <param name="parentReference">The reference to parent node.</param>
        /// <param name="traceEvent">The trace event.</param>
        /// <returns>An object of <see cref="INodeFactory"/>.</returns>
        internal static void ValidateExportNode(IUANodeBase nodeContext, INodeContainer exportFactory, UAReferenceContext parentReference, Action <TraceMessage> traceEvent)
        {
            Debug.Assert(nodeContext != null, "Validator.ValidateExportNode the argument nodeContext is null.");
            //TODO Handle HasComponent ReferenceType errors. #42
            if (nodeContext.UANode == null)
            {
                string     _msg = string.Format("The node {0} is undefined", nodeContext.NodeIdContext);
                BuildError _be  = null;
                if (parentReference == null || parentReference.ReferenceKind == ReferenceKindEnum.HasProperty)
                {
                    _be = BuildError.UndefinedHasPropertyTarget;
                }
                else
                {
                    _be = BuildError.UndefinedHasComponentTarget;
                }
                TraceMessage _traceMessage = TraceMessage.BuildErrorTraceMessage(_be, _msg);
                traceEvent(_traceMessage);
                CreateModelDesignStub(exportFactory);
            }
            else
            {
                string nodeType = nodeContext.UANode.GetType().Name;
                switch (nodeType)
                {
                case "UAReferenceType":
                    CreateNode <IReferenceTypeFactory, UAReferenceType>(exportFactory.AddNodeFactory <IReferenceTypeFactory>, nodeContext, (x, y) => Update(x, y, traceEvent), UpdateType, traceEvent);
                    break;

                case "UADataType":
                    CreateNode <IDataTypeFactory, UADataType>(exportFactory.AddNodeFactory <IDataTypeFactory>, nodeContext, (x, y) => Update(x, y, nodeContext.UAModelContext, traceEvent), UpdateType, traceEvent);
                    break;

                case "UAVariableType":
                    CreateNode <IVariableTypeFactory, UAVariableType>(exportFactory.AddNodeFactory <IVariableTypeFactory>, nodeContext, (x, y) => Update(x, y, nodeContext, traceEvent), UpdateType, traceEvent);
                    break;

                case "UAObjectType":
                    CreateNode <IObjectTypeFactory, UAObjectType>(exportFactory.AddNodeFactory <IObjectTypeFactory>, nodeContext, Update, UpdateType, traceEvent);
                    break;

                case "UAView":
                    CreateNode <IViewInstanceFactory, UAView>(exportFactory.AddNodeFactory <IViewInstanceFactory>, nodeContext, (x, y) => Update(x, y, traceEvent), UpdateInstance, traceEvent);
                    break;

                case "UAMethod":
                    CreateNode <IMethodInstanceFactory, UAMethod>(exportFactory.AddNodeFactory <IMethodInstanceFactory>, nodeContext, (x, y) => Update(x, y, nodeContext, parentReference, traceEvent), UpdateInstance, traceEvent);
                    break;

                case "UAVariable":
                    if (parentReference == null || parentReference.ReferenceKind == ReferenceKindEnum.HasProperty)
                    {
                        CreateNode <IPropertyInstanceFactory, UAVariable>(exportFactory.AddNodeFactory <IPropertyInstanceFactory>, nodeContext, (x, y) => Update(x, y, nodeContext, parentReference, traceEvent), UpdateInstance, traceEvent);
                    }
                    else
                    {
                        CreateNode <IVariableInstanceFactory, UAVariable>(exportFactory.AddNodeFactory <IVariableInstanceFactory>, nodeContext, (x, y) => Update(x, y, nodeContext, parentReference, traceEvent), UpdateInstance, traceEvent);
                    }
                    break;

                case "UAObject":
                    CreateNode <IObjectInstanceFactory, UAObject>(exportFactory.AddNodeFactory <IObjectInstanceFactory>, nodeContext, (x, y) => Update(x, y, traceEvent), UpdateInstance, traceEvent);
                    break;

                default:
                    Debug.Assert(false, "Wrong node type");
                    break;
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceResultException"/> class.
 /// </summary>
 /// <param name="traceMessage">The trace message.</param>
 /// <param name="message">The message.</param>
 /// <param name="inner">The inner.</param>
 public ServiceResultException(TraceMessage traceMessage, string message, Exception inner)
     : base(message, inner)
 {
     TraceMessage = traceMessage;
 }