Exemple #1
0
        public IList <LineDto> GetLines(string jobId, DateTime timestamp, LineType type = LineType.Any)
        {
            var consoleId = new ConsoleId(jobId, timestamp);

            var count  = _storage.GetLineCount(consoleId);
            var result = new List <LineDto>(count);

            if (count > 0)
            {
                Dictionary <string, ProgressBarDto> progressBars = null;

                foreach (var entry in _storage.GetLines(consoleId, 0, count))
                {
                    if (entry.ProgressValue.HasValue)
                    {
                        if (type == LineType.Text)
                        {
                            continue;
                        }

                        // aggregate progress value updates into single record

                        if (progressBars != null)
                        {
                            ProgressBarDto prev;
                            if (progressBars.TryGetValue(entry.Message, out prev))
                            {
                                prev.Progress = entry.ProgressValue.Value;
                                prev.Color    = entry.TextColor;
                                continue;
                            }
                        }
                        else
                        {
                            progressBars = new Dictionary <string, ProgressBarDto>();
                        }

                        var line = new ProgressBarDto(entry, timestamp);

                        progressBars.Add(entry.Message, line);
                        result.Add(line);
                    }
                    else
                    {
                        if (type == LineType.ProgressBar)
                        {
                            continue;
                        }

                        result.Add(new TextLineDto(entry, timestamp));
                    }
                }
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Fetches console lines from storage.
        /// </summary>
        /// <param name="storage">Console data accessor</param>
        /// <param name="consoleId">Console identifier</param>
        /// <param name="start">Offset to read lines from</param>
        /// <remarks>
        /// On completion, <paramref name="start"/> is set to the end of the current batch,
        /// and can be used for next requests (or set to -1, if the job has finished processing).
        /// </remarks>
        private static IEnumerable <ConsoleLine> ReadLines(IConsoleStorage storage, ConsoleId consoleId, ref int start)
        {
            if (start < 0)
            {
                return(null);
            }

            var count  = storage.GetLineCount(consoleId);
            var result = new List <ConsoleLine>(Math.Max(1, count - start));

            if (count > start)
            {
                // has some new items to fetch

                Dictionary <string, ConsoleLine> progressBars = null;

                foreach (var entry in storage.GetLines(consoleId, start, count - 1))
                {
                    if (entry.ProgressValue.HasValue)
                    {
                        // aggregate progress value updates into single record

                        if (progressBars != null)
                        {
                            ConsoleLine prev;
                            if (progressBars.TryGetValue(entry.Message, out prev))
                            {
                                prev.ProgressValue = entry.ProgressValue;
                                prev.TextColor     = entry.TextColor;
                                continue;
                            }
                        }
                        else
                        {
                            progressBars = new Dictionary <string, ConsoleLine>();
                        }

                        progressBars.Add(entry.Message, entry);
                    }

                    result.Add(entry);
                }
            }

            if (count <= start || start == 0)
            {
                // no new items or initial load, check if the job is still performing

                var state = storage.GetState(consoleId);
                if (state == null)
                {
                    // No state found for a job, probably it was deleted
                    count = -2;
                }
                else
                {
                    if (!string.Equals(state.Name, ProcessingState.StateName, StringComparison.OrdinalIgnoreCase) ||
                        !consoleId.Equals(new ConsoleId(consoleId.JobId, JobHelper.DeserializeDateTime(state.Data["StartedAt"]))))
                    {
                        // Job state has changed (either not Processing, or another Processing with different console id)
                        count = -1;
                    }
                }
            }

            start = count;
            return(result);
        }