Close() public method

Completes reading and closes the stream.
public Close ( ) : void
return void
Exemplo n.º 1
0
        /// <summary>
        /// Acknowledges the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="eventId">The event id.</param>
        /// <param name="comment">The comment.</param>
        /// <returns></returns>
        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;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Decodes a message from a buffer.
        /// </summary>
        public static IEncodeable DecodeMessage(byte[] buffer, System.Type expectedType, ServiceMessageContext context)
        {
            if (buffer  == null) throw new ArgumentNullException("buffer");
            if (context == null) throw new ArgumentNullException("context");

            BinaryDecoder decoder = new BinaryDecoder(buffer, context);

            try
            {
                return decoder.DecodeMessage(expectedType);
            }
            finally
            {
                decoder.Close();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Converts a VARIANT value to a Builtin Type.
        /// </summary>
        private object VariantValueToScalarValue(object value, NodeId builtinTypeId)
        {        
            switch ((uint)builtinTypeId.Identifier)
            {
                case DataTypes.Guid:
                {
                    return new Uuid((string)value);
                }

                case DataTypes.XmlElement:
                {    
                    XmlDocument document = new XmlDocument();
                    document.InnerXml = (string)value;
                    return document.DocumentElement;
                }

                case DataTypes.NodeId:
                {
                    return NodeId.Parse((string)value);
                }

                case DataTypes.ExpandedNodeId:
                {
                    return ExpandedNodeId.Parse((string)value);
                }

                case DataTypes.QualifiedName:
                {
                    return QualifiedName.Parse((string)value);
                }

                case DataTypes.LocalizedText:
                {
                    return new LocalizedText(ComUtils.GetLocale(m_lcid), (string)value);
                }

                case DataTypes.StatusCode:
                {
                     return new StatusCode((uint)value);
                }

                case DataTypes.DiagnosticInfo:
                {
                    BinaryDecoder decoder = new BinaryDecoder((byte[])value, m_session.MessageContext);
                    DiagnosticInfo decodedValue = decoder.ReadDiagnosticInfo(null);
                    decoder.Close();
                    return decodedValue; 
                }

                case DataTypes.DataValue:
                {
                    BinaryDecoder decoder = new BinaryDecoder((byte[])value, m_session.MessageContext);
                    DataValue decodedValue = decoder.ReadDataValue(null);
                    decoder.Close();
                    return decodedValue; 
                }

                case DataTypes.Structure:
                {
                    BinaryDecoder decoder = new BinaryDecoder((byte[])value, m_session.MessageContext);
                    ExtensionObject decodedValue = decoder.ReadExtensionObject(null);
                    decoder.Close();
                    return decodedValue; 
                }
            }

            return value;
        }