Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christiansen committed Jan 5, 2015
1 parent 8a6ea7a commit 49cb4ba
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 187 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -24,3 +24,4 @@ _ReSharper*
*.vs10x
*.docstates
UpgradeLog*.htm
/src/packages
21 changes: 21 additions & 0 deletions appveyor.yml
@@ -0,0 +1,21 @@
version: 5.0.{build}
branches:
except:
- master
skip_tags: true
assembly_info:
patch: true
file: '**\AssemblyInfo.*'
assembly_version: '{version}'
assembly_file_version: '{version}'
assembly_informational_version: '{version}'
before_build:
- cd .\src
- nuget restore
- cd ..\
build:
project: src\DotNetOpenAuth.sln
parallel: true
verbosity: normal
test:
assemblies: DotNetOpenAuth.Test.dll
252 changes: 122 additions & 130 deletions samples/OpenIdOfflineProvider/TextLogProvider.cs
Expand Up @@ -15,139 +15,131 @@

namespace DotNetOpenAuth.OpenIdOfflineProvider {

/// <summary>
/// Sends logging events to a <see cref="TextWriter"/>.
/// </summary>
/// <remarks>
/// <para>
/// An Appender that writes to a <see cref="TextWriter"/>.
/// </para>
/// <para>
/// This appender may be used stand alone if initialized with an appropriate
/// writer, however it is typically used as a base class for an appender that
/// can open a <see cref="TextWriter"/> to write to.
/// </para>
/// </remarks>
/// <author>Nicko Cadell</author>
/// <author>Gert Driesen</author>
/// <author>Douglas de la Torre</author>
public class TextWriterLogProvider : ILogProvider {
public class TextWriterLogger : ILog {
private const string LogSystem = "LibLog";

private readonly string _category;
private readonly WriteDelegate _logWriteDelegate;
private readonly int _skipLevel;

internal TextWriterLogger(string category, WriteDelegate logWriteDelegate) {
_category = category;
_logWriteDelegate = logWriteDelegate;
_skipLevel = 1;
}

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());

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");
}
}

/// <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
);
}

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();
}

/// <summary>
/// Gets or sets a value indicating whether [provider is available override]. Used in tests.
/// </summary>
/// <value>
/// <c>true</c> if [provider is available override]; otherwise, <c>false</c>.
/// </value>
public static bool ProviderIsAvailableOverride
{
get { return _providerIsAvailableOverride; }
set { _providerIsAvailableOverride = value; }
}

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");
}

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[]
/// <summary>
/// Sends logging events to a <see cref="TextWriter"/>.
/// </summary>
/// <remarks>
/// <para>
/// An Appender that writes to a <see cref="TextWriter"/>.
/// </para>
/// <para>
/// This appender may be used stand alone if initialized with an appropriate
/// writer, however it is typically used as a base class for an appender that
/// can open a <see cref="TextWriter"/> to write to.
/// </para>
/// </remarks>
/// <author>Nicko Cadell</author>
/// <author>Gert Driesen</author>
/// <author>Douglas de la Torre</author>
public class TextWriterLogProvider : ILogProvider {

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();
}

/// <summary>
/// Gets or sets a value indicating whether [provider is available override]. Used in tests.
/// </summary>
/// <value>
/// <c>true</c> if [provider is available override]; otherwise, <c>false</c>.
/// </value>
public static bool ProviderIsAvailableOverride {
get { return _providerIsAvailableOverride; }
set { _providerIsAvailableOverride = value; }
}

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");
}

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;
}
}
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;

internal TextWriterLogger(string category, WriteDelegate logWriteDelegate) {
_category = category;
_logWriteDelegate = logWriteDelegate;
_skipLevel = 1;
}

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());

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");
}
}

/// <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
);
}
}
}
17 changes: 16 additions & 1 deletion samples/Settings.StyleCop
@@ -1,4 +1,4 @@
<StyleCopSettings Version="4.3">
<StyleCopSettings Version="105">
<Analyzers>
<Analyzer AnalyzerId="StyleCop.CSharp.DocumentationRules">
<Rules>
Expand Down Expand Up @@ -37,6 +37,21 @@
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FieldNamesMustNotBeginWithUnderscore">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.OrderingRules">
<Rules>
<Rule Name="UsingDirectivesMustBePlacedWithinNamespace">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
Expand Down
4 changes: 3 additions & 1 deletion src/DotNetOpenAuth.Core/DotNetOpenAuth.Core.csproj
Expand Up @@ -19,7 +19,9 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<ItemGroup>
<Compile Include="App_Packages\LibLog.2.0\LibLog.cs" />
<Compile Include="App_Packages\LibLog.2.0\LibLog.cs">
<ExcludeFromStyleCop>True</ExcludeFromStyleCop>
</Compile>
<Compile Include="Assumes.cs" />
<Compile Include="IHostFactories.cs" />
<Compile Include="IRequireHostFactories.cs" />
Expand Down
4 changes: 2 additions & 2 deletions src/DotNetOpenAuth.Core/Logger.cs
Expand Up @@ -12,7 +12,7 @@ namespace DotNetOpenAuth {
using DotNetOpenAuth.Messaging;
using Validation;

/// <summary>
/// <summary>
/// A general logger for the entire DotNetOpenAuth library.
/// </summary>
/// <remarks>
Expand Down Expand Up @@ -167,7 +167,7 @@ internal static partial class Logger {
/// <param name="name">The name of the log to initialize.</param>
/// <returns>The <see cref="ILog"/> instance of the logger to use.</returns>
private static ILog InitializeFacade(string name) {
return LogProvider.GetLogger(name);
return LogProvider.GetLogger(name);
}
}
}
26 changes: 17 additions & 9 deletions src/DotNetOpenAuth.Test/App.config
@@ -1,12 +1,12 @@
<?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"/>
<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" />
<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>
</configSections>

Expand Down Expand Up @@ -48,17 +48,25 @@
<!--<store type=""/>-->
<security protectDownlevelReplayAttacks="true" minimumHashBitLength="7" maximumHashBitLength="302">
<associations>
<add type="HMAC-SHA1" lifetime="2.00:00:02" />
<add type="HMAC-SHA256" lifetime="14.00:00:14" />
<add type="HMAC-SHA1" lifetime="2.00:00:02"/>
<add type="HMAC-SHA256" lifetime="14.00:00:14"/>
</associations>
</security>
</provider>
</openid>
<!-- We definitely do NOT want to report on events that happen while running tests. -->
<reporting enabled="false" />
<reporting enabled="false"/>
</dotNetOpenAuth>

<system.diagnostics>
<assert assertuienabled="false"/>
</system.diagnostics>
</configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

0 comments on commit 49cb4ba

Please sign in to comment.