public async Task Rollback() { ServiceEventSource.Current.ServiceMessage(_context, "CE Transaction - Rollback!"); Console.WriteLine("Request for rollback!"); var storage = new CEStorageProxy(ConfigurationReader.ReadValue(_context, "Settings", "CES") ?? "fabric:/ServiceFabricApp/CEStorageService"); await storage.SetTransactionalModel(new Dictionary <FTN.Common.DMSType, FTN.Services.NetworkModelService.Container>()); }
public async Task <bool> Commit() { ServiceEventSource.Current.ServiceMessage(_context, "CE Transaction - Commit!"); Console.WriteLine("Commited? YES"); var storage = new CEStorageProxy(ConfigurationReader.ReadValue(_context, "Settings", "CES") ?? "fabric:/ServiceFabricApp/CEStorageService"); var tModel = await storage.GetTransactionalModel(); var count = tModel[FTN.Common.DMSType.ASYNCHRONOUSMACHINE].Count; await storage.SetModel(tModel); await storage.SetTransactionalModel(new Dictionary <FTN.Common.DMSType, FTN.Services.NetworkModelService.Container>()); var ceService = new CEServiceProxy(ConfigurationReader.ReadValue(_context, "Settings", "CEService") ?? "fabric:/ServiceFabricApp/CEService"); await ceService.SetPoints(count); return(true); }
public async Task <bool> ModelUpdate(AffectedEntities model) { ServiceEventSource.Current.ServiceMessage(_context, "CE ModelUpdate!"); var proxy = new NetworkModelServiceProxy(ConfigurationReader.ReadValue(_context, "Settings", "NMS") ?? "net.tcp://localhost:22330/NetworkModelServiceSF"); var storage = new CEStorageProxy(ConfigurationReader.ReadValue(_context, "Settings", "CES") ?? "fabric:/ServiceFabricApp/CEStorageService"); var ceModel = await storage.GetModel(); if (ceModel == null) { ceModel = new Dictionary <DMSType, Container>(); } Console.WriteLine("New update request!"); model.Insert = model.Insert.Where(x => GetDMSType(x) == DMSType.ASYNCHRONOUSMACHINE).ToList(); model.Update = model.Update.Where(x => GetDMSType(x) == DMSType.ASYNCHRONOUSMACHINE).ToList(); model.Delete = model.Delete.Where(x => GetDMSType(x) == DMSType.ASYNCHRONOUSMACHINE).ToList(); if (model.Insert.Count > 0) { var dataInsert = await proxy.GetValues(model.Insert); foreach (var item in dataInsert) { var dmsType = GetDMSType(item.GID); if (!ceModel.ContainsKey(dmsType)) { ceModel.Add(dmsType, new Container()); } ceModel[dmsType].AddEntity(item); } } if (model.Update.Count > 0) { var dataUpdate = await proxy.GetValues(model.Update); foreach (var item in dataUpdate) { var dmsType = GetDMSType(item.GID); if (!ceModel.ContainsKey(dmsType)) { ceModel.Add(dmsType, new Container()); } ceModel[dmsType].RemoveEntity(item.GID); ceModel[dmsType].AddEntity(item); } } if (model.Delete.Count > 0) { var dataDelete = await proxy.GetValues(model.Delete); foreach (var item in dataDelete) { var dmsType = GetDMSType(item.GID); if (!ceModel.ContainsKey(dmsType)) { ceModel.Add(dmsType, new Container()); } ceModel[dmsType].RemoveEntity(item.GID); } } await storage.SetTransactionalModel(ceModel); EnList(); return(true); }