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);
                    }
                }
            }
        }
        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);
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 7
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);
        }
        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);
        }
Ejemplo n.º 9
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);
        }