public async Task <string> ApplyUpdates(Delta delta) { string updateResult = "Apply Updates Report:\r\n"; System.Globalization.CultureInfo culture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); if ((delta != null) && (delta.NumberOfOperations != 0)) { var nmsGdaClient = NetworkModelGdaClient.CreateClient(); if (nmsGdaClient == null) { string message = "NetworkModelGdaClient is null."; Logger.LogWarning(message); throw new NullReferenceException(message); } var result = await nmsGdaClient.ApplyUpdate(delta); updateResult = result.ToString(); } Thread.CurrentThread.CurrentCulture = culture; return(updateResult); }
public async Task <ResourceDescription> GetValues(long globalId, List <ModelCode> properties) { string message = "Getting values method started."; Logger.LogInformation(message); ResourceDescription rd = null; try { var nmsClient = NetworkModelGdaClient.CreateClient(); if (nmsClient == null) { string errMsg = "NetworkModelGdaClient is null."; Logger.LogWarning(errMsg); throw new NullReferenceException(errMsg); } rd = await nmsClient.GetValues(globalId, properties); message = "Getting values method SUCCESSFULLY finished."; Logger.LogInformation(message); } catch (Exception e) { message = string.Format("Getting values method for entered id = {0} failed.\n\t{1}", globalId, e.Message); Logger.LogError(message); } return(rd); }
private Task InitializeGlobalIdentifiers() { return(Task.Run(async() => { var gdaClient = NetworkModelGdaClient.CreateClient(); List <ModelCode> propIds = new List <ModelCode> { ModelCode.IDOBJ_GID }; foreach (DMSType dmsType in Enum.GetValues(typeof(DMSType))) { if (dmsType == DMSType.MASK_TYPE || ignorableTypes.Contains(dmsType)) { continue; } ModelCode dmsTypesModelCode = modelResourcesDesc.GetModelCodeFromType(dmsType); int iteratorId; int resourcesLeft; int numberOfResources = 10000; //MODO: connfigurabilno try { iteratorId = await gdaClient.GetExtentValues(dmsTypesModelCode, propIds); resourcesLeft = await gdaClient.IteratorResourcesLeft(iteratorId); while (resourcesLeft > 0) { List <ResourceDescription> gdaResult = await gdaClient.IteratorNext(numberOfResources, iteratorId); foreach (ResourceDescription rd in gdaResult) { Dispatcher.Invoke(() => { GlobalIdentifiers.Add(new GlobalIDBindingModel(rd.Id)); }); } resourcesLeft = await gdaClient.IteratorResourcesLeft(iteratorId); } await gdaClient.IteratorClose(iteratorId); } catch (Exception e) { string message = string.Format("Getting extent values method failed for {0}.\n\t{1}", dmsTypesModelCode, e.Message); Logger.LogError(message); } } })); }
private async Task <Dictionary <long, ResourceDescription> > GetExtentValues(ModelCode entityType, List <ModelCode> propIds) { int iteratorId; try { INetworkModelGDAContract gdaClient = NetworkModelGdaClient.CreateClient(); iteratorId = await gdaClient.GetExtentValues(entityType, propIds); } catch (Exception e) { string message = $"GetExtentValues => Entity type: {entityType}, Exception Message: {e.Message}."; Logger.LogError(message, e); throw e; } return(await ProcessIterator(iteratorId)); }
public async Task <ResourceDescription> GetValues(long globalId) { string message = "Getting values method started."; Console.WriteLine(message); //CommonTrace.WriteTrace(CommonTrace.TraceError, message); XmlTextWriter xmlWriter = null; ResourceDescription rd = null; try { short type = ModelCodeHelper.ExtractTypeFromGlobalId(globalId); List <ModelCode> properties = modelResourcesDesc.GetAllPropertyIds((DMSType)type); networkModelGdaClient = NetworkModelGdaClient.CreateClient(); rd = await networkModelGdaClient.GetValues(globalId, properties); xmlWriter = new XmlTextWriter(Config.Instance.ResultDirecotry + "\\GetValues_Results.xml", Encoding.Unicode); xmlWriter.Formatting = Formatting.Indented; rd.ExportToXml(xmlWriter); xmlWriter.Flush(); message = "Getting values method successfully finished."; Console.WriteLine(message); //CommonTrace.WriteTrace(CommonTrace.TraceError, message); } catch (Exception e) { message = string.Format("Getting values method for entered id = {0} failed.\n\t{1}", globalId, e.Message); Console.WriteLine(message); //CommonTrace.WriteTrace(CommonTrace.TraceError, message); } finally { if (xmlWriter != null) { xmlWriter.Close(); } } return(rd); }
public async Task <long> TestGetversion() { string message = "Get versions method started."; Console.WriteLine(message); long version = -1; try { networkModelGdaClient = NetworkModelGdaClient.CreateClient(); version = await networkModelGdaClient.GetVersion(); } catch (Exception e) { Console.WriteLine($"Get version failed with error: {e.Message}"); } return(version); }
public async Task <UpdateResult> TestApplyDeltaDelete(List <long> gids) { string message = "Testing apply delta delete method started."; Console.WriteLine(message); //CommonTrace.WriteTrace(CommonTrace.TraceInfo, message); UpdateResult updateResult = null; try { Delta delta = new Delta(); ResourceDescription rd = null; foreach (long gid in gids) { rd = new ResourceDescription(gid); delta.AddDeltaOperation(DeltaOpType.Delete, rd, true); } networkModelGdaClient = NetworkModelGdaClient.CreateClient(); updateResult = await networkModelGdaClient.ApplyUpdate(delta); message = "Testing apply delta delete method finished. \n" + updateResult.ToString(); Console.WriteLine(message); //CommonTrace.WriteTrace(CommonTrace.TraceInfo, message); } catch (Exception ex) { message = string.Format("Testing apply delta delete method failed. {0}\n", ex.Message); if (updateResult != null) { message += updateResult.ToString(); } Console.WriteLine(message); //CommonTrace.WriteTrace(CommonTrace.TraceError, message); } return(updateResult); }
public async Task <UpdateResult> TestApplyDeltaInsert() { string message = "Apply update method started."; Console.WriteLine(message); //CommonTrace.WriteTrace(CommonTrace.TraceInfo, message); UpdateResult updateResult = null; try { Dictionary <DMSType, ResourceDescription> updates = CreateResourcesToInsert(); Delta delta = new Delta(); foreach (ResourceDescription rd in updates.Values) { delta.AddDeltaOperation(DeltaOpType.Insert, rd, true); } networkModelGdaClient = NetworkModelGdaClient.CreateClient(); updateResult = await networkModelGdaClient.ApplyUpdate(delta); message = "Apply update method finished. \n" + updateResult.ToString(); Console.WriteLine(message); //CommonTrace.WriteTrace(CommonTrace.TraceInfo, message); } catch (Exception ex) { message = string.Format("Apply update method failed. {0}\n", ex.Message); if (updateResult != null) { message += updateResult.ToString(); } Console.WriteLine(message); // CommonTrace.WriteTrace(CommonTrace.TraceError, message); } return(updateResult); }
public async Task <List <Equipment> > CreateEquipmentEntitiesFromNmsDataAsync(List <long> entityIds) { var networkModelGdaClient = NetworkModelGdaClient.CreateClient(); List <Equipment> equipments = new List <Equipment>(); List <ModelCode> propIds = new List <ModelCode>() { ModelCode.IDOBJ_MRID }; foreach (long gid in entityIds) { ResourceDescription rd = null; try { rd = await networkModelGdaClient.GetValues(gid, propIds); } catch (Exception e) { Logger.LogError($"{baseLogString} CreateEquipmentEntitiesFromNmsDataAsync => Exception: {e.Message}"); throw e; } if (rd == null) { continue; } Equipment createdEquipment = new Equipment() { EquipmentId = rd.Id, EquipmentMRID = rd.Properties[0].AsString(), }; equipments.Add(createdEquipment); } return(equipments); }
private async Task <List <ResourceDescription> > ProcessIteratorAsync(int iteratorId) { string verboseMessage = $"{baseLogString} entering ProcessIteratorAsync method."; Logger.LogVerbose(verboseMessage); int resourcesLeft; int numberOfResources = 10000; List <ResourceDescription> resourceDescriptions; try { var networkModelGdaClient = NetworkModelGdaClient.CreateClient(); resourcesLeft = await networkModelGdaClient.IteratorResourcesTotal(iteratorId); resourceDescriptions = new List <ResourceDescription>(resourcesLeft); while (resourcesLeft > 0) { List <ResourceDescription> rds = await networkModelGdaClient.IteratorNext(numberOfResources, iteratorId); resourceDescriptions.AddRange(rds); resourcesLeft = await networkModelGdaClient.IteratorResourcesLeft(iteratorId); } await networkModelGdaClient.IteratorClose(iteratorId); } catch (Exception e) { string message = $"{baseLogString} ProcessIteratorAsync => Failed to process iterator." + $"{Environment.NewLine} Exception message: {e.Message}" + $"{Environment.NewLine} Stack trace: {e.StackTrace}"; Logger.LogError(message); throw new Exception(message); } return(resourceDescriptions); }
public async Task <List <ResourceDescription> > GetRelatedValuesAsync(long source, List <ModelCode> propIds, Association association) { string verboseMessage = $"{baseLogString} entering GetRelatedValuesAsync method."; Logger.LogVerbose(verboseMessage); int iteratorId; try { var networkModelGdaClient = NetworkModelGdaClient.CreateClient(); iteratorId = await networkModelGdaClient.GetRelatedValues(source, propIds, association); } catch (Exception e) { string message = $"{baseLogString} GetRelatedValuesAsync => Failed to get related values for GID {source:X16}." + $"{Environment.NewLine} Exception message: {e.Message}" + $"{Environment.NewLine} Stack trace: {e.StackTrace}"; Logger.LogError(message); throw new Exception(message); } return(await ProcessIteratorAsync(iteratorId)); }
public async Task <ResourceDescription> GetValuesAsync(long resourceId, List <ModelCode> propIds) { string verboseMessage = $"{baseLogString} entering GetValuesAsync method."; Logger.LogVerbose(verboseMessage); ResourceDescription resource; try { var networkModelGdaClient = NetworkModelGdaClient.CreateClient(); resource = await networkModelGdaClient.GetValues(resourceId, propIds); } catch (Exception e) { string message = $"{baseLogString} GetValuesAsync => Failed to get values for GID {resourceId:X16}." + $"{Environment.NewLine} Exception message: {e.Message}" + $"{Environment.NewLine} Stack trace: {e.StackTrace}"; Logger.LogError(message); throw new Exception(message); } return(resource); }
public async Task <List <ResourceDescription> > GetExtentValuesAsync(ModelCode entityType, List <ModelCode> propIds) { string verboseMessage = $"{baseLogString} entering GetExtentValuesAsync method."; Logger.LogVerbose(verboseMessage); int iteratorId; try { var networkModelGdaClient = NetworkModelGdaClient.CreateClient(); iteratorId = await networkModelGdaClient.GetExtentValues(entityType, propIds); } catch (Exception e) { string message = $"{baseLogString} GetExtentValuesAsync => Failed to get extent values for dms type {entityType}." + $"{Environment.NewLine} Exception message: {e.Message}" + $"{Environment.NewLine} Stack trace: {e.StackTrace}"; Logger.LogError(message); throw new Exception(message); } return(await ProcessIteratorAsync(iteratorId)); }
private async Task <Dictionary <long, ResourceDescription> > ProcessIterator(int iteratorId) { int resourcesLeft; int numberOfResources = 10000; Dictionary <long, ResourceDescription> resourceDescriptions; try { INetworkModelGDAContract gdaClient = NetworkModelGdaClient.CreateClient(); resourcesLeft = await gdaClient.IteratorResourcesTotal(iteratorId); resourceDescriptions = new Dictionary <long, ResourceDescription>(resourcesLeft); while (resourcesLeft > 0) { List <ResourceDescription> resources = await gdaClient.IteratorNext(numberOfResources, iteratorId); foreach (ResourceDescription resource in resources) { resourceDescriptions.Add(resource.Id, resource); } resourcesLeft = await gdaClient.IteratorResourcesLeft(iteratorId); } await gdaClient.IteratorClose(iteratorId); } catch (Exception e) { string message = $"Failed to retrieve all Resourse descriptions with iterator {iteratorId}."; Logger.LogError(message, e); throw e; } return(resourceDescriptions); }
private async Task <Dictionary <long, IScadaModelPointItem> > CreatePointItemsFromNetworkModelMeasurements(Dictionary <byte, List <long> > modelChanges) { Dictionary <long, IScadaModelPointItem> pointItems = new Dictionary <long, IScadaModelPointItem>(); INetworkModelGDAContract nmsGdaClient = NetworkModelGdaClient.CreateClient(); int iteratorId; int resourcesLeft; int numberOfResources = 10000; List <ModelCode> props; //TOOD: change service contract IModelUpdateNotificationContract to receive types of all changed elements from NMS var changedTypesHashSet = new HashSet <ModelCode>(); foreach (var gids in modelChanges.Values) { foreach (var gid in gids) { ModelCode type = modelResourceDesc.GetModelCodeFromId(gid); changedTypesHashSet.Add(type); } } foreach (ModelCode type in changedTypesHashSet) { if (type != ModelCode.ANALOG && type != ModelCode.DISCRETE) { continue; } props = modelResourceDesc.GetAllPropertyIds(type); try { iteratorId = await nmsGdaClient.GetExtentValues(type, props); resourcesLeft = await nmsGdaClient.IteratorResourcesLeft(iteratorId); while (resourcesLeft > 0) { List <ResourceDescription> resources = await nmsGdaClient.IteratorNext(numberOfResources, iteratorId); foreach (ResourceDescription rd in resources) { if (pointItems.ContainsKey(rd.Id)) { string message = $"{baseLogString} CreatePointItemsFromNetworkModelMeasurements => Trying to create point item for resource that already exists in model. Gid: 0x{rd.Id:X16}"; Logger.LogError(message); throw new ArgumentException(message); } IScadaModelPointItem point; //change service contract IModelUpdateNotificationContract => change List<long> to Hashset<long> if (modelChanges[(byte)DeltaOpType.Update].Contains(rd.Id) || modelChanges[(byte)DeltaOpType.Insert].Contains(rd.Id)) { point = CreatePointItemFromResource(rd); pointItems.Add(rd.Id, point); } } resourcesLeft = await nmsGdaClient.IteratorResourcesLeft(iteratorId); } await nmsGdaClient.IteratorClose(iteratorId); } catch (Exception ex) { string errorMessage = $"{baseLogString} CreatePointItemsFromNetworkModelMeasurements => Failed with error: {ex.Message}"; Logger.LogError(errorMessage, ex); } } return(pointItems); }
public async Task <List <long> > GetExtentValues(ModelCode modelCodeType, List <ModelCode> properties, StringBuilder sb) { string message = "Getting extent values method started."; Logger.LogInformation(message); int iteratorId; int resourcesLeft; int numberOfResources = 300; List <long> ids = new List <long>(); StringBuilder tempSb = new StringBuilder(); try { var nmsClient = NetworkModelGdaClient.CreateClient(); if (nmsClient == null) { string errMsg = "NetworkModelGdaClient is null."; Logger.LogWarning(errMsg); throw new NullReferenceException(errMsg); } iteratorId = await nmsClient.GetExtentValues(modelCodeType, properties); resourcesLeft = await nmsClient.IteratorResourcesLeft(iteratorId); while (resourcesLeft > 0) { List <ResourceDescription> rds = await nmsClient.IteratorNext(numberOfResources, iteratorId); for (int i = 0; i < rds.Count; i++) { if (rds[i] == null) { continue; } tempSb.Append($"Entity with gid: 0x{rds[i].Id:X16}" + Environment.NewLine); foreach (Property property in rds[i].Properties) { switch (property.Type) { case PropertyType.Int64: StringAppender.AppendLong(tempSb, property); break; case PropertyType.Float: StringAppender.AppendFloat(tempSb, property); break; case PropertyType.String: StringAppender.AppendString(tempSb, property); break; case PropertyType.Reference: StringAppender.AppendReference(tempSb, property); break; case PropertyType.ReferenceVector: StringAppender.AppendReferenceVector(tempSb, property); break; default: tempSb.Append($"{property.Id}: {property.PropertyValue.LongValue}{Environment.NewLine}"); break; } } ids.Add(rds[i].Id); } resourcesLeft = await nmsClient.IteratorResourcesLeft(iteratorId); } await nmsClient.IteratorClose(iteratorId); message = "Getting extent values method SUCCESSFULLY finished."; Logger.LogInformation(message); } catch (Exception e) { message = string.Format("Getting extent values method failed for {0}.\n\t{1}", modelCodeType, e.Message); Logger.LogError(message); } if (sb != null) { sb.Append(tempSb.ToString()); } return(ids); }
private async Task <bool> PopulateNmsDataFromServer(ModelResourcesDesc resourcesDesc) { bool success = false; string message = "Getting nms data from server started."; Logger.LogInformation(message); var nmsGdaClient = NetworkModelGdaClient.CreateClient(); if (nmsGdaClient == null) { string errMessage = "PopulateNmsDataFromServer() => NetworkModelGdaClient is null."; Logger.LogError(errMessage); throw new NullReferenceException(errMessage); } HashSet <ModelCode> requiredEntityTypes = new HashSet <ModelCode>(); foreach (DMSType dmsType in Enum.GetValues(typeof(DMSType))) { if (dmsType == DMSType.MASK_TYPE) { continue; } ModelCode mc = resourcesDesc.GetModelCodeFromType(dmsType); if (!requiredEntityTypes.Contains(mc)) { requiredEntityTypes.Add(mc); } } List <ModelCode> mrIdProp = new List <ModelCode>() { ModelCode.IDOBJ_MRID }; foreach (ModelCode modelCodeType in requiredEntityTypes) { int iteratorId = 0; int resourcesLeft = 0; int numberOfResources = 10000; //potencijalno connfigurabilno try { iteratorId = await nmsGdaClient.GetExtentValues(modelCodeType, mrIdProp); resourcesLeft = await nmsGdaClient.IteratorResourcesLeft(iteratorId); while (resourcesLeft > 0) { List <ResourceDescription> gdaResult = await nmsGdaClient.IteratorNext(numberOfResources, iteratorId); foreach (ResourceDescription rd in gdaResult) { if (rd.Properties[0].Id != ModelCode.IDOBJ_MRID) { continue; } string mrId = rd.Properties[0].PropertyValue.StringValue; if (!MridToPositiveGidFromServer.ContainsKey(mrId)) { MridToPositiveGidFromServer.Add(mrId, rd.Id); } else { throw new NotImplementedException("Method PopulateNmsDataFromServer() -> MridToPositiveGid.ContainsKey(mrId) == true"); } } resourcesLeft = await nmsGdaClient.IteratorResourcesLeft(iteratorId); } await nmsGdaClient.IteratorClose(iteratorId); message = "Getting nms data from server SUCCESSFULLY finished."; Logger.LogInformation(message); success = true; } catch (Exception e) { message = string.Format("Getting extent values method failed for {0}.\n\t{1}", modelCodeType, e.Message); Logger.LogError(message); success = false; } } return(success); }
private async Task <bool> ImportDiscrete() { bool success; int numberOfResources = 1000; List <ModelCode> props = modelResourceDesc.GetAllPropertyIds(ModelCode.DISCRETE); try { var nmsGdaClient = NetworkModelGdaClient.CreateClient(); int iteratorId = await nmsGdaClient.GetExtentValues(ModelCode.DISCRETE, props); int resourcesLeft = await nmsGdaClient.IteratorResourcesLeft(iteratorId); while (resourcesLeft > 0) { List <ResourceDescription> rds = await nmsGdaClient.IteratorNext(numberOfResources, iteratorId); for (int i = 0; i < rds.Count; i++) { if (rds[i] == null) { continue; } long gid = rds[i].Id; ModelCode type = modelResourceDesc.GetModelCodeFromId(gid); DiscretePointItem discretePoint = new DiscretePointItem(AlarmConfigDataHelper.GetAlarmConfigData()); string debugMessage = $"{baseLogString} ImportDiscrete => Before Initialization => Gid: 0x{discretePoint.Gid:X16}, Address: {discretePoint.Address}, CurrentValue: {discretePoint.CurrentValue}, Alarm: {discretePoint.Alarm}, AbnormalValue: {discretePoint.AbnormalValue}, DiscreteType: {discretePoint.DiscreteType}, MinValue: {discretePoint.MinValue}, MaxValue: {discretePoint.MaxValue}, NormalValue: {discretePoint.NormalValue}, RegisterType: {discretePoint.RegisterType}, Name: {discretePoint.Name}, Initialized: {discretePoint.Initialized}"; Logger.LogDebug(debugMessage); pointItemHelper.InitializeDiscretePointItem(discretePoint, rds[i].Properties, ModelCode.DISCRETE, enumDescs); debugMessage = $"{baseLogString} ImportDiscrete => After Initialization => Gid: 0x{discretePoint.Gid:X16}, Address: {discretePoint.Address}, CurrentValue: {discretePoint.CurrentValue}, Alarm: {discretePoint.Alarm}, AbnormalValue: {discretePoint.AbnormalValue}, DiscreteType: {discretePoint.DiscreteType}, MinValue: {discretePoint.MinValue}, MaxValue: {discretePoint.MaxValue}, NormalValue: {discretePoint.NormalValue}, RegisterType: {discretePoint.RegisterType}, Name: {discretePoint.Name}, Initialized: {discretePoint.Initialized}"; Logger.LogDebug(debugMessage); if (await GidToPointItemMap.ContainsKeyAsync(gid)) { string errorMessage = $"{baseLogString} ImportDiscrete => SCADA model is invalid => Gid: 0x{gid:X16} belongs to more than one entity."; Logger.LogError(errorMessage); throw new InternalSCADAServiceException(errorMessage); } await GidToPointItemMap.SetAsync(gid, discretePoint); #if DEBUG var pointItemResult = await GidToPointItemMap.TryGetValueAsync(gid); if (pointItemResult.HasValue) { DiscretePointItem controlPointItem = pointItemResult.Value as DiscretePointItem; debugMessage = $"{baseLogString} ImportDiscrete => Control after CurrentGidToPointItemMap.SetAsync => Gid: 0x{controlPointItem.Gid:X16}, Address: {controlPointItem.Address}, CurrentValue: {controlPointItem.CurrentValue}, Alarm: {controlPointItem.Alarm}, AbnormalValue: {controlPointItem.AbnormalValue}, DiscreteType: {controlPointItem.DiscreteType}, MinValue: {controlPointItem.MinValue}, MaxValue: {controlPointItem.MaxValue}, NormalValue: {controlPointItem.NormalValue}, RegisterType: {controlPointItem.RegisterType}, Name: {controlPointItem.Name}, Initialized: {controlPointItem.Initialized}"; Logger.LogDebug(debugMessage); } else { string warningMessage = $"{baseLogString} ImportDiscrete => Control after CurrentGidToPointItemMap.SetAsync => Gid: 0x{gid:X16} was not found in reliable collection '{ReliableDictionaryNames.GidToPointItemMap}' after the value was supposedly set."; Logger.LogWarning(warningMessage); } #endif short registerType = (short)discretePoint.RegisterType; if (!(await AddressToGidMap.ContainsKeyAsync(registerType))) { await AddressToGidMap.SetAsync(registerType, new Dictionary <ushort, long>()); } var addressToGidDictionaryResult = await AddressToGidMap.TryGetValueAsync(registerType); if (!addressToGidDictionaryResult.HasValue) { string message = $"{baseLogString} ImportDiscrete => reliable collection '{ReliableDictionaryNames.AddressToGidMap}' is not initialized properly."; Logger.LogError(message); throw new InternalSCADAServiceException(message); } var addressToGidDictionary = addressToGidDictionaryResult.Value; if (addressToGidDictionary.ContainsKey(discretePoint.Address)) { string errorMessage = $"{baseLogString} ImportDiscrete => SCADA model is invalid => Address: {discretePoint.Address} (RegType: {registerType}) belongs to more than one entity."; Logger.LogError(errorMessage); throw new InternalSCADAServiceException(errorMessage); } addressToGidDictionary.Add(discretePoint.Address, rds[i].Id); await AddressToGidMap.SetAsync(registerType, addressToGidDictionary); debugMessage = $"{baseLogString} ImportDiscrete => ANALOG measurement added to SCADA model [Gid: 0x{gid:X16}, Address: {discretePoint.Address}]"; Logger.LogDebug(debugMessage); } resourcesLeft = await nmsGdaClient.IteratorResourcesLeft(iteratorId); } await nmsGdaClient.IteratorClose(iteratorId); success = true; } catch (Exception ex) { success = false; string errorMessage = $"{baseLogString} ImportDiscrete => failed with error: {ex.Message}"; Console.WriteLine(errorMessage); Logger.LogError(errorMessage, ex); } return(success); }
public async Task <List <long> > GetExtentValues(ModelCode modelCode) { string message = "Getting extent values method started."; Console.WriteLine(message); //CommonTrace.WriteTrace(CommonTrace.TraceError, message); XmlTextWriter xmlWriter = null; int iteratorId = 0; List <long> ids = new List <long>(); try { int numberOfResources = 2; int resourcesLeft = 0; List <ModelCode> properties = modelResourcesDesc.GetAllPropertyIds(modelCode); networkModelGdaClient = NetworkModelGdaClient.CreateClient(); iteratorId = await networkModelGdaClient.GetExtentValues(modelCode, properties); resourcesLeft = await networkModelGdaClient.IteratorResourcesLeft(iteratorId); xmlWriter = new XmlTextWriter(Config.Instance.ResultDirecotry + "\\GetExtentValues_Results.xml", Encoding.Unicode); xmlWriter.Formatting = Formatting.Indented; while (resourcesLeft > 0) { networkModelGdaClient = NetworkModelGdaClient.CreateClient(); List <ResourceDescription> rds = await networkModelGdaClient.IteratorNext(numberOfResources, iteratorId); for (int i = 0; i < rds.Count; i++) { ids.Add(rds[i].Id); rds[i].ExportToXml(xmlWriter); xmlWriter.Flush(); } resourcesLeft = await networkModelGdaClient.IteratorResourcesLeft(iteratorId); } networkModelGdaClient = NetworkModelGdaClient.CreateClient(); await networkModelGdaClient.IteratorClose(iteratorId); message = "Getting extent values method successfully finished."; Console.WriteLine(message); //CommonTrace.WriteTrace(CommonTrace.TraceError, message); } catch (Exception e) { message = string.Format("Getting extent values method failed for {0}.\n\t{1}", modelCode, e.Message); Console.WriteLine(message); //CommonTrace.WriteTrace(CommonTrace.TraceError, message); } finally { if (xmlWriter != null) { xmlWriter.Close(); } } return(ids); }
public async Task <List <long> > GetRelatedValues(long sourceGlobalId, Association association) { string message = "Getting related values method started."; Console.WriteLine(message); //CommonTrace.WriteTrace(CommonTrace.TraceError, message); List <long> resultIds = new List <long>(); XmlTextWriter xmlWriter = null; int numberOfResources = 2; try { List <ModelCode> properties = new List <ModelCode>(); //properties.Add(ModelCode.IDOBJ_DESCRIPTION); properties.Add(ModelCode.IDOBJ_MRID); properties.Add(ModelCode.IDOBJ_NAME); networkModelGdaClient = NetworkModelGdaClient.CreateClient(); int iteratorId = await networkModelGdaClient.GetRelatedValues(sourceGlobalId, properties, association); int resourcesLeft = await networkModelGdaClient.IteratorResourcesLeft(iteratorId); xmlWriter = new XmlTextWriter(Config.Instance.ResultDirecotry + "\\GetRelatedValues_Results.xml", Encoding.Unicode); xmlWriter.Formatting = Formatting.Indented; while (resourcesLeft > 0) { networkModelGdaClient = NetworkModelGdaClient.CreateClient(); List <ResourceDescription> rds = await networkModelGdaClient.IteratorNext(numberOfResources, iteratorId); for (int i = 0; i < rds.Count; i++) { resultIds.Add(rds[i].Id); rds[i].ExportToXml(xmlWriter); xmlWriter.Flush(); } resourcesLeft = await networkModelGdaClient.IteratorResourcesLeft(iteratorId); } networkModelGdaClient = NetworkModelGdaClient.CreateClient(); await networkModelGdaClient.IteratorClose(iteratorId); message = "Getting related values method successfully finished."; Console.WriteLine(message); // CommonTrace.WriteTrace(CommonTrace.TraceError, message); } catch (Exception e) { message = string.Format("Getting related values method failed for sourceGlobalId = {0} and association (propertyId = {1}, type = {2}). Reason: {3}", sourceGlobalId, association.PropertyId, association.Type, e.Message); Console.WriteLine(message); //CommonTrace.WriteTrace(CommonTrace.TraceError, message); } finally { if (xmlWriter != null) { xmlWriter.Close(); } } return(resultIds); }
public async Task <List <long> > TestGetExtentValuesAllTypes() { string message = "Getting extent values for all DMS types started."; Console.WriteLine(message); //CommonTrace.WriteTrace(CommonTrace.TraceInfo, message); List <ModelCode> properties = new List <ModelCode>(); List <long> ids = new List <long>(); int iteratorId = 0; int numberOfResources = 1000; DMSType currType = 0; try { foreach (DMSType type in Enum.GetValues(typeof(DMSType))) { currType = type; properties = modelResourcesDesc.GetAllPropertyIds(type); networkModelGdaClient = NetworkModelGdaClient.CreateClient(); iteratorId = await networkModelGdaClient.GetExtentValues(modelResourcesDesc.GetModelCodeFromType(type), properties); int count = await networkModelGdaClient.IteratorResourcesLeft(iteratorId); while (count > 0) { networkModelGdaClient = NetworkModelGdaClient.CreateClient(); List <ResourceDescription> rds = await networkModelGdaClient.IteratorNext(numberOfResources, iteratorId); for (int i = 0; i < rds.Count; i++) { ids.Add(rds[i].Id); } count = await networkModelGdaClient.IteratorResourcesLeft(iteratorId); } networkModelGdaClient = NetworkModelGdaClient.CreateClient(); bool ok = await networkModelGdaClient.IteratorClose(iteratorId); message = string.Format("Number of {0} in model {1}.", type, ids.Count); Console.WriteLine(message); // CommonTrace.WriteTrace(CommonTrace.TraceInfo, message); } message = "Getting extent values for all DMS types successfully ended."; Console.WriteLine(message); //CommonTrace.WriteTrace(CommonTrace.TraceInfo, message); } catch (Exception e) { message = string.Format("Getting extent values for all DMS types failed for type {0}.\n\t{1}", currType, e.Message); Console.WriteLine(message); //CommonTrace.WriteTrace(CommonTrace.TraceInfo, message); throw; } return(ids); }