コード例 #1
0
 /// <summary>
 /// Constructs a object by specifying each property.
 /// </summary>
 public ServiceResult(
     StatusCode    code,
     ServiceResult innerResult)
 :
     this(code, null, null, null, null, innerResult)
 {
 }        
コード例 #2
0
ファイル: StatusCode.cs プロジェクト: yuriik83/UA-.NET
        /// <summary>
        /// Checks if the status code is bad.
        /// </summary>
        public static bool IsBad(StatusCode statusCode)
        {
            if ((ToCode(statusCode) & 0x80000000) != 0)
            {
                return true;
            }

            return false;
        }
コード例 #3
0
ファイル: StatusCode.cs プロジェクト: yuriik83/UA-.NET
        /// <summary>
        /// Converts a code to a numeric value.
        /// </summary>
        public static uint ToCode(StatusCode statusCode)
        {
            if (statusCode == null)
            {
                return StatusCodes.Good;
            }

            return statusCode.Code;
        }
コード例 #4
0
 /// <summary>
 /// Constructs a object by specifying each property.
 /// </summary>
 public ServiceResult(
     StatusCode    code,
     string        symbolicId,
     string        namespaceUri,
     LocalizedText localizedText,
     string        additionalInfo)
 :
     this(code, symbolicId, namespaceUri, localizedText, additionalInfo, (ServiceResult)null)
 {
 }
コード例 #5
0
        /// <summary>
        /// Updates the variable after receiving a notification that it has changed in the underlying system.
        /// </summary>
        public void OnDataChange(BaseVariableState variable, object value, StatusCode statusCode, DateTime timestamp)
        {
            lock (Lock)
            {
                variable.Value = value;
                variable.StatusCode = statusCode;
                variable.Timestamp = timestamp;

                // notifies any monitored items that the value has changed.
                variable.ClearChangeMasks(SystemContext, false);
            }
        }
コード例 #6
0
 /// <summary>
 /// Constructs a object by specifying each property.
 /// </summary>
 public ServiceResult(
     StatusCode    code,
     string        symbolicId,
     string        namespaceUri,
     LocalizedText localizedText,
     string        additionalInfo,
     ServiceResult innerResult)
 {
     StatusCode     = code;
     SymbolicId     = symbolicId;
     NamespaceUri   = namespaceUri;
     LocalizedText  = localizedText;
     AdditionalInfo = additionalInfo;
     InnerResult    = innerResult;
 }
コード例 #7
0
 /// <summary>
 /// Constructs a object by specifying each property.
 /// </summary>
 /// <remarks>
 /// The innerException is used to construct the innerResult.
 /// </remarks>
 public ServiceResult(StatusCode code, Exception innerException)
 :
     this(code, null, null, null, null, innerException)
 {
 }
コード例 #8
0
 /// <summary>
 /// Constructs a object by specifying each property.
 /// </summary>
 /// <remarks>
 /// The innerException is used to construct the innerResult.
 /// </remarks>
 public ServiceResult(
     StatusCode    code,
     string        symbolicId,
     string        namespaceUri,           
     Exception     innerException)
 :
     this(code, symbolicId, namespaceUri, null, null, innerException)
 {
 }
コード例 #9
0
 /// <summary>
 /// Constructs a object from a StatusCode.
 /// </summary>
 public ServiceResult(StatusCode status)
 {
     m_code = status.Code;
 }
コード例 #10
0
 /// <summary>
 /// Initializes the object with a status code.
 /// </summary>
 /// <remarks>
 /// Initializes the object with a status code.
 /// </remarks>
 /// <param name="statusCode">The StatusCode to set</param>
 public DataValue(StatusCode statusCode)
 {
     Initialize();
     m_statusCode = statusCode;
 }
コード例 #11
0
ファイル: SubscribeDlg.cs プロジェクト: yuriik83/UA-.NET
        /// <summary>
        /// Adds a value to the grid.
        /// </summary>
        private void AddValue(DataValue value, ModificationInfo modificationInfo)
        {
            DataRow row = m_dataset.Tables[0].NewRow();

            row[0] = m_nextId++;
            row[1] = value.SourceTimestamp.ToLocalTime().ToString("HH:mm:ss.fff");
            row[2] = value.WrappedValue;
            row[3] = new StatusCode(value.StatusCode.Code);

            if (value.WrappedValue.TypeInfo != null)
            {
                row[4] = value.WrappedValue.TypeInfo.BuiltInType.ToString();
            }
            else
            {
                row[4] = String.Empty;
            }

            m_dataset.Tables[0].Rows.Add(row);
        }
コード例 #12
0
 /// <summary>
 /// Returns true if the status is good or uncertain.
 /// </summary>
 /// <remarks>
 /// Returns true if the status is good or uncertain.
 /// </remarks>
 /// <param name="code">The code to check</param>
 public static bool IsNotUncertain(StatusCode code)
 {
     return((code.m_code & 0x40000000) != 0x40000000);
 }
コード例 #13
0
 /// <summary>
 /// Creates a new instance of a ServiceResultException
 /// </summary>
 public static ServiceResultException Create(StatusCode code, int index, DiagnosticInfoCollection diagnosticInfos, IList <string> stringTable)
 {
     return(new ServiceResultException(new ServiceResult(code, index, diagnosticInfos, stringTable)));
 }
コード例 #14
0
        /// <summary>
        /// Applies the multidimensional index range.
        /// </summary>
        private StatusCode ApplyMultiRange(ref object value)
        {
            Array    array    = value as Array;
            TypeInfo typeInfo = null;

            // check for matrix.
            if (array == null)
            {
                Matrix matrix = value as Matrix;

                if (matrix == null || matrix.Dimensions.Length != m_subranges.Length)
                {
                    value = null;
                    return(StatusCodes.BadIndexRangeNoData);
                }

                array = matrix.ToArray();
            }

            typeInfo = TypeInfo.Construct(array);

            // check for matching dimensions.
            NumericRange?finalRange = null;

            if (m_subranges.Length > typeInfo.ValueRank)
            {
                if (typeInfo.BuiltInType == BuiltInType.ByteString || typeInfo.BuiltInType == BuiltInType.String)
                {
                    if (m_subranges.Length == typeInfo.ValueRank + 1)
                    {
                        finalRange = m_subranges[m_subranges.Length - 1];
                    }
                }

                if (finalRange == null)
                {
                    value = null;
                    return(StatusCodes.BadIndexRangeNoData);
                }
            }

            // create the dimensions of the target.
            int[] dimensions = new int[typeInfo.ValueRank];

            for (int ii = 0; ii < dimensions.Length; ii++)
            {
                if (m_subranges.Length > ii)
                {
                    if (m_subranges[ii].m_begin >= array.GetLength(ii))
                    {
                        value = null;
                        return(StatusCodes.BadIndexRangeNoData);
                    }

                    dimensions[ii] = m_subranges[ii].Count;
                }
                else
                {
                    dimensions[ii] = array.GetLength(ii);
                }
            }

            Array subset = TypeInfo.CreateArray(typeInfo.BuiltInType, dimensions);

            int length = subset.Length;

            int[] dstIndexes = new int[dimensions.Length];
            int[] srcIndexes = new int[dimensions.Length];

            bool dataFound = false;

            for (int ii = 0; ii < length; ii++)
            {
                int  divisor    = subset.Length;
                bool outOfRange = false;

                for (int jj = 0; jj < dstIndexes.Length; jj++)
                {
                    divisor       /= dimensions[jj];
                    dstIndexes[jj] = (ii / divisor) % dimensions[jj];
                    srcIndexes[jj] = dstIndexes[jj] + m_subranges[jj].m_begin;

                    if (array.GetLength(jj) <= srcIndexes[jj])
                    {
                        outOfRange = true;
                        break;
                    }
                }

                if (outOfRange)
                {
                    continue;
                }

                object element = array.GetValue(srcIndexes);

                if (element != null)
                {
                    if (finalRange != null)
                    {
                        StatusCode result = finalRange.Value.ApplyRange(ref element);

                        if (StatusCode.IsBad(result))
                        {
                            if (result != StatusCodes.BadIndexRangeNoData)
                            {
                                value = null;
                                return(result);
                            }

                            continue;
                        }
                    }

                    dataFound = true;
                    subset.SetValue(element, dstIndexes);
                }
            }

            if (!dataFound)
            {
                value = null;
                return(StatusCodes.BadIndexRangeNoData);
            }

            value = subset;
            return(StatusCodes.Good);
        }
コード例 #15
0
        /// <summary>
        /// Returns the certificate information for a trusted issuer certificate.
        /// </summary>
        private async Task <CertificateIdentifier> GetIssuer(
            X509Certificate2 certificate,
            CertificateIdentifierCollection explicitList,
            CertificateStoreIdentifier certificateStore,
            bool checkRecovationStatus)
        {
            string subjectName  = certificate.IssuerName.Name;
            string keyId        = null;
            string serialNumber = null;

            // find the authority key identifier.
            X509AuthorityKeyIdentifierExtension authority = FindAuthorityKeyIdentifier(certificate);

            if (authority != null)
            {
                keyId        = authority.KeyId;
                serialNumber = authority.SerialNumber;
            }

            // check in explicit list.
            if (explicitList != null)
            {
                for (int ii = 0; ii < explicitList.Count; ii++)
                {
                    X509Certificate2 issuer = await explicitList[ii].Find(false);

                    if (issuer != null)
                    {
                        if (!IsIssuerAllowed(issuer))
                        {
                            continue;
                        }

                        if (Match(issuer, subjectName, serialNumber, keyId))
                        {
                            // can't check revocation.
                            return(new CertificateIdentifier(issuer, CertificateValidationOptions.SuppressRevocationStatusUnknown));
                        }
                    }
                }
            }

            // check in certificate store.
            if (certificateStore != null)
            {
                ICertificateStore store = certificateStore.OpenStore();

                try
                {
                    X509Certificate2Collection certificates = await store.Enumerate();

                    for (int ii = 0; ii < certificates.Count; ii++)
                    {
                        X509Certificate2 issuer = certificates[ii];

                        if (issuer != null)
                        {
                            if (!IsIssuerAllowed(issuer))
                            {
                                continue;
                            }

                            if (Match(issuer, subjectName, serialNumber, keyId))
                            {
                                CertificateValidationOptions options = certificateStore.ValidationOptions;

                                // already checked revocation for file based stores. windows based stores always suppress.
                                options |= CertificateValidationOptions.SuppressRevocationStatusUnknown;

                                if (checkRecovationStatus)
                                {
                                    StatusCode status = store.IsRevoked(issuer, certificate);

                                    if (StatusCode.IsBad(status))
                                    {
                                        if (status != StatusCodes.BadNotSupported && status != StatusCodes.BadCertificateRevocationUnknown)
                                        {
                                            throw new ServiceResultException(status);
                                        }
                                    }
                                }

                                return(new CertificateIdentifier(certificates[ii], options));
                            }
                        }
                    }
                }
                finally
                {
                    store.Close();
                }
            }

            // not a trusted issuer.
            return(null);
        }
コード例 #16
0
 /// <summary>
 /// Constructs a object by specifying each property.
 /// </summary>
 /// <remarks>
 /// The innerException is used to construct the innerResult.
 /// </remarks>
 public ServiceResult(StatusCode code, Exception innerException)
     :
     this(code, null, null, null, null, innerException)
 {
 }
コード例 #17
0
 /// <summary>
 /// Constructs a object from a StatusCode.
 /// </summary>
 public ServiceResult(StatusCode status)
 {
     m_code = status.Code;
 }
コード例 #18
0
 /// <summary>
 /// Initializes the object with a status code and a server timestamp.
 /// </summary>
 /// <remarks>
 /// Initializes the object with a status code and a server timestamp.
 /// </remarks>
 /// <param name="statusCode">The status code associated with the value.</param>
 /// <param name="serverTimestamp">The timestamp associated with the status code.</param>
 public DataValue(StatusCode statusCode, DateTime serverTimestamp)
 {
     Initialize();
     m_statusCode      = statusCode;
     m_serverTimestamp = serverTimestamp;
 }
コード例 #19
0
 /// <summary>
 /// Constructs a object by specifying each property.
 /// </summary>
 public ServiceResult(
     StatusCode code,
     string     symbolicId,
     string     namespaceUri)
 :
     this(code, symbolicId, namespaceUri, (string)null, (string)null, (ServiceResult)null)
 {
 }
コード例 #20
0
ファイル: XmlDecoder.cs プロジェクト: yuriik83/UA-.NET
        /// <summary>
        /// Reads an StatusCode from the stream.
        /// </summary>
        public StatusCode ReadStatusCode(string fieldName)
        {
            StatusCode value = new StatusCode();

            if (BeginField(fieldName, true))
            {                
                PushNamespace(Namespaces.OpcUaXsd);
                value.Code = ReadUInt32("Code");
                PopNamespace();
                
                EndField(fieldName);
            }

            return value;
        }
コード例 #21
0
        private ServiceResult OnUserArrayValue2(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            DateTime[] dateTimeIn,
            Uuid[] guidIn,
            byte[][] byteStringIn,
            XmlElement[] xmlElementIn,
            NodeId[] nodeIdIn,
            ExpandedNodeId[] expandedNodeIdIn,
            QualifiedName[] qualifiedNameIn,
            LocalizedText[] localizedTextIn,
            StatusCode[] statusCodeIn,
            Variant[] variantIn,
            ref DateTime[] dateTimeOut,
            ref Uuid[] guidOut,
            ref byte[][] byteStringOut,
            ref XmlElement[] xmlElementOut,
            ref NodeId[] nodeIdOut,
            ref ExpandedNodeId[] expandedNodeIdOut,
            ref QualifiedName[] qualifiedNameOut,
            ref LocalizedText[] localizedTextOut,
            ref StatusCode[] statusCodeOut,
            ref Variant[] variantOut)
        {
            dateTimeOut = dateTimeIn;
            guidOut = guidIn;
            byteStringOut = byteStringIn;
            xmlElementOut = xmlElementIn;
            nodeIdOut = nodeIdIn;
            expandedNodeIdOut = expandedNodeIdIn;
            qualifiedNameOut = qualifiedNameIn;
            localizedTextOut = localizedTextIn;
            statusCodeOut = statusCodeIn;
            variantOut = variantIn;

            return ServiceResult.Good;
        }
コード例 #22
0
 /// <summary>
 /// Constructs a object by specifying each property.
 /// </summary>
 public ServiceResult(
     StatusCode       code,
     XmlQualifiedName symbolicId,
     LocalizedText    localizedText)
 :
     this(code, (symbolicId != null) ? symbolicId.Name : null, (symbolicId != null) ? symbolicId.Namespace : null, localizedText, (string)null, (ServiceResult)null)
 {
 }
コード例 #23
0
ファイル: TestDataHelpers.cs プロジェクト: yuriik83/UA-.NET
        /// <summary>
        /// Formats a StatusCide as string for serilization or display.
        /// </summary>
        public static string FormatQuality(StatusCode statusCode)
        {
            StringBuilder buffer = new StringBuilder();
            buffer.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "{0}", new StatusCode(statusCode.CodeBits));

            if ((statusCode.AggregateBits & AggregateBits.Interpolated) != 0)
            {
                buffer.Append(", Interpolated");
            }

            if ((statusCode.AggregateBits & AggregateBits.Calculated) != 0)
            {
                buffer.Append(", Calculated");
            }

            if ((statusCode.AggregateBits & AggregateBits.Partial) != 0)
            {
                buffer.Append(", Partial");
            }

            if ((statusCode.AggregateBits & AggregateBits.MultipleValues) != 0)
            {
                buffer.Append(", MultipleValues");
            }

            return buffer.ToString();
        }
コード例 #24
0
 /// <summary>
 /// Returns true if the status is good or uncertain.
 /// </summary>
 /// <remarks>
 /// Returns true if the status is good or uncertain.
 /// </remarks>
 /// <param name="code">The code to check</param>
 public static bool IsNotBad(StatusCode code)
 {
     return((code.m_code & 0x80000000) == 0);
 }
コード例 #25
0
        /// <summary>
        /// Writes an StatusCode to the stream.
        /// </summary>
        public void WriteStatusCode(string fieldName, StatusCode value)
        {
            if (BeginField(fieldName, false, false))
            {
                PushNamespace(Namespaces.OpcUaXsd);

                if (value != null)
                {
                    WriteUInt32("Code", value.Code);
                }

                PopNamespace();

                EndField(fieldName);
            }
        }
        /// <summary>
        /// Write the value for the value attribute.
        /// </summary>
        protected override ServiceResult WriteValueAttribute(
            ISystemContext context,
            NumericRange indexRange,
            object value,
            StatusCode statusCode,
            DateTime sourceTimestamp)
        {
            ServiceResult result = null;

            if ((WriteMask & AttributeWriteMask.ValueForVariableType) == 0)
            {
                return StatusCodes.BadNotWritable;
            }

            // ensure the source timestamp has a valid value.
            if (sourceTimestamp == DateTime.MinValue)
            {
                sourceTimestamp = DateTime.UtcNow;
            }

            // index range writes not supported.
            if (indexRange != NumericRange.Empty)
            {
                return StatusCodes.BadIndexRangeInvalid;
            }

            // verify data type.
            TypeInfo typeInfo = TypeInfo.IsInstanceOfDataType(
                value,
                m_dataType,
                m_valueRank,
                context.NamespaceUris,
                context.TypeTable);

            if (typeInfo == null || typeInfo == TypeInfo.Unknown)
            {
                return StatusCodes.BadTypeMismatch;
            }

            // check for simple write value handler.
            if (OnSimpleWriteValue != null)
            {
                result = OnSimpleWriteValue(
                    context,
                    this,
                    ref value);

                if (ServiceResult.IsBad(result))
                {
                    return result;
                }
            }

            // update cached values.
            Value = value;

            return ServiceResult.Good;
        }
コード例 #27
0
 /// <summary>
 /// Constructs a object by specifying each property.
 /// </summary>
 public ServiceResult(
     StatusCode    code,
     LocalizedText localizedText)
 :
     this(code, (string)null, (string)null, localizedText, (string)null, (ServiceResult)null)
 {
 }
コード例 #28
0
        /// <summary>
        /// Generates a new value each time the value is read.
        /// </summary>
        private ServiceResult DoDeviceRead(
            ISystemContext context,
            NodeState node,
            NumericRange indexRange,
            QualifiedName dataEncoding,
            ref object value,
            ref StatusCode statusCode,
            ref DateTime timestamp)
        {
            BaseVariableState variable = node as BaseVariableState;

            if (variable == null)
            {
                return ServiceResult.Good;
            }

            if (!SimulationActive.Value)
            {
                return ServiceResult.Good;
            }

            TestDataSystem system = context.SystemHandle as TestDataSystem;

            if (system == null)
            {
                return StatusCodes.BadOutOfService;
            }

            try
            {
                value = system.ReadValue(variable);

                statusCode = StatusCodes.Good;
                timestamp = DateTime.UtcNow;

                ServiceResult error = BaseVariableState.ApplyIndexRangeAndDataEncoding(
                    context,
                    indexRange,
                    dataEncoding,
                    ref value);

                if (ServiceResult.IsBad(error))
                {
                    statusCode = error.StatusCode;
                }
                
                return ServiceResult.Good;
            }
            catch (Exception e)
            {
                return new ServiceResult(e);
            }
        }       
コード例 #29
0
        /// <summary>
        /// Constructs a object by specifying each property.
        /// </summary>
        /// <remarks>
        /// The innerException is used to construct the inner result.
        /// </remarks>
        public ServiceResult(
            StatusCode    code,
            string        symbolicId,
            string        namespaceUri,
            LocalizedText localizedText,
            string        additionalInfo,            
            Exception     innerException)
        {
            ServiceResult innerResult = new ServiceResult(innerException);

            // check if no new information provided.
            if (code.Code == innerResult.Code && symbolicId == null && localizedText == null && additionalInfo == null)
            {
                m_code           = innerResult.Code;
                m_symbolicId     = innerResult.SymbolicId;
                m_namespaceUri   = innerResult.NamespaceUri;
                m_localizedText  = innerResult.LocalizedText;
                m_additionalInfo = innerResult.AdditionalInfo;
                m_innerResult    = innerResult.InnerResult;
            }

            // make the exception the inner result.
            else
            {
                m_code           = code.Code;
                m_symbolicId     = symbolicId;
                m_namespaceUri   = namespaceUri;
                m_localizedText  = localizedText;
                m_additionalInfo = additionalInfo;
                m_innerResult    = innerResult;
            }
        }
コード例 #30
0
        private ServiceResult OnChangePhaseByWrite(
            ISystemContext context,
            NodeState node,
            NumericRange indexRange,
            QualifiedName dataEncoding,
            ref object value,
            ref StatusCode statusCode,
            ref DateTime timestamp)
        {
            string phase = value as string;

            if (phase == null)
            {
                return StatusCodes.BadTypeMismatch;
            }

            List<IReference> references = new List<IReference>();
            m_rig.Phases.GetReferences(context, references, Opc.Ua.ReferenceTypeIds.Organizes, false);

            foreach (IReference reference in references)
            {
                if (reference.TargetId.ToString().Contains(phase))
                {
                    return OnChangePhase(context, m_rig.ChangePhase, m_rig.NodeId, (NodeId)reference.TargetId);
                }
            }

            return StatusCodes.BadTypeMismatch;
        }
コード例 #31
0
 /// <summary>
 /// Constructs a object by specifying each property.
 /// </summary>
 /// <remarks>
 /// The innerException is used to construct the innerResult.
 /// </remarks>
 public ServiceResult(
     StatusCode    code,
     LocalizedText localizedText,            
     Exception     innerException)
 :
     this(code, null, null, localizedText, null, innerException)
 {
 }
コード例 #32
0
        public ServiceResult OnChangeLockByWrite(
            ISystemContext context,
            NodeState node,
            NumericRange indexRange,
            QualifiedName dataEncoding,
            ref object value,
            ref StatusCode statusCode,
            ref DateTime timestamp)
        {
            DsatsDemo.LockConditionState condition = null;

            BaseInstanceState instance = node as BaseInstanceState;

            if (instance.Parent != null)
            {
                condition = instance.Parent as DsatsDemo.LockConditionState;
            }

            if (condition == null)
            {
                return StatusCodes.BadNotWritable;
            }

            string lockState = value as string;

            if (lockState == null)
            {
                return StatusCodes.BadTypeMismatch;
            }

            if (lockState == "Locked")
            {
                ServiceResult result = OnRequestLock(context, condition.Request, condition.NodeId, new object[0], new object[0]);
                value = condition.LockStateAsString.Value;
                return result;
            }

            else if (lockState == "Unlocked")
            {
                ServiceResult result = OnReleaseLock(context, condition.Request, condition.NodeId, new object[0], new object[0]);
                value = condition.LockStateAsString.Value;
                return result;
            }

            return StatusCodes.BadTypeMismatch;
        }
コード例 #33
0
		/// <summary>
		/// Initializes the object with a status code and a diagnostic info structure.
		/// </summary>
		public ServiceResult(StatusCode code, int index, DiagnosticInfoCollection diagnosticInfos, IList<string> stringTable)
		{
			m_code = (uint)code;

            if (index >= 0 && diagnosticInfos != null && index < diagnosticInfos.Count)
            {
                DiagnosticInfo diagnosticInfo = diagnosticInfos[index];
                
                if (diagnosticInfo != null)
                {
				    m_namespaceUri = LookupString(stringTable, diagnosticInfo.NamespaceUri);
				    m_symbolicId = LookupString(stringTable, diagnosticInfo.SymbolicId);
				    
                    string locale = LookupString(stringTable, diagnosticInfo.Locale);
				    string localizedText  = LookupString(stringTable, diagnosticInfo.LocalizedText);
                    m_localizedText  = new LocalizedText(locale, localizedText);

                    m_additionalInfo = diagnosticInfo.AdditionalInfo;

                    if (!StatusCode.IsGood(diagnosticInfo.InnerStatusCode))
                    {
                        m_innerResult = new ServiceResult(diagnosticInfo.InnerStatusCode, diagnosticInfo.InnerDiagnosticInfo, stringTable);
                    }
                }
            }
		}
コード例 #34
0
ファイル: JsonEncoder.cs プロジェクト: OPCFoundation/UA-.NET
        /// <summary>
        /// Writes an StatusCode to the stream.
        /// </summary>
        public void WriteStatusCode(string fieldName, StatusCode value)
        {
            if (value == StatusCodes.Good)
            {
                WriteSimpleField(fieldName, null, false);
                return;
            }

            var text = StatusCode.LookupSymbolicId(value.CodeBits);
            text += ":0x";
            text += value.Code.ToString("X8", CultureInfo.InvariantCulture);

            WriteSimpleField(fieldName, text, true);
        }
コード例 #35
0
ファイル: MemoryBufferState.cs プロジェクト: yuriik83/UA-.NET
        /// <summary>
        /// Handles the read operation for an invidual tag.
        /// </summary>
        public ServiceResult ReadTagValue(
            ISystemContext context,
            NodeState node,
            NumericRange indexRange,
            QualifiedName dataEncoding,
            ref object value,
            ref StatusCode statusCode,
            ref DateTime timestamp)
        {
            MemoryTagState tag = node as MemoryTagState;

            if (tag == null)
            {
                return StatusCodes.BadNodeIdUnknown;
            }

            if (NumericRange.Empty != indexRange)
            {
                return StatusCodes.BadIndexRangeInvalid;
            }

            if (!QualifiedName.IsNull(dataEncoding))
            {
                return StatusCodes.BadDataEncodingInvalid;
            }

            int offset = (int)tag.Offset;

            lock (m_dataLock)
            {
                if (offset < 0 || offset >= m_buffer.Length)
                {
                    return StatusCodes.BadNodeIdUnknown;
                }

                if (m_buffer == null)
                {
                    return StatusCodes.BadOutOfService;
                }

                value = GetValueAtOffset(offset).Value;
            }

            statusCode = StatusCodes.Good;
            timestamp = m_lastScanTime;

            return ServiceResult.Good;
        }
コード例 #36
0
ファイル: MemoryBufferState.cs プロジェクト: yuriik83/UA-.NET
        /// <summary>
        /// Handles a write operation for an individual tag.
        /// </summary>
        public ServiceResult WriteTagValue(
            ISystemContext context,
            NodeState node,
            NumericRange indexRange,
            QualifiedName dataEncoding,
            ref object value,
            ref StatusCode statusCode,
            ref DateTime timestamp)
        {
            MemoryTagState tag = node as MemoryTagState;

            if (tag == null)
            {
                return StatusCodes.BadNodeIdUnknown;
            }

            if (NumericRange.Empty != indexRange)
            {
                return StatusCodes.BadIndexRangeInvalid;
            }

            if (!QualifiedName.IsNull(dataEncoding))
            {
                return StatusCodes.BadDataEncodingInvalid;
            }

            if (statusCode != StatusCodes.Good)
            {
                return StatusCodes.BadWriteNotSupported;
            }

            if (timestamp != DateTime.MinValue)
            {
                return StatusCodes.BadWriteNotSupported;
            }

            bool changed = false;
            int offset = (int)tag.Offset;

            lock (m_dataLock)
            {
                if (offset < 0 || offset >= m_buffer.Length)
                {
                    return StatusCodes.BadNodeIdUnknown;
                }

                if (m_buffer == null)
                {
                    return StatusCodes.BadOutOfService;
                }

                byte[] bytes = null;

                switch (m_elementType)
                {
                    case BuiltInType.UInt32:
                    {
                        uint? valueToWrite = value as uint?;

                        if (valueToWrite == null)
                        {
                            return StatusCodes.BadTypeMismatch;
                        }

                        bytes = BitConverter.GetBytes(valueToWrite.Value);
                        break;
                    }

                    case BuiltInType.Double:
                    {
                        double? valueToWrite = value as double?;

                        if (valueToWrite == null)
                        {
                            return StatusCodes.BadTypeMismatch;
                        }

                        bytes = BitConverter.GetBytes(valueToWrite.Value);
                        break;
                    }

                    default:
                    {
                        return StatusCodes.BadNodeIdUnknown;
                    }
                }

                for (int ii = 0; ii < bytes.Length; ii++)
                {
                    if (!changed)
                    {
                        if (m_buffer[offset + ii] != bytes[ii])
                        {
                            changed = true;
                        }
                    }

                    m_buffer[offset + ii] = bytes[ii];
                }
            }

            if (changed)
            {
                OnBufferChanged(offset);
            }

            return ServiceResult.Good;
        }
コード例 #37
0
 /// <summary>
 /// Constructs a object by specifying each property.
 /// </summary>
 public ServiceResult(
     StatusCode    code,
     string        symbolicId,
     string        namespaceUri,
     LocalizedText localizedText)
 :
     this(code, symbolicId, namespaceUri, localizedText, (string)null, (ServiceResult)null)
 {
 }
コード例 #38
0
        private ServiceResult OnUserScalarValue2(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            DateTime dateTimeIn,
            Uuid guidIn,
            byte[] byteStringIn,
            XmlElement xmlElementIn,
            NodeId nodeIdIn,
            ExpandedNodeId expandedNodeIdIn,
            QualifiedName qualifiedNameIn,
            LocalizedText localizedTextIn,
            StatusCode statusCodeIn,
            object variantIn,
            ref DateTime dateTimeOut,
            ref Uuid guidOut,
            ref byte[] byteStringOut,
            ref XmlElement xmlElementOut,
            ref NodeId nodeIdOut,
            ref ExpandedNodeId expandedNodeIdOut,
            ref QualifiedName qualifiedNameOut,
            ref LocalizedText localizedTextOut,
            ref StatusCode statusCodeOut,
            ref object variantOut)
        {
            dateTimeOut = dateTimeIn;
            guidOut = guidIn;
            byteStringOut = byteStringIn;
            xmlElementOut = xmlElementIn;
            nodeIdOut = nodeIdIn;
            expandedNodeIdOut = expandedNodeIdIn;
            qualifiedNameOut = qualifiedNameIn;
            localizedTextOut = localizedTextIn;
            statusCodeOut = statusCodeIn;
            variantOut = variantIn;

            return ServiceResult.Good;
        }
コード例 #39
0
        /// <summary>
        /// Converts a value to a StatusCode
        /// </summary>
        private static object ToStatusCode(object value, BuiltInType sourceType)
        {            
            // check for array conversions.
            Array array = value as Array;

            if (array != null)
            {
                StatusCode[] output = new StatusCode[array.Length];

                for (int ii = 0; ii < array.Length; ii++)
                {
                    output[ii] = (StatusCode)Cast(array.GetValue(ii), BuiltInType.StatusCode);
                }

                return output;
            }
            
            // handle for supported conversions.
            switch (sourceType)
            {
                case BuiltInType.StatusCode:
                {
                    return (StatusCode)value; 
                }

                case BuiltInType.UInt16:
                {
                    uint code = Convert.ToUInt32((ushort)value);
                    code <<= 16;
                    return (StatusCode)code; 
                }

                case BuiltInType.Int32:
                {
                    return (StatusCode)Convert.ToUInt32((int)value); 
                }               

                case BuiltInType.UInt32:
                {
                    return (StatusCode)(uint)value; 
                }                     
                    
                case BuiltInType.Int64:
                {
                    return (StatusCode)Convert.ToUInt32((long)value); 
                }

                case BuiltInType.UInt64:
                {
                    return (StatusCode)Convert.ToUInt32((ulong)value); 
                }
            }
            
            // conversion not supported.
            return null;
        }
コード例 #40
0
 /// <summary>
 /// Returns true if the status is bad or uncertain.
 /// </summary>
 /// <remarks>
 /// Returns true if the status is bad or uncertain.
 /// </remarks>
 /// <param name="code">The code to check</param>
 public static bool IsNotGood(StatusCode code)
 {
     return((code.m_code & 0xC0000000) != 0);
 }