diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-04-17 17:30:09 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-04-17 17:30:09 -0700 |
commit | 3e611546668fb5399e12968f47b39562bbac2c9c (patch) | |
tree | 8c4e12323844b444d76fffa075e914981f3c482d /samples/OpenIdOfflineProvider/TextBoxTextWriter.cs | |
parent | bb006ecbec46546104de88db21a2114f23565a37 (diff) | |
download | DotNetOpenAuth-3e611546668fb5399e12968f47b39562bbac2c9c.zip DotNetOpenAuth-3e611546668fb5399e12968f47b39562bbac2c9c.tar.gz DotNetOpenAuth-3e611546668fb5399e12968f47b39562bbac2c9c.tar.bz2 |
Added logger box to the Offline Provider app.
Diffstat (limited to 'samples/OpenIdOfflineProvider/TextBoxTextWriter.cs')
-rw-r--r-- | samples/OpenIdOfflineProvider/TextBoxTextWriter.cs | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/samples/OpenIdOfflineProvider/TextBoxTextWriter.cs b/samples/OpenIdOfflineProvider/TextBoxTextWriter.cs new file mode 100644 index 0000000..8118986 --- /dev/null +++ b/samples/OpenIdOfflineProvider/TextBoxTextWriter.cs @@ -0,0 +1,87 @@ +//----------------------------------------------------------------------- +// <copyright file="TextBoxTextWriter.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.OpenIdOfflineProvider { + using System; + using System.Diagnostics.Contracts; + using System.IO; + using System.Text; + using System.Windows.Controls; + + /// <summary> + /// A text writer that appends all write calls to a text box. + /// </summary> + internal class TextBoxTextWriter : TextWriter { + /// <summary> + /// Initializes a new instance of the <see cref="TextBoxTextWriter"/> class. + /// </summary> + /// <param name="box">The text box to append log messages to.</param> + internal TextBoxTextWriter(TextBox box) { + Contract.Requires(box != null); + this.Box = box; + } + + /// <summary> + /// Gets the <see cref="T:System.Text.Encoding"/> in which the output is written. + /// </summary> + /// <returns> + /// The Encoding in which the output is written. + /// </returns> + public override Encoding Encoding { + get { return Encoding.Unicode; } + } + + /// <summary> + /// Gets the box to append to. + /// </summary> + internal TextBox Box { get; private set; } + + /// <summary> + /// Writes a character to the text stream. + /// </summary> + /// <param name="value">The character to write to the text stream.</param> + /// <exception cref="T:System.ObjectDisposedException"> + /// The <see cref="T:System.IO.TextWriter"/> is closed. + /// </exception> + /// <exception cref="T:System.IO.IOException"> + /// An I/O error occurs. + /// </exception> + public override void Write(char value) { + this.Box.Dispatcher.BeginInvoke((Action<string>)this.AppendText, value.ToString()); + } + + /// <summary> + /// Writes a string to the text stream. + /// </summary> + /// <param name="value">The string to write.</param> + /// <exception cref="T:System.ObjectDisposedException"> + /// The <see cref="T:System.IO.TextWriter"/> is closed. + /// </exception> + /// <exception cref="T:System.IO.IOException"> + /// An I/O error occurs. + /// </exception> + public override void Write(string value) { + this.Box.Dispatcher.BeginInvoke((Action<string>)this.AppendText, value); + } + + /// <summary> + /// Verifies conditions that should be true for any valid state of this object. + /// </summary> + [ContractInvariantMethod] + protected void ObjectInvariant() { + Contract.Invariant(this.Box != null); + } + + /// <summary> + /// Appends text to the text box. + /// </summary> + /// <param name="value">The string to append.</param> + private void AppendText(string value) { + this.Box.AppendText(value); + this.Box.ScrollToEnd(); + } + } +} |