IsGood() public static method

Returns true if the status code is good.
public static IsGood ( ServiceResult status ) : bool
status ServiceResult
return bool
Exemplo n.º 1
0
        /// <summary>
        /// Updates an audit event after the method is invoked.
        /// </summary>
        protected virtual void UpdateAuditEvent(
            ISystemContext context,
            MethodState causeMethod,
            uint causeId,
            AuditUpdateStateEventState e,
            ServiceResult result)
        {
            TranslationInfo info = new TranslationInfo(
                "StateTransition",
                "en-US",
                "The {1} method called was on the {0} state machine.",
                this.GetDisplayPath(3, '.'),
                causeMethod.DisplayName);

            e.Initialize(
                context,
                this,
                EventSeverity.Medium,
                new LocalizedText(info),
                ServiceResult.IsGood(result),
                DateTime.UtcNow);

            e.MethodId       = new PropertyState <NodeId>(e);
            e.MethodId.Value = causeMethod.NodeId;

            e.SetChildValue(context, BrowseNames.OldStateId, LastState, false);
            e.SetChildValue(context, BrowseNames.NewStateId, CurrentState, false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Write the value for DataTypeDefinition attribute.
        /// </summary>
        protected override ServiceResult WriteNonValueAttribute(
            ISystemContext context,
            uint attributeId,
            object value)
        {
            ServiceResult result = null;

            switch (attributeId)
            {
            case Attributes.DataTypeDefinition:
            {
                ExtensionObject dataTypeDefinition = value as ExtensionObject;

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

                if (OnWriteDataTypeDefinition != null)
                {
                    result = OnWriteDataTypeDefinition(context, this, ref dataTypeDefinition);
                }

                if (ServiceResult.IsGood(result))
                {
                    m_dataTypeDefinition = dataTypeDefinition;
                }

                return(result);
            }
            }

            return(base.WriteNonValueAttribute(context, attributeId, value));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Reads the value for DataTypeDefinition attribute.
        /// </summary>
        protected override ServiceResult ReadNonValueAttribute(
            ISystemContext context,
            uint attributeId,
            ref object value)
        {
            ServiceResult result = null;

            switch (attributeId)
            {
            case Attributes.DataTypeDefinition:
            {
                ExtensionObject dataTypeDefinition = m_dataTypeDefinition;

                if (OnReadDataTypeDefinition != null)
                {
                    result = OnReadDataTypeDefinition(context, this, ref dataTypeDefinition);
                }

                if (ServiceResult.IsGood(result))
                {
                    value = dataTypeDefinition;
                }

                return(result);
            }
            }

            return(base.ReadNonValueAttribute(context, attributeId, ref value));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Updates an audit event after the method is invoked.
        /// </summary>
        protected override void UpdateAuditEvent(
            ISystemContext context,
            MethodState causeMethod,
            uint causeId,
            AuditUpdateStateEventState e,
            ServiceResult result)
        {
            base.UpdateAuditEvent(
                context,
                causeMethod,
                causeId,
                e,
                result);

            // update program specific event fields.
            if (ServiceResult.IsGood(result))
            {
                ProgramTransitionAuditEventState e2 = e as ProgramTransitionAuditEventState;

                if (e2 != null)
                {
                    e2.SetChildValue(context, BrowseNames.Transition, LastTransition, false);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Reads the value for any non-value attribute.
        /// </summary>
        protected override ServiceResult ReadNonValueAttribute(
            ISystemContext context,
            uint attributeId,
            ref object value)
        {
            ServiceResult result = null;

            switch (attributeId)
            {
            case Attributes.IsAbstract:
            {
                bool isAbstract = m_isAbstract;

                if (OnReadIsAbstract != null)
                {
                    result = OnReadIsAbstract(context, this, ref isAbstract);
                }

                if (ServiceResult.IsGood(result))
                {
                    value = isAbstract;
                }

                return(result);
            }
            }

            return(base.ReadNonValueAttribute(context, attributeId, ref value));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Reads the value for any non-value attribute.
        /// </summary>
        protected override ServiceResult ReadNonValueAttribute(
            ISystemContext context,
            uint attributeId,
            ref object value)
        {
            ServiceResult result = null;

            switch (attributeId)
            {
            case Attributes.EventNotifier:
            {
                byte eventNotifier = m_eventNotifier;

                if (OnReadEventNotifier != null)
                {
                    result = OnReadEventNotifier(context, this, ref eventNotifier);
                }

                if (ServiceResult.IsGood(result))
                {
                    value = eventNotifier;
                }

                return(result);
            }
            }

            return(base.ReadNonValueAttribute(context, attributeId, ref value));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Reads the value for any non-value attribute.
        /// </summary>
        protected override ServiceResult ReadNonValueAttribute(
            ISystemContext context,
            uint attributeId,
            ref object value)
        {
            ServiceResult result = null;

            switch (attributeId)
            {
            case Attributes.DataType: {
                NodeId dataType = m_dataType;

                if (OnReadDataType != null)
                {
                    result = OnReadDataType(context, this, ref dataType);
                }

                if (ServiceResult.IsGood(result))
                {
                    value = dataType;
                }

                return(result);
            }

            case Attributes.ValueRank: {
                int valueRank = m_valueRank;

                if (OnReadValueRank != null)
                {
                    result = OnReadValueRank(context, this, ref valueRank);
                }

                if (ServiceResult.IsGood(result))
                {
                    value = valueRank;
                }

                return(result);
            }

            case Attributes.ArrayDimensions: {
                IList <uint> arrayDimensions = m_arrayDimensions;

                if (OnReadArrayDimensions != null)
                {
                    result = OnReadArrayDimensions(context, this, ref arrayDimensions);
                }

                if (ServiceResult.IsGood(result))
                {
                    value = arrayDimensions;
                }

                return(result);
            }
            }

            return(base.ReadNonValueAttribute(context, attributeId, ref value));
        }
        /// <summary>
        /// Updates an audit event after the method is invoked.
        /// </summary>
        protected virtual void UpdateAuditEvent(
            ISystemContext context,
            MethodState causeMethod,
            IList <object> inputArguments,
            uint causeId,
            AuditUpdateStateEventState e,
            ServiceResult result)
        {
            TranslationInfo info = new TranslationInfo(
                "StateTransition",
                "en-US",
                "The {1} method called was on the {0} state machine.",
                this.GetDisplayPath(3, '.'),
                causeMethod.DisplayName);

            e.Initialize(
                context,
                this,
                EventSeverity.Medium,
                new LocalizedText(info),
                ServiceResult.IsGood(result),
                DateTime.UtcNow);

            e.SetChildValue(context, BrowseNames.SourceNode, NodeId, false);
            e.SetChildValue(context, BrowseNames.SourceName, $"Method/{causeMethod.BrowseName.Name}", false);
            e.SetChildValue(context, BrowseNames.LocalTime, Utils.GetTimeZoneInfo(), false);

            // AuditUpdateMethodStateEventType properties
            e.SetChildValue(context, BrowseNames.MethodId, causeMethod.NodeId, false);
            e.SetChildValue(context, BrowseNames.InputArguments, inputArguments, false);

            // AuditUpdateStateEventType properties
            e.SetChildValue(context, BrowseNames.OldStateId, LastState, false);
            e.SetChildValue(context, BrowseNames.NewStateId, CurrentState, false);
        }
Exemplo n.º 9
0
            /// <summary>
            /// Converts the object to an ContentFilterElementResult.
            /// </summary>
            /// <param name="diagnosticsMasks">The diagnostics masks.</param>
            /// <param name="stringTable">The string table.</param>
            /// <returns></returns>
            public ContentFilterElementResult ToContentFilterElementResult(DiagnosticsMasks diagnosticsMasks, StringTable stringTable)
            {
                ContentFilterElementResult result = new ContentFilterElementResult();

                if (ServiceResult.IsGood(m_status))
                {
                    result.StatusCode = StatusCodes.Good;
                    return(result);
                }

                result.StatusCode = m_status.StatusCode;

                if (m_operandResults.Count == 0)
                {
                    return(result);
                }

                foreach (ServiceResult operandResult in m_operandResults)
                {
                    if (ServiceResult.IsGood(operandResult))
                    {
                        result.OperandStatusCodes.Add(StatusCodes.Good);
                        result.OperandDiagnosticInfos.Add(null);
                    }
                    else
                    {
                        result.OperandStatusCodes.Add(operandResult.StatusCode);
                        result.OperandDiagnosticInfos.Add(new DiagnosticInfo(operandResult, diagnosticsMasks, false, stringTable));
                    }
                }

                return(result);
            }
Exemplo n.º 10
0
        /// <summary>
        /// Called when the add comment method is called.
        /// </summary>
        /// <param name="context">The system context.</param>
        /// <param name="method">The method being called.</param>
        /// <param name="objectId">The id of the object.</param>
        /// <param name="eventId">The identifier for the event which is the target for the comment.</param>
        /// <param name="comment">The comment.</param>
        /// <returns>Any error.</returns>
        protected virtual ServiceResult OnAddCommentCalled(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            byte[] eventId,
            LocalizedText comment)
        {
            ServiceResult error = ProcessBeforeAddComment(context, eventId, comment);

            if (ServiceResult.IsGood(error))
            {
                string         currentUserId = GetCurrentUserId(context);
                ConditionState branch        = GetBranch(eventId);
                if (branch != null)
                {
                    branch.OnAddCommentCalled(context, method, objectId, eventId, comment);
                }

                SetComment(context, comment, currentUserId);
            }

            if (EventsMonitored())
            {
                // report a state change event.
                if (ServiceResult.IsGood(error))
                {
                    ReportStateChange(context, false);
                }

                // raise the audit event.
                AuditConditionCommentEventState e = new AuditConditionCommentEventState(null);

                TranslationInfo info = new TranslationInfo(
                    "AuditConditionComment",
                    "en-US",
                    "The AddComment method was called.");

                e.Initialize(
                    context,
                    this,
                    EventSeverity.Low,
                    new LocalizedText(info),
                    ServiceResult.IsGood(error),
                    DateTime.UtcNow);

                e.SetChildValue(context, BrowseNames.SourceNode, NodeId, false);
                e.SetChildValue(context, BrowseNames.SourceName, "Method/AddComment", false);

                e.SetChildValue(context, BrowseNames.MethodId, method.NodeId, false);
                e.SetChildValue(context, BrowseNames.InputArguments, new object[] { eventId, comment }, false);

                e.SetChildValue(context, BrowseNames.ConditionEventId, eventId, false);
                e.SetChildValue(context, BrowseNames.Comment, comment, false);

                ReportEvent(context, e);
            }

            return(error);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Handles the Disable method.
        /// </summary>
        protected virtual ServiceResult OnDisableCalled(
            ISystemContext context,
            MethodState method,
            IList <object> inputArguments,
            IList <object> outputArguments)
        {
            // check that method can be called.
            ServiceResult error = ProcessBeforeEnableDisable(context, false);

            if (ServiceResult.IsGood(error))
            {
                Dictionary <string, ConditionState> branches = GetBranches();

                foreach (ConditionState branch in branches.Values)
                {
                    branch.OnDisableCalled(context, method, inputArguments, outputArguments);
                }

                UpdateStateAfterDisable(context);
            }

            // raise the audit event.
            if (this.AreEventsMonitored)
            {
                // report a state change event.
                if (ServiceResult.IsGood(error))
                {
                    ReportStateChange(context, true);
                }

                // raise the audit event.
                AuditConditionEnableEventState e = new AuditConditionEnableEventState(null);

                TranslationInfo info = new TranslationInfo(
                    "AuditConditionEnable",
                    "en-US",
                    "The Disable method was called.");

                e.Initialize(
                    context,
                    this,
                    EventSeverity.Low,
                    new LocalizedText(info),
                    ServiceResult.IsGood(error),
                    DateTime.UtcNow);

                e.SourceName.Value = "Attribute/Call";

                e.MethodId       = new PropertyState <NodeId>(e);
                e.MethodId.Value = method.NodeId;

                ReportEvent(context, e);
            }

            return(error);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Called when the Confirm method is called.
        /// </summary>
        /// <param name="context">The system context.</param>
        /// <param name="method">The method being called.</param>
        /// <param name="objectId">The id of the object.</param>
        /// <param name="eventId">The identifier for the event which is the target for the comment.</param>
        /// <param name="comment">The comment.</param>
        /// <returns>Any error.</returns>
        protected virtual ServiceResult OnConfirmCalled(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            byte[] eventId,
            LocalizedText comment)
        {
            ServiceResult error = ProcessBeforeConfirm(context, eventId, comment);

            if (ServiceResult.IsGood(error))
            {
                SetConfirmedState(context, true);
                if (CanSetComment(comment))
                {
                    SetComment(context, comment, GetCurrentUserId(context));
                }
            }

            if (this.AreEventsMonitored)
            {
                // report a state change event.
                if (ServiceResult.IsGood(error))
                {
                    ReportStateChange(context, false);
                }

                // raise the audit event.
                AuditConditionConfirmEventState e = new AuditConditionConfirmEventState(null);

                TranslationInfo info = new TranslationInfo(
                    "AuditConditionConfirm",
                    "en-US",
                    "The Confirm method was called.");

                e.Initialize(
                    context,
                    this,
                    EventSeverity.Low,
                    new LocalizedText(info),
                    ServiceResult.IsGood(error),
                    DateTime.UtcNow);

                e.SourceName.Value = "Attribute/Call";

                e.MethodId       = new PropertyState <NodeId>(e);
                e.MethodId.Value = method.NodeId;

                e.InputArguments       = new PropertyState <object[]>(e);
                e.InputArguments.Value = new object[] { eventId, comment };

                ReportEvent(context, e);
            }

            return(error);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Reads the value for any non-value attribute.
        /// </summary>
        protected override ServiceResult ReadNonValueAttribute(
            ISystemContext context,
            uint attributeId,
            ref object value)
        {
            ServiceResult result = null;

            switch (attributeId)
            {
            case Attributes.Executable:
            {
                bool executable = m_executable;

                if (OnReadExecutable != null)
                {
                    result = OnReadExecutable(context, this, ref executable);
                }

                if (ServiceResult.IsGood(result))
                {
                    value = executable;
                }

                return(result);
            }

            case Attributes.UserExecutable:
            {
                bool userExecutable = m_userExecutable;

                if (OnReadUserExecutable != null)
                {
                    result = OnReadUserExecutable(context, this, ref userExecutable);
                }

                if (ServiceResult.IsGood(result))
                {
                    value = userExecutable;
                }

                return(result);
            }
            }

            return(base.ReadNonValueAttribute(context, attributeId, ref value));
        }
Exemplo n.º 14
0
        /// <summary>
        /// Reads the value for any non-value attribute.
        /// </summary>
        protected override ServiceResult ReadNonValueAttribute(
            ISystemContext context,
            uint attributeId,
            ref object value)
        {
            ServiceResult result = null;

            switch (attributeId)
            {
            case Attributes.InverseName:
            {
                LocalizedText inverseName = m_inverseName;

                if (OnReadInverseName != null)
                {
                    result = OnReadInverseName(context, this, ref inverseName);
                }

                if (ServiceResult.IsGood(result))
                {
                    value = inverseName;
                }

                return(result);
            }

            case Attributes.Symmetric:
            {
                bool symmetric = m_symmetric;

                if (OnReadSymmetric != null)
                {
                    result = OnReadSymmetric(context, this, ref symmetric);
                }

                if (ServiceResult.IsGood(result))
                {
                    value = symmetric;
                }

                return(result);
            }
            }

            return(base.ReadNonValueAttribute(context, attributeId, ref value));
        }
Exemplo n.º 15
0
            ToContextFilterResult(DiagnosticsMasks diagnosticsMasks, StringTable stringTable)
            {
                ContentFilterResult result = new ContentFilterResult();

                if (m_elementResults == null || m_elementResults.Count == 0)
                {
                    return(result);
                }

                bool error = false;

                foreach (ElementResult elementResult in m_elementResults)
                {
                    ContentFilterElementResult elementResult2 = null;

                    if (elementResult == null || ServiceResult.IsGood(elementResult.Status))
                    {
                        elementResult2            = new ContentFilterElementResult();
                        elementResult2.StatusCode = StatusCodes.Good;

                        result.ElementResults.Add(elementResult2);
                        result.ElementDiagnosticInfos.Add(null);
                        continue;
                    }

                    error = true;

                    elementResult2 = elementResult.ToContentFilterElementResult(diagnosticsMasks, stringTable);
                    result.ElementResults.Add(elementResult2);
                    result.ElementDiagnosticInfos.Add(new DiagnosticInfo(elementResult.Status, diagnosticsMasks, false,
                                                                         stringTable));
                }

                if (!error)
                {
                    result.ElementResults.Clear();
                    result.ElementDiagnosticInfos.Clear();
                }

                return(result);
            }
Exemplo n.º 16
0
        /// <summary>
        /// Write the value for any non-value attribute.
        /// </summary>
        protected override ServiceResult WriteNonValueAttribute(
            ISystemContext context,
            uint attributeId,
            object value)
        {
            ServiceResult result = null;

            switch (attributeId)
            {
            case Attributes.IsAbstract:
            {
                bool?isAbstractRef = value as bool?;

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

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

                bool isAbstract = isAbstractRef.Value;

                if (OnWriteIsAbstract != null)
                {
                    result = OnWriteIsAbstract(context, this, ref isAbstract);
                }

                if (ServiceResult.IsGood(result))
                {
                    IsAbstract = isAbstract;
                }

                return(result);
            }
            }

            return(base.WriteNonValueAttribute(context, attributeId, value));
        }
Exemplo n.º 17
0
        /// <summary>
        /// Write the value for any non-value attribute.
        /// </summary>
        protected override ServiceResult WriteNonValueAttribute(
            ISystemContext context,
            uint attributeId,
            object value)
        {
            ServiceResult result = null;

            switch (attributeId)
            {
            case Attributes.EventNotifier:
            {
                byte?eventNotifierRef = value as byte?;

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

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

                byte eventNotifier = eventNotifierRef.Value;

                if (OnWriteEventNotifier != null)
                {
                    result = OnWriteEventNotifier(context, this, ref eventNotifier);
                }

                if (ServiceResult.IsGood(result))
                {
                    EventNotifier = eventNotifier;
                }

                return(result);
            }
            }

            return(base.WriteNonValueAttribute(context, attributeId, value));
        }
Exemplo n.º 18
0
        /// <summary>
        /// Reads the value for DataTypeDefinition attribute.
        /// </summary>
        protected override ServiceResult ReadNonValueAttribute(
            ISystemContext context,
            uint attributeId,
            ref object value)
        {
            ServiceResult result = null;

            switch (attributeId)
            {
            case Attributes.DataTypeDefinition:
            {
                ExtensionObject dataTypeDefinition = m_dataTypeDefinition;

                if (OnReadDataTypeDefinition != null)
                {
                    result = OnReadDataTypeDefinition(context, this, ref dataTypeDefinition);
                }

                if (ServiceResult.IsGood(result))
                {
                    if (dataTypeDefinition?.Body is StructureDefinition structureType &&
                        (structureType.DefaultEncodingId == null ||
                         structureType.DefaultEncodingId.IsNullNodeId))
                    {
                        // one time set the id for binary encoding, currently the only supported encoding
                        structureType.SetDefaultEncodingId(context, NodeId, null);
                    }
                    value = dataTypeDefinition;
                }

                return(result);
            }
            }

            return(base.ReadNonValueAttribute(context, attributeId, ref value));
        }
        /// <summary>
        /// Called when the Acknowledge method is called.
        /// </summary>
        /// <param name="context">The system context.</param>
        /// <param name="method">The method being called.</param>
        /// <param name="objectId">The id of the object.</param>
        /// <param name="eventId">The identifier for the event which is the target for the comment.</param>
        /// <param name="comment">The comment.</param>
        /// <returns>Any error.</returns>
        protected virtual ServiceResult OnAcknowledgeCalled(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            byte[] eventId,
            LocalizedText comment)
        {
            ServiceResult error = ProcessBeforeAcknowledge(context, eventId, comment);

            if (ServiceResult.IsGood(error))
            {
                AcknowledgeableConditionState branch = GetAcknowledgeableBranch(eventId);

                if (branch != null)
                {
                    branch.OnAcknowledgeCalled(context, method, objectId, eventId, comment);

                    if (SupportsConfirm())
                    {
                        ReplaceBranchEvent(eventId, branch);
                    }
                    else
                    {
                        RemoveBranchEvent(eventId);
                    }
                }
                else
                {
                    SetAcknowledgedState(context, true);

                    if (SupportsConfirm())
                    {
                        SetConfirmedState(context, false);
                    }
                }

                // If this is a branch, the comment goes to both the branch and the original event
                if (CanSetComment(comment))
                {
                    SetComment(context, comment, GetCurrentUserId(context));
                }

                UpdateRetainState();
            }

            if (EventsMonitored())
            {
                // report a state change event.
                if (ServiceResult.IsGood(error))
                {
                    ReportStateChange(context, false);
                }

                // raise the audit event.
                AuditConditionAcknowledgeEventState e = new AuditConditionAcknowledgeEventState(null);

                TranslationInfo info = new TranslationInfo(
                    "AuditConditionAcknowledge",
                    "en-US",
                    "The Acknowledge method was called.");

                e.Initialize(
                    context,
                    this,
                    EventSeverity.Low,
                    new LocalizedText(info),
                    ServiceResult.IsGood(error),
                    DateTime.UtcNow);

                e.SourceName.Value = "Attribute/Call";

                e.MethodId       = new PropertyState <NodeId>(e);
                e.MethodId.Value = method.NodeId;

                e.InputArguments       = new PropertyState <object[]>(e);
                e.InputArguments.Value = new object[] { eventId, comment };

                ReportEvent(context, e);
            }

            return(error);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Write the value for any non-value attribute.
        /// </summary>
        protected override ServiceResult WriteNonValueAttribute(
            ISystemContext context,
            uint attributeId,
            object value)
        {
            ServiceResult result = null;

            switch (attributeId)
            {
            case Attributes.InverseName:
            {
                LocalizedText inverseName = value as LocalizedText;

                if (inverseName == null && value != null)
                {
                    return(StatusCodes.BadTypeMismatch);
                }

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

                if (OnWriteInverseName != null)
                {
                    result = OnWriteInverseName(context, this, ref inverseName);
                }

                if (ServiceResult.IsGood(result))
                {
                    InverseName = inverseName;
                }

                return(result);
            }

            case Attributes.Symmetric:
            {
                bool?symmetricRef = value as bool?;

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

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

                bool symmetric = symmetricRef.Value;

                if (OnWriteSymmetric != null)
                {
                    result = OnWriteSymmetric(context, this, ref symmetric);
                }

                if (ServiceResult.IsGood(result))
                {
                    Symmetric = symmetric;
                }

                return(result);
            }
            }

            return(base.WriteNonValueAttribute(context, attributeId, value));
        }
Exemplo n.º 21
0
        /// <summary>
        /// Write the value for any non-value attribute.
        /// </summary>
        protected override ServiceResult WriteNonValueAttribute(
            ISystemContext context,
            uint attributeId,
            object value)
        {
            ServiceResult result = null;

            switch (attributeId)
            {
            case Attributes.DataType:
            {
                NodeId dataType = value as NodeId;

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

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

                if (OnWriteDataType != null)
                {
                    result = OnWriteDataType(context, this, ref dataType);
                }

                if (ServiceResult.IsGood(result))
                {
                    DataType = dataType;
                }

                return(result);
            }

            case Attributes.ValueRank:
            {
                int?valueRankRef = value as int?;

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

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

                int valueRank = valueRankRef.Value;

                if (OnWriteValueRank != null)
                {
                    result = OnWriteValueRank(context, this, ref valueRank);
                }

                if (ServiceResult.IsGood(result))
                {
                    ValueRank = valueRank;
                }

                return(result);
            }

            case Attributes.ArrayDimensions:
            {
                IList <uint> arrayDimensions = value as IList <uint>;

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

                if (OnWriteArrayDimensions != null)
                {
                    result = OnWriteArrayDimensions(context, this, ref arrayDimensions);
                }

                if (ServiceResult.IsGood(result))
                {
                    if (arrayDimensions != null)
                    {
                        m_arrayDimensions = new ReadOnlyList <uint>(arrayDimensions);
                    }
                    else
                    {
                        ArrayDimensions = null;
                    }
                }

                return(result);
            }
            }

            return(base.WriteNonValueAttribute(context, attributeId, value));
        }
Exemplo n.º 22
0
        /// <summary>
        /// Write the value for any non-value attribute.
        /// </summary>
        protected override ServiceResult WriteNonValueAttribute(
            ISystemContext context,
            uint attributeId,
            object value)
        {
            ServiceResult result = null;

            switch (attributeId)
            {
            case Attributes.Executable:
            {
                bool?executableRef = value as bool?;

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

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

                bool executable = executableRef.Value;

                if (OnWriteExecutable != null)
                {
                    result = OnWriteExecutable(context, this, ref executable);
                }

                if (ServiceResult.IsGood(result))
                {
                    Executable = executable;
                }

                return(result);
            }

            case Attributes.UserExecutable:
            {
                bool?userExecutableRef = value as bool?;

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

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

                bool userExecutable = userExecutableRef.Value;

                if (OnWriteUserExecutable != null)
                {
                    result = OnWriteUserExecutable(context, this, ref userExecutable);
                }

                if (ServiceResult.IsGood(result))
                {
                    UserExecutable = userExecutable;
                }

                return(result);
            }
            }

            return(base.WriteNonValueAttribute(context, attributeId, value));
        }
Exemplo n.º 23
0
        /// <summary>
        /// Handles the Unshelve method.
        /// </summary>
        protected virtual ServiceResult OnUnshelve(
            ISystemContext context,
            MethodState method,
            IList <object> inputArguments,
            IList <object> outputArguments)
        {
            ServiceResult error = null;

            try
            {
                if (!this.EnabledState.Id.Value)
                {
                    return(error = StatusCodes.BadConditionDisabled);
                }

                if (!this.ShelvingState.IsCausePermitted(context, Methods.ShelvedStateMachineType_Unshelve, false))
                {
                    return(error = StatusCodes.BadConditionNotShelved);
                }

                if (OnShelve == null)
                {
                    return(error = StatusCodes.BadNotSupported);
                }

                error = OnShelve(context, this, false, false, 0);

                // report a state change event.
                if (ServiceResult.IsGood(error))
                {
                    ReportStateChange(context, false);
                }
            }
            finally
            {
                // raise the audit event.
                if (this.AreEventsMonitored)
                {
                    AuditConditionShelvingEventState e = new AuditConditionShelvingEventState(null);

                    TranslationInfo info = new TranslationInfo(
                        "AuditConditionUnshelve",
                        "en-US",
                        "The Unshelve method was called.");

                    e.Initialize(
                        context,
                        this,
                        EventSeverity.Low,
                        new LocalizedText(info),
                        ServiceResult.IsGood(error),
                        DateTime.UtcNow);

                    e.SourceName.Value = "Attribute/Call";

                    e.MethodId       = new PropertyState <NodeId>(e);
                    e.MethodId.Value = method.NodeId;

                    ReportEvent(context, e);
                }
            }

            return(error);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Handles the TimedShelve method.
        /// </summary>
        protected virtual ServiceResult OnTimedShelve(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            double shelvingTime)
        {
            ServiceResult error = null;

            try
            {
                if (!this.EnabledState.Id.Value)
                {
                    return(error = StatusCodes.BadConditionDisabled);
                }

                if (shelvingTime <= 0 || (this.MaxTimeShelved != null && shelvingTime > this.MaxTimeShelved.Value))
                {
                    return(error = StatusCodes.BadShelvingTimeOutOfRange);
                }

                if (!this.ShelvingState.IsCausePermitted(context, Methods.ShelvedStateMachineType_TimedShelve, false))
                {
                    return(error = StatusCodes.BadConditionAlreadyShelved);
                }

                if (OnShelve == null)
                {
                    return(error = StatusCodes.BadNotSupported);
                }

                error = OnShelve(context, this, true, false, shelvingTime);

                // report a state change event.
                if (ServiceResult.IsGood(error))
                {
                    ReportStateChange(context, false);
                }
            }
            finally
            {
                if (this.AreEventsMonitored)
                {
                    AuditConditionShelvingEventState e = new AuditConditionShelvingEventState(null);

                    TranslationInfo info = new TranslationInfo(
                        "AuditConditionTimedShelve",
                        "en-US",
                        "The TimedShelve method was called.");

                    e.Initialize(
                        context,
                        this,
                        EventSeverity.Low,
                        new LocalizedText(info),
                        ServiceResult.IsGood(error),
                        DateTime.UtcNow);

                    e.SourceName.Value = "Attribute/Call";

                    e.MethodId       = new PropertyState <NodeId>(e);
                    e.MethodId.Value = method.NodeId;

                    e.InputArguments       = new PropertyState <object[]>(e);
                    e.InputArguments.Value = new object[] { shelvingTime };

                    ReportEvent(context, e);
                }
            }

            return(error);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Invokes the methods and returns the output parameters.
        /// </summary>
        /// <param name="context">The context to use.</param>
        /// <param name="objectId">The object being called.</param>
        /// <param name="inputArguments">The input arguments.</param>
        /// <param name="argumentErrors">Any errors for the input arguments.</param>
        /// <param name="outputArguments">The output arguments.</param>
        /// <returns>The result of the method call.</returns>
        public virtual ServiceResult Call(
            ISystemContext context,
            NodeId objectId,
            IList <Variant> inputArguments,
            IList <ServiceResult> argumentErrors,
            IList <Variant> outputArguments)
        {
            // validate input arguments.
            List <object> inputs = new List <object>();

            // check for too few or too many arguments.
            int expectedCount = 0;

            if (InputArguments != null && InputArguments.Value != null)
            {
                expectedCount = InputArguments.Value.Length;
            }

            if (expectedCount != inputArguments.Count)
            {
                return(StatusCodes.BadArgumentsMissing);
            }

            // validate individual arguements.
            bool error = false;

            for (int ii = 0; ii < inputArguments.Count; ii++)
            {
                ServiceResult argumentError = ValidateInputArgument(context, inputArguments[ii], ii);

                if (ServiceResult.IsBad(argumentError))
                {
                    error = true;
                }

                inputs.Add(inputArguments[ii].Value);
                argumentErrors.Add(argumentError);
            }

            // return good - caller must check argument errors.
            if (error)
            {
                return(ServiceResult.Good);
            }

            // set output arguments to default values.
            List <object> outputs = new List <object>();

            if (OutputArguments != null)
            {
                IList <Argument> arguments = OutputArguments.Value;

                if (arguments != null && arguments.Count > 0)
                {
                    for (int ii = 0; ii < arguments.Count; ii++)
                    {
                        outputs.Add(GetArgumentDefaultValue(context, arguments[ii]));
                    }
                }
            }

            // invoke method.
            ServiceResult result = null;

            try
            {
                result = Call(context, objectId, inputs, outputs);
            }
            catch (Exception e)
            {
                result = new ServiceResult(e);
            }

            // copy out arguments.
            if (ServiceResult.IsGood(result))
            {
                for (int ii = 0; ii < outputs.Count; ii++)
                {
                    outputArguments.Add(new Variant(outputs[ii]));
                }
            }

            return(result);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Called when the Respond method is called.
        /// </summary>
        /// <param name="context">The system context.</param>
        /// <param name="method">The method being called.</param>
        /// <param name="objectId">The id of the object.</param>
        /// <param name="selectedResponse">The selected response.</param>
        /// <returns>Any error.</returns>
        protected virtual ServiceResult OnRespondCalled(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            int selectedResponse)
        {
            ServiceResult error = null;

            try {
                if (!this.EnabledState.Id.Value)
                {
                    return(error = StatusCodes.BadConditionDisabled);
                }

                if (!this.DialogState.Id.Value)
                {
                    return(error = StatusCodes.BadDialogNotActive);
                }

                if (selectedResponse < 0 || selectedResponse >= this.ResponseOptionSet.Value.Length)
                {
                    return(error = StatusCodes.BadDialogResponseInvalid);
                }

                if (OnRespond == null)
                {
                    return(error = StatusCodes.BadNotSupported);
                }

                error = OnRespond(context, this, selectedResponse);

                // report a state change event.
                if (ServiceResult.IsGood(error))
                {
                    ReportStateChange(context, false);
                }
            } finally {
                if (this.AreEventsMonitored)
                {
                    AuditConditionRespondEventState e = new AuditConditionRespondEventState(null);

                    TranslationInfo info = new TranslationInfo(
                        "AuditConditionDialogResponse",
                        "en-US",
                        "The Respond method was called.");

                    e.Initialize(
                        context,
                        this,
                        EventSeverity.Low,
                        new LocalizedText(info),
                        ServiceResult.IsGood(error),
                        DateTime.UtcNow);

                    e.SourceName.Value = "Attribute/Call";

                    e.MethodId       = new PropertyState <NodeId>(e);
                    e.MethodId.Value = method.NodeId;

                    e.InputArguments       = new PropertyState <object[]>(e);
                    e.InputArguments.Value = new object[] { selectedResponse };

                    ReportEvent(context, e);
                }
            }

            return(error);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Handles the OneShotShelve method.
        /// </summary>
        protected virtual ServiceResult OnOneShotShelve(
            ISystemContext context,
            MethodState method,
            IList <object> inputArguments,
            IList <object> outputArguments)
        {
            ServiceResult error = null;

            try
            {
                if (!this.EnabledState.Id.Value)
                {
                    return(error = StatusCodes.BadConditionDisabled);
                }

                if (!this.ShelvingState.IsCausePermitted(context, Methods.ShelvedStateMachineType_OneShotShelve, false))
                {
                    return(error = StatusCodes.BadConditionAlreadyShelved);
                }

                if (OnShelve == null)
                {
                    return(error = StatusCodes.BadNotSupported);
                }

                error = OnShelve(context, this, true, true, 0);

                // report a state change event.
                if (ServiceResult.IsGood(error))
                {
                    ReportStateChange(context, false);
                }
            }
            finally
            {
                if (this.AreEventsMonitored)
                {
                    AuditConditionShelvingEventState e = new AuditConditionShelvingEventState(null);

                    TranslationInfo info = new TranslationInfo(
                        "AuditConditionOneShotShelve",
                        "en-US",
                        "The OneShotShelve method was called.");

                    e.Initialize(
                        context,
                        this,
                        EventSeverity.Low,
                        new LocalizedText(info),
                        ServiceResult.IsGood(error),
                        DateTime.UtcNow);

                    e.SetChildValue(context, BrowseNames.SourceNode, NodeId, false);
                    e.SetChildValue(context, BrowseNames.SourceName, "Method/OneShotShelve", false);

                    e.SetChildValue(context, BrowseNames.MethodId, method.NodeId, false);
                    e.SetChildValue(context, BrowseNames.ShelvingTime, null, false);

                    ReportEvent(context, e);
                }
            }

            return(error);
        }
        /// <summary>
        /// Called when the Confirm method is called.
        /// </summary>
        /// <param name="context">The system context.</param>
        /// <param name="method">The method being called.</param>
        /// <param name="objectId">The id of the object.</param>
        /// <param name="eventId">The identifier for the event which is the target for the comment.</param>
        /// <param name="comment">The comment.</param>
        /// <returns>Any error.</returns>
        protected virtual ServiceResult OnConfirmCalled(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            byte[] eventId,
            LocalizedText comment)
        {
            ServiceResult error = ProcessBeforeConfirm(context, eventId, comment);

            if (ServiceResult.IsGood(error))
            {
                AcknowledgeableConditionState branch = GetAcknowledgeableBranch(eventId);

                if (branch != null)
                {
                    branch.OnConfirmCalled(context, method, objectId, eventId, comment);
                    RemoveBranchEvent(eventId);
                }
                else
                {
                    SetConfirmedState(context, true);
                }

                // If this is a branch, the comment goes to both the branch and the original event
                if (CanSetComment(comment))
                {
                    SetComment(context, comment, GetCurrentUserId(context));
                }

                UpdateRetainState();
            }

            if (EventsMonitored())
            {
                // report a state change event.
                if (ServiceResult.IsGood(error))
                {
                    ReportStateChange(context, false);
                }

                // raise the audit event.
                AuditConditionConfirmEventState e = new AuditConditionConfirmEventState(null);

                TranslationInfo info = new TranslationInfo(
                    "AuditConditionConfirm",
                    "en-US",
                    "The Confirm method was called.");

                e.Initialize(
                    context,
                    this,
                    EventSeverity.Low,
                    new LocalizedText(info),
                    ServiceResult.IsGood(error),
                    DateTime.UtcNow);

                e.SetChildValue(context, BrowseNames.SourceNode, NodeId, false);
                e.SetChildValue(context, BrowseNames.SourceName, "Method/Confirm", false);

                e.SetChildValue(context, BrowseNames.MethodId, method.NodeId, false);
                e.SetChildValue(context, BrowseNames.InputArguments, new object[] { eventId, comment }, false);

                e.SetChildValue(context, BrowseNames.ConditionEventId, eventId, false);
                e.SetChildValue(context, BrowseNames.Comment, comment, false);

                ReportEvent(context, e);
            }

            return(error);
        }