/// <summary> /// Gets a single property that is marked with the <see cref="UniqueAttribute"/> for a <see cref="IContainSagaData"/>. /// </summary> /// <param name="entity">A saga entity.</param> /// <returns>A <see cref="PropertyInfo"/> of the property marked with a <see cref="UniqueAttribute"/> or null if not used.</returns> public static KeyValuePair<string, object>? GetUniqueProperty(IContainSagaData entity) { var prop = GetUniqueProperty(entity.GetType()); return prop != null ? new KeyValuePair<string, object>(prop.Name, prop.GetValue(entity, null)) : (KeyValuePair<string, object>?) null; }
public Task Complete(IContainSagaData sagaData, SynchronizedStorageSession session, ContextBag context) { var storageSession = (LearningSynchronizedStorageSession)session; return(storageSession.Complete(sagaData)); }
/// <summary> /// Gets all the properties that are marked with the <see cref="UniqueAttribute"/> for a <see cref="IContainSagaData"/>. /// </summary> /// <param name="entity">A <see cref="IContainSagaData"/>.</param> /// <returns>A <see cref="IDictionary{TKey,TValue}"/> of property names and their values.</returns> public static IDictionary <string, object> GetUniqueProperties(IContainSagaData entity) { return(GetUniqueProperties(entity.GetType()) .ToDictionary(p => p.Name, p => p.GetValue(entity, null))); }
static IContainSagaData DeepCopy(IContainSagaData source) { return(source.DeepCopy()); }
public void Remove(IContainSagaData saga) { var collection = GetCollection(saga.GetType()); collection.DeleteOne(new BsonDocument("_id", saga.Id)); }
public Task Complete(IContainSagaData saga, SynchronizedStorageSession session, ContextBag context) { return(session.Session().DeleteAsync(saga)); }
public void WriteSaga(IContainSagaData sagaData) { var serialized = JsonConvert.SerializeObject(sagaData, Formatting.Indented); logger.Warn("Saga State: \r\n" + serialized); }
void AttachEntity(IContainSagaData sagaEntity) { Instance.Entity = sagaEntity; }
void SetUniqueValueMetadata(IContainSagaData saga, KeyValuePair <string, object> uniqueProperty) { Session.Advanced.GetMetadataFor(saga)[UniqueValueMetadataKey] = uniqueProperty.Value.ToString(); }
static IContainSagaData DeepCopy(IContainSagaData source) { var json = serializer.SerializeObject(source); return((IContainSagaData)serializer.DeserializeObject(json, source.GetType())); }
void ISagaPersister.Update(IContainSagaData saga) { ((ISagaPersister)this).Save(saga); }
public Task Complete(IContainSagaData sagaData, SynchronizedStorageSession session, ContextBag context) { return(_repo.Remove(sagaData)); }
public Task Complete(IContainSagaData saga, SynchronizedStorageSession session, ContextBag context) { session.Session().Delete(saga); return(Task.FromResult(0)); }
void AttachEntity(IContainSagaData sagaEntity) { sagaId = sagaEntity.Id; UpdateModified(); Instance.Entity = sagaEntity; SagaId = sagaEntity.Id.ToString(); var properties = sagaEntity.GetType().GetProperties(); SagaMetadata.CorrelationPropertyMetadata correlatedPropertyMetadata; if (Metadata.TryGetCorrelationProperty(out correlatedPropertyMetadata)) { var propertyInfo = properties.Single(p => p.Name == correlatedPropertyMetadata.Name); var propertyValue = propertyInfo.GetValue(sagaEntity); var defaultValue = GetDefault(propertyInfo.PropertyType); var hasValue = propertyValue != null && !propertyValue.Equals(defaultValue); correlationProperty = new CorrelationPropertyInfo { PropertyInfo = propertyInfo, Value = propertyValue, HasExistingValue = hasValue }; } }
/// <summary> /// Provides a way to update the actual saga entity. /// </summary> /// <param name="sagaEntity">The new entity.</param> public void AttachNewEntity(IContainSagaData sagaEntity) { Guard.AgainstNull(nameof(sagaEntity), sagaEntity); IsNew = true; AttachEntity(sagaEntity); }
private IContainSagaData DeepClone(IContainSagaData source) { var json = serializer.SerializeObject(source); return((IContainSagaData)serializer.DeserializeObject(json, source.GetType())); }
public void Save(IContainSagaData saga) { Session.Store(saga); StoreUniqueProperty(saga); }
public void AttachNewEntity(IContainSagaData sagaEntity) { IsNew = true; AttachEntity(sagaEntity); }
public void Save(IContainSagaData sagaData) { deferredActions.Add(new SaveAction(sagaData, sagaFiles, sagaManifests)); }
public Task Save(IContainSagaData saga, SagaCorrelationProperty correlationProperty, SynchronizedStorageSession session, ContextBag context) { return(session.Session().SaveAsync(saga)); }
public void Complete(IContainSagaData sagaData) { deferredActions.Add(new CompleteAction(sagaData, sagaFiles, sagaManifests)); }
internal override object BuildSagaData(CommandWrapper command, RuntimeSagaInfo sagaInfo, IContainSagaData sagaData) { var writer = command.LeaseWriter(); sagaInfo.ToJson(sagaData, writer); return(writer.ToCharSegment()); }
public SaveAction(IContainSagaData sagaData, Dictionary <string, SagaStorageFile> sagaFiles, SagaManifestCollection sagaManifests) : base(sagaData, sagaFiles, sagaManifests) { }
public Entry(IContainSagaData sagaData, CorrelationId correlationId) { CorrelationId = correlationId; data = sagaData; }
public void Remove(IContainSagaData saga) { var collection = _db.GetCollection(GetCollectionName(saga.GetType())); collection.Remove(Query.EQ("_id", saga.Id)); }
public Entry UpdateTo(IContainSagaData sagaData) { return(new Entry(sagaData, CorrelationId)); }
public Task Update(IContainSagaData sagaData, SynchronizedStorageSession session, ContextBag context) { //no-op since the dirty tracking will handle the update for us return(TaskEx.CompletedTask); }
public Task Save(IContainSagaData sagaData, SagaCorrelationProperty correlationProperty, SynchronizedStorageSession session, ContextBag context) { var storageSession = (LearningSynchronizedStorageSession)session; return(storageSession.Save(sagaData)); }
public void WriteSaga(IContainSagaData sagaData) { var serialized = JsonConvert.SerializeObject(sagaData, Formatting.Indented); log.Warn($"Saga State: \r\n{serialized}"); }
/// <summary> /// Get Dispatcher /// </summary> /// <param name="messageHandlerType">Type of the message Handler</param> /// <param name="builder">Builder</param> /// <param name="message">Message</param> /// <returns>Saga Dispatcher</returns> public IEnumerable <Action> GetDispatcher(Type messageHandlerType, IBuilder builder, object message) { var entitiesHandled = new List <IContainSagaData>(); var sagaTypesHandled = new List <Type>(); foreach (var finder in GetFindersFor(message, builder)) { bool sagaEntityIsPersistent = true; IContainSagaData sagaEntity = UseFinderToFindSaga(finder, message); Type sagaType; if (sagaEntity == null) { sagaType = Features.Sagas.GetSagaTypeToStartIfMessageNotFoundByFinder(message, finder); if (sagaType == null) { continue; } if (sagaTypesHandled.Contains(sagaType)) { continue; // don't create the same saga type twice for the same message } sagaEntity = CreateNewSagaEntity(sagaType); sagaEntityIsPersistent = false; } else { if (entitiesHandled.Contains(sagaEntity)) { continue; // don't call the same saga twice } sagaType = Features.Sagas.GetSagaTypeForSagaEntityType(sagaEntity.GetType()); } if (messageHandlerType.IsAssignableFrom(sagaType)) { yield return () => { var saga = (ISaga)builder.Build(sagaType); saga.Entity = sagaEntity; try { SagaContext.Current = saga; if (IsTimeoutMessage(message)) { HandlerInvocationCache.InvokeTimeout(saga, message); } else { HandlerInvocationCache.InvokeHandle(saga, message); } if (!saga.Completed) { if (!sagaEntityIsPersistent) { Persister.Save(saga.Entity); } else { Persister.Update(saga.Entity); } } else { if (sagaEntityIsPersistent) { Persister.Complete(saga.Entity); } if (saga.Entity.Id != Guid.Empty) { NotifyTimeoutManagerThatSagaHasCompleted(saga); } } LogIfSagaIsFinished(saga); } finally { SagaContext.Current = null; } } } ; sagaTypesHandled.Add(sagaType); entitiesHandled.Add(sagaEntity); } if (entitiesHandled.Count == 0) { yield return () => { logger.InfoFormat("Could not find a saga for the message type {0} with id {1}. Going to invoke SagaNotFoundHandlers.", message.GetType().FullName, Bus.CurrentMessageContext.Id); foreach (var handler in builder.BuildAll <IHandleSagaNotFound>()) { logger.DebugFormat("Invoking SagaNotFoundHandler: {0}", handler.GetType().FullName); handler.Handle(message); } } } ; } IContainSagaData CreateNewSagaEntity(Type sagaType) { var sagaEntityType = Features.Sagas.GetSagaEntityTypeForSagaType(sagaType); if (sagaEntityType == null) { throw new InvalidOperationException("No saga entity type could be found for saga: " + sagaType); } var sagaEntity = (IContainSagaData)Activator.CreateInstance(sagaEntityType); sagaEntity.Id = CombGuid.Generate(); if (Bus.CurrentMessageContext.ReplyToAddress != null) { sagaEntity.Originator = Bus.CurrentMessageContext.ReplyToAddress.ToString(); } sagaEntity.OriginalMessageId = Bus.CurrentMessageContext.Id; return(sagaEntity); }
/// <summary> /// Updates the given saga entity using the current session of the /// injected session factory. /// </summary> /// <param name="saga">the saga entity that will be updated.</param> public void Update(IContainSagaData saga) { UnitOfWorkManager.GetCurrentSession().Update(saga); }
public void Update(IContainSagaData saga) { Save(saga); }
/// <summary> /// Deletes the given saga from the injected session factory's /// current session. /// </summary> /// <param name="saga">The saga entity that will be deleted.</param> public void Complete(IContainSagaData saga) { UnitOfWorkManager.GetCurrentSession().Delete(saga); }
internal void AttachExistingEntity(IContainSagaData loadedEntity) { AttachEntity(loadedEntity); }
/// <summary> /// Gets all the properties that are marked with the <see cref="UniqueAttribute"/> for a <see cref="IContainSagaData"/>. /// </summary> /// <param name="entity">A <see cref="IContainSagaData"/>.</param> /// <returns>A <see cref="IDictionary{TKey,TValue}"/> of property names and their values.</returns> public static IDictionary<string, object> GetUniqueProperties(IContainSagaData entity) { return GetUniqueProperties(entity.GetType()) .ToDictionary(p => p.Name, p => p.GetValue(entity, null)); }
public void AttachExistingEntity(IContainSagaData loadedEntity) { AttachEntity(loadedEntity); }
internal virtual object BuildSagaData(CommandWrapper command, RuntimeSagaInfo sagaInfo, IContainSagaData sagaData) { return(sagaInfo.ToJson(sagaData)); }
void AttachEntity(IContainSagaData sagaEntity) { Instance.Entity = sagaEntity; Handler.InvocationDisabled = false; }
void AttachEntity(IContainSagaData sagaEntity) { sagaId = sagaEntity.Id; Instance.Entity = sagaEntity; SagaId = sagaEntity.Id.ToString(); }