Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,29 @@ public sealed class CaptureConsoleService : IConsoleService

#region IConsoleService

public void Write(string text) => _charToLineConverter.Input(text);

public void WriteWarning(string text) => _charToLineConverter.Input(text);

public void WriteError(string text) => _charToLineConverter.Input(text);

public bool SupportsDml => false;

public void WriteDml(string text) => throw new NotSupportedException();

public void WriteDmlExec(string text, string _) => throw new NotSupportedException();

public CancellationToken CancellationToken { get; set; } = CancellationToken.None;
bool IConsoleService.SupportsDml => false;

int IConsoleService.WindowWidth => int.MaxValue;

CancellationToken IConsoleService.CancellationToken { get; set; } = CancellationToken.None;

void IConsoleService.WriteString(OutputType type, string text)
{
switch (type)
{
case OutputType.Normal:
case OutputType.Warning:
case OutputType.Error:
_charToLineConverter.Input(text);
break;
case OutputType.Dml:
throw new NotSupportedException();
case OutputType.Logging:
default:
break;
}
}

#endregion
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -95,93 +95,34 @@ public void RemoveStream(Stream stream)

#region IConsoleService

public void Write(string text)
{
_consoleService.Write(text);
foreach (StreamWriter writer in _writers)
{
try
{
writer.Write(text);
}
catch (Exception ex) when (ex is IOException or ObjectDisposedException or NotSupportedException)
{
}
}
}

public void WriteWarning(string text)
{
_consoleService.WriteWarning(text);
foreach (StreamWriter writer in _writers)
{
try
{
writer.Write(text);
}
catch (Exception ex) when (ex is IOException or ObjectDisposedException or NotSupportedException)
{
}
}
}

public void WriteError(string text)
{
_consoleService.WriteError(text);
foreach (StreamWriter writer in _writers)
{
try
{
writer.Write(text);
}
catch (Exception ex) when (ex is IOException or ObjectDisposedException or NotSupportedException)
{
}
}
}

public bool SupportsDml => _consoleService.SupportsDml;

public void WriteDml(string text)
public int WindowWidth => _consoleService.WindowWidth;

public CancellationToken CancellationToken
{
_consoleService.WriteDml(text);
foreach (StreamWriter writer in _writers)
{
try
{
// TODO: unwrap the DML?
writer.Write(text);
}
catch (Exception ex) when (ex is IOException or ObjectDisposedException or NotSupportedException)
{
}
}
get { return _consoleService.CancellationToken; }
set { _consoleService.CancellationToken = value; }
}

public void WriteDmlExec(string text, string action)
public void WriteString(OutputType type, string text)
{
_consoleService.WriteDmlExec(text, action);

foreach (StreamWriter writer in _writers)
_consoleService.WriteString(type, text);
if (type != OutputType.Dml)
{
try
{
writer.Write(text);
}
catch (Exception ex) when (ex is IOException or ObjectDisposedException or NotSupportedException)
foreach (StreamWriter writer in _writers)
{
try
{
writer.Write(text);
}
catch (Exception ex) when (ex is IOException or ObjectDisposedException or NotSupportedException)
{
}
}
}
}

public CancellationToken CancellationToken
{
get { return _consoleService.CancellationToken; }
set { _consoleService.CancellationToken = value; }
}

public int WindowWidth => _consoleService.WindowWidth;

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Text;

namespace Microsoft.Diagnostics.Repl
namespace Microsoft.Diagnostics.DebugServices
{
public sealed class CharToLineConverter
{
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Diagnostics.DebugServices/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected void WriteLine()
/// <param name="message">line message</param>
protected void WriteLine(string message)
{
Console.Write(message + Environment.NewLine);
Console.WriteLine(message);
Console.CancellationToken.ThrowIfCancellationRequested();
}

Expand All @@ -63,7 +63,7 @@ protected void WriteLine(string message)
/// <param name="args">arguments</param>
protected void WriteLine(string format, params object[] args)
{
Console.Write(string.Format(format, args) + Environment.NewLine);
Console.WriteLine(format, args);
Console.CancellationToken.ThrowIfCancellationRequested();
}

Expand All @@ -74,7 +74,7 @@ protected void WriteLine(string format, params object[] args)
/// <param name="args">arguments</param>
protected void WriteLineWarning(string format, params object[] args)
{
Console.WriteWarning(string.Format(format, args) + Environment.NewLine);
Console.WriteLineWarning(format, args);
Console.CancellationToken.ThrowIfCancellationRequested();
}

Expand All @@ -85,7 +85,7 @@ protected void WriteLineWarning(string format, params object[] args)
/// <param name="args">arguments</param>
protected void WriteLineError(string format, params object[] args)
{
Console.WriteError(string.Format(format, args) + Environment.NewLine);
Console.WriteLineError(format, args);
Console.CancellationToken.ThrowIfCancellationRequested();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,76 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Xml.Linq;

namespace Microsoft.Diagnostics.DebugServices
{
public static class ConsoleServiceExtensions
{
/// <summary>
/// Write text to console's standard out
/// </summary>
public static void Write(this IConsoleService console, string text) => console.WriteString(OutputType.Normal, text);

/// <summary>
/// Display a blank line
/// </summary>
/// <param name="console"></param>
public static void WriteLine(this IConsoleService console)
{
console.Write(Environment.NewLine);
}
public static void WriteLine(this IConsoleService console) => console.WriteString(OutputType.Normal, Environment.NewLine);

/// <summary>
/// Display text
/// </summary>
/// <param name="console">console service instance</param>
/// <param name="message">text message</param>
public static void WriteLine(this IConsoleService console, string message)
{
console.Write(message + Environment.NewLine);
}
public static void WriteLine(this IConsoleService console, string text) => console.WriteString(OutputType.Normal, text + Environment.NewLine);

/// <summary>
/// Display formatted text
/// </summary>
/// <param name="console">console service instance</param>
/// <param name="format">format string</param>
/// <param name="args">arguments</param>
public static void WriteLine(this IConsoleService console, string format, params object[] args)
{
console.Write(string.Format(format, args) + Environment.NewLine);
}
public static void WriteLine(this IConsoleService console, string format, params object[] args) => console.WriteString(OutputType.Normal, string.Format(format, args) + Environment.NewLine);

/// <summary>
/// Write warning text to console
/// </summary>
public static void WriteWarning(this IConsoleService console, string text) => console.WriteString(OutputType.Warning, text);

/// <summary>
/// Display formatted warning text
/// </summary>
/// <param name="console">console service instance</param>
/// <param name="format">format string</param>
/// <param name="args">arguments</param>
public static void WriteLineWarning(this IConsoleService console, string format, params object[] args)
{
console.WriteWarning(string.Format(format, args) + Environment.NewLine);
}
public static void WriteLineWarning(this IConsoleService console, string format, params object[] args) => console.WriteString(OutputType.Warning, string.Format(format, args) + Environment.NewLine);

/// <summary>
/// Write error text to console
/// </summary>
public static void WriteError(this IConsoleService console, string text) => console.WriteString(OutputType.Error, text);

/// <summary>
/// Display formatted error text
/// </summary>
public static void WriteLineError(this IConsoleService console, string format, params object[] args) => console.WriteString(OutputType.Error, string.Format(format, args) + Environment.NewLine);

/// <summary>
/// Writes Debugger Markup Language (DML) markup text
/// </summary>
public static void WriteDml(this IConsoleService console, string text) => console.WriteString(OutputType.Dml, text);

/// <summary>
/// Writes an exec tag to the output stream.
/// </summary>
/// <param name="console">console service instance</param>
/// <param name="format">format string</param>
/// <param name="args">arguments</param>
public static void WriteLineError(this IConsoleService console, string format, params object[] args)
/// <param name="text">The display text.</param>
/// <param name="cmd">The action to perform.</param>
public static void WriteDmlExec(this IConsoleService console, string text, string cmd)
{
console.WriteError(string.Format(format, args) + Environment.NewLine);
if (!console.SupportsDml || string.IsNullOrWhiteSpace(cmd))
{
console.WriteString(OutputType.Normal, text);
}
else
{
string dml = $"<exec cmd=\"{DmlEscape(cmd)}\">{DmlEscape(text)}</exec>";
console.WriteString(OutputType.Dml, dml);
}
}

private static string DmlEscape(string text) => string.IsNullOrWhiteSpace(text) ? text : new XText(text).ToString();
}
}
Loading
Loading