Opc.Ua.Com.Client.ComAeClient.Acknowledge C# (CSharp) Méthode

Acknowledge() public méthode

Acknowledges the specified context.
public Acknowledge ( ServerSystemContext context, byte eventId, Opc.Ua.LocalizedText comment ) : uint
context Opc.Ua.Server.ServerSystemContext The context.
eventId byte The event id.
comment Opc.Ua.LocalizedText The comment.
Résultat uint
        public uint Acknowledge(
            ServerSystemContext context,
            byte[] eventId,
            LocalizedText comment)
        {
            // get the user name from the context.
            string userName = String.Empty;

            if (context.UserIdentity != null)
            {
                userName = context.UserIdentity.DisplayName;
            }

            // get the comment.
            string commentText = String.Empty;

            if (comment != null)
            {
                commentText = comment.Text;
            }

            System.Runtime.InteropServices.ComTypes.FILETIME ftActiveTime;

            // unpack the event id.
            ServiceMessageContext messageContext = new ServiceMessageContext();

            messageContext.NamespaceUris = context.NamespaceUris;
            messageContext.ServerUris = context.ServerUris;
            messageContext.Factory = context.EncodeableFactory;

            BinaryDecoder decoder = new BinaryDecoder(eventId, messageContext);

            string source = decoder.ReadString(null);
            string conditionName = decoder.ReadString(null);
            ftActiveTime.dwHighDateTime = decoder.ReadInt32(null);
            ftActiveTime.dwLowDateTime = decoder.ReadInt32(null);
            int cookie = decoder.ReadInt32(null);

            decoder.Close();

            string methodName = "IOPCEventServer.AckCondition";

            IntPtr pErrors = IntPtr.Zero;
            
            try
            {
                IOPCEventServer server = BeginComCall<IOPCEventServer>(methodName, true);

                server.AckCondition(
                    1,
                    userName,
                    commentText,
                    new string[] { source },
                    new string[] { conditionName },
                    new System.Runtime.InteropServices.ComTypes.FILETIME[] { ftActiveTime },
                    new int[] { cookie },
                    out pErrors);
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
                return StatusCodes.BadUnexpectedError;
            }
            finally
            {
                EndComCall(methodName);
            }

            // unmarshal results.
            int[] errors = ComUtils.GetInt32s(ref pErrors, 1, true);
                        
            if (errors[0] == ResultIds.S_ALREADYACKED)
            {
                return StatusCodes.BadConditionBranchAlreadyAcked;
            }
            else if (errors[0] < 0)
            {
                return StatusCodes.BadEventIdUnknown;
            }

            return StatusCodes.Good;
        }

Usage Example

        /// <summary>
        /// Called when the alarm is acknowledged.
        /// </summary>
        private ServiceResult OnAcknowledge(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            byte[] eventId,
            LocalizedText comment)
        {
            ComAeClientManager system = (ComAeClientManager)this.SystemContext.SystemHandle;
            ComAeClient        client = (ComAeClient)system.SelectClient((ServerSystemContext)context, false);

            try
            {
                return(client.Acknowledge((ServerSystemContext)context, eventId, comment));
            }
            catch (Exception e)
            {
                return(ServiceResult.Create(e, StatusCodes.BadUnexpectedError, "Could not acknowledge event."));
            }
        }