The base class for all method nodes.
Inheritance: BaseInstanceState
        /// <summary>
        /// Handles the generate values method.
        /// </summary>
        protected override ServiceResult OnGenerateValues(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            uint count)
        {
            TestDataSystem system = context.SystemHandle as TestDataSystem;

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

            GenerateValue(system, SByteValue);
            GenerateValue(system, ByteValue);
            GenerateValue(system, Int16Value);
            GenerateValue(system, UInt16Value);
            GenerateValue(system, Int32Value);
            GenerateValue(system, UInt32Value);
            GenerateValue(system, UInt32Value);
            GenerateValue(system, Int64Value);
            GenerateValue(system, UInt64Value);
            GenerateValue(system, FloatValue);
            GenerateValue(system, DoubleValue);
            GenerateValue(system, NumberValue);
            GenerateValue(system, IntegerValue);
            GenerateValue(system, UIntegerValue);

            return base.OnGenerateValues(context, method, objectId, count);
        }  
Exemplo n.º 2
0
        public override void CreateAddressSpace(IDictionary<NodeId, IList<IReference>> externalReferences)
        {
            base.CreateAddressSpace(externalReferences);
            
            // hard code  a sample branch that has the method added.
            NodeId branchId = DaModelUtils.ConstructIdForDaElement("Static/Simple Types", -1, NamespaceIndex);

            // create the method.
            MethodState method = new MethodState(null);

            method.NodeId = GenerateNodeId();
            method.BrowseName = new QualifiedName("GenerateRandomValues", NamespaceIndex);
            method.DisplayName = method.BrowseName.Name;
            method.Executable = true;
            method.UserExecutable = true;
            method.ReferenceTypeId = ReferenceTypeIds.HasComponent;
            method.Handle = "Static/Simple Types";
            
            method.AddReference(ReferenceTypeIds.HasComponent, true, branchId);
            m_references[branchId] = new IReference[] { new NodeStateReference(ReferenceTypeIds.HasComponent, false, method) };
            
            // save the node for later lookup (all tightly coupled children are added with this call).
            AddPredefinedNode(SystemContext, method);
            
            // register handler.
            method.OnCallMethod = new GenericMethodCalledEventHandler(DoGenerateRandomValues);
        }
        /// <summary>
        /// Handles the generate values method.
        /// </summary>
        protected override ServiceResult OnGenerateValues(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            uint count)
        {
            TestDataSystem system = context.SystemHandle as TestDataSystem;

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

            GenerateValue(system, BooleanValue);
            GenerateValue(system, SByteValue);
            GenerateValue(system, ByteValue);
            GenerateValue(system, Int16Value);
            GenerateValue(system, UInt16Value);
            GenerateValue(system, Int32Value);
            GenerateValue(system, UInt32Value);
            GenerateValue(system, UInt32Value);
            GenerateValue(system, Int64Value);
            GenerateValue(system, UInt64Value);
            GenerateValue(system, FloatValue);
            GenerateValue(system, DoubleValue);
            GenerateValue(system, StringValue);
            GenerateValue(system, DateTimeValue);
            GenerateValue(system, GuidValue);
            GenerateValue(system, ByteStringValue);
            GenerateValue(system, XmlElementValue);
            GenerateValue(system, NodeIdValue);
            GenerateValue(system, ExpandedNodeIdValue);
            GenerateValue(system, QualifiedNameValue);
            GenerateValue(system, LocalizedTextValue);
            GenerateValue(system, StatusCodeValue);
            GenerateValue(system, VariantValue);
            GenerateValue(system, EnumerationValue);
            GenerateValue(system, StructureValue);
            GenerateValue(system, NumberValue);
            GenerateValue(system, IntegerValue);
            GenerateValue(system, UIntegerValue);

            return base.OnGenerateValues(context, method, objectId, count);
        }    
Exemplo n.º 4
0
        private ServiceResult OnScalarValue1(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            bool booleanIn,
            sbyte sByteIn,
            byte byteIn,
            short int16In,
            ushort uInt16In,
            int int32In,
            uint uInt32In,
            long int64In,
            ulong uInt64In,
            float floatIn,
            double doubleIn,
            ref bool booleanOut,
            ref sbyte sByteOut,
            ref byte byteOut,
            ref short int16Out,
            ref ushort uInt16Out,
            ref int int32Out,
            ref uint uInt32Out,
            ref long int64Out,
            ref ulong uInt64Out,
            ref float floatOut,
            ref double doubleOut)
        {
            booleanOut = booleanIn;
            sByteOut = sByteIn;
            byteOut = byteIn;
            int16Out = int16In;
            uInt16Out = uInt16In;
            int32Out = int32In;
            uInt32Out = uInt32In;
            int64Out = int64In;
            uInt64Out = uInt64In;
            floatOut = floatIn;
            doubleOut = doubleIn;

            return ServiceResult.Good;
        }
Exemplo n.º 5
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.º 6
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);
        }
Exemplo n.º 7
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;
        }
Exemplo n.º 8
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;
        }
        /// <summary>
        /// Calls a method on an object.
        /// </summary>
        protected virtual ServiceResult Call(
            ISystemContext context,
            CallMethodRequest methodToCall,
            MethodState method,
            CallMethodResult result)
        {
            ServerSystemContext systemContext = context as ServerSystemContext;
            List<ServiceResult> argumentErrors = new List<ServiceResult>();
            VariantCollection outputArguments = new VariantCollection();

            ServiceResult error = method.Call(
                context,
                methodToCall.ObjectId,
                methodToCall.InputArguments,
                argumentErrors,
                outputArguments);

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

            // check for argument errors.
            bool argumentsValid = true;

            for (int jj = 0; jj < argumentErrors.Count; jj++)
            {
                ServiceResult argumentError = argumentErrors[jj];

                if (argumentError != null)
                {
                    result.InputArgumentResults.Add(argumentError.StatusCode);

                    if (ServiceResult.IsBad(argumentError))
                    {
                        argumentsValid = false;
                    }
                }
                else
                {
                    result.InputArgumentResults.Add(StatusCodes.Good);
                }

                // only fill in diagnostic info if it is requested.
                if (systemContext.OperationContext != null)
                {
                    if ((systemContext.OperationContext.DiagnosticsMask & DiagnosticsMasks.OperationAll) != 0)
                    {
                        if (ServiceResult.IsBad(argumentError))
                        {
                            argumentsValid = false;
                            result.InputArgumentDiagnosticInfos.Add(new DiagnosticInfo(argumentError, systemContext.OperationContext.DiagnosticsMask, false, systemContext.OperationContext.StringTable));
                        }
                        else
                        {
                            result.InputArgumentDiagnosticInfos.Add(null);
                        }
                    }
                }
            }

            // check for validation errors.
            if (!argumentsValid)
            {
                result.StatusCode = StatusCodes.BadInvalidArgument;
                return result.StatusCode;
            }

            // do not return diagnostics if there are no errors.
            result.InputArgumentDiagnosticInfos.Clear();

            // return output arguments.
            result.OutputArguments = outputArguments;

            return ServiceResult.Good;
        }
Exemplo n.º 10
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;
        }
        /// <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.º 12
0
        private ServiceResult OnReleaseLock(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            IList<object> inputArguments,
            IList<object> outputArguments)
        {
            DsatsDemo.LockConditionState node = (DsatsDemo.LockConditionState)FindPredefinedNode(objectId, typeof(DsatsDemo.LockConditionState));

            if (!node.EnabledState.Id.Value)
            {
                return StatusCodes.BadConditionDisabled;
            }

            if (node.LockState.CurrentState.Id.Value == new NodeId(DsatsDemo.Objects.LockStateMachineType_Unlocked, NamespaceIndex))
            {
                return StatusCodes.BadConditionNotShelved;
            }

            // non-admins can only release their own locks.
            if (!CheckAdminAccess(context))
            {
                if (!SessionHasLock(context, objectId))
                {
                    return StatusCodes.BadUserAccessDenied;
                }
            }

            // revoke the lock.
            RevokeLockForSession(context, node.SessionId.Value, objectId);

            node.SessionId.Value = null;
            node.ClientUserId.Value = null;
            node.SubjectName.Value = null;
            node.Unlock(context);
            node.ReportEvent(context, node);
            node.ClearChangeMasks(context, true);

            return ServiceResult.Good;
        }
        /// <summary>
        /// Invokes the specified cause.
        /// </summary>
        public virtual ServiceResult DoCause(
            ISystemContext context, 
            MethodState causeMethod, 
            uint causeId,
            IList<object> inputArguments,
            IList<object> outputArguments)
        {
            ServiceResult result = null;

            try
            {
                // get the transition.
                uint transitionId = GetTransitionForCause(context, causeId);

                if (transitionId == 0)
                {
                    return StatusCodes.BadNotSupported;
                }

                // check access rights.
                result = InvokeCallback(
                    OnCheckUserPermission,
                    context, 
                    this, 
                    transitionId, 
                    causeId,
                    inputArguments,
                    outputArguments);

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

                // do the transition.
                result = DoTransition(context, transitionId, causeId, inputArguments, outputArguments);

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

                // report any changes to state machine.
                ClearChangeMasks(context, true);
            }
            finally
            {
                // report the event.
                if (this.AreEventsMonitored)
                {
                    AuditUpdateStateEventState e = CreateAuditEvent(context, causeMethod, causeId);
                    UpdateAuditEvent(context, causeMethod, causeId, e, result);
                    ReportEvent(context, e);
                }
            }        

            return result;    
        }
 /// <summary>
 /// Creates an instance of an audit event.
 /// </summary>
 protected virtual AuditUpdateStateEventState CreateAuditEvent(
     ISystemContext context,
     MethodState causeMethod,
     uint causeId)
 {
     return new AuditUpdateStateEventState(null);
 }
Exemplo n.º 15
0
        /// <summary>
        /// Creates a new instance.
        /// </summary>
        /// <param name="context">The current context.</param>
        /// <param name="parent">The parent.</param>
        /// <param name="nodeClass">The node class.</param>
        /// <param name="browseName">The browse name.</param>
        /// <param name="referenceTypeId">The reference type between the parent and the node.</param>
        /// <param name="typeDefinitionId">The type definition.</param>
        /// <returns>Returns null if the type is not known.</returns>
        public virtual NodeState CreateInstance(
            ISystemContext context,
            NodeState parent,
            NodeClass nodeClass,
            QualifiedName browseName,
            NodeId referenceTypeId,
            NodeId typeDefinitionId)
        {
            NodeState child = null;

            if (m_types != null && !NodeId.IsNull(typeDefinitionId))
            {
                Type type = null;

                if (m_types.TryGetValue(typeDefinitionId, out type))
                {
                    return(Activator.CreateInstance(type, parent) as NodeState);
                }
            }

            switch (nodeClass)
            {
            case NodeClass.Variable:
            {
                if (context.TypeTable != null && context.TypeTable.IsTypeOf(referenceTypeId, ReferenceTypeIds.HasProperty))
                {
                    child = new PropertyState(parent);
                    break;
                }

                child = new BaseDataVariableState(parent);
                break;
            }

            case NodeClass.Object:
            {
                child = new BaseObjectState(parent);
                break;
            }

            case NodeClass.Method:
            {
                child = new MethodState(parent);
                break;
            }

            case NodeClass.ReferenceType:
            {
                child = new ReferenceTypeState();
                break;
            }

            case NodeClass.ObjectType:
            {
                child = new BaseObjectTypeState();
                break;
            }

            case NodeClass.VariableType:
            {
                child = new BaseDataVariableTypeState();
                break;
            }

            case NodeClass.DataType:
            {
                child = new DataTypeState();
                break;
            }

            case NodeClass.View:
            {
                child = new ViewState();
                break;
            }

            default:
            {
                child = null;
                break;
            }
            }

            return(child);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Creates a new controller file.
        /// </summary>
        private ServiceResult OnCreateController(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            string name,
            ref NodeId nodeId)
        {
            nodeId = null;

            // get the system to use.
            FileSystemMonitor system = context.SystemHandle as FileSystemMonitor;

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

            // get the current dierctory.
            DirectoryInfo directory = GetDirectory(context, this.NodeId);

            if (directory == null || !directory.Exists)
            {
                return StatusCodes.BadOutOfService;
            }

            // build the file path.
            StringBuilder filePath = new StringBuilder();

            filePath.Append(directory.FullName);
            filePath.Append('\\');
            filePath.Append(name);
            filePath.Append(".csv");

            if (File.Exists(filePath.ToString()))
            {
                return StatusCodes.BadNodeIdExists;
            }

            // write a dummy configuration file.
            try
            {
                using (StreamWriter writer = new StreamWriter(filePath.ToString()))
                {
                    writer.WriteLine("Temperature, Double, 15");
                    writer.WriteLine("TemperatureSetPoint, Double, 15");
                }
            }
            catch (Exception e)
            {
                return new ServiceResult(e, StatusCodes.BadUnexpectedError);
            }

            // return the node id.
            nodeId = system.CreateNodeIdFromFilePath(ObjectTypes.ControllerType, filePath.ToString());
            
            return ServiceResult.Good;
        }
Exemplo n.º 17
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.º 18
0
        /// <summary>
        /// Handles a request to change the phase.
        /// </summary>
        public ServiceResult OnChangePhase(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            NodeId phaseId)
        {
            //if (!CheckAdminAccess(context))
            //{
            //    return StatusCodes.BadUserAccessDenied;
            //}

            if (!m_rig.IsValidPhase(phaseId))
            {
                return StatusCodes.BadNodeIdInvalid;
            }

            ChangePhase(context, phaseId);

            return ServiceResult.Good;
        }
Exemplo n.º 19
0
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return null;
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
                case DsatsDemo.BrowseNames.SessionId:
                {
                    if (createOrReplace)
                    {
                        if (SessionId == null)
                        {
                            if (replacement == null)
                            {
                                SessionId = new PropertyState<NodeId>(this);
                            }
                            else
                            {
                                SessionId = (PropertyState<NodeId>)replacement;
                            }
                        }
                    }

                    instance = SessionId;
                    break;
                }

                case DsatsDemo.BrowseNames.SubjectName:
                {
                    if (createOrReplace)
                    {
                        if (SubjectName == null)
                        {
                            if (replacement == null)
                            {
                                SubjectName = new PropertyState<string>(this);
                            }
                            else
                            {
                                SubjectName = (PropertyState<string>)replacement;
                            }
                        }
                    }

                    instance = SubjectName;
                    break;
                }

                case DsatsDemo.BrowseNames.LockState:
                {
                    if (createOrReplace)
                    {
                        if (LockState == null)
                        {
                            if (replacement == null)
                            {
                                LockState = new LockStateMachineState(this);
                            }
                            else
                            {
                                LockState = (LockStateMachineState)replacement;
                            }
                        }
                    }

                    instance = LockState;
                    break;
                }

                case DsatsDemo.BrowseNames.LockStateAsString:
                {
                    if (createOrReplace)
                    {
                        if (LockStateAsString == null)
                        {
                            if (replacement == null)
                            {
                                LockStateAsString = new PropertyState<string>(this);
                            }
                            else
                            {
                                LockStateAsString = (PropertyState<string>)replacement;
                            }
                        }
                    }

                    instance = LockStateAsString;
                    break;
                }

                case DsatsDemo.BrowseNames.Request:
                {
                    if (createOrReplace)
                    {
                        if (Request == null)
                        {
                            if (replacement == null)
                            {
                                Request = new MethodState(this);
                            }
                            else
                            {
                                Request = (MethodState)replacement;
                            }
                        }
                    }

                    instance = Request;
                    break;
                }

                case DsatsDemo.BrowseNames.Release:
                {
                    if (createOrReplace)
                    {
                        if (Release == null)
                        {
                            if (replacement == null)
                            {
                                Release = new MethodState(this);
                            }
                            else
                            {
                                Release = (MethodState)replacement;
                            }
                        }
                    }

                    instance = Release;
                    break;
                }

                case DsatsDemo.BrowseNames.Approve:
                {
                    if (createOrReplace)
                    {
                        if (Approve == null)
                        {
                            if (replacement == null)
                            {
                                Approve = new MethodState(this);
                            }
                            else
                            {
                                Approve = (MethodState)replacement;
                            }
                        }
                    }

                    instance = Approve;
                    break;
                }
            }

            if (instance != null)
            {
                return instance;
            }

            return base.FindChild(context, browseName, createOrReplace, replacement);
        }
Exemplo n.º 20
0
        private ServiceResult OnRequestLock(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            IList<object> inputArguments,
            IList<object> outputArguments)
        {
            DsatsDemo.LockConditionState node = (DsatsDemo.LockConditionState)FindPredefinedNode(objectId, typeof(DsatsDemo.LockConditionState));

            if (!node.EnabledState.Id.Value)
            {
                return StatusCodes.BadConditionDisabled;
            }

            if (node.LockState.CurrentState.Id.Value != new NodeId(DsatsDemo.Objects.LockStateMachineType_Unlocked, NamespaceIndex))
            {
                return StatusCodes.BadConditionAlreadyShelved;
            }

            node.SessionId.Value = context.SessionId;
            node.ClientUserId.Value = null;
            node.SubjectName.Value = null;

            // get the current user name.
            if (context.UserIdentity != null)
            {
                node.ClientUserId.Value = context.UserIdentity.DisplayName;
            }

            X509Certificate2 certificate = null;

            // get the client certificate subject name.
            ServerSystemContext systemContext = context as ServerSystemContext;

            if (systemContext != null && systemContext.OperationContext != null && systemContext.OperationContext.Session != null && systemContext.OperationContext.Session.ClientCertificate != null)
            {
                certificate = systemContext.OperationContext.Session.ClientCertificate;
                node.SubjectName.Value = certificate.Subject;
            }

            node.RequestLock(context);

            // admins get locks immediately.
            if (CheckAdminAccess(context) || (certificate != null && node.HasPermission(certificate)))
            {
                GrantLockToSession(context, node.SessionId.Value, objectId);
                node.SetLock(context);
            }

            node.ReportEvent(context, node);
            node.ClearChangeMasks(context, true);

            return ServiceResult.Good;
        }
        /// <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.º 22
0
        private ServiceResult OnApproveLock(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            IList<object> inputArguments,
            IList<object> outputArguments)
        {
            DsatsDemo.LockConditionState node = (DsatsDemo.LockConditionState)FindPredefinedNode(objectId, typeof(DsatsDemo.LockConditionState));

            if (!node.EnabledState.Id.Value)
            {
                return StatusCodes.BadConditionDisabled;
            }

            if (node.LockState.CurrentState.Id.Value != new NodeId(DsatsDemo.Objects.LockStateMachineType_WaitingForApproval, NamespaceIndex))
            {
                return StatusCodes.BadConditionNotShelved;
            }

            // only admins can approve locks.
            if (!CheckAdminAccess(context))
            {
                return StatusCodes.BadUserAccessDenied;
            }

            // grant the lock.
            GrantLockToSession(context, node.SessionId.Value, objectId);

            node.SetLock(context);
            node.ReportEvent(context, node);
            node.ClearChangeMasks(context, true);

            return ServiceResult.Good;
        }
        /// <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);
        }
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;
        }
 /// <summary>
 /// Creates an instance of an audit event.
 /// </summary>
 protected override AuditUpdateStateEventState CreateAuditEvent(
     ISystemContext context,
     MethodState causeMethod,
     uint causeId)
 {
     return new ProgramTransitionAuditEventState(null);
 }
Exemplo n.º 26
0
        private ServiceResult OnArrayValue3(       
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            Variant[] variantIn,
            int[] enumerationIn,
            ExtensionObject[] structureIn,
            ref Variant[] variantOut,
            ref int[] enumerationOut,
            ref ExtensionObject[] structureOut)
        {
            variantOut = variantIn;
            enumerationOut = enumerationIn;
            structureOut = structureIn;

            return ServiceResult.Good;
        }        
 /// <summary>
 /// Handles the reset method.
 /// </summary>
 protected virtual ServiceResult OnReset(
     ISystemContext context,
     MethodState method,
     IList<object> inputArguments,
     IList<object> outputArguments)
 {
     return DoCause(context, method, Methods.ProgramStateMachineType_Reset, inputArguments, outputArguments);
 }
Exemplo n.º 28
0
        private ServiceResult OnUserArrayValue1(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            bool[] booleanIn,
            sbyte[] sByteIn,
            byte[] byteIn,
            short[] int16In,
            ushort[] uInt16In,
            int[] int32In,
            uint[] uInt32In,
            long[] int64In,
            ulong[] uInt64In,
            float[] floatIn,
            double[] doubleIn,
            string[] stringIn,
            ref bool[] booleanOut,
            ref sbyte[] sByteOut,
            ref byte[] byteOut,
            ref short[] int16Out,
            ref ushort[] uInt16Out,
            ref int[] int32Out,
            ref uint[] uInt32Out,
            ref long[] int64Out,
            ref ulong[] uInt64Out,
            ref float[] floatOut,
            ref double[] doubleOut,
            ref string[] stringOut)
        {
            booleanOut = booleanIn;
            sByteOut = sByteIn;
            byteOut = byteIn;
            int16Out = int16In;
            uInt16Out = uInt16In;
            int32Out = int32In;
            uInt32Out = uInt32In;
            int64Out = int64In;
            uInt64Out = uInt64In;
            floatOut = floatIn;
            doubleOut = doubleIn;
            stringOut = stringIn;

            return ServiceResult.Good;
        }
Exemplo n.º 29
0
        /// <summary>
        /// Called when the Start method is called.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="method">The method.</param>
        /// <param name="inputArguments">The input arguments.</param>
        /// <param name="outputArguments">The output arguments.</param>
        /// <returns></returns>
        public ServiceResult OnStart(
            ISystemContext context, 
            MethodState method, 
            IList<object> inputArguments, 
            IList<object> outputArguments)
        {
            // all arguments must be provided.
            if (inputArguments.Count < 2)
            {
                return StatusCodes.BadArgumentsMissing;
            }

            // check the data type of the input arguments.
            uint? initialState = inputArguments[0] as uint?;
            uint? finalState = inputArguments[1] as uint?;

            if (initialState == null || finalState == null)
            {
                return StatusCodes.BadTypeMismatch;
            }

            lock (m_processLock)
            {
                // check if the process is running.
                if (m_processTimer != null)
                {
                    m_processTimer.Dispose();
                    m_processTimer = null;
                }

                // start the process.
                m_state = initialState.Value;
                m_finalState = finalState.Value;
                m_processTimer = new Timer(OnUpdateProcess, null, 1000, 1000);

                // the calling function sets default values for all output arguments.
                // only need to update them here.
                outputArguments[0] = m_state;
                outputArguments[1] = m_finalState;
            }

            // signal update to state node.
            lock (Lock)
            {
                m_stateNode.Value = m_state;
                m_stateNode.ClearChangeMasks(SystemContext, true);
            }

            return ServiceResult.Good;
        }
Exemplo n.º 30
0
        /// <summary>
        /// Handles the generate values method.
        /// </summary>
        protected virtual ServiceResult OnGenerateValues(
            ISystemContext context, 
            MethodState method,
            NodeId objectId,
            uint count)
        {
            ClearChangeMasks(context, true);

            if (AreEventsMonitored)
            {
                GenerateValuesEventState e = new GenerateValuesEventState(null);
                            
                TranslationInfo message = new TranslationInfo(
                    "GenerateValuesEventType",
                    "en-US",
                    "New values generated for test source '{0}'.",
                    this.DisplayName);
                
                e.Initialize(
                    context,
                    this,
                    EventSeverity.MediumLow,
                    new LocalizedText(message));

                e.Iterations = new PropertyState<uint>(e);
                e.Iterations.Value = count;

                e.NewValueCount = new PropertyState<uint>(e);
                e.NewValueCount.Value = 10;

                ReportEvent(context, e);
            }
            
            #if CONDITION_SAMPLES
            this.CycleComplete.RequestAcknowledgement(context, (ushort)EventSeverity.Low);
            #endif
            
            return ServiceResult.Good;
        }
Exemplo n.º 31
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);
        }
        /// <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.º 33
0
        /// <summary>
        /// Verifies that the specified node exists.
        /// </summary>
        protected override NodeState ValidateNode(
            ServerSystemContext context,
            NodeHandle handle,
            IDictionary<NodeId, NodeState> cache)
        {
            // not valid if no root.
            if (handle == null)
            {
                return null;
            }

            // check if previously validated.
            if (handle.Validated)
            {
                return handle.Node;
            }

            // lookup in operation cache.
            NodeState target = FindNodeInCache(context, handle, cache);

            if (target != null)
            {
                handle.Node = target;
                handle.Validated = true;
                return handle.Node;
            }

            try
            {
                Opc.Ua.Client.Session client = GetClientSession(context);

                // get remote node.
                NodeId targetId = m_mapper.ToRemoteId(handle.NodeId);
                ILocalNode node = client.ReadNode(targetId) as ILocalNode;

                if (node == null)
                {
                    return null;
                }

                // map remote node to local object.
                switch (node.NodeClass)
                {
                    case NodeClass.ObjectType:
                    {
                        BaseObjectTypeState value = new BaseObjectTypeState();
                        value.IsAbstract = ((IObjectType)node).IsAbstract;
                        target = value;
                        break;
                    }

                    case NodeClass.VariableType:
                    {
                        BaseVariableTypeState value = new BaseDataVariableTypeState();
                        value.IsAbstract = ((IVariableType)node).IsAbstract;
                        value.Value = m_mapper.ToLocalValue(((IVariableType)node).Value);
                        value.DataType = m_mapper.ToLocalId(((IVariableType)node).DataType);
                        value.ValueRank = ((IVariableType)node).ValueRank;
                        value.ArrayDimensions = new ReadOnlyList<uint>(((IVariableType)node).ArrayDimensions);
                        target = value;
                        break;
                    }

                    case NodeClass.DataType:
                    {
                        DataTypeState value = new DataTypeState();
                        value.IsAbstract = ((IDataType)node).IsAbstract;
                        target = value;
                        break;
                    }

                    case NodeClass.ReferenceType:
                    {
                        ReferenceTypeState value = new ReferenceTypeState();
                        value.IsAbstract = ((IReferenceType)node).IsAbstract;
                        value.InverseName = ((IReferenceType)node).InverseName;
                        value.Symmetric = ((IReferenceType)node).Symmetric;
                        target = value;
                        break;
                    }

                    case NodeClass.Object:
                    {
                        BaseObjectState value = new BaseObjectState(null);
                        value.EventNotifier = ((IObject)node).EventNotifier;
                        target = value;
                        break;
                    }

                    case NodeClass.Variable:
                    {
                        BaseDataVariableState value = new BaseDataVariableState(null);
                        value.Value = m_mapper.ToLocalValue(((IVariable)node).Value);
                        value.DataType = m_mapper.ToLocalId(((IVariable)node).DataType);
                        value.ValueRank = ((IVariable)node).ValueRank;
                        value.ArrayDimensions = new ReadOnlyList<uint>(((IVariable)node).ArrayDimensions);
                        value.AccessLevel = ((IVariable)node).AccessLevel;
                        value.UserAccessLevel = ((IVariable)node).UserAccessLevel;
                        value.Historizing = ((IVariable)node).Historizing;
                        value.MinimumSamplingInterval = ((IVariable)node).MinimumSamplingInterval;
                        target = value;
                        break;
                    }

                    case NodeClass.Method:
                    {
                        MethodState value = new MethodState(null);
                        value.Executable = ((IMethod)node).Executable;
                        value.UserExecutable = ((IMethod)node).UserExecutable;
                        target = value;
                        break;
                    }

                    case NodeClass.View:
                    {
                        ViewState value = new ViewState();
                        value.ContainsNoLoops = ((IView)node).ContainsNoLoops;
                        target = value;
                        break;
                    }
                }

                target.NodeId = handle.NodeId;
                target.BrowseName = m_mapper.ToLocalName(node.BrowseName);
                target.DisplayName = node.DisplayName;
                target.Description = node.Description;
                target.WriteMask = node.WriteMask;
                target.UserWriteMask = node.UserWriteMask;
                target.Handle = node;
                target.OnCreateBrowser = OnCreateBrowser;
            }

            // ignore errors.
            catch
            {
                return null;
            }

            // put root into operation cache.
            if (cache != null)
            {
                cache[handle.NodeId] = target;
            }

            handle.Node = target;
            handle.Validated = true;
            return handle.Node;
        }
Exemplo n.º 34
0
        /// <summary>
        /// Does any initialization required before the address space can be used.
        /// </summary>
        /// <remarks>
        /// The externalReferences is an out parameter that allows the node manager to link to nodes
        /// in other node managers. For example, the 'Objects' node is managed by the CoreNodeManager and
        /// should have a reference to the root folder node(s) exposed by this node manager.  
        /// </remarks>
        public override void CreateAddressSpace(IDictionary<NodeId, IList<IReference>> externalReferences)
        {
            lock (Lock)
            {
                // create a object to represent the process being controlled.
                BaseObjectState process = new BaseObjectState(null);

                process.NodeId = new NodeId(1, NamespaceIndex);
                process.BrowseName = new QualifiedName("My Process", NamespaceIndex);
                process.DisplayName = process.BrowseName.Name;
                process.TypeDefinitionId = ObjectTypeIds.BaseObjectType; 

                // ensure the process object can be found via the server object. 
                IList<IReference> references = null;

                if (!externalReferences.TryGetValue(ObjectIds.ObjectsFolder, out references))
                {
                    externalReferences[ObjectIds.ObjectsFolder] = references = new List<IReference>();
                }

                process.AddReference(ReferenceTypeIds.Organizes, true, ObjectIds.ObjectsFolder);
                references.Add(new NodeStateReference(ReferenceTypeIds.Organizes, false, process.NodeId));

                // a property to report the process state.
                PropertyState<uint> state = m_stateNode = new PropertyState<uint>(process);

                state.NodeId = new NodeId(2, NamespaceIndex);
                state.BrowseName = new QualifiedName("State", NamespaceIndex);
                state.DisplayName = state.BrowseName.Name;
                state.TypeDefinitionId = VariableTypeIds.PropertyType;
                state.ReferenceTypeId = ReferenceTypeIds.HasProperty;
                state.DataType = DataTypeIds.UInt32;
                state.ValueRank = ValueRanks.Scalar;

                process.AddChild(state);

                // a method to start the process.
                MethodState start = new MethodState(process);

                start.NodeId = new NodeId(3, NamespaceIndex);
                start.BrowseName = new QualifiedName("Start", NamespaceIndex);
                start.DisplayName = start.BrowseName.Name;
                start.ReferenceTypeId = ReferenceTypeIds.HasComponent;
                start.UserExecutable = true;
                start.Executable = true;

                // add input arguments.
                start.InputArguments = new PropertyState<Argument[]>(start);
                start.InputArguments.NodeId = new NodeId(4, NamespaceIndex);
                start.InputArguments.BrowseName = BrowseNames.InputArguments;
                start.InputArguments.DisplayName = start.InputArguments.BrowseName.Name;
                start.InputArguments.TypeDefinitionId = VariableTypeIds.PropertyType;
                start.InputArguments.ReferenceTypeId = ReferenceTypeIds.HasProperty;
                start.InputArguments.DataType = DataTypeIds.Argument;
                start.InputArguments.ValueRank = ValueRanks.OneDimension;

                Argument[] args = new Argument[2];
                args[0] = new Argument();
                args[0].Name = "Initial State";
                args[0].Description = "The initialize state for the process.";
                args[0].DataType = DataTypeIds.UInt32;
                args[0].ValueRank = ValueRanks.Scalar;

                args[1] = new Argument();
                args[1].Name = "Final State";
                args[1].Description = "The final state for the process.";
                args[1].DataType = DataTypeIds.UInt32;
                args[1].ValueRank = ValueRanks.Scalar;

                start.InputArguments.Value = args;

                // add output arguments.
                start.OutputArguments = new PropertyState<Argument[]>(start);
                start.OutputArguments.NodeId = new NodeId(5, NamespaceIndex);
                start.OutputArguments.BrowseName = BrowseNames.OutputArguments;
                start.OutputArguments.DisplayName = start.OutputArguments.BrowseName.Name;
                start.OutputArguments.TypeDefinitionId = VariableTypeIds.PropertyType;
                start.OutputArguments.ReferenceTypeId = ReferenceTypeIds.HasProperty;
                start.OutputArguments.DataType = DataTypeIds.Argument;
                start.OutputArguments.ValueRank = ValueRanks.OneDimension;

                args = new Argument[2];
                args[0] = new Argument();
                args[0].Name = "Revised Initial State";
                args[0].Description = "The revised initialize state for the process.";
                args[0].DataType = DataTypeIds.UInt32;
                args[0].ValueRank = ValueRanks.Scalar;

                args[1] = new Argument();
                args[1].Name = "Revised Final State";
                args[1].Description = "The revised final state for the process.";
                args[1].DataType = DataTypeIds.UInt32;
                args[1].ValueRank = ValueRanks.Scalar;

                start.OutputArguments.Value = args;

                process.AddChild(start);

                // save in dictionary. 
                AddPredefinedNode(SystemContext, process);

                // set up method handlers. 
                start.OnCallMethod = new GenericMethodCalledEventHandler(OnStart);
            } 
        }
        /// <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);
                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.º 36
0
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return null;
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
                case FileSystem.BrowseNames.Temperature:
                {
                    if (createOrReplace)
                    {
                        if (Temperature == null)
                        {
                            if (replacement == null)
                            {
                                Temperature = new AnalogItemState<double>(this);
                            }
                            else
                            {
                                Temperature = (AnalogItemState<double>)replacement;
                            }
                        }
                    }

                    instance = Temperature;
                    break;
                }

                case FileSystem.BrowseNames.TemperatureSetPoint:
                {
                    if (createOrReplace)
                    {
                        if (TemperatureSetPoint == null)
                        {
                            if (replacement == null)
                            {
                                TemperatureSetPoint = new AnalogItemState<double>(this);
                            }
                            else
                            {
                                TemperatureSetPoint = (AnalogItemState<double>)replacement;
                            }
                        }
                    }

                    instance = TemperatureSetPoint;
                    break;
                }

                case FileSystem.BrowseNames.State:
                {
                    if (createOrReplace)
                    {
                        if (State == null)
                        {
                            if (replacement == null)
                            {
                                State = new BaseDataVariableState<int>(this);
                            }
                            else
                            {
                                State = (BaseDataVariableState<int>)replacement;
                            }
                        }
                    }

                    instance = State;
                    break;
                }

                case FileSystem.BrowseNames.PowerConsumption:
                {
                    if (createOrReplace)
                    {
                        if (PowerConsumption == null)
                        {
                            if (replacement == null)
                            {
                                PowerConsumption = new DataItemState<double>(this);
                            }
                            else
                            {
                                PowerConsumption = (DataItemState<double>)replacement;
                            }
                        }
                    }

                    instance = PowerConsumption;
                    break;
                }

                case FileSystem.BrowseNames.Start:
                {
                    if (createOrReplace)
                    {
                        if (Start == null)
                        {
                            if (replacement == null)
                            {
                                Start = new MethodState(this);
                            }
                            else
                            {
                                Start = (MethodState)replacement;
                            }
                        }
                    }

                    instance = Start;
                    break;
                }

                case FileSystem.BrowseNames.Stop:
                {
                    if (createOrReplace)
                    {
                        if (Stop == null)
                        {
                            if (replacement == null)
                            {
                                Stop = new MethodState(this);
                            }
                            else
                            {
                                Stop = (MethodState)replacement;
                            }
                        }
                    }

                    instance = Stop;
                    break;
                }
            }

            if (instance != null)
            {
                return instance;
            }

            return base.FindChild(context, browseName, createOrReplace, replacement);
        }
        /// <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);
        }