object IMutateOutgoingMessages.MutateOutgoing(object message)
        {
            var timeToBeReceived = TimeToBeReceived(message);

            using (new TransactionScope(TransactionScopeOption.Suppress))
            {
                foreach (var property in GetDataBusProperties(message))
                {
                    var propertyValue = property.GetValue(message, null);

                    if (propertyValue == null)
                    {
                        continue;
                    }

                    using (var stream = new MemoryStream())
                    {
                        var dataBusProperty = propertyValue as IDataBusProperty;

                        if (dataBusProperty != null)
                        {
                            propertyValue = dataBusProperty.GetValue();
                        }

                        serializer.Serialize(propertyValue, stream);
                        stream.Position = 0;

                        var    headerValue = dataBus.Put(stream, timeToBeReceived);
                        string headerKey;

                        if (dataBusProperty != null)
                        {
                            dataBusProperty.Key = headerValue;
                            //we use the headers to in order to allow the infrastructure (eg. the gateway) to modify the actual key
                            headerKey = headerValue;
                        }
                        else
                        {
                            property.SetValue(message, null, null);
                            headerKey = String.Format("{0}.{1}", message.GetType().FullName, property.Name);
                        }

                        //we use the headers to in order to allow the infrastructure (eg. the gateway) to modify the actual key
                        message.SetHeader(DATABUS_PREFIX + headerKey, headerValue);
                    }
                }
            }

            return(message);
        }
Exemple #2
0
        object IMutateOutgoingMessages.MutateOutgoing(object message)
        {
            var timeToBeReceived = message.TimeToBeReceived();

            using (new TransactionScope(TransactionScopeOption.Suppress))
                foreach (var dataBusProperty in message.DataBusPropertiesWithValues())
                {
                    using (var stream = new MemoryStream())
                    {
                        serializer.Serialize(dataBusProperty.GetValue(), stream);
                        stream.Position = 0;

                        dataBusProperty.Key = dataBus.Put(stream, timeToBeReceived);

                        //we use the headers to in order to allow the infrastructure (eg. the gateway) to modify the actual key
                        message.SetHeader(DATABUS_PREFIX + dataBusProperty.Key, dataBusProperty.Key);
                    }
                }

            return(message);
        }
Exemple #3
0
        private void PutValueOnDataBus(IDataBusProperty propertyInstance, object valueToPutOnBus, DataBusPropertyInfo dataBusPropertyInfo)
        {
            propertyInstance.HasValue = true;

            using (MemoryStream memoryStream = new MemoryStream())
            {
                _dataBusSerializer.Serialize(valueToPutOnBus, memoryStream);

                if (_dataBusSettings.IsChecksummingEnabled)
                {
                    memoryStream.Position     = 0;
                    propertyInstance.Checksum = Checksum.GetSha256HashBuffered(memoryStream);

                    _log.Info("SHA256 checksum of databus property '{0}' is '{1}'.", dataBusPropertyInfo.Name, propertyInstance.Checksum);
                }

                string claimKey;

                using (new TransactionScope(_dataBusSettings.TransactionScope))
                {
                    memoryStream.Position = 0;
                    claimKey = _dataBus.Put(memoryStream, dataBusPropertyInfo.IsCompressedProperty);
                }

                if (String.IsNullOrWhiteSpace(claimKey))
                {
                    string errorMsg = String.Format("The claimkey for databus property '{0}' returned by the databus is null or whitespace! You can't claim anything without a claim key.", dataBusPropertyInfo.Name);

                    _log.Error(errorMsg);

                    throw new DataBusPropertyOffoadException(errorMsg);
                }

                propertyInstance.ClaimKey = claimKey;
            }
        }