示例#1
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);
        }
示例#2
0
        private ISCADAModelPointItem CreatePointItemFromResource(ResourceDescription resource)
        {
            long      gid  = resource.Id;
            ModelCode type = modelResourceDesc.GetModelCodeFromId(gid);

            ISCADAModelPointItem pointItem;

            if (type == ModelCode.ANALOG)
            {
                pointItem = new AnalogSCADAModelPointItem(resource.Properties, type, enumDescs);
            }
            else if (type == ModelCode.DISCRETE)
            {
                pointItem = new DiscreteSCADAModelPointItem(resource.Properties, type, enumDescs);
            }
            else
            {
                string errMessage = $"ResourceDescription type is neither analog nor digital. Type: {type}.";
                Logger.LogWarn(errMessage);
                pointItem = null;
            }

            return(pointItem);
        }