public async Task <SagaConsumeContext <TSaga, T> > CreateSagaConsumeContext <T>(IndexedSagaDictionary <TSaga> context, ConsumeContext <T> consumeContext, TSaga instance, SagaConsumeContextMode mode) where T : class { SagaInstance <TSaga> sagaInstance; switch (mode) { case SagaConsumeContextMode.Add: case SagaConsumeContextMode.Insert: sagaInstance = new SagaInstance <TSaga>(instance); await sagaInstance.MarkInUse(consumeContext.CancellationToken).ConfigureAwait(false); context.Add(sagaInstance); break; case SagaConsumeContextMode.Load: sagaInstance = context[instance.CorrelationId]; await sagaInstance.MarkInUse(consumeContext.CancellationToken).ConfigureAwait(false); break; default: throw new ArgumentOutOfRangeException(nameof(mode)); } return(new InMemorySagaConsumeContext <TSaga, T>(consumeContext, sagaInstance, context)); }
public void Remove(SagaInstance <TSaga> item) { lock (_lock) { foreach (IIndexedSagaProperty <TSaga> index in _indices.Values) { index.Remove(item); } } }
public void Add(SagaInstance <TSaga> instance) { lock (_lock) { foreach (IIndexedSagaProperty <TSaga> index in _indices.Values) { index.Add(instance); } } }
public void Add(SagaInstance <TSaga> newItem) { var key = _getProperty(newItem.Instance); if (!_values.TryGetValue(key, out HashSet <SagaInstance <TSaga> > hashSet)) { hashSet = new HashSet <SagaInstance <TSaga> >(); _values.Add(key, hashSet); } hashSet.Add(newItem); }
public bool Equals(SagaInstance <TSaga> other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(EqualityComparer <TSaga> .Default.Equals(_instance, other._instance)); }
public void Remove(SagaInstance <TSaga> instance) { var key = _getProperty(instance.Instance); if (!_values.TryGetValue(key, out HashSet <SagaInstance <TSaga> > hashSet)) { return; } if (hashSet.Remove(instance) && hashSet.Count == 0) { _values.Remove(key); } }