/// <summary> /// Attempt to retrieve an existing saga instance identified by the specified <paramref name="type"/> and <paramref name="id"/>. /// </summary> /// <param name="type">The type of saga to be retrieved.</param> /// <param name="id">The correlation id of the saga to be retrieved.</param> /// <param name="saga">The <see cref="Saga"/> instance if found; otherwise <value>null</value>.</param> public Boolean TryGetSaga(Type type, Guid id, out Saga saga) { var result = sagaStore.TryGetSaga(type, id, out saga); statistics.IncrementQueryCount(); return(result); }
/// <summary> /// Get or create the target saga instance. /// </summary> /// <param name="sagaType">The saga type.</param> /// <param name="sagaId">The saga correlation id.</param> /// <param name="e">The event instance to handle.</param> private Saga GetOrCreateSaga(Type sagaType, Guid sagaId, Event e) { Saga saga; if (!sagaStore.TryGetSaga(sagaType, sagaId, out saga) && sagaMetadata.CanStartWith(e.GetType())) { saga = sagaStore.CreateSaga(sagaType, sagaId); } return(saga); }
/// <summary> /// Attempt to retrieve an existing saga instance identified by the specified <paramref name="type"/> and <paramref name="id"/>. /// </summary> /// <param name="type">The type of saga to be retrieved.</param> /// <param name="id">The correlation id of the saga to be retrieved.</param> /// <param name="saga">The <see cref="Saga"/> instance if found; otherwise <value>null</value>.</param> public Boolean TryGetSaga(Type type, Guid id, out Saga saga) { Boolean result; InvokePreGetHooks(type, id); result = sagaStore.TryGetSaga(type, id, out saga); InvokePostGetHooks(saga); return(result); }
/// <summary> /// Attempt to retrieve an existing saga instance identified by the specified <paramref name="type"/> and <paramref name="id"/>. /// </summary> /// <param name="type">The type of saga to be retrieved.</param> /// <param name="id">The correlation id of the saga to be retrieved.</param> /// <param name="saga">The <see cref="Saga"/> instance if found; otherwise <value>null</value>.</param> public Boolean TryGetSaga(Type type, Guid id, out Saga saga) { Verify.NotNull(type, nameof(type)); var key = String.Concat(type.GetFullNameWithAssembly(), "-", id); using (var sagaLock = new SagaLock(type, id)) { sagaLock.Aquire(); //NOTE: We do not want to cache a NULL saga reference, thus explicitly check for existance and add to cache if instance found. saga = (Saga)memoryCache.Get(key); if (saga == null && sagaStore.TryGetSaga(type, id, out saga)) { memoryCache.Add(key, saga, CreateCacheItemPolicy()); } } //NOTE: Given that saga state is modified during `Handling`, we must always return a copy of the cached instance. return((saga == null ? null : saga = saga.Copy()) != null); }