private static void AttachConsole(bool isAttachedToParent) { Console.OutputEncoding = Encoding.UTF8; Console.InputEncoding = Encoding.UTF8; var consoleDumper = isAttachedToParent ? (IConsoleDumper) new JsonConsoleDumper() : new DirectConsoleDumper(); if (consoleDumper.SupportsRedirect) { Console.SetOut(consoleDumper.CreateWriter()); Console.SetError(consoleDumper.CreateWriter("Error")); Console.SetIn(consoleDumper.CreateReader()); AppDomain.CurrentDomain.UnhandledException += (o, e) => { consoleDumper.DumpException((Exception)e.ExceptionObject); Environment.Exit(1); }; Helpers.Progress += progress => consoleDumper.DumpProgress(ProgressResultObject.Create(progress)); } ObjectExtensions.Dumped += data => consoleDumper.Dump(data); ObjectExtensions.DictionaryListDumped += data => consoleDumper.DumpDictionaryList(DictionaryListResultObject.Create(data !)); AppDomain.CurrentDomain.ProcessExit += (o, e) => consoleDumper.Flush(); }
public void DumpProgress(ProgressResultObject result) { lock (_lock) { string jsonValue = result.Progress.HasValue ? result.Progress.Value.ToString(CultureInfo.InvariantCulture) : "null"; using (var jsonWriter = CreateJsonWriter()) { jsonWriter.WriteStartElement("root", string.Empty); jsonWriter.WriteAttributeString("type", "object"); jsonWriter.WriteElementString("$type", _progressResultTypeName); jsonWriter.WriteElementString("p", jsonValue); jsonWriter.WriteEndElement(); } DumpNewLine(); } }
public void DumpProgress(ProgressResultObject result) => throw new NotSupportedException($"Dumping progress is not supported with {nameof(DirectConsoleDumper)}");