public async Task <bool> LoadChangelog(StreamReader reader) { const int INDENT = 15; var fontHeader = new System.Drawing.Font("Segoe UI Semibold", 9f, System.Drawing.FontStyle.Bold); var fontLight = new System.Drawing.Font("Segoe UI Semilight", 8.25f, System.Drawing.FontStyle.Regular); var fontDefault = this.Font; int x = 0, y = 0; Func <bool> onComplete = delegate { panelContent.Height = y; scrollV.Maximum = panelContent.Height - panelContainer.Height; scrollV.Visible = scrollV.Maximum > 0; return(y > 0); }; while (!reader.EndOfStream) { var line = await reader.ReadLineAsync(); if (line.Length == 0) { continue; } Label l; switch (line[0]) { case '=': if (line.Length > 1) { int depth = 0; for (int i = 1, li = line.Length; i < li; i++) { if (line[i] == '=') { depth++; } else { break; } } x = depth * INDENT; if (depth < line.Length) { y += 5; l = new Label() { Font = fontHeader, Text = line.Substring(depth + 1), AutoSize = true, Location = new Point(x, y), MaximumSize = new Size(panelContent.Width - x, 0) }; panelContent.Controls.Add(l); x += INDENT; y += l.Height + 10; } } else { x = 0; } break; case '*': l = new BulletLabel() { Font = fontDefault, Text = line.Substring(1), AutoSize = true, Location = new Point(x, y), MaximumSize = new Size(panelContent.Width - x, 0), Padding = new Padding(INDENT, 0, 0, 0), }; panelContent.Controls.Add(l); y += l.Height + 5; break; case '#': if (line.StartsWith("#build")) { var parts = line.Split(';'); var release = int.Parse(parts[1]); if (release <= Program.RELEASE_VERSION) { return(onComplete()); } x = 0; if (panelContent.Controls.Count > 0) { y += 10; var ls = new LineSeperator() { Location = new Point(panelContent.Width / 8, y), Size = new Size(panelContent.Width * 3 / 4, 1), ForeColor = Color.LightGray, }; panelContent.Controls.Add(ls); y += ls.Height + 20; } l = new Label() { Font = fontDefault, Text = parts[3], AutoSize = true, Location = new Point(x, y), MaximumSize = new Size(panelContent.Width - x, 0), }; panelContent.Controls.Add(l); y += l.Height + 5; l = new Label() { Font = fontLight, ForeColor = SystemColors.GrayText, Text = "build " + parts[2] + " | release " + parts[1], AutoSize = true, Location = new Point(l.Right + 1, l.Top), MaximumSize = new Size(panelContent.Width - x, 0), }; panelContent.Controls.Add(l); } break; default: l = new Label() { Font = fontDefault, Text = line, AutoSize = true, Location = new Point(x, y), MaximumSize = new Size(panelContent.Width - x, 0), }; panelContent.Controls.Add(l); y += l.Height + 5; break; } } return(onComplete()); }
private static void ConsoleLog(string category, object message, LoggerVerbosity messageVerbosity = LoggerVerbosity.Info, bool seperateLineHere = false) { if (messageVerbosity == LoggerVerbosity.None) { return; } lock (Console.Out) { if (Verbosity > messageVerbosity) { return; } if (CategoryVerbosities != null) { if (!CategoryVerbosities.ContainsKey(category) && !CategoryVerbosities.ContainsKey(AllowAnyCategoryVerbosities)) { return; } if (CategoryVerbosities.ContainsKey(category)) { if (CategoryVerbosities[category] > messageVerbosity) { return; } } } MessageCount++; string output = string.Concat(GetMessageHeader(messageVerbosity, category), message); string messageSeperator = string.Empty; if (!string.IsNullOrEmpty(LineSeperator) && (seperateLineHere || LineSeperatorMessageInterval > 0 && MessageCount % LineSeperatorMessageInterval == 0)) { messageSeperator = LineSeperator.Multiply(output.Length); } if ((LogDestination & LoggerDestination.File) != 0) { messageBuffer.AppendLine(output); if (!string.IsNullOrEmpty(messageSeperator)) { messageBuffer.AppendLine(messageSeperator); } } if ((LogDestination & LoggerDestination.Output) != 0) { ConsoleColor oldConsoleColor = Console.ForegroundColor; Console.ForegroundColor = GetConsoleColour(messageVerbosity); Console.WriteLine(output); if (!string.IsNullOrEmpty(messageSeperator)) { Console.WriteLine(messageSeperator); } Console.ForegroundColor = oldConsoleColor; } messageCountSinceLastFlush++; if (messageVerbosity >= FlushVerbosity || messageCountSinceLastFlush == FlushBufferMessageCapacity) { FlushMessageBuffer(); } } if (!isFirstLog) { return; } messageBufferFlushTimer.Start(); isFirstLog = false; }
/// <summary> /// Log a message in a category with a specified verbosity. /// </summary> /// <param name="category">The category to log in.</param> /// <param name="message">The message to log.</param> /// <param name="messageVerbosity">The verbosity to log with.</param> /// <param name="separateLineHere">Should this message be separated by a line?</param> public static void Log(string category, object message, LoggerVerbosity messageVerbosity = LoggerVerbosity.Info, bool separateLineHere = false) { // The none verbosity turns off logging. if (messageVerbosity == LoggerVerbosity.None) { return; } // Lock the output stream of the console for operation. lock (Console.Out) { if (Verbosity > messageVerbosity) { return; } // Check if the category we are trying to log into allows the specified verbosity. if (CategoryVerbosities != null) { bool allowAnyCategoryVerbosities = CategoryVerbosities.ContainsKey(AllowAnyCategoryVerbosities); if (!CategoryVerbosities.ContainsKey(category) && !allowAnyCategoryVerbosities) { return; } if (CategoryVerbosities.ContainsKey(category)) { if (CategoryVerbosities[category] > messageVerbosity) { return; } } } MessageCount++; string output = string.Concat(GetMessageHeader(messageVerbosity, category), message, MessageSuffix); string messageSeperator = string.Empty; bool shouldSeparateLine = separateLineHere || LineSeperatorMessageInterval > 0 && MessageCount % LineSeperatorMessageInterval == 0; if (!string.IsNullOrEmpty(LineSeperator) && shouldSeparateLine) { messageSeperator = LineSeperator.Multiply(output.Length); } // Log to the file. if ((Destination & LoggerDestination.File) != 0) { messageBuffer.AppendLine(output); if (!string.IsNullOrEmpty(messageSeperator)) { messageBuffer.AppendLine(messageSeperator); } } // Log to the console. if ((Destination & LoggerDestination.Output) != 0) { ConsoleColor oldConsoleColor = Console.ForegroundColor; Console.ForegroundColor = GetVerbosityConsoleColour(messageVerbosity); if (messageVerbosity == LoggerVerbosity.Plain) { Console.WriteLine(message); } else { Console.WriteLine(output); } if (!string.IsNullOrEmpty(messageSeperator)) { Console.WriteLine(messageSeperator); } Console.ForegroundColor = oldConsoleColor; } if (Destination != LoggerDestination.None) { OnMessageLogged(new MessagedLoggerEventArgs(message.ToString())); } // Flush the message buffer if it is time. messageCountSinceLastFlush++; if (messageVerbosity >= FlushVerbosity || messageCountSinceLastFlush == FlushBufferMessageCapacity) { FlushMessageBuffer(); } } }
/// <summary> /// Log a message in a category with a specified verbosity. /// </summary> /// <param name="category">The category to log in.</param> /// <param name="message">The message to log.</param> /// <param name="messageVerbosity">The verbosity to log with.</param> /// <param name="separateLineHere">Should this message be separated by a line?</param> /// <param name="destinationOverride"> /// Overrides the message log destination. /// Defaults to <see cref="LoggerDestination.None"/> indicating no log destination override. /// </param> public static void Log(string category, object message, LoggerVerbosity messageVerbosity = LoggerVerbosity.Info, LoggerDestination destinationOverride = LoggerDestination.None, bool separateLineHere = false) { // The none verbosity turns off logging. if (messageVerbosity == LoggerVerbosity.None) { return; } // Lock the output stream of the console for operation. lock (Console.Out) { if (Verbosity > messageVerbosity) { return; } // Check if the category we are trying to log into allows the specified verbosity. if (CategoryVerbosities != null) { bool allowAnyCategoryVerbosities = CategoryVerbosities.ContainsKey(AllowAnyCategoryVerbosities); if (!CategoryVerbosities.ContainsKey(category) && !allowAnyCategoryVerbosities) { return; } if (CategoryVerbosities.ContainsKey(category)) { if (CategoryVerbosities[category] > messageVerbosity) { return; } } } MessageCount++; string output = string.Concat(GetMessageHeader(messageVerbosity, category), message, MessageSuffix); string messageSeperator = string.Empty; bool shouldSeparateLine = separateLineHere || LineSeperatorMessageInterval > 0 && MessageCount % LineSeperatorMessageInterval == 0; if (!string.IsNullOrEmpty(LineSeperator) && shouldSeparateLine) { messageSeperator = LineSeperator.Multiply(output.Length); } LoggerDestination destination = destinationOverride == LoggerDestination.None ? Destination : destinationOverride; // Log to the file. if (destination.HasFlag(LoggerDestination.File)) { messageBuffer.AppendLine(output); if (!string.IsNullOrEmpty(messageSeperator)) { messageBuffer.AppendLine(messageSeperator); } } // Log to the console. if (destination.HasFlag(LoggerDestination.Output)) { ConsoleColor oldConsoleColor = Console.ForegroundColor; Console.ForegroundColor = GetVerbosityConsoleColour(messageVerbosity); if (messageVerbosity == LoggerVerbosity.Plain) { Console.WriteLine(message); } else { Console.WriteLine(output); } if (!string.IsNullOrEmpty(messageSeperator)) { Console.WriteLine(messageSeperator); } Console.ForegroundColor = oldConsoleColor; } // Log using message box if (destination.HasFlag(LoggerDestination.Form)) { // The caption of the message box is either the category or assembly name. string caption = string.IsNullOrEmpty(category) ? Assembly.GetEntryAssembly().GetName().Name : category; // Show a message box with the appropriate icon corresponding to the message verbosity switch (messageVerbosity) { case LoggerVerbosity.Plain: MessageBox.Show(message.ToString(), caption, MessageBoxButton.OK, MessageBoxImage.None); break; case LoggerVerbosity.Info: MessageBox.Show(message.ToString(), caption, MessageBoxButton.OK, MessageBoxImage.Information); break; case LoggerVerbosity.Warning: MessageBox.Show(message.ToString(), caption, MessageBoxButton.OK, MessageBoxImage.Warning); break; case LoggerVerbosity.Error: MessageBox.Show(message.ToString(), caption, MessageBoxButton.OK, MessageBoxImage.Error); break; } } if (!destination.HasFlag(LoggerDestination.None)) { OnMessageLogged(new MessagedLoggerEventArgs(message.ToString())); } // Flush the message buffer if it is time. messageCountSinceLastFlush++; if (messageVerbosity >= FlushVerbosity || messageCountSinceLastFlush == FlushBufferMessageCapacity) { FlushMessageBuffer(); } } }