summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/.gitignore1
-rw-r--r--src/Settings.StyleCop69
-rw-r--r--src/YOURLIBNAME.Test/.gitignore1
-rw-r--r--src/YOURLIBNAME.Test/TestBase.cs10
-rw-r--r--src/YOURLIBNAME/.gitignore1
-rw-r--r--src/YOURLIBNAME/Logger.cs62
-rw-r--r--src/YOURLIBNAME/Loggers/ILog.cs12
-rw-r--r--src/YOURLIBNAME/Loggers/Log4NetLogger.cs74
-rw-r--r--src/YOURLIBNAME/Loggers/NoOpLogger.cs54
-rw-r--r--src/YOURLIBNAME/Loggers/TraceLogger.cs67
-rw-r--r--src/YOURLIBNAME/Properties/AssemblyInfo.cs12
-rw-r--r--src/YOURLIBNAME/Settings.StyleCop1
-rw-r--r--src/YOURLIBNAME/Util.cs7
13 files changed, 229 insertions, 142 deletions
diff --git a/src/.gitignore b/src/.gitignore
index e1aecd5..084a966 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -1,3 +1,4 @@
+StyleCop.Cache
*.suo
*.cache
PrecompiledWeb
diff --git a/src/Settings.StyleCop b/src/Settings.StyleCop
new file mode 100644
index 0000000..c5b920c
--- /dev/null
+++ b/src/Settings.StyleCop
@@ -0,0 +1,69 @@
+<StyleCopSettings Version="4.3">
+ <Analyzers>
+ <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.SpacingRules">
+ <Rules>
+ <Rule Name="TabsMustNotBeUsed">
+ <RuleSettings>
+ <BooleanProperty Name="Enabled">False</BooleanProperty>
+ </RuleSettings>
+ </Rule>
+ </Rules>
+ <AnalyzerSettings />
+ </Analyzer>
+ <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.LayoutRules">
+ <Rules>
+ <Rule Name="CurlyBracketsForMultiLineStatementsMustNotShareLine">
+ <RuleSettings>
+ <BooleanProperty Name="Enabled">False</BooleanProperty>
+ </RuleSettings>
+ </Rule>
+ </Rules>
+ <AnalyzerSettings />
+ </Analyzer>
+ <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.OrderingRules">
+ <Rules>
+ <Rule Name="ElementsMustBeOrderedByAccess">
+ <RuleSettings>
+ <BooleanProperty Name="Enabled">False</BooleanProperty>
+ </RuleSettings>
+ </Rule>
+ </Rules>
+ <AnalyzerSettings />
+ </Analyzer>
+ <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.DocumentationRules">
+ <Rules>
+ <Rule Name="ElementsMustBeDocumented">
+ <RuleSettings>
+ <BooleanProperty Name="Enabled">False</BooleanProperty>
+ </RuleSettings>
+ </Rule>
+ <Rule Name="FileMustHaveHeader">
+ <RuleSettings>
+ <BooleanProperty Name="Enabled">False</BooleanProperty>
+ </RuleSettings>
+ </Rule>
+ </Rules>
+ <AnalyzerSettings />
+ </Analyzer>
+ <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.MaintainabilityRules">
+ <Rules>
+ <Rule Name="AccessModifierMustBeDeclared">
+ <RuleSettings>
+ <BooleanProperty Name="Enabled">False</BooleanProperty>
+ </RuleSettings>
+ </Rule>
+ </Rules>
+ <AnalyzerSettings />
+ </Analyzer>
+ <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.ReadabilityRules">
+ <Rules>
+ <Rule Name="PrefixLocalCallsWithThis">
+ <RuleSettings>
+ <BooleanProperty Name="Enabled">False</BooleanProperty>
+ </RuleSettings>
+ </Rule>
+ </Rules>
+ <AnalyzerSettings />
+ </Analyzer>
+ </Analyzers>
+</StyleCopSettings> \ No newline at end of file
diff --git a/src/YOURLIBNAME.Test/.gitignore b/src/YOURLIBNAME.Test/.gitignore
new file mode 100644
index 0000000..58b701f
--- /dev/null
+++ b/src/YOURLIBNAME.Test/.gitignore
@@ -0,0 +1 @@
+StyleCop.Cache
diff --git a/src/YOURLIBNAME.Test/TestBase.cs b/src/YOURLIBNAME.Test/TestBase.cs
index 3c9788f..94b2f4f 100644
--- a/src/YOURLIBNAME.Test/TestBase.cs
+++ b/src/YOURLIBNAME.Test/TestBase.cs
@@ -1,10 +1,10 @@
-using System.Reflection;
-using log4net;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+namespace YOURLIBNAME.Test {
+ using System.Reflection;
+ using log4net;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
-namespace YOURLIBNAME.Test {
public class TestBase {
- internal readonly static ILog Logger = LogManager.GetLogger("YOURLIBNAME.Test");
+ internal static readonly ILog Logger = LogManager.GetLogger("YOURLIBNAME.Test");
/// <summary>
/// Gets or sets the test context which provides
diff --git a/src/YOURLIBNAME/.gitignore b/src/YOURLIBNAME/.gitignore
index 5c901c6..2a08796 100644
--- a/src/YOURLIBNAME/.gitignore
+++ b/src/YOURLIBNAME/.gitignore
@@ -2,3 +2,4 @@
bin
obj
Bin
+StyleCop.Cache
diff --git a/src/YOURLIBNAME/Logger.cs b/src/YOURLIBNAME/Logger.cs
index c8a4ee9..f316495 100644
--- a/src/YOURLIBNAME/Logger.cs
+++ b/src/YOURLIBNAME/Logger.cs
@@ -1,8 +1,8 @@
-using System;
-using System.Globalization;
-using YOURLIBNAME.Loggers;
-
namespace YOURLIBNAME {
+ using System;
+ using System.Globalization;
+ using YOURLIBNAME.Loggers;
+
/// <summary>
/// A general logger for the entire YOURLIBNAME library.
/// </summary>
@@ -12,17 +12,31 @@ namespace YOURLIBNAME {
/// <see cref="CultureInfo.InvariantCulture"/> is used implicitly.
/// </remarks>
static class Logger {
- static ILog facade = initializeFacade();
+ static ILog facade = InitializeFacade();
- static ILog initializeFacade() {
- ILog result = Log4NetLogger.Initialize() ?? TraceLogger.Initialize() ?? NoOpLogger.Initialize();
- result.Info(Util.LibraryVersion);
- return result;
+ #region ILog Members
+ //// Although this static class doesn't literally implement the ILog interface,
+ //// we implement (mostly) all the same methods in a static way.
+
+ public static bool IsDebugEnabled {
+ get { return facade.IsDebugEnabled; }
}
- #region ILog Members
- // Although this static class doesn't literally implement the ILog interface,
- // we implement (mostly) all the same methods in a static way.
+ public static bool IsInfoEnabled {
+ get { return facade.IsInfoEnabled; }
+ }
+
+ public static bool IsWarnEnabled {
+ get { return facade.IsWarnEnabled; }
+ }
+
+ public static bool IsErrorEnabled {
+ get { return facade.IsErrorEnabled; }
+ }
+
+ public static bool IsFatalEnabled {
+ get { return facade.IsFatalEnabled; }
+ }
public static void Debug(object message) {
facade.Debug(message);
@@ -174,26 +188,12 @@ namespace YOURLIBNAME {
}
*/
- public static bool IsDebugEnabled {
- get { return facade.IsDebugEnabled; }
- }
-
- public static bool IsInfoEnabled {
- get { return facade.IsInfoEnabled; }
- }
-
- public static bool IsWarnEnabled {
- get { return facade.IsWarnEnabled; }
- }
-
- public static bool IsErrorEnabled {
- get { return facade.IsErrorEnabled; }
- }
+ #endregion
- public static bool IsFatalEnabled {
- get { return facade.IsFatalEnabled; }
+ static ILog InitializeFacade() {
+ ILog result = Log4NetLogger.Initialize() ?? TraceLogger.Initialize() ?? NoOpLogger.Initialize();
+ result.Info(Util.LibraryVersion);
+ return result;
}
-
- #endregion
}
}
diff --git a/src/YOURLIBNAME/Loggers/ILog.cs b/src/YOURLIBNAME/Loggers/ILog.cs
index a88bfd9..2f5fa82 100644
--- a/src/YOURLIBNAME/Loggers/ILog.cs
+++ b/src/YOURLIBNAME/Loggers/ILog.cs
@@ -1,3 +1,5 @@
+// <auto-generated />
+
#region Copyright & License
//
// Copyright 2001-2006 The Apache Software Foundation
@@ -16,11 +18,6 @@
//
#endregion
-using System;
-using System.Reflection;
-using log4net;
-using log4net.Core;
-
// This interface is designed to look like log4net's ILog interface.
// We have this as a facade in front of it to avoid crashing if the
// hosting web site chooses not to deploy log4net.dll along with
@@ -28,6 +25,11 @@ using log4net.Core;
namespace YOURLIBNAME.Loggers
{
+ using System;
+ using System.Reflection;
+ using log4net;
+ using log4net.Core;
+
/// <summary>
/// The ILog interface is use by application to log messages into
/// the log4net framework.
diff --git a/src/YOURLIBNAME/Loggers/Log4NetLogger.cs b/src/YOURLIBNAME/Loggers/Log4NetLogger.cs
index fdf9b2f..2823ca5 100644
--- a/src/YOURLIBNAME/Loggers/Log4NetLogger.cs
+++ b/src/YOURLIBNAME/Loggers/Log4NetLogger.cs
@@ -1,9 +1,9 @@
-using System;
-using System.Globalization;
-using System.IO;
-using System.Reflection;
+namespace YOURLIBNAME.Loggers {
+ using System;
+ using System.Globalization;
+ using System.IO;
+ using System.Reflection;
-namespace YOURLIBNAME.Loggers {
class Log4NetLogger : ILog {
private log4net.ILog log4netLogger;
@@ -11,14 +11,7 @@ namespace YOURLIBNAME.Loggers {
log4netLogger = logger;
}
- /// <summary>
- /// Returns a new log4net logger if it exists, or returns null if the assembly cannot be found.
- /// </summary>
- internal static ILog Initialize() {
- return isLog4NetPresent ? createLogger() : null;
- }
-
- static bool isLog4NetPresent {
+ static bool IsLog4NetPresent {
get {
try {
Assembly.Load("log4net");
@@ -29,14 +22,27 @@ namespace YOURLIBNAME.Loggers {
}
}
- /// <summary>
- /// Creates the log4net.LogManager. Call ONLY once log4net.dll is known to be present.
- /// </summary>
- static ILog createLogger() {
- return new Log4NetLogger(log4net.LogManager.GetLogger("YOURLIBNAME"));
+ #region ILog Members
+
+ public bool IsDebugEnabled {
+ get { return log4netLogger.IsDebugEnabled; }
}
- #region ILog Members
+ public bool IsInfoEnabled {
+ get { return log4netLogger.IsInfoEnabled; }
+ }
+
+ public bool IsWarnEnabled {
+ get { return log4netLogger.IsWarnEnabled; }
+ }
+
+ public bool IsErrorEnabled {
+ get { return log4netLogger.IsErrorEnabled; }
+ }
+
+ public bool IsFatalEnabled {
+ get { return log4netLogger.IsFatalEnabled; }
+ }
public void Debug(object message) {
log4netLogger.Debug(message);
@@ -178,26 +184,22 @@ namespace YOURLIBNAME.Loggers {
log4netLogger.FatalFormat(provider, format, args);
}
- public bool IsDebugEnabled {
- get { return log4netLogger.IsDebugEnabled; }
- }
-
- public bool IsInfoEnabled {
- get { return log4netLogger.IsInfoEnabled; }
- }
-
- public bool IsWarnEnabled {
- get { return log4netLogger.IsWarnEnabled; }
- }
+ #endregion
- public bool IsErrorEnabled {
- get { return log4netLogger.IsErrorEnabled; }
+ /// <summary>
+ /// Returns a new log4net logger if it exists, or returns null if the assembly cannot be found.
+ /// </summary>
+ /// <returns>The created <see cref="ILog"/> instance.</returns>
+ internal static ILog Initialize() {
+ return IsLog4NetPresent ? CreateLogger() : null;
}
- public bool IsFatalEnabled {
- get { return log4netLogger.IsFatalEnabled; }
+ /// <summary>
+ /// Creates the log4net.LogManager. Call ONLY after log4net.dll is known to be present.
+ /// </summary>
+ /// <returns>The created <see cref="ILog"/> instance.</returns>
+ static ILog CreateLogger() {
+ return new Log4NetLogger(log4net.LogManager.GetLogger("YOURLIBNAME"));
}
-
- #endregion
}
}
diff --git a/src/YOURLIBNAME/Loggers/NoOpLogger.cs b/src/YOURLIBNAME/Loggers/NoOpLogger.cs
index b8c62ba..9adbfa9 100644
--- a/src/YOURLIBNAME/Loggers/NoOpLogger.cs
+++ b/src/YOURLIBNAME/Loggers/NoOpLogger.cs
@@ -1,16 +1,28 @@
-using System;
+namespace YOURLIBNAME.Loggers {
+ using System;
-namespace YOURLIBNAME.Loggers {
class NoOpLogger : ILog {
+ #region ILog Members
- /// <summary>
- /// Returns a new logger that does nothing when invoked.
- /// </summary>
- internal static ILog Initialize() {
- return new NoOpLogger();
+ public bool IsDebugEnabled {
+ get { return false; }
}
- #region ILog Members
+ public bool IsInfoEnabled {
+ get { return false; }
+ }
+
+ public bool IsWarnEnabled {
+ get { return false; }
+ }
+
+ public bool IsErrorEnabled {
+ get { return false; }
+ }
+
+ public bool IsFatalEnabled {
+ get { return false; }
+ }
public void Debug(object message) {
return;
@@ -152,26 +164,14 @@ namespace YOURLIBNAME.Loggers {
return;
}
- public bool IsDebugEnabled {
- get { return false; }
- }
-
- public bool IsInfoEnabled {
- get { return false; }
- }
-
- public bool IsWarnEnabled {
- get { return false; }
- }
-
- public bool IsErrorEnabled {
- get { return false; }
- }
+ #endregion
- public bool IsFatalEnabled {
- get { return false; }
+ /// <summary>
+ /// Returns a new logger that does nothing when invoked.
+ /// </summary>
+ /// <returns>The created <see cref="ILog"/> instance.</returns>
+ internal static ILog Initialize() {
+ return new NoOpLogger();
}
-
- #endregion
}
}
diff --git a/src/YOURLIBNAME/Loggers/TraceLogger.cs b/src/YOURLIBNAME/Loggers/TraceLogger.cs
index 83e4aa4..33447f7 100644
--- a/src/YOURLIBNAME/Loggers/TraceLogger.cs
+++ b/src/YOURLIBNAME/Loggers/TraceLogger.cs
@@ -1,21 +1,13 @@
-using System;
-using System.Diagnostics;
-using System.Security;
-using System.Security.Permissions;
+namespace YOURLIBNAME.Loggers {
+ using System;
+ using System.Diagnostics;
+ using System.Security;
+ using System.Security.Permissions;
-namespace YOURLIBNAME.Loggers {
class TraceLogger : ILog {
TraceSwitch traceSwitch = new TraceSwitch("OpenID", "OpenID Trace Switch");
- /// <summary>
- /// Returns a new logger that uses the <see cref="System.Diagnostics.Trace"/> class
- /// if sufficient CAS permissions are granted to use it, otherwise returns false.
- /// </summary>
- internal static ILog Initialize() {
- return isSufficientPermissionGranted ? new TraceLogger() : null;
- }
-
- static bool isSufficientPermissionGranted {
+ static bool IsSufficientPermissionGranted {
get {
PermissionSet permissions = new PermissionSet(PermissionState.None);
permissions.AddPermission(new KeyContainerPermission(PermissionState.Unrestricted));
@@ -36,6 +28,26 @@ namespace YOURLIBNAME.Loggers {
#region ILog Members
+ public bool IsDebugEnabled {
+ get { return traceSwitch.TraceVerbose; }
+ }
+
+ public bool IsInfoEnabled {
+ get { return traceSwitch.TraceInfo; }
+ }
+
+ public bool IsWarnEnabled {
+ get { return traceSwitch.TraceWarning; }
+ }
+
+ public bool IsErrorEnabled {
+ get { return traceSwitch.TraceError; }
+ }
+
+ public bool IsFatalEnabled {
+ get { return traceSwitch.TraceError; }
+ }
+
public void Debug(object message) {
Trace.TraceInformation(message.ToString());
}
@@ -176,26 +188,15 @@ namespace YOURLIBNAME.Loggers {
Trace.TraceError(format, args);
}
- public bool IsDebugEnabled {
- get { return traceSwitch.TraceVerbose; }
- }
-
- public bool IsInfoEnabled {
- get { return traceSwitch.TraceInfo; }
- }
-
- public bool IsWarnEnabled {
- get { return traceSwitch.TraceWarning; }
- }
-
- public bool IsErrorEnabled {
- get { return traceSwitch.TraceError; }
- }
+ #endregion
- public bool IsFatalEnabled {
- get { return traceSwitch.TraceError; }
+ /// <summary>
+ /// Returns a new logger that uses the <see cref="System.Diagnostics.Trace"/> class
+ /// if sufficient CAS permissions are granted to use it, otherwise returns false.
+ /// </summary>
+ /// <returns>The created <see cref="ILog"/> instance.</returns>
+ internal static ILog Initialize() {
+ return IsSufficientPermissionGranted ? new TraceLogger() : null;
}
-
- #endregion
}
}
diff --git a/src/YOURLIBNAME/Properties/AssemblyInfo.cs b/src/YOURLIBNAME/Properties/AssemblyInfo.cs
index 3d46464..14abe90 100644
--- a/src/YOURLIBNAME/Properties/AssemblyInfo.cs
+++ b/src/YOURLIBNAME/Properties/AssemblyInfo.cs
@@ -1,4 +1,10 @@
-// Uncomment this line to build a partially trusted assembly.
+//-----------------------------------------------------------------------
+// <copyright file="AssemblyInfo.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+// Uncomment this line to build a partially trusted assembly.
// This has some security bonuses in that if there was a way to
// hijack this assembly to do something it is not designed to do,
// it will fail before doing much damage.
@@ -8,7 +14,7 @@
// strong-name signed assembly must use AllowPartiallyTrustedCallers
// to be called from a web page, but defining PARTIAL_TRUST below also
// accomplishes this.
-//#define PARTIAL_TRUST
+////#define PARTIAL_TRUST
// We DON'T put an AssemblyVersionAttribute in here because it is generated in the build.
@@ -37,6 +43,7 @@ using System.Web.UI;
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: CLSCompliant(true)]
+
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
@@ -62,6 +69,7 @@ using System.Web.UI;
// We need to be allowed to execute code. Besides, it gives a good baseline RequestMinimum permission.
[assembly: SecurityPermission(SecurityAction.RequestMinimum, Execution = true)]
+
// Allows the consumer to call out to the web server. This is unnecessary in provider-only scenarios.
// Note: we don't use a single demand for https?://.* because the regex pattern must exactly
// match the one used by hosting providers. Listing them individually seems to be more common.
diff --git a/src/YOURLIBNAME/Settings.StyleCop b/src/YOURLIBNAME/Settings.StyleCop
new file mode 100644
index 0000000..7f55ce6
--- /dev/null
+++ b/src/YOURLIBNAME/Settings.StyleCop
@@ -0,0 +1 @@
+<StyleCopSettings Version="4.3" /> \ No newline at end of file
diff --git a/src/YOURLIBNAME/Util.cs b/src/YOURLIBNAME/Util.cs
index 5c8943d..fed1c85 100644
--- a/src/YOURLIBNAME/Util.cs
+++ b/src/YOURLIBNAME/Util.cs
@@ -1,12 +1,13 @@
-using System.Globalization;
-using System.Reflection;
+namespace YOURLIBNAME {
+ using System.Globalization;
+ using System.Reflection;
-namespace YOURLIBNAME {
class Util {
public static string LibraryVersion {
get {
string assemblyFullName = Assembly.GetExecutingAssembly().FullName;
bool official = assemblyFullName.Contains("PublicKeyToken=2780ccd10d57b246");
+
// We use InvariantCulture since this is used for logging.
return string.Format(CultureInfo.InvariantCulture, "{0} ({1})", assemblyFullName, official ? "official" : "private");
}