Skip to content
This repository was archived by the owner on Mar 20, 2019. It is now read-only.

Commit 49cb4ba

Browse files
author
David Christiansen
committed
Resolves #363
1 parent 8a6ea7a commit 49cb4ba

10 files changed

Lines changed: 206 additions & 187 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ _ReSharper*
2424
*.vs10x
2525
*.docstates
2626
UpgradeLog*.htm
27+
/src/packages

appveyor.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: 5.0.{build}
2+
branches:
3+
except:
4+
- master
5+
skip_tags: true
6+
assembly_info:
7+
patch: true
8+
file: '**\AssemblyInfo.*'
9+
assembly_version: '{version}'
10+
assembly_file_version: '{version}'
11+
assembly_informational_version: '{version}'
12+
before_build:
13+
- cd .\src
14+
- nuget restore
15+
- cd ..\
16+
build:
17+
project: src\DotNetOpenAuth.sln
18+
parallel: true
19+
verbosity: normal
20+
test:
21+
assemblies: DotNetOpenAuth.Test.dll

samples/OpenIdOfflineProvider/TextLogProvider.cs

Lines changed: 122 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -15,139 +15,131 @@
1515

1616
namespace DotNetOpenAuth.OpenIdOfflineProvider {
1717

18-
/// <summary>
19-
/// Sends logging events to a <see cref="TextWriter"/>.
20-
/// </summary>
21-
/// <remarks>
22-
/// <para>
23-
/// An Appender that writes to a <see cref="TextWriter"/>.
24-
/// </para>
25-
/// <para>
26-
/// This appender may be used stand alone if initialized with an appropriate
27-
/// writer, however it is typically used as a base class for an appender that
28-
/// can open a <see cref="TextWriter"/> to write to.
29-
/// </para>
30-
/// </remarks>
31-
/// <author>Nicko Cadell</author>
32-
/// <author>Gert Driesen</author>
33-
/// <author>Douglas de la Torre</author>
34-
public class TextWriterLogProvider : ILogProvider {
35-
public class TextWriterLogger : ILog {
36-
private const string LogSystem = "LibLog";
37-
38-
private readonly string _category;
39-
private readonly WriteDelegate _logWriteDelegate;
40-
private readonly int _skipLevel;
41-
42-
internal TextWriterLogger(string category, WriteDelegate logWriteDelegate) {
43-
_category = category;
44-
_logWriteDelegate = logWriteDelegate;
45-
_skipLevel = 1;
46-
}
47-
48-
public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception) {
49-
if (messageFunc == null) {
50-
//nothing to log..
51-
return true;
52-
}
53-
54-
_logWriteDelegate((int)ToLogMessageSeverity(logLevel), LogSystem, _skipLevel, exception, true, 0, null,
55-
_category, null, messageFunc.Invoke());
56-
57-
return true;
58-
}
59-
60-
public TraceEventType ToLogMessageSeverity(LogLevel logLevel) {
61-
switch (logLevel) {
62-
case LogLevel.Trace:
63-
return TraceEventType.Verbose;
64-
case LogLevel.Debug:
65-
return TraceEventType.Verbose;
66-
case LogLevel.Info:
67-
return TraceEventType.Information;
68-
case LogLevel.Warn:
69-
return TraceEventType.Warning;
70-
case LogLevel.Error:
71-
return TraceEventType.Error;
72-
case LogLevel.Fatal:
73-
return TraceEventType.Critical;
74-
default:
75-
throw new ArgumentOutOfRangeException("logLevel");
76-
}
77-
}
78-
79-
/// <summary>
80-
/// The form of the Loupe Log.Write method we're using
81-
/// </summary>
82-
internal delegate void WriteDelegate(
83-
int severity,
84-
string logSystem,
85-
int skipFrames,
86-
Exception exception,
87-
bool attributeToException,
88-
int writeMode,
89-
string detailsXml,
90-
string category,
91-
string caption,
92-
string description,
93-
params object[] args
94-
);
95-
}
96-
97-
private static bool _providerIsAvailableOverride = true;
98-
private readonly TextWriterLogger.WriteDelegate _logWriteDelegate;
99-
100-
public TextWriterLogProvider()
101-
{
102-
if (!IsLoggerAvailable())
103-
{
104-
throw new InvalidOperationException("Gibraltar.Agent.Log (Loupe) not found");
105-
}
106-
107-
_logWriteDelegate = GetLogWriteDelegate();
108-
}
109-
110-
/// <summary>
111-
/// Gets or sets a value indicating whether [provider is available override]. Used in tests.
112-
/// </summary>
113-
/// <value>
114-
/// <c>true</c> if [provider is available override]; otherwise, <c>false</c>.
115-
/// </value>
116-
public static bool ProviderIsAvailableOverride
117-
{
118-
get { return _providerIsAvailableOverride; }
119-
set { _providerIsAvailableOverride = value; }
120-
}
121-
122-
public ILog GetLogger(string name)
123-
{
124-
return new TextWriterLogProvider.TextWriterLogger(name, _logWriteDelegate);
125-
}
126-
127-
public static bool IsLoggerAvailable()
128-
{
129-
return ProviderIsAvailableOverride && GetLogManagerType() != null;
130-
}
131-
132-
private static Type GetLogManagerType()
133-
{
134-
return Type.GetType("Gibraltar.Agent.Log, Gibraltar.Agent");
135-
}
136-
137-
private static TextWriterLogger.WriteDelegate GetLogWriteDelegate()
138-
{
139-
Type logManagerType = GetLogManagerType();
140-
Type logMessageSeverityType = Type.GetType("Gibraltar.Agent.LogMessageSeverity, Gibraltar.Agent");
141-
Type logWriteModeType = Type.GetType("Gibraltar.Agent.LogWriteMode, Gibraltar.Agent");
142-
143-
MethodInfo method = logManagerType.GetMethod("Write", new[]
18+
/// <summary>
19+
/// Sends logging events to a <see cref="TextWriter"/>.
20+
/// </summary>
21+
/// <remarks>
22+
/// <para>
23+
/// An Appender that writes to a <see cref="TextWriter"/>.
24+
/// </para>
25+
/// <para>
26+
/// This appender may be used stand alone if initialized with an appropriate
27+
/// writer, however it is typically used as a base class for an appender that
28+
/// can open a <see cref="TextWriter"/> to write to.
29+
/// </para>
30+
/// </remarks>
31+
/// <author>Nicko Cadell</author>
32+
/// <author>Gert Driesen</author>
33+
/// <author>Douglas de la Torre</author>
34+
public class TextWriterLogProvider : ILogProvider {
35+
36+
private static bool _providerIsAvailableOverride = true;
37+
private readonly TextWriterLogger.WriteDelegate _logWriteDelegate;
38+
39+
public TextWriterLogProvider() {
40+
if (!IsLoggerAvailable()) {
41+
throw new InvalidOperationException("Gibraltar.Agent.Log (Loupe) not found");
42+
}
43+
44+
_logWriteDelegate = GetLogWriteDelegate();
45+
}
46+
47+
/// <summary>
48+
/// Gets or sets a value indicating whether [provider is available override]. Used in tests.
49+
/// </summary>
50+
/// <value>
51+
/// <c>true</c> if [provider is available override]; otherwise, <c>false</c>.
52+
/// </value>
53+
public static bool ProviderIsAvailableOverride {
54+
get { return _providerIsAvailableOverride; }
55+
set { _providerIsAvailableOverride = value; }
56+
}
57+
58+
public ILog GetLogger(string name) {
59+
return new TextWriterLogProvider.TextWriterLogger(name, _logWriteDelegate);
60+
}
61+
62+
public static bool IsLoggerAvailable() {
63+
return ProviderIsAvailableOverride && GetLogManagerType() != null;
64+
}
65+
66+
private static Type GetLogManagerType() {
67+
return Type.GetType("Gibraltar.Agent.Log, Gibraltar.Agent");
68+
}
69+
70+
private static TextWriterLogger.WriteDelegate GetLogWriteDelegate() {
71+
Type logManagerType = GetLogManagerType();
72+
Type logMessageSeverityType = Type.GetType("Gibraltar.Agent.LogMessageSeverity, Gibraltar.Agent");
73+
Type logWriteModeType = Type.GetType("Gibraltar.Agent.LogWriteMode, Gibraltar.Agent");
74+
75+
MethodInfo method = logManagerType.GetMethod("Write", new[]
14476
{
14577
logMessageSeverityType, typeof(string), typeof(int), typeof(Exception), typeof(bool),
14678
logWriteModeType, typeof(string), typeof(string), typeof(string), typeof(string), typeof(object[])
14779
});
14880

149-
var callDelegate = (TextWriterLogger.WriteDelegate)Delegate.CreateDelegate(typeof(TextWriterLogger.WriteDelegate), method);
150-
return callDelegate;
151-
}
152-
}
81+
var callDelegate = (TextWriterLogger.WriteDelegate)Delegate.CreateDelegate(typeof(TextWriterLogger.WriteDelegate), method);
82+
return callDelegate;
83+
}
84+
public class TextWriterLogger : ILog {
85+
private const string LogSystem = "LibLog";
86+
87+
private readonly string _category;
88+
private readonly WriteDelegate _logWriteDelegate;
89+
private readonly int _skipLevel;
90+
91+
internal TextWriterLogger(string category, WriteDelegate logWriteDelegate) {
92+
_category = category;
93+
_logWriteDelegate = logWriteDelegate;
94+
_skipLevel = 1;
95+
}
96+
97+
public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception) {
98+
if (messageFunc == null) {
99+
//nothing to log..
100+
return true;
101+
}
102+
103+
_logWriteDelegate((int)ToLogMessageSeverity(logLevel), LogSystem, _skipLevel, exception, true, 0, null, _category, null, messageFunc.Invoke());
104+
105+
return true;
106+
}
107+
108+
public TraceEventType ToLogMessageSeverity(LogLevel logLevel) {
109+
switch (logLevel) {
110+
case LogLevel.Trace:
111+
return TraceEventType.Verbose;
112+
case LogLevel.Debug:
113+
return TraceEventType.Verbose;
114+
case LogLevel.Info:
115+
return TraceEventType.Information;
116+
case LogLevel.Warn:
117+
return TraceEventType.Warning;
118+
case LogLevel.Error:
119+
return TraceEventType.Error;
120+
case LogLevel.Fatal:
121+
return TraceEventType.Critical;
122+
default:
123+
throw new ArgumentOutOfRangeException("logLevel");
124+
}
125+
}
126+
127+
/// <summary>
128+
/// The form of the Loupe Log.Write method we're using
129+
/// </summary>
130+
internal delegate void WriteDelegate(
131+
int severity,
132+
string logSystem,
133+
int skipFrames,
134+
Exception exception,
135+
bool attributeToException,
136+
int writeMode,
137+
string detailsXml,
138+
string category,
139+
string caption,
140+
string description,
141+
params object[] args
142+
);
143+
}
144+
}
153145
}

samples/Settings.StyleCop

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<StyleCopSettings Version="4.3">
1+
<StyleCopSettings Version="105">
22
<Analyzers>
33
<Analyzer AnalyzerId="StyleCop.CSharp.DocumentationRules">
44
<Rules>
@@ -37,6 +37,21 @@
3737
<BooleanProperty Name="Enabled">False</BooleanProperty>
3838
</RuleSettings>
3939
</Rule>
40+
<Rule Name="FieldNamesMustNotBeginWithUnderscore">
41+
<RuleSettings>
42+
<BooleanProperty Name="Enabled">False</BooleanProperty>
43+
</RuleSettings>
44+
</Rule>
45+
</Rules>
46+
<AnalyzerSettings />
47+
</Analyzer>
48+
<Analyzer AnalyzerId="StyleCop.CSharp.OrderingRules">
49+
<Rules>
50+
<Rule Name="UsingDirectivesMustBePlacedWithinNamespace">
51+
<RuleSettings>
52+
<BooleanProperty Name="Enabled">False</BooleanProperty>
53+
</RuleSettings>
54+
</Rule>
4055
</Rules>
4156
<AnalyzerSettings />
4257
</Analyzer>

src/DotNetOpenAuth.Core/DotNetOpenAuth.Core.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2020
</PropertyGroup>
2121
<ItemGroup>
22-
<Compile Include="App_Packages\LibLog.2.0\LibLog.cs" />
22+
<Compile Include="App_Packages\LibLog.2.0\LibLog.cs">
23+
<ExcludeFromStyleCop>True</ExcludeFromStyleCop>
24+
</Compile>
2325
<Compile Include="Assumes.cs" />
2426
<Compile Include="IHostFactories.cs" />
2527
<Compile Include="IRequireHostFactories.cs" />

src/DotNetOpenAuth.Core/Logger.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace DotNetOpenAuth {
1212
using DotNetOpenAuth.Messaging;
1313
using Validation;
1414

15-
/// <summary>
15+
/// <summary>
1616
/// A general logger for the entire DotNetOpenAuth library.
1717
/// </summary>
1818
/// <remarks>
@@ -167,7 +167,7 @@ internal static ILog Create(Type type) {
167167
/// <param name="name">The name of the log to initialize.</param>
168168
/// <returns>The <see cref="ILog"/> instance of the logger to use.</returns>
169169
private static ILog InitializeFacade(string name) {
170-
return LogProvider.GetLogger(name);
170+
return LogProvider.GetLogger(name);
171171
}
172172
}
173173
}

src/DotNetOpenAuth.Test/App.config

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<configSections>
44
<section name="uri" type="System.Configuration.UriSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
55
<sectionGroup name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection, DotNetOpenAuth.Core">
6-
<section name="openid" type="DotNetOpenAuth.Configuration.OpenIdElement, DotNetOpenAuth.OpenId" requirePermission="false" allowLocation="true" />
7-
<section name="oauth" type="DotNetOpenAuth.Configuration.OAuthElement, DotNetOpenAuth.OAuth" requirePermission="false" allowLocation="true" />
8-
<section name="messaging" type="DotNetOpenAuth.Configuration.MessagingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" />
9-
<section name="reporting" type="DotNetOpenAuth.Configuration.ReportingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" />
6+
<section name="openid" type="DotNetOpenAuth.Configuration.OpenIdElement, DotNetOpenAuth.OpenId" requirePermission="false" allowLocation="true"/>
7+
<section name="oauth" type="DotNetOpenAuth.Configuration.OAuthElement, DotNetOpenAuth.OAuth" requirePermission="false" allowLocation="true"/>
8+
<section name="messaging" type="DotNetOpenAuth.Configuration.MessagingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true"/>
9+
<section name="reporting" type="DotNetOpenAuth.Configuration.ReportingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true"/>
1010
</sectionGroup>
1111
</configSections>
1212

@@ -48,17 +48,25 @@
4848
<!--<store type=""/>-->
4949
<security protectDownlevelReplayAttacks="true" minimumHashBitLength="7" maximumHashBitLength="302">
5050
<associations>
51-
<add type="HMAC-SHA1" lifetime="2.00:00:02" />
52-
<add type="HMAC-SHA256" lifetime="14.00:00:14" />
51+
<add type="HMAC-SHA1" lifetime="2.00:00:02"/>
52+
<add type="HMAC-SHA256" lifetime="14.00:00:14"/>
5353
</associations>
5454
</security>
5555
</provider>
5656
</openid>
5757
<!-- We definitely do NOT want to report on events that happen while running tests. -->
58-
<reporting enabled="false" />
58+
<reporting enabled="false"/>
5959
</dotNetOpenAuth>
6060

6161
<system.diagnostics>
6262
<assert assertuienabled="false"/>
6363
</system.diagnostics>
64-
</configuration>
64+
<runtime>
65+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
66+
<dependentAssembly>
67+
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
68+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0"/>
69+
</dependentAssembly>
70+
</assemblyBinding>
71+
</runtime>
72+
</configuration>

0 commit comments

Comments
 (0)