/// <summary> /// Gets resource iterator that holds descriptions for all entities of the specified type. /// </summary> /// <param name="type">Type of entity that is requested</param> /// <param name="properties">List of requested properties</param> /// <returns>Resource iterator for the requested entities</returns> public ResourceIterator GetExtentValues(ModelCode entityType, List <ModelCode> properties) { CommonTrace.WriteTrace(CommonTrace.TraceVerbose, "Getting extent values for entity type = {0} .", entityType); try { List <long> globalIds = new List <long>(); Dictionary <DMSType, List <ModelCode> > class2PropertyIDs = new Dictionary <DMSType, List <ModelCode> >(); DMSType entityDmsType = ModelCodeHelper.GetTypeFromModelCode(entityType); if (ContainerExists(entityDmsType)) { Container container = GetContainer(entityDmsType); globalIds = container.GetEntitiesGlobalIds(); class2PropertyIDs.Add(entityDmsType, properties); } ResourceIterator ri = new ResourceIterator(globalIds, class2PropertyIDs); CommonTrace.WriteTrace(CommonTrace.TraceVerbose, "Getting extent values for entity type = {0} succedded.", entityType); return(ri); } catch (Exception ex) { string message = string.Format("Failed to get extent values for entity type = {0}. {1}", entityType, ex.Message); throw new Exception(message); } }
private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (SelectedType == null) { return; } Properties.Children.Clear(); Label label = new Label() { FontWeight = FontWeights.UltraBold, Content = "Properties (for selected class)", }; Properties.Children.Add(label); List <ModelCode> properties = modelResourcesDesc.GetAllPropertyIds(ModelCodeHelper.GetTypeFromModelCode(SelectedType.ClassType)); propertiesDesc.Clear(); foreach (ModelCode property in properties) { propertiesDesc.Add(property, property.ToString()); CheckBox checkBox = new CheckBox() { Content = property.ToString(), }; checkBox.Unchecked += CheckBox_Unchecked; Properties.Children.Add(checkBox); } CheckAllBtn.IsEnabled = true; }
private void FindPropertyModelCode(ModelCode property) { string[] props = (property.ToString()).Split('_'); props[1] = props[1].TrimEnd('S'); DMSType propertyCode = ModelResourcesDesc.GetTypeFromModelCode(property); // DMSType propertyCode = ModelCodeHelper.GetDMSTypeFromString(property); ModelCode mc; ModelCodeHelper.GetModelCodeFromString(propertyCode.ToString(), out mc); foreach (ModelCode modelCode in Enum.GetValues(typeof(ModelCode))) { if ((String.Compare(modelCode.ToString(), mc.ToString()) != 0) && (String.Compare(property.ToString(), modelCode.ToString()) != 0) && (String.Compare(props[1], modelCode.ToString())) == 0) { DMSType type = ModelCodeHelper.GetTypeFromModelCode(modelCode); if (type == 0) { FindChildren(modelCode); } else { childrenType = new List <ModelCode>(); childrenType.Add(modelCode); } } } }
/// <summary> /// Returns related gids with source according to the association /// </summary> /// <param name="source">source id</param> /// <param name="association">desinition of association</param> /// <returns>related gids</returns> private List <long> ApplyAssocioationOnSource(long source, Association association) { List <long> relatedGids = new List <long>(); if (association == null) { association = new Association(); } lock (SmartContainer.Instance.Lock2PC) { IdentifiedObject io = smartContainer.GetEntity(smartContainer.Original, source); if (!io.HasProperty(association.PropertyId)) { throw new Exception(string.Format("Entity with GID = 0x{0:x16} does not contain prperty with Id = {1}.", source, association.PropertyId)); } Property propertyRef = null; if (Property.GetPropertyType(association.PropertyId) == PropertyType.Reference) { propertyRef = io.GetProperty(association.PropertyId); long relatedGidFromProperty = propertyRef.AsReference(); if (relatedGidFromProperty != 0) { if (association.Type == 0 || (short)ModelCodeHelper.GetTypeFromModelCode(association.Type) == ModelCodeHelper.ExtractTypeFromGlobalId(relatedGidFromProperty)) { relatedGids.Add(relatedGidFromProperty); } } } else if (Property.GetPropertyType(association.PropertyId) == PropertyType.ReferenceVector) { propertyRef = io.GetProperty(association.PropertyId); List <long> relatedGidsFromProperty = propertyRef.AsReferences(); if (relatedGidsFromProperty != null) { foreach (long relatedGidFromProperty in relatedGidsFromProperty) { if (association.Type == 0 || (short)ModelCodeHelper.GetTypeFromModelCode(association.Type) == ModelCodeHelper.ExtractTypeFromGlobalId(relatedGidFromProperty)) { relatedGids.Add(relatedGidFromProperty); } } } } else { throw new Exception(string.Format("Association propertyId = {0} is not reference or reference vector type.", association.PropertyId)); } } return(relatedGids); }
public string GetDMSTypeOfTopologyElement(long gid) { logger.LogDebug($"Getting element DMStype for GID {gid}."); try { return(ModelCodeHelper.GetTypeFromModelCode(modelResourcesDesc.GetModelCodeFromId(gid)).ToString()); } catch (Exception) { return("FIELD"); } }
public TopologyType GetElementTopologyType(long gid) { logger.LogDebug($"Getting element topology type for GID {gid}."); TopologyType retVal; DMSType type = ModelCodeHelper.GetTypeFromModelCode(modelResourcesDesc.GetModelCodeFromId(gid)); foreach (var item in topologyTypes) { if (item.Value.Contains(type)) { retVal = item.Key; return(retVal); } } return(TopologyType.None); }
public TopologyStatus GetElementTopologyStatus(long gid) { logger.LogDebug($"Getting element topology status for GID {gid}."); TopologyStatus retVal; DMSType type = ModelCodeHelper.GetTypeFromModelCode(modelResourcesDesc.GetModelCodeFromId(gid)); foreach (var item in elementsStatus) { if (item.Value.Contains(type)) { retVal = item.Key; return(retVal); } } return(TopologyStatus.Regular); }
private void FindChildren(ModelCode modelCode) { StringBuilder sb = new StringBuilder(); sb.Append("0x"); List <ModelCode> retCodes = new List <ModelCode>(); long lmc = (long)modelCode; string smc = String.Format("0x{0:x16}", lmc); string[] newS = smc.Split('x'); char[] c = (newS[1]).ToCharArray(); foreach (char ch in c) { if (ch != '0') { sb.Append(ch); } else { break; } } foreach (ModelCode mc in Enum.GetValues(typeof(ModelCode))) { DMSType type = ModelCodeHelper.GetTypeFromModelCode(mc); short sh = (short)mc; if ((modelCode != mc) && (sh == 0) && (type != 0)) { lmc = (long)mc; smc = String.Format("0x{0:x16}", lmc); if (smc.StartsWith(sb.ToString())) { retCodes.Add(mc); } } } childrenType = retCodes; }
private List <ModelCode> NadjiTipove(ModelCode kodProp) { ModelResourcesDesc modResDes = new ModelResourcesDesc(); //List<DMSType> tip = new List<DMSType>(); string[] props = (kodProp.ToString()).Split('_'); props[1] = props[1].TrimEnd('S'); DMSType propertyCode = ModelResourcesDesc.GetTypeFromModelCode(kodProp); ModelCode mc; ModelCodeHelper.GetModelCodeFromString(propertyCode.ToString(), out mc); foreach (ModelCode modelCode in Enum.GetValues(typeof(ModelCode))) { if (String.Compare(props[1], modelCode.ToString()) == 0) { DMSType type = ModelCodeHelper.GetTypeFromModelCode(modelCode); if (type == 0) { tipovi = new List <ModelCode>(); List <DMSType> r = modResDes.GetLeaves(modelCode); foreach (DMSType ff in r) { tipovi.Add(modResDes.GetModelCodeFromType(ff)); } } else { tipovi = new List <ModelCode>(); tipovi.Add(modelCode); } } } return(new List <ModelCode>()); }
private void FindCommandExecute(string textForFind) { var hex_val = textForFind; ResList.Clear(); List <ModelCode> forFind = getModelCodes(); var allSelected = getSelectedProp(); foreach (var modCode in forFind) { var myProps = modelResourcesDesc.GetAllPropertyIds(ModelCodeHelper.GetTypeFromModelCode(modCode)); var mySelected = myProps.Where(x => allSelected.Contains(x)); var retExtentValues = testGda.GetExtentValues(modCode, mySelected.ToList()); foreach (var res in retExtentValues) { ResList.Add(res); } } //if (hex_val.Trim() != string.Empty) //{ // try // { // long gid = Convert.ToInt64(hex_val, 16); // ResourceDescription rd = testGda.GetValues(gid); // if (!ResList.ToList().Exists((x) => x.Id == rd.Id)) // { // ResList.Add(rd); // } // } // catch (Exception ex) // { // Console.WriteLine(ex.Message); // } //} }
/// <summary> /// Gets resource iterator that holds descriptions for all entities of the specified type. /// </summary> /// <param name="type">Type of entity that is requested</param> /// <param name="properties">List of requested properties</param> /// <returns>Resource iterator for the requested entities</returns> public ResourceIterator GetExtentValues(ModelCode entityType, List <ModelCode> properties) { string message = String.Format("Getting extent values for entity type = {0} .", entityType); LogHelper.Log(LogTarget.File, LogService.NMSNetworkModel, " INFO - NetworkModel.cs - " + message); try { ResourceIterator ri; lock (SmartContainer.Instance.Lock2PC) { List <long> globalIds = new List <long>(); Dictionary <DMSType, List <ModelCode> > class2PropertyIDs = new Dictionary <DMSType, List <ModelCode> >(); DMSType entityDmsType = ModelCodeHelper.GetTypeFromModelCode(entityType); if (smartContainer.ContainerExists(smartContainer.Original, entityDmsType)) { Container container = smartContainer.GetContainer(smartContainer.Original, entityDmsType); globalIds = container.GetEntitiesGlobalIds(); class2PropertyIDs.Add(entityDmsType, properties); } ri = new ResourceIterator(globalIds, class2PropertyIDs); message = String.Format("Getting extent values for entity type = {0} succedded.", entityType); LogHelper.Log(LogTarget.File, LogService.NMSNetworkModel, " INFO - NetworkModel.cs - " + message); } return(ri); } catch (Exception ex) { message = string.Format("Failed to get extent values for entity type = {0}. {1}", entityType, ex.Message); LogHelper.Log(LogTarget.File, LogService.NMSNetworkModel, " ERROR - NetworkModel.cs - " + message); throw new Exception(message); } }
private void DMSTypes_SelectionChanged(object sender, SelectionChangedEventArgs e) { selectedDMSType = (long)DMSTypes.SelectedItem; PopulateProperties(PropertiesExtent, propertiesDescExtended, ModelCodeHelper.GetTypeFromModelCode((ModelCode)selectedDMSType)); }
public UpdateResult Prepare(ref Delta delta) { try { transactionCallback = OperationContext.Current.GetCallbackChannel <ITransactionCallback>(); updateResult = new UpdateResult(); internalGeneratorsCopy.Clear(); foreach (ResourceDescription rd in internalGenerators) { internalGeneratorsCopy.Add(rd.Clone() as ResourceDescription); } internalEnergyConsumersCopy.Clear(); foreach (ResourceDescription rd in internalEnergyConsumers) { internalEnergyConsumersCopy.Add(rd.Clone() as ResourceDescription); } foreach (ResourceDescription rd in delta.InsertOperations) { foreach (Property prop in rd.Properties) { if (ModelCodeHelper.GetTypeFromModelCode(prop.Id).Equals(DMSType.GENERATOR)) { internalGeneratorsCopy.Add(rd); break; } else if (ModelCodeHelper.GetTypeFromModelCode(prop.Id).Equals(DMSType.ENERGY_CONSUMER)) { internalEnergyConsumersCopy.Add(rd); break; } } } foreach (ResourceDescription rd in delta.UpdateOperations) { foreach (Property prop in rd.Properties) { if ((DMSType)ModelCodeHelper.ExtractTypeFromGlobalId(rd.Id) == (DMSType.GENERATOR)) { foreach (ResourceDescription res in internalGeneratorsCopy) { if (rd.Id.Equals(res.Id)) { foreach (Property p in res.Properties) { if (prop.Id.Equals(p.Id)) { p.PropertyValue = prop.PropertyValue; break; } } } } } else if ((DMSType)ModelCodeHelper.ExtractTypeFromGlobalId(rd.Id) == (DMSType.ENERGY_CONSUMER)) { foreach (ResourceDescription res in internalEnergyConsumersCopy) { if (rd.Id.Equals(res.Id)) { foreach (Property p in res.Properties) { if (prop.Id.Equals(p.Id)) { p.PropertyValue = prop.PropertyValue; break; } } } } } } } updateResult.Message = "CE Transaction Prepare finished."; updateResult.Result = ResultType.Succeeded; CommonTrace.WriteTrace(CommonTrace.TraceInfo, "CETransaction Prepare finished successfully."); transactionCallback.Response("OK"); } catch (Exception e) { updateResult.Message = "CE Transaction Prepare finished."; updateResult.Result = ResultType.Failed; CommonTrace.WriteTrace(CommonTrace.TraceWarning, "CE Transaction Prepare failed. Message: {0}", e.Message); transactionCallback.Response("ERROR"); } return(updateResult); }
private void RelationalPropertiesDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (SelectedProperty == null) { return; } RelatedEntityDmsTypes.Clear(); SelectedDmsType = null; PropertiesInRelated.Children.Clear(); RelatedValues.Document.Blocks.Clear(); List <DMSType> dmsTypes = new List <DMSType>(); if (RelationalPropertiesHelper.Relations.ContainsKey(SelectedProperty.Property)) { ModelCode relatedEntity = RelationalPropertiesHelper.Relations[SelectedProperty.Property]; dmsTypes.AddRange(ModelResourcesDesc.GetLeavesForCoreEntities(relatedEntity)); if (dmsTypes.Count == 0) { dmsTypes.Add(ModelCodeHelper.GetTypeFromModelCode(relatedEntity)); } } foreach (DMSType type in dmsTypes) { RelatedEntityDmsTypes.Add(new DmsTypeViewModel() { DmsType = type }); } HashSet <ModelCode> referencedTypeProperties = new HashSet <ModelCode>(); if (RelatedEntityDmsTypes.Count > 0) { foreach (DmsTypeViewModel referencedDmsType in RelatedEntityDmsTypes) { foreach (ModelCode propInReferencedType in modelResourcesDesc.GetAllPropertyIds(referencedDmsType.DmsType)) { if (!referencedTypeProperties.Contains(propInReferencedType)) { referencedTypeProperties.Add(propInReferencedType); } } } } Label label = new Label() { FontWeight = FontWeights.UltraBold, Content = "Properties (for classes in selected relation)", }; PropertiesInRelated.Children.Add(label); propertiesDesc.Clear(); if (referencedTypeProperties.Count > 0) { foreach (ModelCode property in referencedTypeProperties) { if (propertiesDesc.ContainsKey(property)) { continue; } propertiesDesc.Add(property, property.ToString()); CheckBox checkBox = new CheckBox() { Content = property.ToString(), }; checkBox.Unchecked += CheckBox_Unchecked; PropertiesInRelated.Children.Add(checkBox); } CheckAllBtn.IsEnabled = true; } }
public ResourceIterator GetRelatedValues(long source, List <ModelCode> propIds, Association association) { rwLock.EnterReadLock(); try { IdentifiedObject io; if (!TryGetEntity(source, out io)) { return(null); } Property property = io.GetProperty(association.PropertyId); if (property == null) { return(null); } List <long> relatedGIDs = new List <long>(); Dictionary <DMSType, List <ModelCode> > properties = new Dictionary <DMSType, List <ModelCode> >(); DMSType associationType = ModelCodeHelper.GetTypeFromModelCode(association.Type); switch (property.Type) { case PropertyType.Reference: { long target = ((ReferenceProperty)property).Value; DMSType targetType = ModelCodeHelper.GetTypeFromGID(target); if (target == 0 || (association.Type != 0 && associationType != targetType)) { break; } relatedGIDs.Add(target); properties[targetType] = propIds; } break; case PropertyType.ReferenceVector: { List <long> targets = ((ReferencesProperty)property).Value; foreach (long target in targets) { DMSType targetType = ModelCodeHelper.GetTypeFromGID(target); if (association.Type != 0 && associationType != targetType) { continue; } relatedGIDs.Add(target); properties[targetType] = propIds; } } break; default: return(null); } return(new ResourceIterator(relatedGIDs, properties)); } finally { rwLock.ExitReadLock(); } }