예제 #1
0
        public void SetReplyCommandData(WSCommandTypeBase command, MessageReceivedEventArgs args)
        {
            if (ContentType == MessageContentType.Text)
            {
                args.ResponseContent = SerializationUtility.ToXmlString(command);
            }
            else if (ContentType == MessageContentType.Binary)
            {
                args.ResponseData = BinaryCommandTypeSerializer.ToBinary(command as WSBinaryCommandType);
            }

            throw new NotSupportedException("不支持的命令格式:" + ContentType.ToString());
        }
        public override bool CanRead(MessageReceivedEventArgs args, out WSCommandTypeBase command)
        {
            command = null;
            if (args.ContentType == TransferEncoder)
            {
                if (args.Data != null && args.Data.Length >= 2 &&
                    args.Data[0] == 0 && args.Data[1] == 0)
                {
                    command = BinaryCommandTypeSerializer.ToCommandType(args.Data);
                    return(true);
                }
            }

            return(false);
        }
예제 #3
0
        public WSCommandTypeBase GetCommand(MessageReceivedEventArgs args)
        {
            WSCommandTypeBase command = null;

            switch (ContentType)
            {
            case MessageContentType.Text:
                command = SerializationUtility.ToObject <WSCommandType>(args.Content);
                break;

            case MessageContentType.Binary:
                command = BinaryCommandTypeSerializer.ToCommandType(args.Data);
                break;
            }

            return(command);
        }
 public override void SetReplyCommand(MessageReceivedEventArgs args, WSCommandTypeBase command)
 {
     args.ResponseData = BinaryCommandTypeSerializer.ToBinary(command as WSBinaryCommandType);
 }
 public override byte[] ToBinary(WSCommandTypeBase command)
 {
     return(BinaryCommandTypeSerializer.ToBinary(command as WSBinaryCommandType));
 }