public void Load(DataBusPropertyInfo propertyInfo, object message) { if (propertyInfo == null) { throw new ArgumentNullException("propertyInfo"); } if (message == null) { throw new ArgumentNullException("message"); } _log.Info( "Loading databus property '{0}' on message of type '{1}'.", propertyInfo.Name, message.GetType().FullName); IDataBusProperty propertyInstance = propertyInfo.GetPropertyInstance(message) as IDataBusProperty; if (propertyInstance == null || !propertyInstance.HasValue) { _log.Warn( String.Format( "Databus property '{0}' on message of type '{1}' is null or doesn't have a value.", propertyInfo.Name, message.GetType().FullName)); return; } LoadValueFromDataBus(propertyInstance, propertyInfo); }
private void LoadValueFromDataBus(IDataBusProperty propertyInstance, DataBusPropertyInfo propertyInfo) { if (String.IsNullOrWhiteSpace(propertyInstance.ClaimKey)) { string errorMsg = String.Format("Claim key of databus property '{0}' is missing. We can't fetch anything from the databus if the claimkey is null or whitespace.", propertyInfo.Name); _log.Error(errorMsg); throw new DataBusPropertyLoadException(errorMsg); } using (new TransactionScope(_dataBusSettings.TransactionScope)) { //todo remove file from databus? using (Stream stream = _dataBus.Get(propertyInstance.ClaimKey, propertyInfo.IsCompressedProperty)) { if (_dataBusSettings.IsChecksummingEnabled) { DoChecksumming(propertyInstance, propertyInfo, stream); } stream.Position = 0; object obj = _dataBusSerializer.Deserialize(stream); if (obj == null) { _log.Warn("Deserializing databus stream resulted in a null object."); } propertyInstance.SetValue(obj); } } }
private void DoChecksumming(IDataBusProperty propertyInstance, DataBusPropertyInfo propertyInfo, Stream stream) { if (propertyInstance.Checksum == null) { _log.Warn( "Can't perform checksum validation if the checksum of the databus property '{0}' is not provided by the sender.", propertyInfo.Name); } else { stream.Position = 0; string actualChecksum = Checksum.GetSha256HashBuffered(stream); _log.Info("SHA256 checksum of databus property '{0}' is '{1}'.", propertyInfo.Name, actualChecksum); if (actualChecksum != propertyInstance.Checksum) { string errorMsg = String.Format( "Databus property '{0}' checksum error. Expected checksum value '{1}' but actual checksum value is '{2}'.", propertyInfo.Name, propertyInstance.Checksum, actualChecksum); _log.Error(errorMsg); throw new DataBusPropertyLoadException(errorMsg); } } }
public void Offload(DataBusPropertyInfo propertyInfo, object message) { if (propertyInfo == null) { throw new ArgumentNullException("propertyInfo"); } if (message == null) { throw new ArgumentNullException("message"); } _log.Info( "Offloading databus property '{0}' on message of type {1}.", propertyInfo.Name, message.GetType().FullName); IDataBusProperty propertyInstance = propertyInfo.GetPropertyInstance(message) as IDataBusProperty; if (propertyInstance == null) { _log.Warn( String.Format( "Databus property '{0}' on message of type '{1}'. is null.", propertyInfo.Name, message.GetType().FullName)); return; } object valueToPutOnBus = propertyInstance.GetValue(); if (valueToPutOnBus != null) { PutValueOnDataBus(propertyInstance, valueToPutOnBus, propertyInfo); } else { _log.Warn("Value of databus property '{0} ' is null.", propertyInfo.Name); } }
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; } }