Esempio n. 1
0
        /// <summary>
        /// This is a custom implementation of AF SDK's CreateConfig() that does not require a 1-by-1 element check out/in.
        /// Create PI Points according to configstring values.
        /// Modify the configstring afterward by stripping off the trailing key-value pairs.
        /// </summary>
        private void CreatePIPoints()
        {
            EventHandler <AFProgressEventArgs> PIPointCreationEventHandler = new EventHandler <AFProgressEventArgs>(NotifyPIPointCreationToConsole);

            AFElements leafElements = _afContext.Database.Elements["LeafElements"].Elements;
            OrderablePartitioner <Tuple <int, int> > rangePartition = Partitioner.Create(0, _conf.TotalLeafs, _conf.PointsChunkSize / 2);

            Parallel.ForEach(rangePartition, new ParallelOptions {
                MaxDegreeOfParallelism = _conf.MaxParallel
            }, range =>
            {
                List <AFElement> chunk = new List <AFElement>();
                for (int i = range.Item1; i < range.Item2; i++)
                {
                    chunk.Add(leafElements[i]);
                }

                ElementCreator.CreateorUpdatePIPointDataReference(chunk, PIPointCreationEventHandler);
            });
        }