public static List <AbstractRetrievePoints> LoadTagClassesRecorded(
            String inputFilePath,
            String outputDirectory,
            String timeResolution,
            int numYears,
            int pageSize,
            PIServer piServer,
            PISystem piSystem,
            int numParallelTasks,
            Logger logger)
        {
            var inputLines = LoadInputFile(inputFilePath);

            List <AbstractRetrievePoints> tagClasses = new List <AbstractRetrievePoints>();

            Parallel.ForEach(
                inputLines,
                new ParallelOptions {
                MaxDegreeOfParallelism = numParallelTasks
            },
                (String[] line) =>
            {
                string tagName         = line[0];
                string startTimeString = line[1];
                string endTimeString   = line[2];

                PIPoint tag;
                try
                {
                    tag = PIPoint.FindPIPoint(piServer, tagName);
                    AFTime startTime      = new AFTime(startTimeString);
                    AFTime endTime        = new AFTime(endTimeString);
                    AFTimeRange timeRange = new AFTimeRange(startTime, endTime);

                    string startTimeStamp = startTime.UtcTime.ToString("yyyy/MM/dd HH:mm:ss");
                    string endTimeStamp   = endTime.UtcTime.ToString("yyyy/MM/dd HH:mm:ss");
                    lock (logger) { logger.Log($"{startTimeStamp} : {endTimeStamp}, {tagName}"); }
                    lock (tagClasses)
                    {
                        tagClasses.Add(new PIRecordedPointRetrievalClass(
                                           tag,
                                           timeRange,
                                           outputDirectory,
                                           PIRandomFunctionsUtil.ParseTimeResolutionString(timeResolution),
                                           numYears,
                                           pageSize,
                                           logger));
                    }
                }
                catch (Exception e)
                {
                    logger.Log("Exception: could not FindPiPoint: " + e.ToString());
                }
            });

            return(tagClasses);
        }
Пример #2
0
        override public void WriteNextResult()
        {
            try
            {
                values = valuesTask.Result;
            }
            catch (PITimeoutException)
            {
                fetchNextPage = true;
                exceptionCount++;
                if (exceptionCount > 10)
                {
                    throw new Exception("EXCEPTION: Too many retries: " + this.tag.Name);
                }
                return;
            }

            string nextStartTimeStamp = nextStartTime.UtcTime.ToString("yyyy/MM/dd HH:mm:ss");
            string nextEndTimeStamp   = timeRange.EndTime.UtcTime.ToString("yyyy/MM/dd HH:mm:ss");

            lock (logger)
            {
                logger.Log($"{k}, {nextStartTimeStamp} : {nextEndTimeStamp}, {values.Count}, {tag.Name}");
            }
            k++;

            for (int i = skipCount; i < values.Count; i++)
            {
                string datePath = PIRandomFunctionsUtil.DateTimeToDatePath(values[i].Timestamp, timeResolution, numYears);
                if (outputStreamWriter == null || lastDatePath != datePath)
                {
                    string outputPath = Path.Combine(outputDirectory, datePath, tag.Name);
                    Directory.CreateDirectory(new FileInfo(outputPath).Directory.FullName);
                    if (outputStreamWriter != null)
                    {
                        outputStreamWriter.Close();
                    }
                    outputStreamWriter = new StreamWriter(outputPath);
                    lastDatePath       = datePath;
                }
                outputStreamWriter.WriteLine($"{values[i].Timestamp.UtcTime.ToString("o")},{values[i].Value}");
            }

            fetchNextPage = values.Count >= pageSize;
            if (fetchNextPage)
            {
                int lastIndex = values.Count - 1;
                skipCount     = 1;
                nextStartTime = values[lastIndex].Timestamp;
                for (int i = lastIndex - 1; i >= 0; --i)
                {
                    if (values[i].Timestamp == nextStartTime)
                    {
                        ++skipCount;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (!fetchNextPage)
            {
                this.Close();
                lock (closedLock) { closed = true; }
            }
        }
        public static List <AbstractRetrievePoints> LoadAttributeClassesRecorded(
            String inputFilePath,
            String outputDirectory,
            String timeResolution,
            int numYears,
            int pageSize,
            PIServer piServer,
            PISystem piSystem,
            AFDatabase database,
            int numParallelTasks,
            Logger logger)
        {
            var inputLines = new List <String[]>();

            using (var inputStreamReader = new StreamReader(inputFilePath))
            {
                while (!inputStreamReader.EndOfStream)
                {
                    inputLines.Add(inputStreamReader.ReadLine().Split(','));
                }
            }

            List <AbstractRetrievePoints> tagClasses = new List <AbstractRetrievePoints>();

            Parallel.ForEach(
                inputLines,
                new ParallelOptions {
                MaxDegreeOfParallelism = numParallelTasks
            },
                (String[] line) =>
            {
                string tagName         = line[0];
                string startTimeString = line[1];
                string endTimeString   = line[2];

                PIPoint tag;
                try
                {
                    AFAttribute attribute = AFUtil.FindAttribute(database, tagName);
                    tag = attribute.PIPoint;

                    AFTime startTime      = new AFTime(startTimeString);
                    AFTime endTime        = new AFTime(endTimeString);
                    AFTimeRange timeRange = new AFTimeRange(startTime, endTime);

                    string startTimeStamp = startTime.UtcTime.ToString("yyyy/MM/dd HH:mm:ss");
                    string endTimeStamp   = endTime.UtcTime.ToString("yyyy/MM/dd HH:mm:ss");
                    lock (logger) { logger.Log($"{startTimeStamp} : {endTimeStamp}, {tagName}"); }
                    lock (tagClasses)
                    {
                        tagClasses.Add(new AFRecordedAttributeRetrievalClass(
                                           attribute,
                                           timeRange,
                                           outputDirectory,
                                           PIRandomFunctionsUtil.ParseTimeResolutionString(timeResolution),
                                           numYears,
                                           pageSize,
                                           logger));
                    }
                }
                catch (Exception e)
                {
                    logger.Log("Exception: could not FindPiPoint: " + e.ToString());
                }
            });

            return(tagClasses);
        }
        public static List <AbstractRetrievePoints> LoadTagClassesInterpolated(
            String inputFilePath,
            String outputDirectory,
            String timeResolution,
            int numYears,
            int pageSize,
            PIServer piServer,
            PISystem piSystem,
            int numParallelTasks,
            Logger logger)
        {
            var inputLines = new List <String[]>();

            using (var inputStreamReader = new StreamReader(inputFilePath))
            {
                while (!inputStreamReader.EndOfStream)
                {
                    inputLines.Add(inputStreamReader.ReadLine().Split(','));
                }
            }

            List <AbstractRetrievePoints> tagClasses = new List <AbstractRetrievePoints>();

            Parallel.ForEach(
                inputLines,
                new ParallelOptions {
                MaxDegreeOfParallelism = numParallelTasks
            },
                (String[] line) =>
            {
                string tagName         = line[0];
                string startTimeString = line[1];
                string endTimeString   = line[2];
                string intervalString  = line[3];

                PIPoint tag;
                try
                {
                    tag = PIPoint.FindPIPoint(piServer, tagName);

                    AFTime startTime = new AFTime(startTimeString);
                    AFTime nextTime  = AFQueryUtil.GetNextRecordedValue(tag, startTime).Timestamp;
                    if (nextTime > startTime)
                    {
                        startTime = new AFTime(nextTime.UtcTime.Date);
                    }
                    AFTime endTime        = new AFTime(endTimeString);
                    AFTimeRange timeRange = new AFTimeRange(startTime, endTime);
                    AFTimeSpan timeSpan   = new AFTimeSpan(TimeSpan.FromSeconds(Int32.Parse(intervalString)));

                    string startTimeStamp = startTime.UtcTime.ToString("yyyy/MM/dd HH:mm:ss");
                    string endTimeStamp   = endTime.UtcTime.ToString("yyyy/MM/dd HH:mm:ss");
                    lock (logger) { logger.Log($"{startTimeStamp} : {timeSpan} : {endTimeStamp}, {tagName}"); }

                    lock (tagClasses)
                    {
                        tagClasses.Add(new PIInterpolatedPointRetrievalClass(
                                           tag,
                                           timeRange,
                                           timeSpan,
                                           outputDirectory,
                                           PIRandomFunctionsUtil.ParseTimeResolutionString(timeResolution),
                                           numYears,
                                           pageSize,
                                           logger));
                    }
                }
                catch (Exception e)
                {
                    logger.Log("Exception: could not FindPiPoint: " + e.ToString());
                }
            });

            return(tagClasses);
        }