Exemple #1
0
        void DataReceivedOnChannel(object sender, DataReceivedOnChannelArgs e)
        {
            using (e.Data)
            {
                var callInfo = ChannelReceiverHeaderReader.GetCallInfo(e);

                Logger.DebugFormat("Received message of type {0} for client id: {1}", callInfo.Type, callInfo.ClientId);

                using (var scope = GatewayTransaction.Scope())
                {
                    switch (callInfo.Type)
                    {
                    case CallType.SingleCallDatabusProperty:
                        HandleDatabusProperty(callInfo);
                        break;

                    case CallType.SingleCallSubmit:
                        HandleSubmit(callInfo);
                        break;

                    default:
                        receiver.DispatchReceivedCallInfo(callInfo);
                        break;
                    }
                    scope.Complete();
                }
            }
        }
        void DataReceivedOnChannel(object sender, DataReceivedOnChannelArgs e)
        {
            using (e.Data)
            {
                var callInfo = ChannelReceiverHeaderReader.GetCallInfo(e);

                Logger.DebugFormat("Received message of type {0} for client id: {1}", callInfo.Type, callInfo.ClientId);

                using (var scope = transaction.Scope())
                {
                    switch (callInfo.Type)
                    {
                        case CallType.SingleCallDatabusProperty:
                            HandleDatabusProperty(callInfo);
                            break;
                        case CallType.SingleCallSubmit:
                            HandleSubmit(callInfo);
                            break;
                        default:
                            throw new Exception("Unknown call type: " + callInfo.Type);
                    }
                    scope.Complete();
                }
            }
        }
        CallInfo GetCallInfo(DataReceivedOnChannelArgs receivedData)
        {
            var headers = receivedData.Headers;

            var callType = headers[GatewayHeaders.CallTypeHeader];

            if (!Enum.IsDefined(typeof(CallType), callType))
            {
                throw new ChannelException(400, "Required header '" + GatewayHeaders.CallTypeHeader + "' missing.");
            }

            var type = (CallType)Enum.Parse(typeof(CallType), callType);

            var clientId = headers[GatewayHeaders.ClientIdHeader];

            if (clientId == null)
            {
                throw new ChannelException(400, "Required header '" + GatewayHeaders.ClientIdHeader + "' missing.");
            }

            return(new CallInfo
            {
                ClientId = clientId,
                Type = type,
                Headers = headers,
                Data = receivedData.Data,
                AutoAck = headers.ContainsKey(GatewayHeaders.AutoAck)
            });
        }
Exemple #4
0
        async Task DataReceivedOnChannel(DataReceivedOnChannelArgs e)
        {
            using (e.Data)
            {
                var callInfo = ChannelReceiverHeaderReader.GetCallInfo(e);

                Logger.DebugFormat("Received message of type {0} for client id: {1}", callInfo.Type, callInfo.ClientId);

                using (var scope = GatewayTransaction.Scope())
                {
                    switch (callInfo.Type)
                    {
                    case CallType.SingleCallDatabusProperty:
                        await HandleDatabusProperty(callInfo).ConfigureAwait(false);

                        break;

                    case CallType.SingleCallSubmit:
                        await HandleSubmit(callInfo).ConfigureAwait(false);

                        break;

                    default:
                        throw new Exception("Unknown call type: " + callInfo.Type);
                    }
                    scope.Complete();
                }
            }
        }
 public static CallInfo GetCallInfo(DataReceivedOnChannelArgs receivedData)
 {
     return(new CallInfo
     {
         ClientId = ReadClientId(receivedData.Headers),
         TimeToBeReceived = ReadTimeToBeReceived(receivedData.Headers),
         Type = ReadCallType(receivedData.Headers),
         Headers = receivedData.Headers,
         Data = receivedData.Data,
         Md5 = ReadMd5(receivedData.Headers)
     });
 }
 public static CallInfo GetCallInfo(DataReceivedOnChannelArgs receivedData)
 {
     return new CallInfo
         {
             ClientId = ReadClientId(receivedData.Headers),
             TimeToBeReceived = ReadTimeToBeReceived(receivedData.Headers),
             Type = ReadCallType(receivedData.Headers),
             Headers = receivedData.Headers,
             Data = receivedData.Data,
             Md5 = ReadMd5(receivedData.Headers)
         };
 }
Exemple #7
0
    protected override void OnMessage(MessageEventArgs e)
    {
        using (var ms = new MemoryStream(e.RawData))
        {
            var formatter = new BinaryFormatter();
            var headers   = (IDictionary <string, string>)formatter.Deserialize(ms);

            var args = new DataReceivedOnChannelArgs
            {
                Data    = ms,
                Headers = headers
            };
            dataReceivedOnChannel(args);
        }
    }
Exemple #8
0
        void DataReceivedOnChannel(object sender, DataReceivedOnChannelArgs e)
        {
            using (e.Data)
            {
                var callInfo = GetCallInfo(e);

                Logger.DebugFormat("Received message of type {0} for client id: {1}", callInfo.Type, callInfo.ClientId);

                using (var scope = DefaultTransactionScope())
                {
                    DispatchReceivedCallInfo(callInfo);
                    scope.Complete();
                }
            }
        }
        void DataReceivedOnChannel(object sender, DataReceivedOnChannelArgs e)
        {
            using (e.Data)
            {
                var callInfo = ChannelReceiverHeaderReader.GetCallInfo(e);

                Hasher.Verify(callInfo.Data, callInfo.Md5);
                Logger.DebugFormat("Received message of type {0} for client id: {1}", callInfo.Type, callInfo.ClientId);

                using (var scope = GatewayTransaction.Scope())
                {
                    DispatchReceivedCallInfo(callInfo);
                    scope.Complete();
                }
            }
        }
        void DataReceivedOnChannel(object sender, DataReceivedOnChannelArgs e)
        {
            using (e.Data)
            {
                var callInfo = ChannelReceiverHeaderReader.GetCallInfo(e);

                Hasher.Verify(callInfo.Data,callInfo.Md5);
                Logger.DebugFormat("Received message of type {0} for client id: {1}", callInfo.Type, callInfo.ClientId);

                using (var scope = GatewayTransaction.Scope())
                {
                    DispatchReceivedCallInfo(callInfo);
                    scope.Complete();
                }
            }
        }
Exemple #11
0
        CallInfo GetCallInfo(DataReceivedOnChannelArgs receivedData)
        {
            var headers = receivedData.Headers;

            var callType = headers[GatewayHeaders.CallTypeHeader];

            if (!Enum.IsDefined(typeof(CallType), callType))
            {
                throw new ChannelException(400, "Required header '" + GatewayHeaders.CallTypeHeader + "' missing.");
            }

            var type = (CallType)Enum.Parse(typeof(CallType), callType);

            var clientId = headers[GatewayHeaders.ClientIdHeader];

            if (clientId == null)
            {
                throw new ChannelException(400, "Required header '" + GatewayHeaders.ClientIdHeader + "' missing.");
            }

            var md5 = headers[HttpHeaders.ContentMd5Key];

            if (md5 == null)
            {
                throw new ChannelException(400, "Required header '" + HttpHeaders.ContentMd5Key + "' missing.");
            }

            var hash = Hasher.Hash(receivedData.Data);

            if (receivedData.Data.Length > 0 && hash != md5)
            {
                throw new ChannelException(412,
                                           "MD5 hash received does not match hash calculated on server. Consider resubmitting.");
            }


            return(new CallInfo
            {
                ClientId = clientId,
                Type = type,
                Headers = headers,
                Data = receivedData.Data,
                AutoAck = headers.ContainsKey(GatewayHeaders.AutoAck)
            });
        }
        async Task DataReceivedOnChannel(DataReceivedOnChannelArgs e, CancellationToken cancellationToken)
        {
            using (e.Data)
            {
                var callInfo = ChannelReceiverHeaderReader.GetCallInfo(e);

                Logger.DebugFormat("Received message of type {0} for client id: {1}", callInfo.Type, callInfo.ClientId);

                if (useTransactionScope)
                {
                    using (var scope = GatewayTransaction.Scope())
                    {
                        await Receive(callInfo).ConfigureAwait(false);

                        scope.Complete();
                    }
                }
                else
                {
                    // create no transaction scope to avoid that only the persistence or the transport enlist with a transaction.
                    // this would cause issues when commiting the transaction fails after the persistence or transport operation has succeeded.
                    await Receive(callInfo).ConfigureAwait(false);
                }
            }

            async Task Receive(CallInfo callInfo)
            {
                switch (callInfo.Type)
                {
                case CallType.SingleCallDatabusProperty:
                    await HandleDatabusProperty(callInfo, cancellationToken).ConfigureAwait(false);

                    break;

                case CallType.SingleCallSubmit:
                    await HandleSubmit(callInfo, cancellationToken).ConfigureAwait(false);

                    break;

                default:
                    throw new Exception("Unknown call type: " + callInfo.Type);
                }
            }
        }
        void DataReceivedOnChannel(object sender, DataReceivedOnChannelArgs e)
        {
            using (e.Data)
            {
                var callInfo = GetCallInfo(e);

                Logger.DebugFormat("Received message of type {0} for client id: {1}", callInfo.Type, callInfo.ClientId);

                //todo this is a msmq specific validation and should be moved to the layer above that is sending the message onto the main transport
                //if (callInfo.Type == CallType.Submit && e.Data.Length > 4 * 1024 * 1024)
                //    throw new Exception("Cannot accept messages larger than 4MB.");

                switch (callInfo.Type)
                {
                    case CallType.Submit: HandleSubmit(callInfo); break;
                    case CallType.DatabusProperty: HandleDatabusProperty(callInfo); break;
                    case CallType.Ack: HandleAck(callInfo); break;
                }
            }
        }
        void DataReceivedOnChannel(object sender, DataReceivedOnChannelArgs e)
        {
            using (e.Data)
            {
                var callInfo = GetCallInfo(e);

                Logger.DebugFormat("Received message of type {0} for client id: {1}", callInfo.Type, callInfo.ClientId);

                using (var scope = DefaultTransactionScope())
                {
                    switch (callInfo.Type)
                    {
                    case CallType.Submit: HandleSubmit(callInfo); break;

                    case CallType.DatabusProperty: HandleDatabusProperty(callInfo); break;

                    case CallType.Ack: HandleAck(callInfo); break;
                    }

                    scope.Complete();
                }
            }
        }
        CallInfo GetCallInfo(DataReceivedOnChannelArgs receivedData)
        {
            var headers = receivedData.Headers;

            var callType = headers[GatewayHeaders.CallTypeHeader];
            if (!Enum.IsDefined(typeof(CallType), callType))
            {
                throw new ChannelException(400, "Required header '" + GatewayHeaders.CallTypeHeader + "' missing.");
            }

            var type = (CallType) Enum.Parse(typeof(CallType), callType);

            var clientId = headers[GatewayHeaders.ClientIdHeader];
            if (clientId == null)
            {
                throw new ChannelException(400, "Required header '" + GatewayHeaders.ClientIdHeader + "' missing.");
            }

            return new CallInfo
            {
                ClientId = clientId,
                Type = type,
                Headers = headers,
                Data = receivedData.Data,
                AutoAck = headers.ContainsKey(GatewayHeaders.AutoAck)
            };
        }
        void DataReceivedOnChannel(object sender, DataReceivedOnChannelArgs e)
        {
            using (e.Data)
            {
                var callInfo = GetCallInfo(e);

                Logger.DebugFormat("Received message of type {0} for client id: {1}", callInfo.Type, callInfo.ClientId);

                using (var scope = DefaultTransactionScope())
                {
                    switch (callInfo.Type)
                    {
                        case CallType.SingleCallDatabusProperty:
                            HandleDatabusProperty(callInfo);
                            break;
                        case CallType.SingleCallSubmit:
                            HandleSubmit(callInfo);
                            break;
                        default:
                            receiver.DispatchReceivedCallInfo(callInfo);
                            break;
                    }
                    scope.Complete();
                }
            }
        }
        void DataReceivedOnChannel(object sender, DataReceivedOnChannelArgs e)
        {
            using (e.Data)
            {
                var callInfo = GetCallInfo(e);

                Logger.DebugFormat("Received message of type {0} for client id: {1}", callInfo.Type, callInfo.ClientId);

                using (var scope = DefaultTransactionScope())
                {
                    DispatchReceivedCallInfo(callInfo);
                    scope.Complete();
                }
            }
        }
        CallInfo GetCallInfo(DataReceivedOnChannelArgs receivedData)
        {
            var headers = receivedData.Headers;

            string callType = headers[GatewayHeaders.CallTypeHeader];
            if (!Enum.IsDefined(typeof(CallType), callType))
                throw new HttpChannelException(400, "Required header '" + GatewayHeaders.CallTypeHeader + "' missing.");

            var type = (CallType)Enum.Parse(typeof(CallType), callType);

            var clientId = headers[GatewayHeaders.ClientIdHeader];
            if (clientId == null)
                throw new HttpChannelException(400, "Required header '" + GatewayHeaders.ClientIdHeader + "' missing.");

            var md5 = headers[HttpHeaders.ContentMd5Key];

            if (md5 == null)
                throw new HttpChannelException(400, "Required header '" + HttpHeaders.ContentMd5Key + "' missing.");

            var hash = Hasher.Hash(receivedData.Data);

            if (receivedData.Data.Length > 0 && hash != md5)
                throw new HttpChannelException(412, "MD5 hash received does not match hash calculated on server. Consider resubmitting.");

            return new CallInfo
            {
                ClientId = clientId,
                Type = type,
                Headers = headers,
                Data = receivedData.Data
            };
        }