public async Task SqlSaveAsync(PostgreSqlDbContext db, List <EventStorageBufferWrap> eventWraps) { using (var trans = db.BeginTransaction()) { try { foreach (var wrap in eventWraps) { EventSingleStorageModel model = wrap.Value; var data = this.GetSerializer().Serialize(model.Event); wrap.Result = await db.ExecuteAsync(this.insertSql, new { StateId = model.StateId, RelationEvent = model.Event.RelationEvent, TypeCode = model.Event.TypeCode, Data = data, DataType = this.options.SerializationType, Version = model.Event.Version, AddTime = model.Event.Timestamp }) > 0; } trans.Commit(); eventWraps.ForEach(wrap => wrap.TaskSource.TrySetResult(wrap.Result)); } catch (Exception ex) { trans.Rollback(); eventWraps.ForEach(wrap => wrap.TaskSource.TrySetException(ex)); } } }
public async Task SqlSaveAsync(PostgreSqlDbContext db, List <IDataflowBufferWrap <EventStorageModel> > eventWraps) { using (var trans = db.BeginTransaction()) { try { foreach (var wrap in eventWraps) { EventStorageModel model = wrap.Data; var data = this.GetSerializer().Serialize(model.Event); wrap.Data.Result = await db.ExecuteAsync(this.insertSql, new { Id = model.Id, RelationEvent = model.Event.RelationEvent, TypeCode = model.Event.TypeCode, Data = data, DataType = this.options.SerializationType, Version = model.Event.Version, AddTime = model.Event.Timestamp }) > 0; } trans.Commit(); eventWraps.ForEach(wrap => wrap.CompleteHandler(wrap.Data.Result)); } catch (Exception ex) { trans.Rollback(); eventWraps.ForEach(wrap => wrap.ExceptionHandler(ex)); } } }