示例#1
0
        private List <TimeSeriesPoint> GetPoints()
        {
            if (DeleteCommands.Contains(Context.Command))
            {
                return(new List <TimeSeriesPoint>());
            }

            if (Context.ManualPoints.Any())
            {
                return(Context.ManualPoints);
            }

            if (Context.SourceTimeSeries != null)
            {
                return(new ExternalPointsReader(Context)
                       .LoadPoints());
            }

            if (Context.CsvFiles.Any())
            {
                return(new CsvReader(Context)
                       .LoadPoints());
            }

            if (!string.IsNullOrEmpty(Context.WaveFormTextX) || !string.IsNullOrEmpty(Context.WaveFormTextY))
            {
                return(new TextGenerator(Context)
                       .GeneratePoints());
            }

            return(new WaveformGenerator(Context)
                   .GeneratePoints());
        }
示例#2
0
        private TimeSeriesIdentifier CreateTimeSeriesIdentifier()
        {
            if (Context.SourceTimeSeries != null)
            {
                return(Context.SourceTimeSeries);
            }

            if (!string.IsNullOrEmpty(Context.TimeSeries))
            {
                return(TimeSeriesIdentifierParser.ParseExtendedIdentifier(Context.TimeSeries));
            }

            string parameter;
            var    label = "Points";
            var    locationIdentifier = "PointZilla";

            if (DeleteCommands.Contains(Context.Command))
            {
                parameter = "Deleted";
            }

            else if (Context.ManualPoints.Any())
            {
                parameter = "ManuallyEntered";
            }
            else if (Context.CsvFiles.Any())
            {
                parameter = "OtherCsvFile";
            }
            else
            {
                parameter = Context.WaveformType.ToString();
            }

            return(new TimeSeriesIdentifier
            {
                Parameter = parameter,
                Label = label,
                LocationIdentifier = locationIdentifier,
                Identifier = $"{parameter}.{label}@{locationIdentifier}"
            });
        }
示例#3
0
        public void AppendPoints()
        {
            Log.Info(Context.ExecutingFileVersion);

            Points = GetPoints();

            if (Points.All(p => p.Type != PointType.Gap))
            {
                Points = Points
                         .OrderBy(p => p.Time)
                         .ToList();
            }

            ThrowIfInvalidGapInterval();

            AdjustGradesAndQualifiers(Points);

            if (!string.IsNullOrEmpty(Context.SaveCsvPath))
            {
                new CsvWriter(Context)
                .WritePoints(Points);

                if (Context.StopAfterSavingCsv)
                {
                    return;
                }
            }

            Log.Info($"Connecting to {Context.Server} ...");

            using (var client = CreateConnectedClient())
            {
                Log.Info($"Connected to {Context.Server} ({client.ServerVersion})");

                ThrowIfGapsNotSupported(client);

                if (Context.CreateMode != CreateMode.Never)
                {
                    new TimeSeriesCreator
                    {
                        Context = Context,
                        Client  = client
                    }.CreateMissingTimeSeries(Context.TimeSeries);
                }

                var timeSeries = client.GetTimeSeriesInfo(Context.TimeSeries);

                var isReflected  = Context.Command == CommandType.Reflected || timeSeries.TimeSeriesType == TimeSeriesType.Reflected;
                var hasTimeRange = isReflected || DeleteCommands.Contains(Context.Command) || Context.Command == CommandType.OverwriteAppend;

                var pointExtents = Points.Any()
                    ? $" [{Points.First().Time} to {Points.Last().Time}]"
                    : "";

                Log.Info(Context.Command == CommandType.DeleteAllPoints
                    ? $"Deleting all existing points from {timeSeries.Identifier} ({timeSeries.TimeSeriesType}) ..."
                    : hasTimeRange
                        ? $"Appending {"point".ToQuantity(Points.Count)} {pointExtents} within TimeRange={GetTimeRange()} to {timeSeries.Identifier} ({timeSeries.TimeSeriesType}) ..."
                        : $"Appending {"point".ToQuantity(Points.Count)} {pointExtents} to {timeSeries.Identifier} ({timeSeries.TimeSeriesType}) ...");

                var numberOfPointsAppended = 0;
                var numberOfPointsDeleted  = 0;
                var stopwatch = Stopwatch.StartNew();

                var pointBatches = GetPointBatches(Points).ToList();
                var isBatched    = pointBatches.Count > 1;
                var batchIndex   = 1;

                foreach (var batch in pointBatches)
                {
                    if (isBatched)
                    {
                        var batchSummary =
                            $"Appending batch #{batchIndex}: {"point".ToQuantity(batch.Points.Count)} [{batch.Points.First().Time} to {batch.Points.Last().Time}]";

                        Log.Info(hasTimeRange
                            ? $"{batchSummary} within TimeRange={batch.TimeRange} ..."
                            : $"{batchSummary} ...");
                    }

                    var result = AppendPointBatch(client, timeSeries, batch.Points, batch.TimeRange, isReflected, hasTimeRange);
                    numberOfPointsAppended += result.NumberOfPointsAppended;
                    numberOfPointsDeleted  += result.NumberOfPointsDeleted;
                    ++batchIndex;

                    if (result.AppendStatus != AppendStatusCode.Completed)
                    {
                        throw new ExpectedException($"Unexpected append status={result.AppendStatus}");
                    }
                }

                var batchText = isBatched ? $" using {"append".ToQuantity(pointBatches.Count)}" : "";
                Log.Info($"Appended {"point".ToQuantity(numberOfPointsAppended)} (deleting {"point".ToQuantity(numberOfPointsDeleted)}) in {stopwatch.ElapsedMilliseconds / 1000.0:F1} seconds{batchText}.");
            }
        }
        public void AppendPoints()
        {
            Log.Info(Context.ExecutingFileVersion);

            (Points, Notes) = GetPoints();

            AdjustNotes();

            if (Points.All(p => p.Type != PointType.Gap))
            {
                Points = Points
                         .OrderBy(p => p.Time)
                         .ToList();
            }

            ThrowIfInvalidGapInterval();

            AdjustGradesAndQualifiers(Points);

            if (!string.IsNullOrEmpty(Context.SaveCsvPath))
            {
                new CsvWriter(Context)
                .WritePoints(Points, Notes);

                if (Context.StopAfterSavingCsv)
                {
                    return;
                }
            }

            Log.Info($"Connecting to {Context.Server} ...");

            using (var client = CreateConnectedClient())
            {
                Log.Info($"Connected to {Context.Server} ({client.ServerVersion})");

                ThrowIfGapsNotSupported(client);

                if (Context.CreateMode != CreateMode.Never)
                {
                    new TimeSeriesCreator
                    {
                        Context = Context,
                        Client  = client
                    }.CreateMissingTimeSeries(Context.TimeSeries);
                }

                var timeSeries = client.GetTimeSeriesInfo(Context.TimeSeries);

                var isReflected  = Context.Command == CommandType.Reflected || timeSeries.TimeSeriesType == TimeSeriesType.Reflected;
                var hasTimeRange = isReflected || DeleteCommands.Contains(Context.Command) || Context.Command == CommandType.OverwriteAppend;

                if (hasTimeRange)
                {
                    var timeRange = GetTimeRange();

                    if (Notes.Any(note => note.TimeRange != null && (!timeRange.Contains(note.TimeRange.Value.Start) ||
                                                                     !timeRange.Contains(note.TimeRange.Value.End))))
                    {
                        throw new ExpectedException($"All notes to append must be completely within the {timeRange} interval.");
                    }
                }

                Log.Info(Context.Command == CommandType.DeleteAllPoints
                    ? $"Deleting all existing points from {timeSeries.Identifier} ({timeSeries.TimeSeriesType}) ..."
                    : hasTimeRange
                        ? $"Appending {PointSummarizer.Summarize(Points)} and {"note".ToQuantity(Notes.Count)} within TimeRange={GetTimeRange()} to {timeSeries.Identifier} ({timeSeries.TimeSeriesType}) ..."
                        : $"Appending {PointSummarizer.Summarize(Points)} and {"note".ToQuantity(Notes.Count)} to {timeSeries.Identifier} ({timeSeries.TimeSeriesType}) ...");

                var numberOfPointsAppended = 0;
                var numberOfPointsDeleted  = 0;
                var numberOfNotesAppended  = 0;
                var numberOfNotesDeleted   = 0;
                var stopwatch = Stopwatch.StartNew();

                var pointBatches = GetPointBatches(Points).ToList();
                var isBatched    = pointBatches.Count > 1;
                var batchIndex   = 1;

                foreach (var batch in pointBatches)
                {
                    if (isBatched)
                    {
                        var batchSummary =
                            $"Appending batch #{batchIndex}: {PointSummarizer.Summarize(batch.Points)}";

                        Log.Info(hasTimeRange
                            ? $"{batchSummary} within TimeRange={batch.TimeRange} ..."
                            : $"{batchSummary} ...");
                    }

                    var result = AppendPointBatch(client, timeSeries, batch.Points, batch.TimeRange, isReflected, hasTimeRange);
                    numberOfPointsAppended += result.NumberOfPointsAppended;
                    numberOfPointsDeleted  += result.NumberOfPointsDeleted;
                    ++batchIndex;

                    if (!ValidStatusCodesByWaitMode[Context.Wait].Contains(result.AppendStatus))
                    {
                        throw new ExpectedException($"Unexpected append status={result.AppendStatus}");
                    }
                }

                if (DeleteCommands.Contains(Context.Command))
                {
                    numberOfNotesDeleted += DeleteNotesWithinTimeRange(client, timeSeries, GetTimeRange());
                }
                else
                {
                    numberOfNotesAppended += AppendNotes(client, timeSeries);
                }

                var batchText = isBatched ? $" using {"append".ToQuantity(pointBatches.Count)}" : "";
                var waitText  = Context.Wait ? string.Empty : " (without waiting for appends to complete)";

                Log.Info($"Appended {"point".ToQuantity(numberOfPointsAppended)} and {"note".ToQuantity(numberOfNotesAppended)} (deleting {"point".ToQuantity(numberOfPointsDeleted)} and {"note".ToQuantity(numberOfNotesDeleted)}) in {stopwatch.ElapsedMilliseconds / 1000.0:F1} seconds{batchText}{waitText}.");
            }
        }
示例#5
0
 public ICallback Send(params IDeleteEntityCommand[] deleteCommands)
 {
     DeleteCommands.AddRange(deleteCommands);
     MessageSent.Raise(this, new CommandEventArgs(deleteCommands));
     return(null);
 }