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);
                    }
                }
            }
        }
        private List <ModelCode> GetAllReferenceProperties(DMSType type)
        {
            List <ModelCode> properties = new List <ModelCode>();

            if (!ReferenceProperties.TryGetValue(type, out properties))
            {
                logger.LogWarn($"[NMSManager] DMSType {type.ToString()} does not have declared reference properties.");
            }

            return(properties);
        }
Exemplo n.º 3
0
        public List <long> FindIds(DMSType chosenDMSType)
        {
            ModelCode mc;

            ModelCodeHelper.GetModelCodeFromString(chosenDMSType.ToString(), out mc);
            List <ModelCode>           properties = Connection.Connection.Instance().ModelResourceDesc.GetAllPropertyIds(chosenDMSType);
            List <ResourceDescription> rds        = Connection.Connection.Instance().GetExtentValues(mc, properties);

            List <long> ids = new List <long>();

            foreach (ResourceDescription rd in rds)
            {
                ids.Add(rd.Id);
            }

            return(ids);
        }
Exemplo n.º 4
0
        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>());
        }
Exemplo n.º 5
0
 /// <summary>
 /// Gets ModelCode from DMSType
 /// </summary>
 /// <param name="type">DMSType</param>
 /// <returns>ModelCode</returns>
 private ModelCode GetModelCodeFromTypeForCore(DMSType type)
 {
     return((ModelCode)Enum.Parse(typeof(ModelCode), type.ToString()));
 }
Exemplo n.º 6
0
        private void Initialize()
        {
            // populating model type and property descriptions
            this.resourceDescs = new Dictionary <long, ResourcePropertiesDesc>();

            ResourcePropertiesDesc desc = null;

            InitializeTypeIdsInInsertOrder();

            //// Initialize metadata for core entities
            InitializeNotSettablePropertyIds();

            foreach (ModelCode code in Enum.GetValues(typeof(ModelCode)))
            {
                allModelCodes.Add(code);
            }

            foreach (DMSType type in Enum.GetValues(typeof(DMSType)))
            {
                allDMSTypes.Add(type);
            }

            #region get all class model codes from core

            //// Get all class model codes for all services and for all classes, abstract or not. Extensibility included
            List <ModelCode> classIds = new List <ModelCode>();
            foreach (ModelCode code in allModelCodes)
            {
                // don't insert attribute codes
                if (((long)code & (long)ModelCodeMask.MASK_ATTRIBUTE_TYPE) == 0)
                {
                    classIds.Add(code);
                }
            }

            #endregion get all class model codes from core

            #region Initialize non abstract class and resourceDescription map from core

            foreach (ModelCode classId in classIds)
            {
                //// Initialize leafs
                if (((long)classId & (long)ModelCodeMask.MASK_TYPE) != 0)
                {
                    nonAbstractClassIds.Add(classId);
                }

                //// Initialize resourceDescription map
                desc = this.AddResourceDesc(classId);
                long classIdMask = unchecked ((long)0xffffffff00000000);

                foreach (ModelCode propertyId in allModelCodes)
                {
                    PropertyType propertyType = Property.GetPropertyType(propertyId);

                    if (propertyType == 0)
                    {
                        continue;
                    }

                    if (((long)propertyId & classIdMask) == ((long)classId & classIdMask))
                    {
                        if (!desc.PropertyExists(propertyId))
                        {
                            desc.AddPropertyId(propertyId);
                        }
                    }
                }
            }

            #endregion Initialize non abstract class and resourceDescription map from core

            #region Initialize type 2 model code map

            //// Model codes names from enum, these are only names for core model codes
            string[] modelCodeNamesFromCore = Enum.GetNames(typeof(ModelCode));

            classIds = new List <ModelCode>();
            foreach (ModelCode code in allModelCodes)
            {
                // don't insert attribute codes
                if (((long)code & (long)ModelCodeMask.MASK_ATTRIBUTE_TYPE) == 0)
                {
                    classIds.Add(code);
                }
            }

            //// Initialize DMSType 2 ModelCode map
            foreach (DMSType t in allDMSTypes)
            {
                DMSType type = t & DMSType.MASK_TYPE;

                ////  if DMSType is not addad and it is not mask
                if (!this.type2modelCode.ContainsKey(type) && type != DMSType.MASK_TYPE)
                {
                    //// DMSTypes that have same name as appropriete model code
                    if (modelCodeNamesFromCore.Contains(type.ToString()))
                    {
                        this.type2modelCode[type] = GetModelCodeFromTypeForCore(type);
                    }
                    else // for DMSTypes which don't have it's ModelCode with same name or are not in core
                    {
                        try // for DMSTypes which have it's ModelCode but with different name
                        {
                            foreach (ModelCode classId in classIds)
                            {
                                if (GetTypeFromModelCode(classId) == type)
                                {
                                    this.type2modelCode[type] = classId;
                                    break;
                                }
                            }
                        }
                        catch { }
                    }
                }
            }

            #endregion Initialize type 2 model code map
        }
        private ITopologyElement GetPopulatedElement(ResourceDescription rs)
        {
            string           errorMessage    = $"[NMSManager] Failed to populate element with GID 0x{rs.Id:X16}. ";
            ITopologyElement topologyElement = new TopologyElement(rs.Id);

            try
            {
                DMSType type = GetDMSTypeOfTopologyElement(rs.Id);
                topologyElement.Mrid        = rs.GetProperty(ModelCode.IDOBJ_MRID).AsString();
                topologyElement.Name        = rs.GetProperty(ModelCode.IDOBJ_NAME).AsString();
                topologyElement.Description = rs.GetProperty(ModelCode.IDOBJ_DESCRIPTION).AsString();
                topologyElement.DmsType     = type.ToString();

                if (rs.ContainsProperty(ModelCode.CONDUCTINGEQUIPMENT_ISREMOTE))
                {
                    topologyElement.IsRemote = rs.GetProperty(ModelCode.CONDUCTINGEQUIPMENT_ISREMOTE).AsBool();
                }
                else
                {
                    topologyElement.IsRemote = false;
                }

                if (rs.ContainsProperty(ModelCode.BREAKER_NORECLOSING))
                {
                    topologyElement.NoReclosing = rs.GetProperty(ModelCode.BREAKER_NORECLOSING).AsBool();
                    if (!topologyElement.NoReclosing)
                    {
                        topologyElement = new Recloser(topologyElement);
                    }
                }
                else
                {
                    topologyElement.NoReclosing = true;
                }

                if (rs.ContainsProperty(ModelCode.CONDUCTINGEQUIPMENT_BASEVOLTAGE))
                {
                    long baseVoltageGid = rs.GetProperty(ModelCode.CONDUCTINGEQUIPMENT_BASEVOLTAGE).AsLong();
                    if (BaseVoltages.TryGetValue(baseVoltageGid, out float voltage))
                    {
                        topologyElement.NominalVoltage = voltage;
                    }
                    else if (baseVoltageGid == 0)
                    {
                        logger.LogError($"{errorMessage} BaseVoltage with GID 0x{baseVoltageGid.ToString("X16")} does not exist in baseVoltages collection.");
                    }
                }
                else
                {
                    topologyElement.NominalVoltage = 0;
                }

                if (rs.ContainsProperty(ModelCode.BREAKER_NORECLOSING) && !rs.GetProperty(ModelCode.BREAKER_NORECLOSING).AsBool())
                {
                    Reclosers.Add(topologyElement.Id);
                }

                if (rs.ContainsProperty(ModelCode.ENERGYCONSUMER_TYPE))
                {
                    topologyElement = new EnergyConsumer(topologyElement)
                    {
                        Type = (EnergyConsumerType)rs.GetProperty(ModelCode.ENERGYCONSUMER_TYPE).AsEnum()
                    };
                }

                if (type == DMSType.SYNCHRONOUSMACHINE)
                {
                    topologyElement = new SynchronousMachine(topologyElement);

                    if (rs.ContainsProperty(ModelCode.SYNCHRONOUSMACHINE_CAPACITY))
                    {
                        ((SynchronousMachine)topologyElement).Capacity = rs.GetProperty(ModelCode.SYNCHRONOUSMACHINE_CAPACITY).AsFloat();
                    }

                    if (rs.ContainsProperty(ModelCode.SYNCHRONOUSMACHINE_CURRENTREGIME))
                    {
                        ((SynchronousMachine)topologyElement).CurrentRegime = rs.GetProperty(ModelCode.SYNCHRONOUSMACHINE_CURRENTREGIME).AsFloat();
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogError($"{errorMessage} Could not get all properties.Excepiton message: {ex.Message}");
            }
            return(topologyElement);
        }
        private async Task <ITopologyElement> GetPopulatedElement(ResourceDescription rs)
        {
            string verboseMessage = $"{baseLogString} entering GetPopulatedElement method.";

            Logger.LogVerbose(verboseMessage);

            ITopologyElement topologyElement = new TopologyElement(rs.Id);

            try
            {
                DMSType type = GetDMSTypeOfTopologyElement(rs.Id);
                topologyElement.Mrid        = rs.GetProperty(ModelCode.IDOBJ_MRID).AsString();
                topologyElement.Name        = rs.GetProperty(ModelCode.IDOBJ_NAME).AsString();
                topologyElement.Description = rs.GetProperty(ModelCode.IDOBJ_DESCRIPTION).AsString();
                topologyElement.DmsType     = type.ToString();

                if (rs.ContainsProperty(ModelCode.CONDUCTINGEQUIPMENT_ISREMOTE))
                {
                    topologyElement.IsRemote = rs.GetProperty(ModelCode.CONDUCTINGEQUIPMENT_ISREMOTE).AsBool();
                }
                else
                {
                    topologyElement.IsRemote = false;
                }

                if (rs.ContainsProperty(ModelCode.BREAKER_NORECLOSING))
                {
                    topologyElement.NoReclosing = rs.GetProperty(ModelCode.BREAKER_NORECLOSING).AsBool();
                    if (!topologyElement.NoReclosing)
                    {
                        topologyElement = new Recloser(topologyElement);
                    }
                }
                else
                {
                    topologyElement.NoReclosing = true;
                }

                if (rs.ContainsProperty(ModelCode.CONDUCTINGEQUIPMENT_BASEVOLTAGE))
                {
                    long baseVoltageGid = rs.GetProperty(ModelCode.CONDUCTINGEQUIPMENT_BASEVOLTAGE).AsLong();

                    var voltageResult = await BaseVoltages.TryGetValueAsync(baseVoltageGid);

                    if (voltageResult.HasValue)
                    {
                        topologyElement.NominalVoltage = voltageResult.Value;
                    }
                    else if (baseVoltageGid == 0)
                    {
                        Logger.LogError($"{baseLogString} GetPopulatedElement => BaseVoltage with GID {baseVoltageGid:X16} does not exist in baseVoltages collection.");
                    }
                }
                else
                {
                    topologyElement.NominalVoltage = 0;
                }

                if (rs.ContainsProperty(ModelCode.BREAKER_NORECLOSING) && !rs.GetProperty(ModelCode.BREAKER_NORECLOSING).AsBool())
                {
                    var reclosersResult = await Reclosers.TryGetValueAsync(ReliableDictionaryNames.Reclosers);

                    if (reclosersResult.HasValue)
                    {
                        var reclosers = reclosersResult.Value;
                        reclosers.Add(topologyElement.Id);

                        await Reclosers.SetAsync(ReliableDictionaryNames.Reclosers, reclosers);
                    }
                    else
                    {
                        Logger.LogWarning($"{baseLogString} Reliable collection '{ReliableDictionaryNames.Reclosers}' was not defined yet. Handling...");
                        await Reclosers.SetAsync(ReliableDictionaryNames.Reclosers, new HashSet <long>() { topologyElement.Id });
                    }
                }

                if (rs.ContainsProperty(ModelCode.ENERGYCONSUMER_TYPE))
                {
                    topologyElement = new EnergyConsumer(topologyElement)
                    {
                        Type = (EnergyConsumerType)rs.GetProperty(ModelCode.ENERGYCONSUMER_TYPE).AsEnum()
                    };
                }

                if (type == DMSType.SYNCHRONOUSMACHINE)
                {
                    topologyElement = new SynchronousMachine(topologyElement);

                    if (rs.ContainsProperty(ModelCode.SYNCHRONOUSMACHINE_CAPACITY))
                    {
                        ((SynchronousMachine)topologyElement).Capacity = rs.GetProperty(ModelCode.SYNCHRONOUSMACHINE_CAPACITY).AsFloat();
                    }

                    if (rs.ContainsProperty(ModelCode.SYNCHRONOUSMACHINE_CURRENTREGIME))
                    {
                        ((SynchronousMachine)topologyElement).CurrentRegime = rs.GetProperty(ModelCode.SYNCHRONOUSMACHINE_CURRENTREGIME).AsFloat();
                    }
                }
            }
            catch (Exception e)
            {
                Logger.LogError($"{baseLogString} GetPopulatedElement => Could not get all properties." +
                                $"{Environment.NewLine}Excepiton message: {e.Message}" +
                                $"{Environment.NewLine} Stack trace: {e.StackTrace}");
            }
            return(topologyElement);
        }
        private List <ModelCode> GetAllReferenceProperties(DMSType type)
        {
            string verboseMessage = $"{baseLogString} entering GetAllReferenceProperties method.";

            Logger.LogVerbose(verboseMessage);

            List <ModelCode> properties = new List <ModelCode>();

            if (!ReferenceProperties.TryGetValue(type, out properties))
            {
                Logger.LogError($"{baseLogString} GetAllReferenceProperties => DMSType {type.ToString()} does not have declared reference properties.");
            }

            return(properties);
        }