aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Synchronization/Conversion/TriggerSchema.cs
blob: 88dc6b2262d210e678220952cd31c3aa0ab5e4f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using 
/span>/// Represents stand-alone visual console emulation logger. /// </summary> /// <seealso cref="Tango.Logging.ILogger" /> public class ConsoleLogger : ILogger { private bool _consoleOpened; private String _consoleTitle; private ConsoleWindow console; /// <summary> /// Gets or sets a value indicating whether this <see cref="ILogger" /> is enabled. /// </summary> public bool Enabled { get; set; } /// <summary> /// Initializes a new instance of the <see cref="ConsoleLogger"/> class. /// </summary> public ConsoleLogger(String consoleTitle) { _consoleTitle = consoleTitle; Enabled = true; } /// <summary> /// Called when a new library trace is available. /// </summary> /// <param name="output">The output.</param> public void OnLog(LogItemBase output) { EnsureConsoleOpen(() => { switch (output.Category) { case LogCategory.Info: console.SetColor(ConsoleColor.White); break; case LogCategory.Warning: console.SetColor(ConsoleColor.Yellow); break; case LogCategory.Error: console.SetColor(ConsoleColor.Red); break; case LogCategory.Critical: console.SetColor(ConsoleColor.DarkRed); break; case LogCategory.Debug: console.SetColor(ConsoleColor.Gray); break; } console.WriteLine(output.ToString()); }); } /// <summary> /// Waits until user closes the console. /// </summary> /// <returns></returns> public async Task WaitForConsoleExit() { if (console != null) { await console.WaitForUserClose(); } } /// <summary> /// Ensures the console is open. /// </summary> private void EnsureConsoleOpen(Action post) { if (!_consoleOpened) { Thread t = new Thread(() => { console = new ConsoleWindow(); console.Title += " - " + _consoleTitle; _consoleOpened = true; console.Show(); console.Closed += (sender2, e2) => console.Dispatcher.InvokeShutdown(); System.Windows.Threading.Dispatcher.Run(); }); t.IsBackground = true; t.SetApartmentState(ApartmentState.STA); t.Start(); } while (!_consoleOpened) { Thread.Sleep(10); } post(); } } }