public JToken GetSingle(dynamic container, string dataProviderKey, Guid transactionId) { using (new StopwatchLog(Metrics.TransactionalServiceGetSingle)) { var state = this.evSourceService.GetState(dataProviderKey, transactionId); if (string.IsNullOrEmpty(state?.Data)) { throw new EntityNotFoundException($"there is no transaction state for id:{transactionId}"); } JObject stateObj = JsonConvert.DeserializeObject <JObject>(state.Data, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }); var evs = this.evSourceService.GetTransactionEvents(dataProviderKey, transactionId).OrderBy(x => x.DeltaTimeStamp); var edms = evs.Select(x => JsonConvert.DeserializeObject <JObject>(x.Delta, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All })).ToList(); foreach (var edm in edms) { stateObj.ApplyPatch(edm); } this.RemoveDeleted(ObjectHelper.GetInnerObject(stateObj), false); this.transactonCacheService.InjectMasterData(stateObj); return(stateObj); } }
public void AddToServiceContainer(dynamic container) { container.Init = new Func <string, PivotData, JToken>((rootCode, initData) => { var modelInfo = this.storageProvider.GetModelElementTree(rootCode); var model = this.modelsHelper.Init(modelInfo, modelInfo.Code); if (initData.PivotDefinition.Type == PivotType.Transaction) { return(new JObject { [modelInfo.Code] = model }); } return(model); }); container.Create = new Func <ModelElementObjectBase, JObject, JToken>((modelInfo, obj) => { JObject modelVal = null; var context = (EventContext)container.Context; using (new StopwatchLog(Metrics.Init)) { modelVal = this.modelsHelper.Init(modelInfo, modelInfo.Code); } using (new StopwatchLog(Metrics.Create)) { var model = new JObject { [modelInfo.Code] = modelVal }; this.infraService.AddModifyByObj(obj[modelInfo.Code], context); model.ApplyPatch(obj); var tr = this.transactionalService.CreateTransaction(context.AgentIdentity, model); context.Data = tr; return(tr); } }); }