private void Initiate(IConsoleConfiguration consoleConfiguration) { SetColor(consoleConfiguration); UpdateTitle(consoleConfiguration); ShowSplashScreen(consoleConfiguration); ShowAssemblyInfo(consoleConfiguration); }
private void Initiate(IConsoleConfiguration consoleConfiguration) { //SetLocation(consoleConfiguration); //SetTopMost(consoleConfiguration.TopMost); SetColor(consoleConfiguration); UpdateTitle(consoleConfiguration); ShowSplashScreen(consoleConfiguration); ShowAssemblyInfo(consoleConfiguration); }
private void ShowSplashScreen(IConsoleConfiguration consoleConfiguration) { if (string.IsNullOrEmpty(consoleConfiguration.SplashScreen)) { return; } Output(new WriteEventArgs(consoleConfiguration.SplashScreen)); }
public ConfigurationProperties(IConsoleConfiguration configs, ICremaHost cremaHost) { this.cremaHost = cremaHost; this.cremaHost.Opened += CremaHost_Opened; this.cremaHost.Closed += CremaHost_Closed; foreach (var item in configs.Properties) { this.properties.Add(item); } }
private void ShowAssemblyInfo(IConsoleConfiguration consoleConfiguration) { if (consoleConfiguration.ShowAssemblyInfo) { var info = AssemblyHelper.GetAssemblyInfo(); if (!string.IsNullOrEmpty(info)) { Output(new WriteEventArgs(info, OutputLevel.Default)); } } }
private void UpdateTitle(IConsoleConfiguration consoleConfiguration) { try { ConsoleManager.Title = consoleConfiguration.Title ?? AssemblyHelper.GetAssemblyInfo() ?? "Tharga Console"; } catch (IOException exception) { Trace.TraceError($"Cannot set console title. {exception.Message}"); } }
//public bool TopMost //{ // get { return _topMost; } // set { SetTopMost(value); } //} //private void SetLocation(IConsoleConfiguration consoleConfiguration) //{ // try // { // var hWnd = Process.GetCurrentProcess().MainWindowHandle; // Position position = null; // if (consoleConfiguration.StartPosition != null) // { // position = consoleConfiguration.StartPosition; // } // else if (consoleConfiguration.RememberStartPosition) // { // position = GetStoredPosition(); // //SubscribeToWindowMovement(hWnd); // } // if (position != null) // { // SetWidth(position); // SetHeight(position); // //NOTE: Do not send the window where it cannot be visible. For instance, a secondary screen that is no longer attached. // var monitors = GetMonitors(); // var monitor = VisibleOnMonitor(monitors, Offset(position, GetWindowRect())); // if (monitor != null) // { // //OutputEvent($"SetWindowPos {position.Left}:{position.Top}"); // ExecuteApiFunction(() => SetWindowPos(hWnd, IntPtr.Zero, position.Left, position.Top, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW)); // } // else // { // OutputWarning("Console location is reset since it otherwise sould appear outside the visual field."); // } // //NOTE: This code will reposition the window at startup, the same way as a "scr reset" command will. // //For some reason the "SetWindowPos" does not act the same when run directly when the console starts as it does when the application has been running for a short while. // //Task.Run(() => // //{ // // var monitors = GetMonitors(); // // var monitor = VisibleOnMonitor(monitors, Offset(GetWindowRect(), position)); // // if (monitor != null) // // { // // System.Threading.Thread.Sleep(1000); // // SetWindowPos(hWnd, IntPtr.Zero, position.Left, position.Top, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW); // // } // // else // // { // // OutputWarning("Console location is reset since it otherwise sould appear outside the visual field."); // // } // //}); // //System.Console.WriteLine($"set: {position.Left}:{position.Top} {hWnd}"); // } // } // catch (Exception exception) // { // OutputError(exception); // } //} //private void ExecuteApiFunction(Action apiCall) //{ // try // { // var pre = GetLastError(); // apiCall(); // var aft = GetLastError(); // if (aft != 0 && pre != aft) // { // OutputWarning($"Error {aft} when calling api method {apiCall.Method.Name}."); // } // } // catch (Exception exception) // { // OutputError(exception); // } //} //private RECT Offset(Position position, RECT rect) //{ // var height = rect.Bottom - rect.Top; // var width = rect.Right - rect.Left; // var rct = new RECT // { // Top = position.Top, // Left = position.Left, // Bottom = position.Top + height, // Right = position.Left + width, // }; // return rct; //} //private int? VisibleOnMonitor(List<RECT> monitors, RECT window) //{ // var index = 0; // foreach (var monitor in monitors) // { // if (window.Right >= monitor.Left && (window.Left <= monitor.Right && (window.Bottom >= monitor.Top && window.Top <= monitor.Bottom))) // { // return index; // } // index++; // } // return null; //} //private List<RECT> GetMonitors() //{ // var monitors = new List<RECT>(); // MonitorEnumProc callback = (IntPtr hDesktop, IntPtr hdc, ref RECT prect, int d) => { monitors.Add(prect); return true; }; // ExecuteApiFunction(() => EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero, callback, 0)); // return monitors; //} //private Position GetCurrentPosition() //{ // var rct = GetWindowRect(); // return new Position(rct.Left, rct.Top, ConsoleManager.WindowWidth, ConsoleManager.WindowHeight, ConsoleManager.BufferWidth, ConsoleManager.BufferHeight); //} //private RECT GetWindowRect() //{ // var hWnd = Process.GetCurrentProcess().MainWindowHandle; // var rct = new RECT(); // ExecuteApiFunction(() => GetWindowRect(hWnd, out rct)); // //Trace.TraceInformation($"GetWindowRect {hWnd} {rct.Left}:{rct.Top}."); // //OutputEvent($"GetWindowRect {hWnd} {rct.Left}:{rct.Top}."); // //var wp = new WINDOWPLACEMENT(); // //GetWindowPlacement(hWnd, ref wp); // //ExecuteApiFunction(); // //System.Console.WriteLine($"get: {wp.rcNormalPosition.Left}:{wp.rcNormalPosition.Top}"); // return rct; //} //private Position GetStoredPosition() //{ // //try // //{ // // var val = Registry.GetSetting("StartPosition", Registry.RegistryHKey.CurrentUser, string.Empty); // // if (string.IsNullOrEmpty(val)) return null; // // var segments = val.Split('|'); // // var pos = segments[0].Split(':'); // // var wz = segments[1].Split(':'); // // var bz = segments[2].Split(':'); // // return new Position(int.Parse(pos[0]), int.Parse(pos[1]), int.Parse(wz[0]), int.Parse(wz[1]), int.Parse(bz[0]), int.Parse(bz[1])); // //} // //catch (Exception exception) // //{ // // OutputError(exception); // // return null; // //} // return null; //} //private void StoreCurrentPosition() //{ // //try // //{ // // var position = GetCurrentPosition(); // // var val = $"{position.Left}:{position.Top}|{position.Width}:{position.Height}|{position.BufferWidth}:{position.BufferHeight}"; // // //ConsoleManager.WriteLine(val); // // Trace.TraceInformation($"StoreCurrentPosition {val}."); // // Registry.SetSetting("StartPosition", val, Registry.RegistryHKey.CurrentUser); // //} // //catch (Exception exception) // //{ // // OutputError(exception); // //} //} //private void SetWidth(Position position) //{ // try // { // if (position.Width != null && position.Width.Value > 0) // ConsoleManager.WindowWidth = position.Width.Value; // if (position.BufferWidth != null) // ConsoleManager.BufferWidth = position.BufferWidth.Value; // else if (ConsoleManager.WindowWidth > 0) // ConsoleManager.BufferWidth = ConsoleManager.WindowWidth; // } // catch (Exception exception) // { // OutputError(exception); // } //} //private void SetHeight(Position position) //{ // try // { // if (position.Height != null) // ConsoleManager.WindowHeight = position.Height.Value; // if (position.BufferHeight != null) // ConsoleManager.BufferHeight = position.BufferHeight.Value; // } // catch (Exception exception) // { // OutputError(exception); // } //} private void SetColor(IConsoleConfiguration consoleConfiguration) { if (ConsoleManager.BackgroundColor == consoleConfiguration.BackgroundColor && ConsoleManager.ForegroundColor == consoleConfiguration.DefaultTextColor) { return; } ConsoleManager.BackgroundColor = consoleConfiguration.BackgroundColor; ConsoleManager.ForegroundColor = consoleConfiguration.DefaultTextColor; ConsoleManager.Clear(); }
/// <summary> /// Initializes a new instance of the <see cref="ConsoleTelemetron"/> class. /// </summary> /// <param name="configuration"></param> public ConsoleTelemetron(IConsoleConfiguration configuration) : base(configuration) { this.CopyConfigLocal(configuration); this.CorrelationContext = new CorrelationContext(1337); this.cancellationTokenSource = new CancellationTokenSource(); this.cancellationToken = this.cancellationTokenSource.Token; this.eventQueue = new ConcurrentQueue <ConsoleEvent>(); this.queueTask = this.QueueJob(this.cancellationToken); }
//private bool _topMost; public ClientConsole(IConsoleConfiguration consoleConfiguration = null) : base(new ConsoleManager(System.Console.Out, System.Console.In)) { _consoleConfiguration = consoleConfiguration ?? new ConsoleConfiguration(); //_initialPosition = GetCurrentPosition(); Initiate(_consoleConfiguration); //NOTE: Listen to the dispose event, and trigger a location save before exit. DisposeEvent += (sender, e) => { //if (_consoleConfiguration.RememberStartPosition) //{ // StoreCurrentPosition(); //} }; }
public static TracerDecoration Create(IConsoleConfiguration config) { if (!config.Enabled) { return(NoopTracerDecorationFactory.Instance.ToPublicType()); } ColoredConsoleTracerDecoration.ColorChooser colorChooser = GetColorChooser(config.ColorMode, () => config.ColorsForTheBasedOnCategoryColorMode); ColoredConsoleTracerDecoration.TextFormatter textFormatter = GetTextFormatter(config.Format, config.OutputSpanNameOnCategory); ColoredConsoleTracerDecoration.LogSerializer logSerializer = GetLogSerializer(config.DataSerialization.Log); ColoredConsoleTracerDecoration.SetTagSerializer setTagSerializer = GetSetTagSerializer(config.DataSerialization.SetTag); return(new ColoredConsoleTracerDecoration( colorChooser, logSerializer, textFormatter, setTagSerializer, config.OutputDurationOnFinished) .ToPublicType()); }
private static void Main(string[] args) { var tracingConfigurationSection = ((TracingConfigurationSection)ConfigurationManager.GetSection("tracing")); IConsoleConfiguration consoleConfiguration = tracingConfigurationSection.Console; IFileConfiguration fileElement = tracingConfigurationSection.File; var builder = TracingConfigurationBuilder.Instance // no file tracing //.WithFileTracing .WithConsoleTracing( "[{date:h:mm:ss tt}] {spanId}{spanIdFloatPadding} | {logCategory}{logCategoryPadding} | {outputData}", settings => settings .WithColorMode(ColorMode.BasedOnCategory) .WithColorsForTheBasedOnCategoryColorMode( ConsoleColor.Green, ConsoleColor.Red, ConsoleColor.Magenta, ConsoleColor.Blue) .WithOutputSpanNameOnCategory( activated: true, finished: true) .WithOutputDurationOnFinished(true) .WithDataSerialization( SetTagDataSerialization.Simple, LogDataSerialization.Json)); consoleConfiguration = builder.BuildConsoleConfiguration(); fileElement = builder.BuildFileConfiguration(); var tracer = new MockTracer() .Decorate(ColoredConsoleTracerDecorationFactory.Create(consoleConfiguration)) .Decorate(FileTracerDecorationFactory.Create(fileElement)); using (tracer.BuildSpan("test").StartActive()) { tracer.ActiveSpan.Log( new[] { new KeyValuePair <string, object>("a", "b"), new KeyValuePair <string, object>("b", "b"), new KeyValuePair <string, object>("c", "b"), new KeyValuePair <string, object>("d", "b"), }); Console.WriteLine("Inside span"); using (tracer.BuildSpan("inner") .WithTag("foo", "bar,\nhi") .StartActive()) { Console.WriteLine("Inside inner"); } List <object> selfReferencingObject = new List <object>(); selfReferencingObject.Add(selfReferencingObject); tracer.ActiveSpan.Log( new Dictionary <string, object> { [nameof(selfReferencingObject)] = selfReferencingObject }); } }
private void CopyConfigLocal(IConsoleConfiguration configuration) { ////// // debug if (!configuration.DebugForegroundColor.HasValue) { this.debugForegroundColor = ConsoleColor.DarkGray; } else { this.debugForegroundColor = configuration.DebugForegroundColor.Value; } if (!configuration.DebugBackgroundColor.HasValue) { this.debugBackgroundColor = ConsoleColor.Black; } else { this.debugBackgroundColor = configuration.DebugBackgroundColor.Value; } ////// // verbose if (!configuration.VerboseForegroundColor.HasValue) { this.verboseForegroundColor = ConsoleColor.Gray; } else { this.verboseForegroundColor = configuration.VerboseForegroundColor.Value; } if (!configuration.VerboseBackgroundColor.HasValue) { this.verboseBackgroundColor = ConsoleColor.Black; } else { this.verboseBackgroundColor = configuration.VerboseBackgroundColor.Value; } ////// // info if (!configuration.InfoForegroundColor.HasValue) { this.infoForegroundColor = ConsoleColor.White; } else { this.infoForegroundColor = configuration.InfoForegroundColor.Value; } if (!configuration.InfoBackgroundColor.HasValue) { this.infoBackgroundColor = ConsoleColor.Black; } else { this.infoBackgroundColor = configuration.InfoBackgroundColor.Value; } ////// // warning if (!configuration.WarningForegroundColor.HasValue) { this.warningForegroundColor = ConsoleColor.Yellow; } else { this.warningForegroundColor = configuration.WarningForegroundColor.Value; } if (!configuration.WarningBackgroundColor.HasValue) { this.warningBackgroundColor = ConsoleColor.Black; } else { this.warningBackgroundColor = configuration.WarningBackgroundColor.Value; } ////// // error if (!configuration.ErrorForegroundColor.HasValue) { this.errorForegroundColor = ConsoleColor.Red; } else { this.errorForegroundColor = configuration.ErrorForegroundColor.Value; } if (!configuration.ErrorBackgroundColor.HasValue) { this.errorBackgroundColor = ConsoleColor.Black; } else { this.errorBackgroundColor = configuration.ErrorBackgroundColor.Value; } ////// // fatal if (!configuration.FatalForegroundColor.HasValue) { this.fatalForegroundColor = ConsoleColor.White; } else { this.fatalForegroundColor = configuration.FatalForegroundColor.Value; } if (!configuration.FatalBackgroundColor.HasValue) { this.fatalBackgroundColor = ConsoleColor.DarkRed; } else { this.fatalBackgroundColor = configuration.FatalBackgroundColor.Value; } ////// // operationInfo if (!configuration.OperationInfoForegroundColor.HasValue) { this.operationInfoForegroundColor = ConsoleColor.DarkGray; } else { this.operationInfoForegroundColor = configuration.OperationInfoForegroundColor.Value; } if (!configuration.OperationInfoBackgroundColor.HasValue) { this.operationInfoBackgroundColor = ConsoleColor.Black; } else { this.operationInfoBackgroundColor = configuration.OperationInfoBackgroundColor.Value; } ////// // operationError if (!configuration.OperationErrorForegroundColor.HasValue) { this.operationErrorForegroundColor = ConsoleColor.DarkGray; } else { this.operationErrorForegroundColor = configuration.OperationErrorForegroundColor.Value; } if (!configuration.OperationErrorBackgroundColor.HasValue) { this.operationErrorBackgroundColor = ConsoleColor.Black; } else { this.operationErrorBackgroundColor = configuration.OperationErrorBackgroundColor.Value; } ////// // metric if (!configuration.MetricForegroundColor.HasValue) { this.metricForegroundColor = ConsoleColor.Magenta; } else { this.metricForegroundColor = configuration.MetricForegroundColor.Value; } if (!configuration.MetricBackgroundColor.HasValue) { this.metricBackgroundColor = ConsoleColor.Black; } else { this.metricBackgroundColor = configuration.MetricBackgroundColor.Value; } ////// // event if (!configuration.EventForegroundColor.HasValue) { this.eventForegroundColor = ConsoleColor.Cyan; } else { this.eventForegroundColor = configuration.EventForegroundColor.Value; } if (!configuration.EventBackgroundColor.HasValue) { this.eventBackgroundColor = ConsoleColor.Black; } else { this.eventBackgroundColor = configuration.EventBackgroundColor.Value; } }
public ActionConsole(Action <IActionConsoleOutput> action, IConsoleConfiguration consoleConfiguration = null) : base(new ConsoleManager(System.Console.Out, System.Console.In)) { _action = action; }
public ClientConsole(IConsoleConfiguration consoleConfiguration = null) : base(new ConsoleManager(System.Console.Out, System.Console.In)) { Initiate(consoleConfiguration ?? new ConsoleConfiguration()); }