public FlowNodeStatusChangedEventArgs(IFlowNode node, FlowNodeStatus newStatus, MessageHeader header, IMessageBody body)
 {
     Node      = node ?? throw new ArgumentNullException(nameof(node));
     NewStatus = newStatus;
     Header    = header;
     Body      = body;
 }
Example #2
0
        public void SendOneWay(IServiceRemotingRequestMessage requestMessage)
        {
            IMessageBody   outgoingMessageBody   = null;
            IMessageHeader outgoingMessageHeader = null;

            try
            {
                var headerSerialzier = this.serializersManager.GetHeaderSerializer();
                outgoingMessageHeader = headerSerialzier.SerializeRequestHeader(requestMessage.GetHeader());
                var requestSerializer =
                    this.serializersManager.GetRequestBodySerializer(requestMessage.GetHeader().InterfaceId);
                outgoingMessageBody = requestSerializer.Serialize(requestMessage.GetBody());
                this.callbackChannel.SendOneWay(outgoingMessageHeader.GetSendBuffer(),
                                                outgoingMessageBody.GetSendBuffers());
            }
            finally
            {
                if (outgoingMessageHeader != null)
                {
                    outgoingMessageHeader.Dispose();
                }
                if (outgoingMessageBody != null)
                {
                    outgoingMessageBody.Dispose();
                }
            }
        }
        /// <summary>
        ///     Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader" /> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>The object value.</returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
                                        JsonSerializer serializer)
        {
            IMessageBody body            = null;
            var          jbody           = JObject.Load(reader);
            var          hasTemplateName = jbody.Properties()
                                           .Any(p => p.Name.Equals("templatename", StringComparison.OrdinalIgnoreCase));

            if (hasTemplateName)
            {
                body = jbody.ToObject <TemplateBody>();
            }
            else
            {
                var hasContentProperties = jbody.Properties()
                                           .Any(p => p.Name.Equals("PlainTextContent", StringComparison.OrdinalIgnoreCase) ||
                                                p.Name.Equals("HtmlContent", StringComparison.OrdinalIgnoreCase));
                if (hasContentProperties)
                {
                    body = jbody.ToObject <ContentBody>();
                }
            }

            return(body);
        }
Example #4
0
            public async Task <ResponseMessage> RequestResponseAsync(ArraySegment <byte> messageHeaders,
                                                                     IEnumerable <ArraySegment <byte> > requestBody)
            {
                IMessageBody   outgoingMessageBody   = null;
                IMessageHeader outgoingMessageHeader = null;

                try
                {
                    var headerSerializer   = this.serializersManager.GetHeaderSerializer();
                    var deSerializedHeader =
                        headerSerializer.DeserializeRequestHeaders(
                            new IncomingMessageHeader(new SegmentedReadMemoryStream(messageHeaders)));

                    var msgBodySerializer =
                        this.serializersManager.GetRequestBodySerializer(deSerializedHeader.InterfaceId);
                    var deserializedMsg =
                        msgBodySerializer.Deserialize(
                            new IncomingMessageBody(new SegmentedReadMemoryStream(requestBody)));

                    var msg    = new ServiceRemotingRequestMessage(deSerializedHeader, deserializedMsg);
                    var retval = await
                                 this.messageHandler.HandleRequestResponseAsync(
                        this.requestContext,
                        msg);

                    if (retval == null)
                    {
                        return(new ResponseMessage());
                    }

                    outgoingMessageHeader = headerSerializer.SerializeResponseHeader(retval.GetHeader());

                    var responseSerializer =
                        this.serializersManager.GetResponseBodySerializer(deSerializedHeader.InterfaceId);

                    outgoingMessageBody = responseSerializer.Serialize(retval.GetBody());

                    var responseMessage = new ResponseMessage();
                    responseMessage.ResponseBody = outgoingMessageBody != null
                        ? outgoingMessageBody.GetSendBuffers()
                        : new List <ArraySegment <byte> >();

                    responseMessage.MessageHeaders = outgoingMessageHeader != null
                        ? outgoingMessageHeader.GetSendBuffer()
                        : new ArraySegment <byte>();

                    return(responseMessage);
                }
                catch (Exception e)
                {
                    ServiceTrace.Source.WriteInfo("WcfRemotingService", "Remote Exception occured {0}", e);
                    throw new FaultException <RemoteException>(RemoteException.FromException(e), e.Message);
                }
            }
Example #5
0
        /// <summary>
        /// 创建消息
        /// </summary>
        /// <param name="msgType">消息类型</param>
        /// <param name="msgBody">消息体</param>
        /// <returns></returns>
        public static MessageModel BuildMessage(UInt32 msgType, IMessageBody msgBody)
        {
            MessageModel data = new MessageModel();

            data.mMsgHeader = new MessageHeaderNode();
            data.mMsgBody   = msgBody;
            data.mMsgTailer = new MessageTailerNode();

            data.mMsgHeader.msgType    = msgType;
            data.mMsgHeader.bodyLength = (UInt32)data.mMsgBody.GetBytes().Length;


            data.mMsgTailer.checkSum = (UInt32)data.GetMessageCheckSum();

            return(data);
        }
        public void Union2()
        {
            var a = MessagePackSerializer.Serialize <IMessageBody>(new TextMessageBody()
            {
                Text = "hoge"
            });
            var b = MessagePackSerializer.Serialize <IMessageBody>(new StampMessageBody()
            {
                StampId = 10
            });
            var c = MessagePackSerializer.Serialize <IMessageBody>(new QuestMessageBody()
            {
                Text = "hugahuga", QuestId = 99
            });

            IMessageBody a2 = MessagePackSerializer.Deserialize <IMessageBody>(a);
            IMessageBody b2 = MessagePackSerializer.Deserialize <IMessageBody>(b);
            IMessageBody c2 = MessagePackSerializer.Deserialize <IMessageBody>(c);

            (a2 as TextMessageBody).Text.Is("hoge");
            (b2 as StampMessageBody).StampId.Is(10);
            (c2 as QuestMessageBody).Is(x => x.Text == "hugahuga" && x.QuestId == 99);
        }
 public static Message ProduceMessage(MessageType _type, IMessageBody _body)
 {
     return(new Message(idmodel.GetLongId, _type, _body));
 }
Example #8
0
 internal HttpRequest(IRequestLine requestLine, IHttpHeaders httpHeaders, IMessageBody messageBody)
 {
     _requestLine = requestLine;
     _httpHeaders = httpHeaders;
     MessageBody  = messageBody;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ProbeNet.Messages.Message"/> class with a default header.
 /// </summary>
 /// <param name="body">Body.</param>
 public Message(IMessageBody body) :
     this(new MessageHeader(), body)
 {
 }
Example #10
0
 public Message(long _id, MessageType _msgType, IMessageBody _body)
 {
     id      = _id;
     msgType = _msgType;
     body    = _body;
 }
Example #11
0
 public MessageReceivedEventArgs(MessageHeader header, IMessageBody body)
 {
     Header = header ?? throw new ArgumentNullException(nameof(header));
     Body   = body ?? throw new ArgumentNullException(nameof(body));
 }
Example #12
0
 private async Task SendMessage(IMessageBody msg)
 {
     var serialized = MessagePackSerializer.Serialize <IMessageBody>(msg);
     await pipelineServer.Write(serialized);
 }
 //--------------------------------
 public void Recevive(int _type, IMessageBody _body)
 {
     Recevive((MessageType)_type, _body);
 }
 public void Recevive(MessageType _type, IMessageBody _body)
 {
     Recevive(MessageFactory.ProduceMessage(_type, _body));
 }
Example #15
0
        public async Task <IServiceRemotingResponseMessage> RequestResponseAsync(IServiceRemotingRequestMessage requestMessage)
        {
            IMessageBody   serializedMsgBody = null;
            IMessageHeader serializedHeader  = null;

            try
            {
                //Find the Serializer
                var interfaceId = requestMessage.GetHeader().InterfaceId;
                serializedHeader = this.serializersManager.GetHeaderSerializer()
                                   .SerializeRequestHeader(requestMessage.GetHeader());
                var msgBodySeriaizer = this.serializersManager.GetRequestBodySerializer(interfaceId);
                serializedMsgBody = msgBodySeriaizer.Serialize(requestMessage.GetBody());

                var responseMessage = await this.WcfClient.Channel.RequestResponseAsync(
                    serializedHeader.GetSendBuffer(),
                    serializedMsgBody == null?new List <ArraySegment <byte> >() : serializedMsgBody.GetSendBuffers())
                                      .ContinueWith(
                    t => t.GetAwaiter().GetResult(),
                    TaskScheduler.Default);

                // the code above (TaskScheduler.Default) for dispatches the responses on different thread
                // so that if the user code blocks, we do not stop the response receive pump in WCF
                var incomingHeader = (responseMessage != null && responseMessage.MessageHeaders != null)
                    ? new IncomingMessageHeader(
                    new SegmentedReadMemoryStream(responseMessage.MessageHeaders))
                    : null;

                ////DeSerialize Response Header
                var header =
                    this.serializersManager.GetHeaderSerializer()
                    .DeserializeResponseHeaders(
                        incomingHeader);

                ////DeSerialize Response Body

                var responseSerializer = this.serializersManager.GetResponseBodySerializer(interfaceId);

                var incomingMsgBody = (responseMessage != null && responseMessage.ResponseBody != null)
                    ? new IncomingMessageBody(new SegmentedReadMemoryStream(responseMessage.ResponseBody))
                    : null;

                var msgBody =
                    responseSerializer.Deserialize(incomingMsgBody);
                //Create Response Message
                return((IServiceRemotingResponseMessage) new ServiceRemotingResponseMessage(header,
                                                                                            msgBody));
            }
            catch (FaultException <RemoteException> faultException)
            {
                Exception remoteException;
                if (RemoteException.ToException(new SegmentedReadMemoryStream(faultException.Detail.Data),
                                                out remoteException))
                {
                    throw new AggregateException(remoteException);
                }

                throw new ServiceException(remoteException.GetType().FullName, string.Format(
                                               CultureInfo.InvariantCulture,
                                               Microsoft.ServiceFabric.Services.Wcf.SR.ErrorDeserializationFailure,
                                               remoteException.ToString()));
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ProbeNet.Messages.Message"/> class.
 /// </summary>
 /// <param name="header">Header.</param>
 /// <param name="body">Body.</param>
 public Message(MessageHeader header, IMessageBody body)
 {
     this.header = header;
     this.body   = body;
 }
Example #17
0
 /// <summary>
 ///     Adds the specified body to the message.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="body">The body.</param>
 /// <returns>MailerMessage.</returns>
 public static MailerMessage WithBody(this MailerMessage message, IMessageBody body)
 {
     message.Body = body;
     return(message);
 }
 public Message(IMessageHeader messageHeader, IMessageBody messageBody)
 {
     this.messageBody   = messageBody;
     this.messageHeader = messageHeader;
 }