/// <summary>
        /// Constructs an event and reports to the server.
        /// </summary>
        private void RaiseAuditUpdateMethodEvent(
            ISystemContext context,
            MethodState method,
            bool status,
            IList <object> inputArguments)
        {
            BaseObjectState parent = method.Parent as BaseObjectState;

            #region Task #D6 - Add Support for Notifiers
            // check if it is even necessary to produce an event.
            if (parent != null && !parent.AreEventsMonitored)
            {
                return;
            }
            #endregion

            // construct translation object with default text.
            TranslationInfo info = new TranslationInfo(
                "AuditUpdateMethodEvent",
                "en-US",
                "A method was called.");

            // intialize the event.
            AuditUpdateMethodEventState e = new AuditUpdateMethodEventState(null);

            e.Initialize(
                SystemContext,
                null,
                EventSeverity.Medium,
                new LocalizedText(info),
                true,
                DateTime.UtcNow);

            // fill in additional fields.
            e.SetChildValue(SystemContext, Opc.Ua.BrowseNames.SourceNode, method.Parent.NodeId, false);
            e.SetChildValue(SystemContext, Opc.Ua.BrowseNames.SourceName, "Attribute/Call", false);
            e.SetChildValue(SystemContext, Opc.Ua.BrowseNames.ServerId, context.ServerUris.GetString(0), false);
            e.SetChildValue(SystemContext, Opc.Ua.BrowseNames.ClientAuditEntryId, context.AuditEntryId, false);

            if (context.UserIdentity != null)
            {
                e.SetChildValue(SystemContext, Opc.Ua.BrowseNames.ClientUserId, context.UserIdentity.DisplayName, false);
            }

            e.SetChildValue(SystemContext, Opc.Ua.BrowseNames.MethodId, method.NodeId, false);

            // need to change data type.
            Variant[] values = new Variant[inputArguments.Count];

            for (int ii = 0; ii < values.Length; ii++)
            {
                values[ii] = new Variant(inputArguments[ii]);
            }

            e.SetChildValue(SystemContext, Opc.Ua.BrowseNames.InputArguments, values, false);

            #region Task #D6 - Add Support for Notifiers
            // report the event to the parent. let it propagate up the tree.
            if (parent != null && parent.AreEventsMonitored)
            {
                parent.ReportEvent(context, e);
                return;
            }
            #endregion

            // report the event to the server object.
            Server.ReportEvent(e);
        }
        /// <summary>
        /// Constructs an event and reports to the server.
        /// </summary>
        private void RaiseAuditUpdateMethodEvent(
            ISystemContext context,
            MethodState method,
            bool status,
            IList<object> inputArguments)
        {
            BaseObjectState parent = method.Parent as BaseObjectState;

            #region Task #D6 - Add Support for Notifiers
            // check if it is even necessary to produce an event.
            if (parent != null && !parent.AreEventsMonitored)
            {
                return;
            }
            #endregion

            // construct translation object with default text.
            TranslationInfo info = new TranslationInfo(
                "AuditUpdateMethodEvent",
                "en-US",
                "A method was called.");

            // intialize the event.
            AuditUpdateMethodEventState e = new AuditUpdateMethodEventState(null);

            e.Initialize(
                SystemContext,
                null,
                EventSeverity.Medium,
                new LocalizedText(info),
                true,
                DateTime.UtcNow);

            // fill in additional fields.
            e.SetChildValue(SystemContext, Opc.Ua.BrowseNames.SourceNode, method.Parent.NodeId, false);
            e.SetChildValue(SystemContext, Opc.Ua.BrowseNames.SourceName, "Attribute/Call", false);
            e.SetChildValue(SystemContext, Opc.Ua.BrowseNames.ServerId, context.ServerUris.GetString(0), false);
            e.SetChildValue(SystemContext, Opc.Ua.BrowseNames.ClientAuditEntryId, context.AuditEntryId, false);

            if (context.UserIdentity != null)
            {
                e.SetChildValue(SystemContext, Opc.Ua.BrowseNames.ClientUserId, context.UserIdentity.DisplayName, false);
            }

            e.SetChildValue(SystemContext, Opc.Ua.BrowseNames.MethodId, method.NodeId, false);

            // need to change data type.
            Variant[] values = new Variant[inputArguments.Count];

            for (int ii = 0; ii < values.Length; ii++)
            {
                values[ii] = new Variant(inputArguments[ii]);
            }

            e.SetChildValue(SystemContext, Opc.Ua.BrowseNames.InputArguments, values, false);

            #region Task #D6 - Add Support for Notifiers
            // report the event to the parent. let it propagate up the tree. 
            if (parent != null && parent.AreEventsMonitored)
            {
                parent.ReportEvent(context, e);
                return;
            }
            #endregion

            // report the event to the server object.
            Server.ReportEvent(e);
        }
Exemple #3
0
        private 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 (_processLock)
            {
                // check if the process is running.
                if (_processTimer != null)
                {
                    _processTimer.Dispose();
                    _processTimer = null;
                }
                // start the process.
                _state        = initialState.Value;
                _finalState   = finalState.Value;
                _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] = _state;
                outputArguments[1] = _finalState;
            }
            // signal update to state node.
            lock (ApplicationNodeManager.Lock)
            {
                _stateNode.Value = _state;
                _stateNode.ClearChangeMasks(ApplicationNodeManager.SystemContext, true);
            }
            TranslationInfo info = new TranslationInfo(
                "OnStart",
                "en-US",
                "The Confirm method was called.");
            AuditUpdateMethodEventState auditUpdateMethodEventState = new AuditUpdateMethodEventState(method);

            auditUpdateMethodEventState.Initialize(
                context,
                method,
                EventSeverity.Low,
                new LocalizedText(info),
                ServiceResult.IsGood(StatusCodes.Good),
                DateTime.UtcNow);
            auditUpdateMethodEventState.SourceName.Value = "Attribute/Call";
            auditUpdateMethodEventState.MethodId         = new PropertyState <NodeId>(method)
            {
                Value = method.NodeId
            };
            auditUpdateMethodEventState.InputArguments = new PropertyState <object[]>(method)
            {
                Value = new object[] { inputArguments }
            };
            auditUpdateMethodEventState.SetChildValue(context, BrowseNames.InputArguments, inputArguments.ToArray(), true);
            bool valid = auditUpdateMethodEventState.Validate(context);

            if (valid)
            {
                ApplicationNodeManager.Server.ReportEvent(auditUpdateMethodEventState);
            }
            return(ServiceResult.Good);
        }
Exemple #4
0
        private ServiceResult AddApplication(ISystemContext context, MethodState method, IList <object> inputArguments, IList <object> outputArguments)
        {
            if (inputArguments.Count != 1)
            {
                return(StatusCodes.BadArgumentsMissing);
            }
            // check the data type of the input arguments.
            string value = inputArguments[0] as string;

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

            if (_applications == null)
            {
                _applications = new List <string>();
            }
            _applications.Add(value);

            if (_processor == null)
            {
                _processor          = new Processor();
                _processor.Name     = "Turbo";
                _processor.MinSpeed = 0;
                _processor.MaxSpeed = 0;
            }
            _processor.MinSpeed  = 1;
            _processor.MaxSpeed += 1;

            //Could not encode outgoing
            outputArguments[0] = _applications.ToArray();
            outputArguments[1] = _processor;

            //Report
            TranslationInfo info = new TranslationInfo(
                "AddApplication",
                "en-US",
                "The Confirm method was called.");
            AuditUpdateMethodEventState auditUpdateMethodEventState = new AuditUpdateMethodEventState(method);

            auditUpdateMethodEventState.Initialize(
                context,
                method,
                EventSeverity.Low,
                new LocalizedText(info),
                ServiceResult.IsGood(StatusCodes.Good),
                DateTime.UtcNow);
            auditUpdateMethodEventState.SourceName.Value = "Attribute/Call";
            auditUpdateMethodEventState.MethodId         = new PropertyState <NodeId>(method)
            {
                Value = method.NodeId
            };
            auditUpdateMethodEventState.InputArguments = new PropertyState <object[]>(method)
            {
                Value = new object[] { inputArguments }
            };
            auditUpdateMethodEventState.SetChildValue(context, BrowseNames.InputArguments, inputArguments.ToArray(), true);
            bool valid = auditUpdateMethodEventState.Validate(context);

            if (valid)
            {
                ApplicationNodeManager.Server.ReportEvent(auditUpdateMethodEventState);
            }
            return(ServiceResult.Good);
        }