コード例 #1
0
        private async Task <bool> ImportDiscrete()
        {
            bool             success;
            int              numberOfResources = 1000;
            List <ModelCode> props             = modelResourceDesc.GetAllPropertyIds(ModelCode.DISCRETE);

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

                try
                {
                    int iteratorId    = gdaProxy.GetExtentValues(ModelCode.DISCRETE, 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 DiscreteSCADAModelPointItem(rds[i].Properties, ModelCode.DISCRETE, enumDescs);
                                CurrentScadaModel.Add(gid, pointItem);
                                CurrentAddressToGidMap[pointItem.RegisterType].Add(pointItem.Address, gid);
                                Logger.LogDebug($"DISCRETE measurement added to SCADA model [Gid: {gid}, Address: {pointItem.Address}]");
                            }
                        }
                        resourcesLeft = gdaProxy.IteratorResourcesLeft(iteratorId);
                    }

                    success = true;
                }
                catch (Exception ex)
                {
                    success = false;
                    string errorMessage = $"ImportDiscrete 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);
        }