public MysqlConsole(IConsoleStorage storage) { if (storage == null) { throw new ArgumentNullException(nameof(IConsoleStorage)); } Storage = storage; _lastTimeOffset = 0; }
public ConsoleApi(IStorageConnection connection) { if (connection == null) { throw new ArgumentNullException(nameof(connection)); } _storage = new ConsoleStorage(connection); }
public ConsoleContext(ConsoleId consoleId, IConsoleStorage storage) { _consoleId = consoleId ?? throw new ArgumentNullException(nameof(consoleId)); _storage = storage ?? throw new ArgumentNullException(nameof(storage)); _lastTimeOffset = 0; _nextProgressBarId = 0; _storage.InitConsole(_consoleId); }
public ConsoleContext(ConsoleId consoleId, IConsoleStorage storage) { if (consoleId == null) { throw new ArgumentNullException(nameof(consoleId)); } if (storage == null) { throw new ArgumentNullException(nameof(storage)); } _consoleId = consoleId; _storage = storage; _lastTimeOffset = 0; _nextProgressBarId = 0; }
/// <summary> /// Fetches and renders console line buffer. /// </summary> /// <param name="builder">Buffer</param> /// <param name="storage">Console data accessor</param> /// <param name="consoleId">Console identifier</param> /// <param name="start">Offset to read lines from</param> public static void RenderLineBuffer(StringBuilder builder, IConsoleStorage storage, ConsoleId consoleId, int start) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (storage == null) { throw new ArgumentNullException(nameof(storage)); } if (consoleId == null) { throw new ArgumentNullException(nameof(consoleId)); } var items = ReadLines(storage, consoleId, ref start); builder.AppendFormat("<div class=\"line-buffer\" data-n=\"{1}\">", consoleId, start); RenderLines(builder, items, consoleId.DateValue); builder.Append("</div>"); }
/// <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); }