Пример #1
0
        /// <summary>
        /// Converts an expanded node id to a node id using a namespace table.
        /// </summary>
        public static QualifiedName Create(string name, string namespaceUri, NamespaceTable namespaceTable)
        {
            // check for null.
            if (String.IsNullOrEmpty(name))
            {
                return(QualifiedName.Null);
            }
            // return a name using the default namespace.
            if (String.IsNullOrEmpty(namespaceUri))
            {
                return(new QualifiedName(name));
            }
            // find the namespace index.
            int namespaceIndex = -1;

            if (namespaceTable != null)
            {
                namespaceIndex = namespaceTable.GetIndex(namespaceUri);
            }
            // oops - not found.
            if (namespaceIndex < 0)
            {
                throw new ServiceResultException
                          (TraceMessage.BuildErrorTraceMessage(BuildError.QualifiedNameInvalidSyntax, String.Format("NamespaceUri ({0}) is not in the NamespaceTable.", namespaceUri)), "Cannot create the QualifiedName because NamespaceUri is not in the NamespaceTable.");
            }
            // return the name.
            return(new QualifiedName(name, (ushort)namespaceIndex));
        }
Пример #2
0
        //methods
        private static Exception GetResultException(string _msg)
        {
            BuildError _be = BuildError.ExpandedNodeIdInvalidSyntax;
            Exception  _ex = new ServiceResultException(TraceMessage.BuildErrorTraceMessage(_be, _msg), _be.ToString() + _msg);

            return(_ex);
        }
Пример #3
0
 internal static ModelDesign.AccessLevel GetAccessLevel(this byte?accessLevel, Action <bool> accessLevelSpecified, Action <TraceMessage> traceEvent)
 {
     ModelDesign.AccessLevel _ret = ModelDesign.AccessLevel.None;
     if (!accessLevel.HasValue)
     {
         accessLevelSpecified(false);
         return(_ret);
     }
     if (accessLevel == Opc.Ua.AccessLevels.CurrentReadOrWrite)
     {
         _ret = ModelDesign.AccessLevel.ReadWrite;
     }
     else if (accessLevel == Opc.Ua.AccessLevels.CurrentRead)
     {
         _ret = ModelDesign.AccessLevel.Read;
     }
     else if (accessLevel == Opc.Ua.AccessLevels.CurrentWrite)
     {
         _ret = ModelDesign.AccessLevel.Write;
     }
     else
     {
         traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NotSupportedFeature, String.Format("The AccessLevel value {0:X} is not supported", accessLevel)));
     }
     accessLevelSpecified((int)_ret != 1);
     return(_ret);
 }
Пример #4
0
        public void TraceDiagnosticTestMethod2()
        {
            List <TraceMessage> _listOfTraceMessage = new List <TraceMessage>();
            int _diagnosticCounter = 0;

            TraceHelper.TraceDiagnostic(TraceMessage.BuildErrorTraceMessage(BuildError.NonCategorized, "Test string"), _listOfTraceMessage, ref _diagnosticCounter);
            Assert.AreEqual <int>(1, _listOfTraceMessage.Count);
            Assert.AreEqual <int>(1, _diagnosticCounter);
        }
Пример #5
0
        public void TraceDiagnosticTestMethod3()
        {
            List <TraceMessage> _listOfTraceMessage = new List <TraceMessage>();
            int _diagnosticCounter = 0;

            TraceHelper.TraceDiagnostic(TraceMessage.BuildErrorTraceMessage(BuildError.NodeIdInvalidSyntax, "NodeIdInvalidSyntax"), _listOfTraceMessage, ref _diagnosticCounter);
            Assert.AreEqual <int>(1, _listOfTraceMessage.Count);
            Assert.AreEqual <int>(0, _diagnosticCounter);
        }
Пример #6
0
 /// <summary>
 /// Parses a node id string and returns a node id object.
 /// </summary>
 /// <remarks>
 /// Parses a NodeId String and returns a NodeId object
 /// </remarks>
 /// <param name="text">The NodeId value as a string.</param>
 /// <exception cref="ServiceResultException">Thrown under a variety of circumstances, each time with a specific message.</exception>
 public static NodeId Parse(string text)
 {
     try
     {
         if (String.IsNullOrEmpty(text))
         {
             return(NodeId.Null);
         }
         ushort namespaceIndex = 0;
         // parse the namespace index if present.
         if (text.StartsWith("ns=", StringComparison.Ordinal))
         {
             int index = text.IndexOf(';');
             if (index == -1)
             {
                 throw new ServiceResultException
                           (TraceMessage.BuildErrorTraceMessage(BuildError.NodeIdInvalidSyntax, String.Format("Cannot parse node id text: '{0}'", text)), "BuildError_BadNodeIdInvalid");
             }
             namespaceIndex = Convert.ToUInt16(text.Substring(3, index - 3), CultureInfo.InvariantCulture);
             text           = text.Substring(index + 1);
         }
         // parse numeric node identifier.
         if (text.StartsWith("i=", StringComparison.Ordinal))
         {
             return(new NodeId(Convert.ToUInt32(text.Substring(2), CultureInfo.InvariantCulture), namespaceIndex));
         }
         // parse string node identifier.
         if (text.StartsWith("s=", StringComparison.Ordinal))
         {
             return(new NodeId(text.Substring(2), namespaceIndex));
         }
         // parse guid node identifier.
         if (text.StartsWith("g=", StringComparison.Ordinal))
         {
             return(new NodeId(new System.Guid(text.Substring(2)), namespaceIndex));
         }
         // parse opaque node identifier.
         if (text.StartsWith("b=", StringComparison.Ordinal))
         {
             return(new NodeId(Convert.FromBase64String(text.Substring(2)), namespaceIndex));
         }
         // treat as a string identifier if a namespace was specified.
         if (namespaceIndex != 0)
         {
             return(new NodeId(text, namespaceIndex));
         }
         // treat as URI identifier.
         return(new NodeId(text, 0));
     }
     catch (Exception e)
     {
         throw new ServiceResultException
                   (TraceMessage.BuildErrorTraceMessage(BuildError.NodeIdInvalidSyntax, String.Format("Cannot parse node id text: '{0}'", text)), "BuildError_BadNodeIdInvalid", e);
     }
 }
Пример #7
0
 /// <summary>
 /// Gets the supports events.
 /// </summary>
 /// <param name="eventNotifier">The event notifier. The EventNotifier represents the mandatory EventNotifier attribute of the Object NodeClass and identifies whether
 /// the object can be used to subscribe to events or to read and write the history of the events.</param>
 /// <param name="traceEvent">The trace event.</param>
 /// <returns><c>true</c> if supports events, <c>false</c> otherwise.</returns>
 internal static bool?GetSupportsEvents(this byte eventNotifier, Action <TraceMessage> traceEvent)
 {
     if (eventNotifier > EventNotifiers.SubscribeToEvents + EventNotifiers.HistoryRead + EventNotifiers.HistoryWrite)
     {
         traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongEventNotifier, String.Format("EventNotifier value: {0}", eventNotifier)));
     }
     else if (eventNotifier > EventNotifiers.SubscribeToEvents)
     {
         traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.EventNotifierValueNotSupported, String.Format("EventNotifier value: {0}", eventNotifier)));
     }
     return(eventNotifier != 0 ? (eventNotifier & EventNotifiers.SubscribeToEvents) != 0 : new Nullable <bool>());
 }
Пример #8
0
 internal static QualifiedName Parse(this string qualifiedName, Action <TraceMessage> traceEvent)
 {
     try
     {
         return(QualifiedName.Parse(qualifiedName));
     }
     catch (ServiceResultException _sre)
     {
         traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.QualifiedNameInvalidSyntax, String.Format("Error message: {0}", _sre.Message)));
         return(QualifiedName.Null);
     }
 }
Пример #9
0
 internal static void AddLocalizedText(string keyField, string valueField, ref ModelDesign.LocalizedText description, Action <TraceMessage> traceEvent)
 {
     if (description != null)
     {
         traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NotSupportedFeature, "Parameter.Description does not supports array. The description is skipped."));
         return;
     }
     description = new ModelDesign.LocalizedText()
     {
         Key   = keyField,
         Value = valueField,
     };
 }
Пример #10
0
        public void ServiceResultExceptionCreateWithMessageTestMethod()
        {
            TraceMessage           traceMessage = TraceMessage.BuildErrorTraceMessage(BuildError.NodeIdInvalidSyntax, "BuildError_BadNodeIdInvalid");
            ServiceResultException _ex          = new ServiceResultException(traceMessage, "test message");

            Assert.IsNotNull(_ex);
            Assert.IsNotNull(_ex.TraceMessage);
            Assert.IsNull(_ex.InnerException);
            Assert.AreEqual <string>("test message", _ex.Message);
            Assert.IsNotNull(_ex.TraceMessage);
            Assert.AreEqual <Focus>(BuildError.NodeIdInvalidSyntax.Focus, _ex.TraceMessage.BuildError.Focus);
            Assert.AreEqual <TraceEventType>(TraceEventType.Information, _ex.TraceMessage.TraceLevel);
        }
Пример #11
0
        internal static byte?GetAccessLevel(this byte accessLevel, Action <TraceMessage> traceEvent)
        {
            byte?_ret = new Nullable <byte>();

            if (accessLevel <= 0x7F)
            {
                _ret = accessLevel;
            }
            else
            {
                traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongAccessLevel, String.Format("The AccessLevel value {0:X} is not supported", accessLevel)));
            }
            return(_ret);
        }
Пример #12
0
        /// <summary>
        /// Converts an identifier and a namespaceUri to a local NodeId using the namespaceTable.
        /// </summary>
        /// <param name="identifier">The identifier for the node.</param>
        /// <param name="namespaceUri">The URI to look up.</param>
        /// <param name="namespaceTable">The table to use for the URI lookup.</param>
        /// <returns>A local NodeId</returns>
        /// <exception cref="ServiceResultException">Thrown when the namespace cannot be found</exception>
        public static NodeId Create(object identifier, string namespaceUri, NamespaceTable namespaceTable)
        {
            int index = -1;

            if (namespaceTable != null)
            {
                index = namespaceTable.GetIndex(namespaceUri);
            }
            if (index < 0)
            {
                throw new ServiceResultException(TraceMessage.BuildErrorTraceMessage(BuildError.NodeIdNotDefined, $"NamespaceUri ({namespaceUri}) is not in the namespace table."), "BuildError_BadNodeIdInvalid");
            }
            return(new NodeId(identifier, (ushort)index));
        }
Пример #13
0
 /// <summary>
 /// Parses a expanded node id string and returns a node id object.
 /// </summary>
 /// <remarks>
 /// Parses a ExpandedNodeId String and returns a NodeId object
 /// </remarks>
 /// <param name="text">The ExpandedNodeId value as a string.</param>
 /// <exception cref="ServiceResultException">Thrown under a variety of circumstances, each time with a specific message.</exception>
 public static ExpandedNodeId Parse(string text)
 {
     try
     {
         // check for null.
         if (String.IsNullOrEmpty(text))
         {
             return(ExpandedNodeId.Null);
         }
         uint serverIndex = 0;
         // parse the server index if present.
         if (text.StartsWith("svr=", StringComparison.Ordinal))
         {
             int index = text.IndexOf(';');
             if (index == -1)
             {
                 throw new ServiceResultException(TraceMessage.BuildErrorTraceMessage(BuildError.ExpandedNodeIdInvalidSyntax, "Invalid server index."), "ExpandedNodeId invalid syntax: invalid server index.");
             }
             serverIndex = Convert.ToUInt32(text.Substring(4, index - 4), CultureInfo.InvariantCulture);
             text        = text.Substring(index + 1);
         }
         string namespaceUri = null;
         // parse the namespace uri if present.
         if (text.StartsWith("nsu=", StringComparison.Ordinal))
         {
             int index = text.IndexOf(';');
             if (index == -1)
             {
                 throw GetResultException("Invalid namespace uri.");
             }
             StringBuilder buffer = new StringBuilder();
             UnescapeUri(text, 4, index, buffer);
             namespaceUri = buffer.ToString();
             text         = text.Substring(index + 1);
         }
         // parse the node id.
         NodeId nodeId = NodeId.Parse(text);
         // crete the node id.
         return(new ExpandedNodeId(nodeId, namespaceUri, serverIndex));
     }
     catch (Exception _ex)
     {
         throw GetResultException(String.Format("Cannot parse expanded node id text: '{0}' because of error {1}", text, _ex.Message));
     }
 }
Пример #14
0
        /// <summary>
        /// Gets the value rank.
        /// </summary>
        /// <param name="valueRank">The value rank.</param>
        /// <param name="traceEvent">An <see cref="Action" /> delegate is used to trace event as the <see cref="TraceMessage" />.</param>
        /// <returns>Returns validated value.</returns>
        internal static int?GetValueRank(this int valueRank, Action <TraceMessage> traceEvent)
        {
            int?_vr = new Nullable <int>();

            if (valueRank < -2)
            {
                traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongValueRank, String.Format("The value {0} is not supported", valueRank)));
            }
            else if (valueRank == -3)
            {
                traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongValueRank, String.Format("The value {0} is not supported", valueRank)));
            }
            else if (valueRank != -1)
            {
                _vr = valueRank;
            }
            return(_vr);
        }
Пример #15
0
        /// <summary>
        /// Parses an absolute NodeId formatted as a string and converts it a local NodeId.
        /// </summary>
        /// <param name="namespaceUris">The current namespace table.</param>
        /// <param name="text">The text to parse.</param>
        /// <returns>The local identifier.</returns>
        /// <exception cref="ServiceResultException">Thrown if the namespace URI is not in the namespace table.</exception>
        public static NodeId Parse(string text, NamespaceTable namespaceUris)
        {
            ExpandedNodeId nodeId = ExpandedNodeId.Parse(text);

            if (!nodeId.IsAbsolute)
            {
                return(nodeId.InnerNodeId);
            }
            NodeId localId = ExpandedNodeId.ToNodeId(nodeId, namespaceUris);

            if (localId == null)
            {
                throw new ServiceResultException(
                          TraceMessage.BuildErrorTraceMessage(BuildError.ExpandedNodeIdInvalidSyntax, String.Format("NamespaceUri ({0}) is not in the namespace table.", nodeId.NamespaceUri)),
                          "ExpandedNodeId invalid syntax: namespace URI is not in the namespace table. ");
            }
            return(localId);
        }
Пример #16
0
        //private
        protected void ExportNodes(List <NodeDesign> members, List <string> path, Action <InstanceDesign, List <string> > createInstanceType)
        {
            NodeFactoryBase _currItem = null;

            foreach (NodeFactoryBase _item in m_Nodes)
            {
                try
                {
                    _currItem = _item;
                    NodeDesign _newNode = _item.Export(new List <string>(path), createInstanceType);
                    members.Add(_newNode);
                }
                catch (Exception _ex)
                {
                    string _msg = String.Format("Error caught while processing the node {0}. The message: {1} at {2}.", _currItem.SymbolicName, _ex.Message, _ex.StackTrace);
                    TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NonCategorized, _msg));
                }
            }
        }
Пример #17
0
 /// <summary>
 /// Gets the value rank.
 /// </summary>
 /// <param name="valueRank">The value rank.</param>
 /// <param name="specified">if set to <c>true</c> the parameter is specified.</param>
 /// <param name="traceEvent">An <see cref="Action"/> delegate is used to trace event as the <see cref="TraceMessage"/>.</param>
 /// <returns>Returns value of <see cref="ModelDesign.ValueRank" />.</returns>
 internal static ModelDesign.ValueRank GetValueRank(this int?valueRank, Action <bool> specified, Action <TraceMessage> traceEvent)
 {
     ModelDesign.ValueRank _vr = ModelDesign.ValueRank.Scalar;
     if (!valueRank.HasValue)
     {
         specified(false);
         return(_vr);
     }
     specified(true);
     if (valueRank < -2)
     {
         traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongValueRank, String.Format("The value {0} is not supported", valueRank)));
     }
     else if (valueRank == -3)
     {
         traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongValueRank, String.Format("The value {0} is not supported", valueRank)));
     }
     //_vr = ModelDesign.ValueRank.ScalarOrOneDimension;
     else if (valueRank == -2)
     {
         _vr = ModelDesign.ValueRank.ScalarOrArray;
     }
     else if (valueRank == -1)
     {
         _vr = ModelDesign.ValueRank.Scalar;
         specified(false);
     }
     else if (valueRank == 0)
     {
         _vr = ModelDesign.ValueRank.OneOrMoreDimensions;
     }
     else if (valueRank == 1)
     {
         _vr = ModelDesign.ValueRank.Array;
     }
     else
     {
         _vr = ModelDesign.ValueRank.OneOrMoreDimensions;
     }
     return(_vr);
 }