private async void InitializeGlobalIdentifiers()
        {
            using (NetworkModelGDAProxy gdaProxy = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
            {
                if (gdaProxy == null)
                {
                    throw new NullReferenceException("InitializeGlobalIdentifiers => NetworkModelGDAProxy is null.");
                }

                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; //TODO: connfigurabilno

                    try
                    {
                        iteratorId    = gdaProxy.GetExtentValues(dmsTypesModelCode, propIds);
                        resourcesLeft = gdaProxy.IteratorResourcesLeft(iteratorId);

                        while (resourcesLeft > 0)
                        {
                            List <ResourceDescription> gdaResult = gdaProxy.IteratorNext(numberOfResources, iteratorId);

                            foreach (ResourceDescription rd in gdaResult)
                            {
                                Dispatcher.Invoke(() =>
                                {
                                    GlobalIdentifiers.Add(new GlobalIDBindingModel()
                                    {
                                        GID  = rd.Id,
                                        Type = dmsTypesModelCode.ToString(),
                                    });
                                });
                            }

                            resourcesLeft = gdaProxy.IteratorResourcesLeft(iteratorId);
                        }

                        gdaProxy.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);
                    }
                }
            }
        }
Example #2
0
        public 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))
            {
                using (NetworkModelGDAProxy nmsProxy = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
                {
                    if (nmsProxy == null)
                    {
                        string message = "NetworkModelGdaClient is null.";
                        Logger.LogWarn(message);
                        throw new NullReferenceException(message);
                    }

                    var result = nmsProxy.ApplyUpdate(delta);
                    updateResult = result.ToString();
                }
            }

            Thread.CurrentThread.CurrentCulture = culture;
            return(updateResult);
        }
        public async Task <List <ResourceDescription> > GetExtentValues(ModelCode entityType, List <ModelCode> propIds)
        {
            int iteratorId;

            using (NetworkModelGDAProxy gdaQueryProxy = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
            {
                if (gdaQueryProxy == null)
                {
                    string message = "GetExtentValues() => NetworkModelGDAProxy is null.";
                    Logger.LogError(message);
                    throw new NullReferenceException(message);
                }

                try
                {
                    iteratorId = gdaQueryProxy.GetExtentValues(entityType, propIds);
                }
                catch (Exception e)
                {
                    string message = $"Failed to get extent values for dms type {entityType}.";
                    Logger.LogError(message, e);
                    throw e;
                }
            }

            return(await ProcessIterator(iteratorId));
        }
        private void buttonQuery1_Click(object sender, EventArgs e)
        {
            richTextBoxOutput.Text = string.Empty;
            long             resourceID  = Convert.ToInt64(textBoxTargetGID1.Text, 16);
            List <ModelCode> propertyIDs = new List <ModelCode>();

            foreach (object selectedItem in listBoxProperties1.SelectedItems)
            {
                propertyIDs.Add((ModelCode)selectedItem);
            }
            NetworkModelGDAProxy networkModelGDAProxy = new NetworkModelGDAProxy("NetworkModelGDAEndpoint");

            try
            {
                ResourceDescription resourceDescription = networkModelGDAProxy.GetValues(resourceID, propertyIDs);
                using (StringWriter stringWriter = new StringWriter())
                {
                    using (XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter))
                    {
                        xmlTextWriter.Formatting = Formatting.Indented;
                        resourceDescription.ExportToXml(xmlTextWriter);
                    }
                    richTextBoxOutput.Text = stringWriter.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Get Values - ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #5
0
        public ResourceDescription GetValues(long globalId, List <ModelCode> properties)
        {
            string message = "Getting values method started.";

            Logger.LogInfo(message);

            ResourceDescription rd = null;

            try
            {
                using (NetworkModelGDAProxy gdaQueryProxy = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
                {
                    if (gdaQueryProxy == null)
                    {
                        string errMsg = "NetworkModelGDAProxy is null.";
                        Logger.LogWarn(errMsg);
                        throw new NullReferenceException(errMsg);
                    }

                    rd      = gdaQueryProxy.GetValues(globalId, properties);
                    message = "Getting values method successfully finished.";
                    Logger.LogInfo(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);
        }
        public async Task <List <ResourceDescription> > GetRelatedValues(long source, List <ModelCode> propIds, Association association)
        {
            int iteratorId;

            using (NetworkModelGDAProxy gdaQueryProxy = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
            {
                if (gdaQueryProxy == null)
                {
                    string message = "GetRelatedValues() => NetworkModelGDAProxy is null.";
                    Logger.LogError(message);
                    throw new NullReferenceException(message);
                }

                try
                {
                    iteratorId = gdaQueryProxy.GetRelatedValues(source, propIds, association);
                }
                catch (Exception e)
                {
                    string message = $"Failed to get related values for element with GID {source}.";
                    Logger.LogError(message, e);
                    throw e;
                }
            }

            return(await ProcessIterator(iteratorId));
        }
        public async Task <ResourceDescription> GetValues(long resourceId, List <ModelCode> propIds)
        {
            ResourceDescription resource;

            using (NetworkModelGDAProxy gdaQueryProxy = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
            {
                if (gdaQueryProxy == null)
                {
                    string message = "GetValues() => NetworkModelGDAProxy is null.";
                    Logger.LogError(message);
                    throw new NullReferenceException(message);
                }

                try
                {
                    resource = gdaQueryProxy.GetValues(resourceId, propIds);
                }
                catch (Exception e)
                {
                    string message = $"Failed to get values for elemnt with GID {resourceId}.";
                    Logger.LogError(message, e);
                    throw e;
                }
            }

            return(resource);
        }
        public bool CheckIfBreakerIsRecloser(long elementId)
        {
            bool isRecloser = false;

            try
            {
                using (NetworkModelGDAProxy gda = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
                {
                    ResourceDescription resourceDescription = gda.GetValues(elementId, new List <ModelCode>()
                    {
                        ModelCode.BREAKER_NORECLOSING
                    });

                    Property property = resourceDescription.GetProperty(ModelCode.BREAKER_NORECLOSING);

                    if (property != null)
                    {
                        isRecloser = !property.AsBool();
                    }
                    else
                    {
                        throw new Exception($"Element with id 0x{elementId:X16} is not a breaker.");
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(isRecloser);
        }
Example #9
0
        public bool ModelUpdate(AffectedEntities model)
        {
            Console.WriteLine("New update request!");
            NetworkModelGDAProxy proxy = new NetworkModelGDAProxy("NetworkModelGDAEndpoint");

            if (CeDataBase.Model == null)
            {
                CeDataBase.Model = new Dictionary <DMSType, Container>();
            }
            if (model.Insert.Count > 0)
            {
                var dataInsert = proxy.GetValues(model.Insert);
                foreach (var item in dataInsert)
                {
                    var dmsType = GetDMSType(item.GID);
                    if (!CeDataBase.Model.ContainsKey(dmsType))
                    {
                        CeDataBase.Model.Add(dmsType, new Container());
                    }
                    CeDataBase.Model[dmsType].AddEntity(item);
                }
            }

            if (model.Update.Count > 0)
            {
                var dataUpdate = proxy.GetValues(model.Update);
                foreach (var item in dataUpdate)
                {
                    var dmsType = GetDMSType(item.GID);
                    if (!CeDataBase.Model.ContainsKey(dmsType))
                    {
                        CeDataBase.Model.Add(dmsType, new Container());
                    }
                    CeDataBase.Model[dmsType].RemoveEntity(item.GID);
                    CeDataBase.Model[dmsType].AddEntity(item);
                }
            }

            if (model.Delete.Count > 0)
            {
                var dataDelete = proxy.GetValues(model.Delete);
                foreach (var item in dataDelete)
                {
                    var dmsType = GetDMSType(item.GID);
                    if (!CeDataBase.Model.ContainsKey(dmsType))
                    {
                        CeDataBase.Model.Add(dmsType, new Container());
                    }
                    CeDataBase.Model[dmsType].RemoveEntity(item.GID);
                }
            }


            //dobio si model, javi se TM-u da ucestvujes u transakciji
            EnList();
            return(true);
        }
        private void buttonQuery3_Click(object sender, EventArgs e)
        {
            richTextBoxOutput.Text = string.Empty;
            long        source      = Convert.ToInt64(textBoxSourceGID3.Text, 16);
            Association association = new Association();

            ModelCodeHelper.GetModelCodeFromString(comboBoxSourceReference3.SelectedItem.ToString(), out ModelCode propertyID);
            association.PropertyId = propertyID;
            if (comboBoxTargetType3.SelectedItem.ToString() == "ANY")
            {
                association.Type = 0;
            }
            else
            {
                ModelCodeHelper.GetModelCodeFromString(comboBoxTargetType3.SelectedItem.ToString(), out ModelCode type);
                association.Type = type;
            }
            List <ModelCode> propertyIDs = new List <ModelCode>();

            foreach (object selectedItem in listBoxProperties3.SelectedItems)
            {
                ModelCodeHelper.GetModelCodeFromString(selectedItem.ToString(), out ModelCode modelCode);
                propertyIDs.Add(modelCode);
            }
            try
            {
                NetworkModelGDAProxy networkModelGDAProxy = new NetworkModelGDAProxy("NetworkModelGDAEndpoint");
                int iteratorID    = networkModelGDAProxy.GetRelatedValues(source, propertyIDs, association);
                int resourcesLeft = networkModelGDAProxy.IteratorResourcesLeft(iteratorID);
                List <ResourceDescription> resourceDescriptions = null;
                using (StringWriter stringWriter = new StringWriter())
                    using (XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter))
                    {
                        xmlTextWriter.Formatting = Formatting.Indented;
                        while (resourcesLeft > 0)
                        {
                            resourceDescriptions = networkModelGDAProxy.IteratorNext(numberOfResources, iteratorID);
                            foreach (ResourceDescription resourceDescription in resourceDescriptions)
                            {
                                resourceDescription.ExportToXml(xmlTextWriter);
                                stringWriter.Write(stringWriter.NewLine);
                            }
                            resourcesLeft = networkModelGDAProxy.IteratorResourcesLeft(iteratorID);
                        }
                        richTextBoxOutput.Text = stringWriter.ToString();
                    }
                networkModelGDAProxy.IteratorClose(iteratorID);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Get Related Values - ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #11
0
 private Connection()
 {
     gdaProxy = new NetworkModelGDAProxy("NetworkModelGDAEndpoint");
     try
     {
         gdaProxy.Open();
     }
     catch
     {
         MessageBox.Show("Service host is not started.");
     }
 }
Example #12
0
        private async Task <bool> ImportAnalog()
        {
            bool             success;
            int              numberOfResources = 1000;
            List <ModelCode> props             = modelResourceDesc.GetAllPropertyIds(ModelCode.ANALOG);

            using (NetworkModelGDAProxy gdaProxy = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
            {
                if (gdaProxy == null)
                {
                    success = false;
                    string errMsg = "From ImportAnalog() method: NetworkModelGDAProxy is null.";
                    Logger.LogWarn(errMsg);
                }

                try
                {
                    int iteratorId    = gdaProxy.GetExtentValues(ModelCode.ANALOG, props);
                    int resourcesLeft = gdaProxy.IteratorResourcesLeft(iteratorId);

                    while (resourcesLeft > 0)
                    {
                        List <ResourceDescription> rds = gdaProxy.IteratorNext(numberOfResources, iteratorId);
                        for (int i = 0; i < rds.Count; i++)
                        {
                            if (rds[i] != null)
                            {
                                long                 gid       = rds[i].Id;
                                ModelCode            type      = modelResourceDesc.GetModelCodeFromId(gid);
                                ISCADAModelPointItem pointItem = new AnalogSCADAModelPointItem(rds[i].Properties, ModelCode.ANALOG, enumDescs);
                                CurrentScadaModel.Add(rds[i].Id, pointItem);
                                CurrentAddressToGidMap[pointItem.RegisterType].Add(pointItem.Address, rds[i].Id);

                                Logger.LogDebug($"ANALOG measurement added to SCADA model [Gid: {gid}, Address: {pointItem.Address}]");
                            }
                        }
                        resourcesLeft = gdaProxy.IteratorResourcesLeft(iteratorId);
                    }

                    success = true;
                }
                catch (Exception ex)
                {
                    success = false;
                    string errorMessage = $"ImportAnalog failed with error: {ex.Message}";
                    Console.WriteLine(errorMessage);
                    Logger.LogError(errorMessage, ex);
                }
            }

            return(success);
        }
Example #13
0
 public TestGda()
 {
     if (gdaQueryProxy == null)
     {
         gdaQueryProxy = new NetworkModelGDAProxy("NetworkModelGDAEndpoint");
         try
         {
             gdaQueryProxy.Open();
         }
         catch
         {
         }
     }
 }
Example #14
0
        public List <Equipment> CreateEquipementEntitiesFromNmsData(List <long> entityIds)
        {
            List <Equipment> equipements = new List <Equipment>();

            List <ModelCode> propIds = new List <ModelCode>()
            {
                ModelCode.IDOBJ_MRID
            };

            using (NetworkModelGDAProxy proxy = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
            {
                if (proxy == null)
                {
                    string message = "OutageModel::CreateEquipementEntitiesFromNmsData => NetworkModelGDAProxy is null";
                    Logger.LogError(message);
                    throw new NullReferenceException();
                }

                foreach (long gid in entityIds)
                {
                    ResourceDescription rd = null;

                    try
                    {
                        rd = proxy.GetValues(gid, propIds);
                    }
                    catch (Exception e)
                    {
                        //TODO: Kad prvi put ovde bude puklo, alarmirajte me. Dimitrije
                        throw e;
                    }

                    if (rd == null)
                    {
                        continue;
                    }

                    Equipment createdEquipement = new Equipment()
                    {
                        EquipmentId   = rd.Id,
                        EquipmentMRID = rd.Properties[0].AsString(),
                    };

                    equipements.Add(createdEquipement);
                }
            }

            return(equipements);
        }
Example #15
0
        private Dictionary <long, ResourceDescription> ProcessIterator(int iteratorId)
        {
            //TODO: mozda vec ovde napakovati dictionary<long, rd> ?
            int resourcesLeft;
            int numberOfResources = 10000;
            Dictionary <long, ResourceDescription> resourceDescriptions;

            using (NetworkModelGDAProxy gdaQueryProxy = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
            {
                if (gdaQueryProxy == null)
                {
                    string message = "ProcessIterator() => NetworkModelGDAProxy is null.";
                    Logger.LogError(message);
                    throw new NullReferenceException(message);
                }

                try
                {
                    resourcesLeft        = gdaQueryProxy.IteratorResourcesTotal(iteratorId);
                    resourceDescriptions = new Dictionary <long, ResourceDescription>(resourcesLeft);

                    while (resourcesLeft > 0)
                    {
                        List <ResourceDescription> resources = gdaQueryProxy.IteratorNext(numberOfResources, iteratorId);

                        foreach (ResourceDescription resource in resources)
                        {
                            resourceDescriptions.Add(resource.Id, resource);
                        }

                        resourcesLeft = gdaQueryProxy.IteratorResourcesLeft(iteratorId);
                    }

                    gdaQueryProxy.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 <List <ResourceDescription> > ProcessIterator(int iteratorId)
        {
            int resourcesLeft;
            int numberOfResources = 10000;
            List <ResourceDescription> resourceDescriptions;

            using (NetworkModelGDAProxy gdaQueryProxy = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
            {
                if (gdaQueryProxy == null)
                {
                    string message = "ProcessIterator() => NetworkModelGDAProxy is null.";
                    Logger.LogError(message);
                    throw new NullReferenceException(message);
                }

                try
                {
                    resourcesLeft        = gdaQueryProxy.IteratorResourcesTotal(iteratorId);
                    resourceDescriptions = new List <ResourceDescription>(resourcesLeft);

                    while (resourcesLeft > 0)
                    {
                        List <ResourceDescription> rds = gdaQueryProxy.IteratorNext(numberOfResources, iteratorId);
                        resourceDescriptions.AddRange(rds);

                        resourcesLeft = gdaQueryProxy.IteratorResourcesLeft(iteratorId);
                    }

                    gdaQueryProxy.IteratorClose(iteratorId);
                }
                catch (Exception e)
                {
                    string message = $"Failed to retrieve all Resourse descriptions with iterator {iteratorId}.";
                    Logger.LogError(message, e);
                    throw e;
                }
            }

            return(resourceDescriptions);
        }
Example #17
0
        private void buttonQuery2_Click(object sender, EventArgs e)
        {
            richTextBoxOutput.Text = string.Empty;
            ModelCodeHelper.GetModelCodeFromString(comboBoxTargetType2.SelectedItem.ToString(), out ModelCode entityType);
            List <ModelCode> propertyIDs = new List <ModelCode>();

            foreach (object selectedItem in listBoxProperties2.SelectedItems)
            {
                ModelCodeHelper.GetModelCodeFromString(selectedItem.ToString(), out ModelCode modelCode);
                propertyIDs.Add(modelCode);
            }
            try
            {
                NetworkModelGDAProxy networkModelGDAProxy = new NetworkModelGDAProxy("NetworkModelGDAEndpoint");
                int iteratorID    = networkModelGDAProxy.GetExtentValues(entityType, propertyIDs);
                int resourcesLeft = networkModelGDAProxy.IteratorResourcesLeft(iteratorID);
                List <ResourceDescription> resourceDescriptions = null;
                using (StringWriter stringWriter = new StringWriter())
                    using (XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter))
                    {
                        xmlTextWriter.Formatting = Formatting.Indented;
                        while (resourcesLeft > 0)
                        {
                            resourceDescriptions = networkModelGDAProxy.IteratorNext(numberOfResources, iteratorID);
                            foreach (ResourceDescription resourceDescription in resourceDescriptions)
                            {
                                resourceDescription.ExportToXml(xmlTextWriter);
                            }
                            resourcesLeft = networkModelGDAProxy.IteratorResourcesLeft(iteratorID);
                        }
                        richTextBoxOutput.Text = stringWriter.ToString();
                    }
                networkModelGDAProxy.IteratorClose(iteratorID);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Get Extent Values - ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public bool ModelUpdate(AffectedEntities model)
        {
            Console.WriteLine("New update request!");
            ScadaStorageProxy    proxy = ScadaProxyFactory.Instance().ScadaStorageProxy();
            NetworkModelGDAProxy nms   = new NetworkModelGDAProxy("NetworkModelGDAEndpoint");
            var cimModel = proxy.GetCimModel();

            if (cimModel == null)
            {
                cimModel = new Dictionary <DMSType, Container>();
            }

            model.Insert = model.Insert.Where(x => this.GetDMSType(x) == DMSType.ANALOG || this.GetDMSType(x) == DMSType.DISCRETE ||
                                              this.GetDMSType(x) == DMSType.BREAKER || this.GetDMSType(x) == DMSType.DISCONNECTOR).ToList();
            model.Update = model.Update.Where(x => this.GetDMSType(x) == DMSType.ANALOG || this.GetDMSType(x) == DMSType.DISCRETE ||
                                              this.GetDMSType(x) == DMSType.BREAKER || this.GetDMSType(x) == DMSType.DISCONNECTOR).ToList();
            model.Delete = model.Delete.Where(x => this.GetDMSType(x) == DMSType.ANALOG || this.GetDMSType(x) == DMSType.DISCRETE ||
                                              this.GetDMSType(x) == DMSType.BREAKER || this.GetDMSType(x) == DMSType.DISCONNECTOR).ToList();

            if (model.Insert.Count > 0)
            {
                var dataInsert = nms.GetValues(model.Insert);
                foreach (var item in dataInsert)
                {
                    var dmsType = GetDMSType(item.GID);
                    if (!cimModel.ContainsKey(dmsType))
                    {
                        cimModel.Add(dmsType, new Container());
                    }
                    cimModel[dmsType].AddEntity(item);
                }
            }
            if (model.Update.Count > 0)
            {
                var dataUpdate = nms.GetValues(model.Update);
                foreach (var item in dataUpdate)
                {
                    var dmsType = GetDMSType(item.GID);
                    if (!cimModel.ContainsKey(dmsType))
                    {
                        cimModel.Add(dmsType, new Container());
                    }
                    cimModel[dmsType].RemoveEntity(item.GID);
                    cimModel[dmsType].AddEntity(item);
                }
            }
            if (model.Delete.Count > 0)
            {
                var dataDelete = nms.GetValues(model.Delete);
                foreach (var item in dataDelete)
                {
                    var dmsType = GetDMSType(item.GID);
                    if (!cimModel.ContainsKey(dmsType))
                    {
                        cimModel.Add(dmsType, new Container());
                    }
                    cimModel[dmsType].RemoveEntity(item.GID);
                }
            }

            proxy.SetCimModel(cimModel);
            //dobio si model, javi se da ucestvujes u transakciji
            EnList();
            return(true);
        }
Example #19
0
        public List <long> GetExtentValues(ModelCode modelCodeType, List <ModelCode> properties, StringBuilder sb)
        {
            string message = "Getting extent values method started.";

            Logger.LogInfo(message);

            int           iteratorId;
            int           resourcesLeft;
            int           numberOfResources = 300;
            List <long>   ids    = new List <long>();
            StringBuilder tempSb = new StringBuilder();

            try
            {
                using (NetworkModelGDAProxy gdaQueryProxy = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
                {
                    if (gdaQueryProxy == null)
                    {
                        string errMsg = "NetworkModelGDAProxy is null.";
                        Logger.LogWarn(errMsg);
                        throw new NullReferenceException(errMsg);
                    }

                    iteratorId    = gdaQueryProxy.GetExtentValues(modelCodeType, properties);
                    resourcesLeft = gdaQueryProxy.IteratorResourcesLeft(iteratorId);

                    while (resourcesLeft > 0)
                    {
                        List <ResourceDescription> rds = gdaQueryProxy.IteratorNext(numberOfResources, iteratorId);

                        for (int i = 0; i < rds.Count; i++)
                        {
                            if (rds[i] != null)
                            {
                                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 = gdaQueryProxy.IteratorResourcesLeft(iteratorId);
                    }

                    gdaQueryProxy.IteratorClose(iteratorId);

                    message = "Getting extent values method successfully finished.";
                    Logger.LogInfo(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);
        }
Example #20
0
 public ClientNMSService()
 {
     modelResourcesDesc = new ModelResourcesDesc();
     gdaQueryProxy      = new NetworkModelGDAProxy("NetworkModelGDAEndpoint");
 }
        private bool PopulateNmsDataFromServer(ModelResourcesDesc resourcesDesc)
        {
            bool   success = false;
            string message = "Getting nms data from server started.";

            Logger.LogInfo(message);

            using (NetworkModelGDAProxy nmsProxy = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
            {
                if (nmsProxy == null)
                {
                    string errMessage = "NetworkModelGdaClient is null.";
                    Logger.LogWarn(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;                     //TODO: connfigurabilno

                    try
                    {
                        iteratorId    = nmsProxy.GetExtentValues(modelCodeType, mrIdProp);
                        resourcesLeft = nmsProxy.IteratorResourcesLeft(iteratorId);

                        while (resourcesLeft > 0)
                        {
                            List <ResourceDescription> gdaResult = nmsProxy.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 = nmsProxy.IteratorResourcesLeft(iteratorId);
                        }

                        nmsProxy.IteratorClose(iteratorId);

                        message = "Getting nms data from server successfully finished.";
                        Logger.LogInfo(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);
        }
Example #22
0
        private async Task <Dictionary <long, ISCADAModelPointItem> > CreatePointItemsFromNetworkModelMeasurements()
        {
            Dictionary <long, ISCADAModelPointItem> pointItems = new Dictionary <long, ISCADAModelPointItem>();

            using (NetworkModelGDAProxy gdaProxy = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
            {
                if (gdaProxy == null)
                {
                    string message = "From method CreatePointItemsFromNetworkModelMeasurements(): NetworkModelGDAProxy is null.";
                    Logger.LogWarn(message);
                    throw new NullReferenceException(message);
                }

                //ModelCode type;

                int iteratorId;
                int resourcesLeft;
                int numberOfResources = 10000;

                List <ModelCode> props;

                //TOOD: change service contract IModelUpdateNotificationContract to receive types of all changed elements from NMS
                HashSet <ModelCode> changedTypes = new HashSet <ModelCode>();
                foreach (List <long> gids in ModelChanges.Values)
                {
                    foreach (long gid in gids)
                    {
                        ModelCode type = modelResourceDesc.GetModelCodeFromId(gid);

                        if (!changedTypes.Contains(type))
                        {
                            changedTypes.Add(type);
                        }
                    }
                }

                foreach (ModelCode type in changedTypes)
                {
                    if (type != ModelCode.ANALOG && type != ModelCode.DISCRETE)
                    {
                        continue;
                    }

                    props = modelResourceDesc.GetAllPropertyIds(type);

                    try
                    {
                        iteratorId    = gdaProxy.GetExtentValues(type, props);
                        resourcesLeft = gdaProxy.IteratorResourcesLeft(iteratorId);

                        while (resourcesLeft > 0)
                        {
                            List <ResourceDescription> resources = gdaProxy.IteratorNext(numberOfResources, iteratorId);

                            foreach (ResourceDescription rd in resources)
                            {
                                if (pointItems.ContainsKey(rd.Id))
                                {
                                    string message = $"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[DeltaOpType.Update].Contains(rd.Id) || ModelChanges[DeltaOpType.Insert].Contains(rd.Id))
                                {
                                    point = CreatePointItemFromResource(rd);
                                    pointItems.Add(rd.Id, point);
                                }
                            }

                            resourcesLeft = gdaProxy.IteratorResourcesLeft(iteratorId);
                        }

                        gdaProxy.IteratorClose(iteratorId);
                    }
                    catch (Exception ex)
                    {
                        string errorMessage = $"CreatePointItemsFromNetworkModelMeasurements failed with error: {ex.Message}";
                        Console.WriteLine(errorMessage);
                        Logger.LogError(errorMessage, ex);
                    }
                }
            }

            return(pointItems);
        }