public void UpdateSaga(Type sagaType, string sagaIdentifier, object saga, ITrackingToken token, IAssociationValues associationValues) { var entry = new SagaEntry(saga, sagaIdentifier, _serializer); _logger.LogDebug($"Updating saga id {sagaIdentifier} as {Encoding.UTF8.GetString(entry.SerializedSaga)}"); int updateCount; try { using (var conn = _connectionProvider()) { conn.Open(); updateCount = _sqldef.SqlUpdateSaga(conn, entry.SagaId, entry.SerializedSaga, entry.SagaType, entry.Revision); if (updateCount != 0) { foreach (var associationValue in associationValues.AddedAssociations) { _sqldef.SqlStoreAssocValue(conn, associationValue.PropertyKey, associationValue.PropertyValue, SagaTypeName(sagaType), sagaIdentifier); } foreach (var associationValue in associationValues.RemovedAssociations) { _sqldef.SqlRemoveAssocValue(conn, associationValue.PropertyKey, associationValue.PropertyValue, SagaTypeName(sagaType), sagaIdentifier); } } } } catch (DataException e) { throw new SagaStorageException("Exception while loading a Saga", e); } if (updateCount == 0) { _logger.LogWarning("Expected to be able to update a Saga instance, but no rows were found. Inserting instead."); InsertSaga(sagaType, sagaIdentifier, saga, token, associationValues.AsSet()); } }
public void UpdateSaga(Type sagaType, string sagaIdentifier, object saga, ITrackingToken token, IAssociationValues associationValues) { _managedSagas.AddOrUpdate(sagaIdentifier, new ManagedSaga(saga, associationValues.AsSet()), (s, managedSaga) => new ManagedSaga(saga, associationValues.AsSet())); }