//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OpenIdOfflineProvider {
using System;
using System.IO;
using System.Text;
using System.Windows.Controls;
using Validation;
///
/// A text writer that appends all write calls to a text box.
///
internal class TextBoxTextWriter : TextWriter {
///
/// Initializes a new instance of the class.
///
/// The text box to append log messages to.
internal TextBoxTextWriter(TextBox box) {
Requires.NotNull(box, "box");
this.Box = box;
}
///
/// Gets the in which the output is written.
///
///
/// The Encoding in which the output is written.
///
public override Encoding Encoding {
get { return Encoding.Unicode; }
}
///
/// Gets the box to append to.
///
internal TextBox Box { get; private set; }
///
/// Writes a character to the text stream.
///
/// The character to write to the text stream.
///
/// The is closed.
///
///
/// An I/O error occurs.
///
public override void Write(char value) {
this.Box.Dispatcher.BeginInvoke((Action)this.AppendText, value.ToString());
}
///
/// Writes a string to the text stream.
///
/// The string to write.
///
/// The is closed.
///
///
/// An I/O error occurs.
///
public override void Write(string value) {
this.Box.Dispatcher.BeginInvoke((Action)this.AppendText, value);
}
///
/// Appends text to the text box.
///
/// The string to append.
private void AppendText(string value) {
this.Box.AppendText(value);
this.Box.ScrollToEnd();
}
}
}