diff options
author | David Christiansen <david.christiansen@civil.lmco.com> | 2015-01-05 15:27:28 +0000 |
---|---|---|
committer | David Christiansen <david.christiansen@civil.lmco.com> | 2015-01-05 15:27:28 +0000 |
commit | bcf4ae4d6928285f006f53150f7c57d0cdd0d71c (patch) | |
tree | e61f86a655cf9f09a34ee86d296994527ba474c0 | |
parent | 113fe90b62afcc36a4d87d630567749f0e3ae0d9 (diff) | |
download | DotNetOpenAuth-bcf4ae4d6928285f006f53150f7c57d0cdd0d71c.zip DotNetOpenAuth-bcf4ae4d6928285f006f53150f7c57d0cdd0d71c.tar.gz DotNetOpenAuth-bcf4ae4d6928285f006f53150f7c57d0cdd0d71c.tar.bz2 |
Switched OfflineProvider to OWIN host and using new logging framework
-rw-r--r-- | samples/OpenIdOfflineProvider/App.config | 24 | ||||
-rw-r--r-- | samples/OpenIdOfflineProvider/App.xaml.cs | 1 | ||||
-rw-r--r-- | samples/OpenIdOfflineProvider/MainWindow.xaml.cs | 44 | ||||
-rw-r--r-- | samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj | 65 | ||||
-rw-r--r-- | samples/OpenIdOfflineProvider/TextLogProvider.cs | 182 | ||||
-rw-r--r-- | samples/OpenIdOfflineProvider/packages.config | 22 |
6 files changed, 187 insertions, 151 deletions
diff --git a/samples/OpenIdOfflineProvider/App.config b/samples/OpenIdOfflineProvider/App.config index 7bd5b37..379ca95 100644 --- a/samples/OpenIdOfflineProvider/App.config +++ b/samples/OpenIdOfflineProvider/App.config @@ -1,22 +1,22 @@ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> - <section name="uri" type="System.Configuration.UriSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> + <section name="uri" type="System.Configuration.UriSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> <sectionGroup name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection, DotNetOpenAuth.Core"> <section name="openid" type="DotNetOpenAuth.Configuration.OpenIdElement, DotNetOpenAuth.OpenId" requirePermission="false" allowLocation="true" /> <section name="oauth" type="DotNetOpenAuth.Configuration.OAuthElement, DotNetOpenAuth.OAuth" requirePermission="false" allowLocation="true" /> <section name="messaging" type="DotNetOpenAuth.Configuration.MessagingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" /> <section name="reporting" type="DotNetOpenAuth.Configuration.ReportingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" /> </sectionGroup> - <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false"/> + <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false" /> </configSections> <!-- The uri section is necessary to turn on .NET 3.5 support for IDN (international domain names), which is necessary for OpenID urls with unicode characters in the domain/host name. It is also required to put the Uri class into RFC 3986 escaping mode, which OpenID and OAuth require. --> <uri> - <idn enabled="All"/> - <iriParsing enabled="true"/> + <idn enabled="All" /> + <iriParsing enabled="true" /> </uri> <!-- this is an optional configuration section where aspects of dotnetopenauth can be customized --> @@ -30,7 +30,7 @@ </untrustedWebRequest> </messaging> <!-- Allow DotNetOpenAuth to publish usage statistics to library authors to improve the library. --> - <reporting enabled="true"/> + <reporting enabled="true" /> </dotNetOpenAuth> <log4net> <appender name="TextBoxAppender" type="log4net.Appender.TextWriterAppender"> @@ -52,4 +52,16 @@ <level value="WARN" /> </logger> </log4net> + <runtime> + <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> + <dependentAssembly> + <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" /> + </dependentAssembly> + </assemblyBinding> + </runtime> </configuration>
\ No newline at end of file diff --git a/samples/OpenIdOfflineProvider/App.xaml.cs b/samples/OpenIdOfflineProvider/App.xaml.cs index 481ddb7..9878681 100644 --- a/samples/OpenIdOfflineProvider/App.xaml.cs +++ b/samples/OpenIdOfflineProvider/App.xaml.cs @@ -18,7 +18,6 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { /// Initializes a new instance of the <see cref="App"/> class. /// </summary> public App() { - LogProvider.SetCurrentLogProvider(new TextWriterLogProvider()); } } } diff --git a/samples/OpenIdOfflineProvider/MainWindow.xaml.cs b/samples/OpenIdOfflineProvider/MainWindow.xaml.cs index ec5bfff..0fe63c5 100644 --- a/samples/OpenIdOfflineProvider/MainWindow.xaml.cs +++ b/samples/OpenIdOfflineProvider/MainWindow.xaml.cs @@ -16,14 +16,26 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { using System.Threading.Tasks; using System.Web; using System.Web.Http; - using System.Web.Http.SelfHost; using System.Windows; using System.Windows.Input; using DotNetOpenAuth.Logging; - using Validation; + using Microsoft.Owin.Hosting; + + using Owin; + using Validation; + public class Startup { + // This code configures Web API. The Startup class is specified as a type + // parameter in the WebApp.Start method. + public void Configuration(IAppBuilder appBuilder) { + // Configure Web API for self-host. + HttpConfiguration config = new HttpConfiguration(); + config.Routes.MapHttpRoute("default", "{controller}/{id}", new { controller = "Home", id = RouteParameter.Optional }); + appBuilder.UseWebApi(config); + } + } /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> @@ -36,23 +48,17 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { /// <summary> /// The logger the application may use. /// </summary> - private ILog logger = LogProvider.GetLogger(typeof(MainWindow)); + private ILog _logger; - /// <summary> - /// The HTTP listener that acts as the OpenID Provider socket. - /// </summary> - private HttpSelfHostServer hostServer; + private IDisposable hostServer; - /// <summary> + /// <summary> /// Initializes a new instance of the <see cref="MainWindow"/> class. /// </summary> public MainWindow() { this.InitializeComponent(); - //TextWriterLogProvider.TextWriterLogger boxLogger = LogProvider.GetRepository().GetAppenders().OfType<TextWriterAppender>().FirstOrDefault(a => a.Name == "TextBoxAppender"); - //if (boxLogger != null) { - // boxLogger.Writer = new TextBoxTextWriter(this.logBox); - //} - + LogProvider.SetCurrentLogProvider(new TextWriterLogProvider(new TextBoxTextWriter(this.logBox))); + _logger = LogProvider.GetLogger(typeof(MainWindow)); Instance = this; this.StartProviderAsync(); } @@ -146,15 +152,10 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { Exception exception = null; try { Verify.Operation(this.hostServer == null, "Server already started."); - int port = 45235; - var baseUri = new UriBuilder("http", "localhost", port); - var configuration = new HttpSelfHostConfiguration(baseUri.Uri); - configuration.Routes.MapHttpRoute("default", "{controller}/{id}", new { controller = "Home", id = RouteParameter.Optional }); try { - var hostServer = new HttpSelfHostServer(configuration); - await hostServer.OpenAsync(); - this.hostServer = hostServer; + this.hostServer = WebApp.Start<Startup>(url: string.Format("http://localhost:{0}", port)); + this._logger.Info("Server Started"); } catch (AddressAccessDeniedException ex) { // If this throws an exception, use an elevated command prompt and execute: // netsh http add urlacl url=http://+:45235/ user=YOUR_USERNAME_HERE @@ -167,7 +168,7 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { throw new InvalidOperationException(message, ex); } - this.opIdentifierLabel.Content = baseUri.Uri.AbsoluteUri; + this.opIdentifierLabel.Content = string.Format("http://localhost:{0}", port); } catch (InvalidOperationException ex) { exception = ex; } @@ -189,7 +190,6 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { /// <returns>A task that completes when the asynchronous operation is finished.</returns> private async Task StopProviderAsync() { if (this.hostServer != null) { - await this.hostServer.CloseAsync(); this.hostServer.Dispose(); this.hostServer = null; } diff --git a/samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj b/samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj index a2627af..357107a 100644 --- a/samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj +++ b/samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj @@ -5,6 +5,7 @@ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\src\</SolutionDir> + <NuGetPackageImportStamp>d651fa8e</NuGetPackageImportStamp> </PropertyGroup> <Import Project="$(ProjectRoot)tools\DotNetOpenAuth.props" /> <PropertyGroup> @@ -61,35 +62,53 @@ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> </PropertyGroup> <ItemGroup> - <Reference Include="Newtonsoft.Json"> - <HintPath>..\..\src\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath> + <Reference Include="Microsoft.Owin"> + <HintPath>..\..\src\packages\Microsoft.Owin.2.0.2\lib\net45\Microsoft.Owin.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="Microsoft.Owin.Host.HttpListener"> + <HintPath>..\..\src\packages\Microsoft.Owin.Host.HttpListener.2.0.2\lib\net45\Microsoft.Owin.Host.HttpListener.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="Microsoft.Owin.Hosting"> + <HintPath>..\..\src\packages\Microsoft.Owin.Hosting.2.0.2\lib\net45\Microsoft.Owin.Hosting.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\src\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath> + </Reference> + <Reference Include="Owin"> + <HintPath>..\..\src\packages\Owin.1.0\lib\net40\Owin.dll</HintPath> + <Private>True</Private> </Reference> <Reference Include="System" /> <Reference Include="System.Core"> <RequiredTargetFramework>3.5</RequiredTargetFramework> </Reference> <Reference Include="System.Net.Http" /> - <Reference Include="System.Net.Http.Extensions, Version=2.2.15.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\src\packages\Microsoft.Net.Http.2.2.15\lib\net45\System.Net.Http.Extensions.dll</HintPath> + <Reference Include="System.Net.Http.Extensions"> + <HintPath>..\..\src\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Extensions.dll</HintPath> + <Private>True</Private> </Reference> - <Reference Include="System.Net.Http.Formatting, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <Reference Include="System.Net.Http.Formatting, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\src\packages\Microsoft.AspNet.WebApi.Client.5.0.0\lib\net45\System.Net.Http.Formatting.dll</HintPath> + <HintPath>..\..\src\packages\Microsoft.AspNet.WebApi.Client.5.2.2\lib\net45\System.Net.Http.Formatting.dll</HintPath> </Reference> - <Reference Include="System.Net.Http.Primitives, Version=4.2.15.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\src\packages\Microsoft.Net.Http.2.2.15\lib\net45\System.Net.Http.Primitives.dll</HintPath> + <Reference Include="System.Net.Http.Primitives"> + <HintPath>..\..\src\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Primitives.dll</HintPath> + <Private>True</Private> </Reference> <Reference Include="System.Net.Http.WebRequest" /> <Reference Include="System.ServiceModel" /> <Reference Include="System.Web" /> - <Reference Include="System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\src\packages\Microsoft.AspNet.WebApi.Core.5.0.0\lib\net45\System.Web.Http.dll</HintPath> + <Reference Include="System.Web.Http"> + <HintPath>..\..\src\packages\Microsoft.AspNet.WebApi.Core.5.2.2\lib\net45\System.Web.Http.dll</HintPath> + <Private>True</Private> </Reference> - <Reference Include="System.Web.Http.SelfHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> - <HintPath>..\..\src\packages\Microsoft.AspNet.WebApi.SelfHost.4.0.30506.0\lib\net40\System.Web.Http.SelfHost.dll</HintPath> + <Reference Include="System.Web.Http.Owin"> + <HintPath>..\..\src\packages\Microsoft.AspNet.WebApi.Owin.5.2.2\lib\net45\System.Web.Http.Owin.dll</HintPath> + <Private>True</Private> </Reference> <Reference Include="System.Xml.Linq"> <RequiredTargetFramework>3.5</RequiredTargetFramework> @@ -102,9 +121,9 @@ <Reference Include="UIAutomationProvider"> <RequiredTargetFramework>3.0</RequiredTargetFramework> </Reference> - <Reference Include="Validation, Version=2.0.0.0, Culture=neutral, PublicKeyToken=2fc06f0d701809a7, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\src\packages\Validation.2.0.2.13022\lib\portable-windows8+net40+sl5+windowsphone8\Validation.dll</HintPath> + <Reference Include="Validation"> + <HintPath>..\..\src\packages\Validation.2.0.6.15003\lib\portable-net40+sl50+win+wpa81+wp80+Xamarin.iOS10+MonoAndroid10+MonoTouch10\Validation.dll</HintPath> + <Private>True</Private> </Reference> <Reference Include="WindowsBase"> <RequiredTargetFramework>3.0</RequiredTargetFramework> @@ -214,9 +233,11 @@ <Import Project="$(ProjectRoot)tools\DotNetOpenAuth.targets" /> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.targets))\EnlistmentInfo.targets" Condition=" '$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.targets))' != '' " /> <Import Project="$(SolutionDir)\.nuget\nuget.targets" /> - <Import Project="..\..\src\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\src\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" /> - <Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''"> - <Error Condition="!Exists('..\..\src\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" /> - <Error Condition="Exists('..\..\src\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" /> + <Import Project="..\..\src\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\src\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" /> + <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> + <PropertyGroup> + <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> + </PropertyGroup> + <Error Condition="!Exists('..\..\src\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\src\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" /> </Target> </Project>
\ No newline at end of file diff --git a/samples/OpenIdOfflineProvider/TextLogProvider.cs b/samples/OpenIdOfflineProvider/TextLogProvider.cs index c023e9f..c927a43 100644 --- a/samples/OpenIdOfflineProvider/TextLogProvider.cs +++ b/samples/OpenIdOfflineProvider/TextLogProvider.cs @@ -1,19 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Diagnostics; -using System.IO; -using System.Reflection; -using System.Runtime.Remoting.Messaging; -using System.ServiceModel.Dispatcher; - -using DotNetOpenAuth.Logging; -using DotNetOpenAuth.Logging.LogProviders; -using DotNetOpenAuth.OpenId.Extensions.AttributeExchange; - -namespace DotNetOpenAuth.OpenIdOfflineProvider { +namespace DotNetOpenAuth.OpenIdOfflineProvider { + using System; + using System.IO; + using System.Text.RegularExpressions; + using System.Threading; + + using DotNetOpenAuth.Logging; /// <summary> /// Sends logging events to a <see cref="TextWriter"/>. @@ -31,17 +22,13 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { /// <author>Nicko Cadell</author> /// <author>Gert Driesen</author> /// <author>Douglas de la Torre</author> - public class TextWriterLogProvider : ILogProvider { + internal class TextWriterLogProvider : ILogProvider { + private readonly TextBoxTextWriter _writer; private static bool _providerIsAvailableOverride = true; - private readonly TextWriterLogger.WriteDelegate _logWriteDelegate; - - public TextWriterLogProvider() { - if (!IsLoggerAvailable()) { - throw new InvalidOperationException("Gibraltar.Agent.Log (Loupe) not found"); - } - _logWriteDelegate = GetLogWriteDelegate(); + internal TextWriterLogProvider(TextBoxTextWriter writer) { + _writer = writer; } /// <summary> @@ -56,90 +43,103 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { } public ILog GetLogger(string name) { - return new TextWriterLogProvider.TextWriterLogger(name, _logWriteDelegate); - } - - public static bool IsLoggerAvailable() { - return ProviderIsAvailableOverride && GetLogManagerType() != null; - } - - private static Type GetLogManagerType() { - return Type.GetType("Gibraltar.Agent.Log, Gibraltar.Agent"); + return new TextWriterLogger(_writer); } - private static TextWriterLogger.WriteDelegate GetLogWriteDelegate() { - Type logManagerType = GetLogManagerType(); - Type logMessageSeverityType = Type.GetType("Gibraltar.Agent.LogMessageSeverity, Gibraltar.Agent"); - Type logWriteModeType = Type.GetType("Gibraltar.Agent.LogWriteMode, Gibraltar.Agent"); - - MethodInfo method = logManagerType.GetMethod("Write", new[] - { - logMessageSeverityType, typeof(string), typeof(int), typeof(Exception), typeof(bool), - logWriteModeType, typeof(string), typeof(string), typeof(string), typeof(string), typeof(object[]) - }); - - var callDelegate = (TextWriterLogger.WriteDelegate)Delegate.CreateDelegate(typeof(TextWriterLogger.WriteDelegate), method); - return callDelegate; - } public class TextWriterLogger : ILog { - private const string LogSystem = "LibLog"; - - private readonly string _category; - private readonly WriteDelegate _logWriteDelegate; private readonly int _skipLevel; + private TextWriter _writer; + private ITextWriterFormatter _textWriterFormatter; + private IDateTimeProvider _dateTimeProvider; - internal TextWriterLogger(string category, WriteDelegate logWriteDelegate) { - _category = category; - _logWriteDelegate = logWriteDelegate; + internal TextWriterLogger(TextBoxTextWriter writer) { + _writer = writer; _skipLevel = 1; + this.DateTimeProvider = new UtcDateTimeProvider(); + this.TextWriterFormatter = new DefaultTextWriterFormatter(); + } + + public TextWriter Writer { + get { + return _writer; + } + + set { + _writer = value; + } } + public ITextWriterFormatter TextWriterFormatter { + get { + return _textWriterFormatter; + } + set { + if (value == null) + throw new ArgumentNullException(); + _textWriterFormatter = value; + } + } + + public IDateTimeProvider DateTimeProvider { + get { + return _dateTimeProvider; + } + set { + if (value == null) + throw new ArgumentNullException(); + _dateTimeProvider = value; + } + } public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception) { if (messageFunc == null) { //nothing to log.. return true; } - - _logWriteDelegate((int)ToLogMessageSeverity(logLevel), LogSystem, _skipLevel, exception, true, 0, null, _category, null, messageFunc.Invoke()); - + string[] lines = Regex.Split(messageFunc(), "\r\n|\r|\n"); + foreach (var line in lines) { + this.TextWriterFormatter.WriteText(_writer, logLevel, this.DateTimeProvider.GetCurrentDateTime(), line); + } + _writer.Flush(); return true; } - - public TraceEventType ToLogMessageSeverity(LogLevel logLevel) { - switch (logLevel) { - case LogLevel.Trace: - return TraceEventType.Verbose; - case LogLevel.Debug: - return TraceEventType.Verbose; - case LogLevel.Info: - return TraceEventType.Information; - case LogLevel.Warn: - return TraceEventType.Warning; - case LogLevel.Error: - return TraceEventType.Error; - case LogLevel.Fatal: - return TraceEventType.Critical; - default: - throw new ArgumentOutOfRangeException("logLevel"); + public interface IDateTimeProvider { + DateTime GetCurrentDateTime(); + } + public interface ITextWriterFormatter { + void WriteText(TextWriter writer, LogLevel level, DateTime dateTime, string text); + } + public class DefaultTextWriterFormatter : ITextWriterFormatter { + public void WriteText(TextWriter writer, LogLevel level, DateTime dateTime, string text) { + string sLevel; + switch (level) { + case LogLevel.Info: + default: + sLevel = "I"; + break; + + case LogLevel.Debug: + sLevel = "D"; + break; + + case LogLevel.Warn: + sLevel = "W"; + break; + + case LogLevel.Error: + sLevel = "E"; + break; + } + + writer.WriteLine("{0}:{1} {2} [{4}]: {3}", + sLevel, dateTime.ToShortDateString(), dateTime.ToLongTimeString(), + text, Thread.CurrentThread.GetHashCode()); + } + } + public class UtcDateTimeProvider : IDateTimeProvider { + public DateTime GetCurrentDateTime() { + return DateTime.UtcNow; } } - - /// <summary> - /// The form of the Loupe Log.Write method we're using - /// </summary> - internal delegate void WriteDelegate( - int severity, - string logSystem, - int skipFrames, - Exception exception, - bool attributeToException, - int writeMode, - string detailsXml, - string category, - string caption, - string description, - params object[] args - ); } } } diff --git a/samples/OpenIdOfflineProvider/packages.config b/samples/OpenIdOfflineProvider/packages.config index a99c31f..68ea9b0 100644 --- a/samples/OpenIdOfflineProvider/packages.config +++ b/samples/OpenIdOfflineProvider/packages.config @@ -1,12 +1,16 @@ <?xml version="1.0" encoding="utf-8"?> <packages> - <package id="AspNetWebApi.SelfHost" version="4.0.20710.0" targetFramework="net45" /> - <package id="Microsoft.AspNet.WebApi.Client" version="5.0.0" targetFramework="net45" /> - <package id="Microsoft.AspNet.WebApi.Core" version="5.0.0" targetFramework="net45" /> - <package id="Microsoft.AspNet.WebApi.SelfHost" version="4.0.30506.0" targetFramework="net45" /> - <package id="Microsoft.Bcl" version="1.1.3" targetFramework="net45" /> - <package id="Microsoft.Bcl.Build" version="1.0.10" targetFramework="net45" /> - <package id="Microsoft.Net.Http" version="2.2.15" targetFramework="net45" /> - <package id="Newtonsoft.Json" version="4.5.11" targetFramework="net45" /> - <package id="Validation" version="2.0.2.13022" targetFramework="net45" /> + <package id="Microsoft.AspNet.WebApi.Client" version="5.2.2" targetFramework="net45" /> + <package id="Microsoft.AspNet.WebApi.Core" version="5.2.2" targetFramework="net45" /> + <package id="Microsoft.AspNet.WebApi.Owin" version="5.2.2" targetFramework="net45" /> + <package id="Microsoft.AspNet.WebApi.OwinSelfHost" version="5.2.2" targetFramework="net45" /> + <package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" /> + <package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net45" /> + <package id="Microsoft.Net.Http" version="2.2.28" targetFramework="net45" /> + <package id="Microsoft.Owin" version="2.0.2" targetFramework="net45" /> + <package id="Microsoft.Owin.Host.HttpListener" version="2.0.2" targetFramework="net45" /> + <package id="Microsoft.Owin.Hosting" version="2.0.2" targetFramework="net45" /> + <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" /> + <package id="Owin" version="1.0" targetFramework="net45" /> + <package id="Validation" version="2.0.6.15003" targetFramework="net45" /> </packages>
\ No newline at end of file |