Пример #1
0
        }//LoadPIPointsFromFile

        private static AFKeyedResults <string, PIPoint> LoadPIPointsFromServer(ServerType serverType)
        {
            //This method pulls a list of PI points from the designated server
            List <string> lstPIPoints_from_File = new List <string>();
            bool          isDestination         = false;

            //Load the points from the point configuration file
            switch (serverType)
            {
            case ServerType.Source:
                lstPIPoints_from_File = PIPoints_from_File.Select(x => @"\\" + ConfigurationParameters.SourcePIDataArchive.Name + @"\" + x).ToList();
                break;

            case ServerType.Destination:
                lstPIPoints_from_File = PIPoints_from_File.Select(x => @"\\" + ConfigurationParameters.DestinationPIDataArchive.Name + @"\" + x).ToList();
                isDestination         = true;
                break;
            }

            //Load the points from the target PI Data Archive
            AFKeyedResults <string, PIPoint> findPointsResult = PIPoint.FindPIPointsByPath(lstPIPoints_from_File);

            //Perform error checking/logging
            CheckPIPointsForErrors(findPointsResult, isDestination);

            return(findPointsResult);
        }//LoadPIPointsFromServer
Пример #2
0
        public static HashSet <AFAttribute> GetValidPIPointAttributes(this IList <AFAttribute> attributes)
        {
            var subset = GetPIPointAttributes(attributes);

            if (subset.Count == 0)
            {
                return(new HashSet <AFAttribute>());
            }

            // Populate found before entering parallel loops so that
            // we can avoid some concurrency issues up-front.
            var found = subset.ToDictionary(key => key, value => false);

            var threadCount = 10;
            var chunkSize   = 1000;
            var chunks      = Partitioner.Create(0, subset.Count, chunkSize);

            // NOTE: OSIsoft recommends you always set MaxDegreeOfParallelism.
            var options = new ParallelOptions();

            options.MaxDegreeOfParallelism = threadCount;

            Parallel.ForEach(chunks, options, chunk =>
            {
                var inclusiveStartIndex = chunk.Item1;
                var exclusiveEndIndex   = chunk.Item2;
                // Gather paths for this chunk.
                var paths = new Dictionary <AFAttribute, string>();
                for (var i = inclusiveStartIndex; i < exclusiveEndIndex; i++)
                {
                    var path = subset[i].RawPIPointPath(AFEncodeType.Name);
                    if (!string.IsNullOrWhiteSpace(path))
                    {
                        path = path.ToUpperInvariant();
                    }
                    paths.Add(subset[i], path);
                }
                // Query PI Server(s) - Issue bulk call for this chunk
                var queryPaths = paths.Values.Where(x => (string.IsNullOrWhiteSpace(x) == false));
                var validated  = PIPoint.FindPIPointsByPath(queryPaths).Results;
                // Try to map back to found dictionary
                for (var i = inclusiveStartIndex; i < exclusiveEndIndex; i++)
                {
                    var attribute = subset[i];
                    var path      = paths[attribute];
                    if (!string.IsNullOrWhiteSpace(path) && validated.ContainsKey(path))
                    {
                        // The PIPoint should be in our cache thanks to FindPIPointsByPath().
                        found[attribute] = true;
                    }
                }
            });

            // return result could be smaller than 'subset' which could be smaller than input 'attributes'.
            return(new HashSet <AFAttribute>(found.Where(x => (x.Value == true)).Select(x => x.Key)));
        }