summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--samples/OpenIdOfflineProvider/App.config7
-rw-r--r--samples/OpenIdOfflineProvider/MainWindow.xaml50
-rw-r--r--samples/OpenIdOfflineProvider/MainWindow.xaml.cs12
-rw-r--r--samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj3
-rw-r--r--samples/OpenIdOfflineProvider/TextBoxTextWriter.cs87
5 files changed, 129 insertions, 30 deletions
diff --git a/samples/OpenIdOfflineProvider/App.config b/samples/OpenIdOfflineProvider/App.config
index dff0cf0..93e2027 100644
--- a/samples/OpenIdOfflineProvider/App.config
+++ b/samples/OpenIdOfflineProvider/App.config
@@ -5,17 +5,16 @@
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false"/>
</configSections>
<log4net>
- <appender name="TraceAppender" type="log4net.Appender.TraceAppender">
+ <appender name="TextBoxAppender" type="log4net.Appender.TextWriterAppender">
<immediateFlush value="true" />
<layout type="log4net.Layout.PatternLayout">
- <conversionPattern value="[%thread] %-5level - %message%newline" />
+ <conversionPattern value="%-5level %message%newline" />
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default level -->
<root>
<level value="Info" />
- <!--<appender-ref ref="RollingFileAppender" />-->
- <appender-ref ref="TraceAppender" />
+ <appender-ref ref="TextBoxAppender" />
</root>
<!-- Specify the level for some specific categories -->
<logger name="DotNetOpenAuth">
diff --git a/samples/OpenIdOfflineProvider/MainWindow.xaml b/samples/OpenIdOfflineProvider/MainWindow.xaml
index 8100fb7..80a9fe4 100644
--- a/samples/OpenIdOfflineProvider/MainWindow.xaml
+++ b/samples/OpenIdOfflineProvider/MainWindow.xaml
@@ -1,32 +1,32 @@
<Window x:Class="DotNetOpenAuth.OpenIdOfflineProvider.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="DotNetOpenAuth Offline OpenID Provider" Height="166" Width="329">
- <StackPanel>
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition />
- <RowDefinition />
- <RowDefinition />
- <RowDefinition />
- <RowDefinition />
- </Grid.RowDefinitions>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="auto" />
- <ColumnDefinition />
- </Grid.ColumnDefinitions>
- <Label >Port</Label>
- <Label Name="portLabel" Grid.Column="1" />
- <Label Grid.Row="1">OP Identifier</Label>
- <Label Grid.Column="1" Grid.Row="1" Name="opIdentifierLabel"></Label>
- <Label Grid.Row="2">Yes Identifier</Label>
- <Label Grid.Column="1" Grid.Row="2" Name="yesIdentity" ></Label>
- <Label Grid.Row="3">No Identifier</Label>
- <Label Grid.Column="1" Grid.Row="3" Name="noIdentity" ></Label>
- </Grid>
- <StackPanel Orientation="Horizontal">
+ Title="DotNetOpenAuth Offline OpenID Provider" Height="289" Width="493">
+ <Grid>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="*"/>
+ </Grid.RowDefinitions>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="auto" />
+ <ColumnDefinition />
+ </Grid.ColumnDefinitions>
+ <Label >Port</Label>
+ <Label Name="portLabel" Grid.Column="1" />
+ <Label Grid.Row="1">OP Identifier</Label>
+ <Label Grid.Column="1" Grid.Row="1" Name="opIdentifierLabel"></Label>
+ <Label Grid.Row="2">Yes Identifier</Label>
+ <Label Grid.Column="1" Grid.Row="2" Name="yesIdentity" ></Label>
+ <Label Grid.Row="3">No Identifier</Label>
+ <Label Grid.Column="1" Grid.Row="3" Name="noIdentity" ></Label>
+ <StackPanel Orientation="Horizontal" Grid.Row="4" Grid.ColumnSpan="2">
<Button Name="startButton" Click="startButton_Click" Padding="10,0,10,0">Start</Button>
<Button Name="stopButton" Click="stopButton_Click" Padding="10,0,10,0">Stop</Button>
</StackPanel>
- </StackPanel>
+ <TextBox Height="auto" Grid.Row="5" Grid.ColumnSpan="2" Name="logBox" IsReadOnly="True" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto" />
+ </Grid>
</Window>
diff --git a/samples/OpenIdOfflineProvider/MainWindow.xaml.cs b/samples/OpenIdOfflineProvider/MainWindow.xaml.cs
index 859558e..d6332dd 100644
--- a/samples/OpenIdOfflineProvider/MainWindow.xaml.cs
+++ b/samples/OpenIdOfflineProvider/MainWindow.xaml.cs
@@ -23,6 +23,9 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider {
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
+ using log4net;
+ using log4net.Appender;
+ using log4net.Core;
/// <summary>
/// Interaction logic for MainWindow.xaml
@@ -34,10 +37,19 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider {
private HostedProvider hostedProvider = new HostedProvider();
/// <summary>
+ /// The logger the application may use.
+ /// </summary>
+ private ILog logger = log4net.LogManager.GetLogger(typeof(MainWindow));
+
+ /// <summary>
/// Initializes a new instance of the <see cref="MainWindow"/> class.
/// </summary>
public MainWindow() {
this.InitializeComponent();
+ TextWriterAppender boxLogger = log4net.LogManager.GetRepository().GetAppenders().OfType<TextWriterAppender>().FirstOrDefault(a => a.Name == "TextBoxAppender");
+ if (boxLogger != null) {
+ boxLogger.Writer = new TextBoxTextWriter(logBox);
+ }
}
#region IDisposable Members
diff --git a/samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj b/samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj
index 3c3c92f..3e9970c 100644
--- a/samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj
+++ b/samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj
@@ -124,6 +124,7 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
+ <Compile Include="TextBoxTextWriter.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
@@ -149,4 +150,4 @@
<Target Name="AfterBuild">
</Target>
-->
-</Project>
+</Project> \ No newline at end of file
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();
+ }
+ }
+}