mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Normalizing some more line endings
This commit is contained in:
parent
4105f4490b
commit
6cc481e825
@ -1,419 +1,419 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Web;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Environment.Configuration;
|
||||
using log4net;
|
||||
using log4net.Core;
|
||||
using log4net.Util;
|
||||
|
||||
using Logger = Castle.Core.Logging.ILogger;
|
||||
|
||||
namespace Orchard.Logging {
|
||||
[Serializable]
|
||||
public class OrchardLog4netLogger : MarshalByRefObject, Logger, IShim {
|
||||
private static readonly Type declaringType = typeof(OrchardLog4netLogger);
|
||||
|
||||
private readonly Lazy<ShellSettings> _shellSettings;
|
||||
|
||||
public IOrchardHostContainer HostContainer { get; set; }
|
||||
|
||||
public OrchardLog4netLogger(log4net.Core.ILogger logger, OrchardLog4netFactory factory) {
|
||||
OrchardHostContainerRegistry.RegisterShim(this);
|
||||
Logger = logger;
|
||||
Factory = factory;
|
||||
|
||||
_shellSettings = new Lazy<ShellSettings>(LoadSettings);
|
||||
}
|
||||
|
||||
internal OrchardLog4netLogger() {
|
||||
}
|
||||
|
||||
internal OrchardLog4netLogger(ILog log, OrchardLog4netFactory factory)
|
||||
: this(log.Logger, factory) {
|
||||
}
|
||||
|
||||
private ShellSettings LoadSettings() {
|
||||
var ctx = HttpContext.Current;
|
||||
if (ctx == null)
|
||||
return null;
|
||||
|
||||
var runningShellTable = HostContainer.Resolve<IRunningShellTable>();
|
||||
if (runningShellTable == null)
|
||||
return null;
|
||||
|
||||
var shellSettings = runningShellTable.Match(new HttpContextWrapper(ctx));
|
||||
if (shellSettings == null)
|
||||
return null;
|
||||
|
||||
var orchardHost = HostContainer.Resolve<IOrchardHost>();
|
||||
if (orchardHost == null)
|
||||
return null;
|
||||
|
||||
var shellContext = orchardHost.GetShellContext(shellSettings);
|
||||
if (shellContext == null || shellContext.Settings == null)
|
||||
return null;
|
||||
|
||||
|
||||
return shellContext.Settings;
|
||||
}
|
||||
|
||||
// Load the log4net thread with additional properties if they are available
|
||||
protected internal void AddExtendedThreadInfo() {
|
||||
if (_shellSettings.Value != null) {
|
||||
ThreadContext.Properties["Tenant"] = _shellSettings.Value.Name;
|
||||
}
|
||||
|
||||
try {
|
||||
var ctx = HttpContext.Current;
|
||||
if (ctx != null) {
|
||||
ThreadContext.Properties["Url"] = ctx.Request.Url.ToString();
|
||||
}
|
||||
}
|
||||
catch(HttpException) {
|
||||
// can happen on cloud service for an unknown reason
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsDebugEnabled {
|
||||
get { return Logger.IsEnabledFor(Level.Debug); }
|
||||
}
|
||||
|
||||
public bool IsErrorEnabled {
|
||||
get { return Logger.IsEnabledFor(Level.Error); }
|
||||
}
|
||||
|
||||
public bool IsFatalEnabled {
|
||||
get { return Logger.IsEnabledFor(Level.Fatal); }
|
||||
}
|
||||
|
||||
public bool IsInfoEnabled {
|
||||
get { return Logger.IsEnabledFor(Level.Info); }
|
||||
}
|
||||
|
||||
public bool IsWarnEnabled {
|
||||
get { return Logger.IsEnabledFor(Level.Warn); }
|
||||
}
|
||||
|
||||
protected internal OrchardLog4netFactory Factory { get; set; }
|
||||
|
||||
protected internal log4net.Core.ILogger Logger { get; set; }
|
||||
|
||||
public override string ToString() {
|
||||
return Logger.ToString();
|
||||
}
|
||||
|
||||
public virtual Logger CreateChildLogger(String name) {
|
||||
return Factory.Create(Logger.Name + "." + name);
|
||||
}
|
||||
|
||||
public void Debug(String message) {
|
||||
if (IsDebugEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Debug, message, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Debug(Func<string> messageFactory) {
|
||||
if (IsDebugEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Debug, messageFactory.Invoke(), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Debug(String message, Exception exception) {
|
||||
if (IsDebugEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Debug, message, exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void DebugFormat(String format, params Object[] args) {
|
||||
if (IsDebugEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Debug, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void DebugFormat(Exception exception, String format, params Object[] args) {
|
||||
if (IsDebugEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Debug, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void DebugFormat(IFormatProvider formatProvider, String format, params Object[] args) {
|
||||
if (IsDebugEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Debug, new SystemStringFormat(formatProvider, format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void DebugFormat(Exception exception, IFormatProvider formatProvider, String format, params Object[] args) {
|
||||
if (IsDebugEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Debug, new SystemStringFormat(formatProvider, format, args), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void Error(String message) {
|
||||
if (IsErrorEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Error, message, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Error(Func<string> messageFactory) {
|
||||
if (IsErrorEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Error, messageFactory.Invoke(), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Error(String message, Exception exception) {
|
||||
if (IsErrorEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Error, message, exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void ErrorFormat(String format, params Object[] args) {
|
||||
if (IsErrorEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Error, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void ErrorFormat(Exception exception, String format, params Object[] args) {
|
||||
if (IsErrorEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Error, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void ErrorFormat(IFormatProvider formatProvider, String format, params Object[] args) {
|
||||
if (IsErrorEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Error, new SystemStringFormat(formatProvider, format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void ErrorFormat(Exception exception, IFormatProvider formatProvider, String format, params Object[] args) {
|
||||
if (IsErrorEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Error, new SystemStringFormat(formatProvider, format, args), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void Fatal(String message) {
|
||||
if (IsFatalEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Fatal, message, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Fatal(Func<string> messageFactory) {
|
||||
if (IsFatalEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Fatal, messageFactory.Invoke(), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Fatal(String message, Exception exception) {
|
||||
if (IsFatalEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Fatal, message, exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void FatalFormat(String format, params Object[] args) {
|
||||
if (IsFatalEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Fatal, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void FatalFormat(Exception exception, String format, params Object[] args) {
|
||||
if (IsFatalEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Fatal, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void FatalFormat(IFormatProvider formatProvider, String format, params Object[] args) {
|
||||
if (IsFatalEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Fatal, new SystemStringFormat(formatProvider, format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void FatalFormat(Exception exception, IFormatProvider formatProvider, String format, params Object[] args) {
|
||||
if (IsFatalEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Fatal, new SystemStringFormat(formatProvider, format, args), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void Info(String message) {
|
||||
if (IsInfoEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Info, message, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Info(Func<string> messageFactory) {
|
||||
if (IsInfoEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Info, messageFactory.Invoke(), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Info(String message, Exception exception) {
|
||||
if (IsInfoEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Info, message, exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void InfoFormat(String format, params Object[] args) {
|
||||
if (IsInfoEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Info, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void InfoFormat(Exception exception, String format, params Object[] args) {
|
||||
if (IsInfoEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Info, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void InfoFormat(IFormatProvider formatProvider, String format, params Object[] args) {
|
||||
if (IsInfoEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Info, new SystemStringFormat(formatProvider, format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void InfoFormat(Exception exception, IFormatProvider formatProvider, String format, params Object[] args) {
|
||||
if (IsInfoEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Info, new SystemStringFormat(formatProvider, format, args), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void Warn(String message) {
|
||||
if (IsWarnEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Warn, message, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Warn(Func<string> messageFactory) {
|
||||
if (IsWarnEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Warn, messageFactory.Invoke(), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Warn(String message, Exception exception) {
|
||||
if (IsWarnEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Warn, message, exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void WarnFormat(String format, params Object[] args) {
|
||||
if (IsWarnEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Warn, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void WarnFormat(Exception exception, String format, params Object[] args) {
|
||||
if (IsWarnEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Warn, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void WarnFormat(IFormatProvider formatProvider, String format, params Object[] args) {
|
||||
if (IsWarnEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Warn, new SystemStringFormat(formatProvider, format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void WarnFormat(Exception exception, IFormatProvider formatProvider, String format, params Object[] args) {
|
||||
if (IsWarnEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Warn, new SystemStringFormat(formatProvider, format, args), exception);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use IsFatalEnabled instead")]
|
||||
public bool IsFatalErrorEnabled {
|
||||
get {
|
||||
return Logger.IsEnabledFor(Level.Fatal);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use DebugFormat instead")]
|
||||
public void Debug(string format, params object[] args) {
|
||||
if (IsDebugEnabled) {
|
||||
Logger.Log(declaringType, Level.Debug, string.Format(format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use ErrorFormat instead")]
|
||||
public void Error(string format, params object[] args) {
|
||||
if (IsErrorEnabled) {
|
||||
Logger.Log(declaringType, Level.Error, string.Format(format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use FatalFormat instead")]
|
||||
public void Fatal(string format, params object[] args) {
|
||||
if (IsFatalEnabled) {
|
||||
Logger.Log(declaringType, Level.Fatal, string.Format(format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use Fatal instead")]
|
||||
public void FatalError(string message) {
|
||||
if (IsFatalErrorEnabled) {
|
||||
Logger.Log(declaringType, Level.Fatal, message, null);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use FatalFormat instead")]
|
||||
public void FatalError(string format, params object[] args) {
|
||||
if (IsFatalErrorEnabled) {
|
||||
Logger.Log(declaringType, Level.Fatal, string.Format(format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use Fatal instead")]
|
||||
public void FatalError(string message, Exception exception) {
|
||||
if (IsFatalErrorEnabled) {
|
||||
Logger.Log(declaringType, Level.Fatal, message, exception);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use InfoFormat instead")]
|
||||
public void Info(string format, params object[] args) {
|
||||
if (IsInfoEnabled) {
|
||||
Logger.Log(declaringType, Level.Info, string.Format(format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use WarnFormat instead")]
|
||||
public void Warn(string format, params object[] args) {
|
||||
if (IsWarnEnabled) {
|
||||
Logger.Log(declaringType, Level.Warn, string.Format(format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Web;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Environment.Configuration;
|
||||
using log4net;
|
||||
using log4net.Core;
|
||||
using log4net.Util;
|
||||
|
||||
using Logger = Castle.Core.Logging.ILogger;
|
||||
|
||||
namespace Orchard.Logging {
|
||||
[Serializable]
|
||||
public class OrchardLog4netLogger : MarshalByRefObject, Logger, IShim {
|
||||
private static readonly Type declaringType = typeof(OrchardLog4netLogger);
|
||||
|
||||
private readonly Lazy<ShellSettings> _shellSettings;
|
||||
|
||||
public IOrchardHostContainer HostContainer { get; set; }
|
||||
|
||||
public OrchardLog4netLogger(log4net.Core.ILogger logger, OrchardLog4netFactory factory) {
|
||||
OrchardHostContainerRegistry.RegisterShim(this);
|
||||
Logger = logger;
|
||||
Factory = factory;
|
||||
|
||||
_shellSettings = new Lazy<ShellSettings>(LoadSettings);
|
||||
}
|
||||
|
||||
internal OrchardLog4netLogger() {
|
||||
}
|
||||
|
||||
internal OrchardLog4netLogger(ILog log, OrchardLog4netFactory factory)
|
||||
: this(log.Logger, factory) {
|
||||
}
|
||||
|
||||
private ShellSettings LoadSettings() {
|
||||
var ctx = HttpContext.Current;
|
||||
if (ctx == null)
|
||||
return null;
|
||||
|
||||
var runningShellTable = HostContainer.Resolve<IRunningShellTable>();
|
||||
if (runningShellTable == null)
|
||||
return null;
|
||||
|
||||
var shellSettings = runningShellTable.Match(new HttpContextWrapper(ctx));
|
||||
if (shellSettings == null)
|
||||
return null;
|
||||
|
||||
var orchardHost = HostContainer.Resolve<IOrchardHost>();
|
||||
if (orchardHost == null)
|
||||
return null;
|
||||
|
||||
var shellContext = orchardHost.GetShellContext(shellSettings);
|
||||
if (shellContext == null || shellContext.Settings == null)
|
||||
return null;
|
||||
|
||||
|
||||
return shellContext.Settings;
|
||||
}
|
||||
|
||||
// Load the log4net thread with additional properties if they are available
|
||||
protected internal void AddExtendedThreadInfo() {
|
||||
if (_shellSettings.Value != null) {
|
||||
ThreadContext.Properties["Tenant"] = _shellSettings.Value.Name;
|
||||
}
|
||||
|
||||
try {
|
||||
var ctx = HttpContext.Current;
|
||||
if (ctx != null) {
|
||||
ThreadContext.Properties["Url"] = ctx.Request.Url.ToString();
|
||||
}
|
||||
}
|
||||
catch(HttpException) {
|
||||
// can happen on cloud service for an unknown reason
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsDebugEnabled {
|
||||
get { return Logger.IsEnabledFor(Level.Debug); }
|
||||
}
|
||||
|
||||
public bool IsErrorEnabled {
|
||||
get { return Logger.IsEnabledFor(Level.Error); }
|
||||
}
|
||||
|
||||
public bool IsFatalEnabled {
|
||||
get { return Logger.IsEnabledFor(Level.Fatal); }
|
||||
}
|
||||
|
||||
public bool IsInfoEnabled {
|
||||
get { return Logger.IsEnabledFor(Level.Info); }
|
||||
}
|
||||
|
||||
public bool IsWarnEnabled {
|
||||
get { return Logger.IsEnabledFor(Level.Warn); }
|
||||
}
|
||||
|
||||
protected internal OrchardLog4netFactory Factory { get; set; }
|
||||
|
||||
protected internal log4net.Core.ILogger Logger { get; set; }
|
||||
|
||||
public override string ToString() {
|
||||
return Logger.ToString();
|
||||
}
|
||||
|
||||
public virtual Logger CreateChildLogger(String name) {
|
||||
return Factory.Create(Logger.Name + "." + name);
|
||||
}
|
||||
|
||||
public void Debug(String message) {
|
||||
if (IsDebugEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Debug, message, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Debug(Func<string> messageFactory) {
|
||||
if (IsDebugEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Debug, messageFactory.Invoke(), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Debug(String message, Exception exception) {
|
||||
if (IsDebugEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Debug, message, exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void DebugFormat(String format, params Object[] args) {
|
||||
if (IsDebugEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Debug, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void DebugFormat(Exception exception, String format, params Object[] args) {
|
||||
if (IsDebugEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Debug, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void DebugFormat(IFormatProvider formatProvider, String format, params Object[] args) {
|
||||
if (IsDebugEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Debug, new SystemStringFormat(formatProvider, format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void DebugFormat(Exception exception, IFormatProvider formatProvider, String format, params Object[] args) {
|
||||
if (IsDebugEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Debug, new SystemStringFormat(formatProvider, format, args), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void Error(String message) {
|
||||
if (IsErrorEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Error, message, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Error(Func<string> messageFactory) {
|
||||
if (IsErrorEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Error, messageFactory.Invoke(), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Error(String message, Exception exception) {
|
||||
if (IsErrorEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Error, message, exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void ErrorFormat(String format, params Object[] args) {
|
||||
if (IsErrorEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Error, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void ErrorFormat(Exception exception, String format, params Object[] args) {
|
||||
if (IsErrorEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Error, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void ErrorFormat(IFormatProvider formatProvider, String format, params Object[] args) {
|
||||
if (IsErrorEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Error, new SystemStringFormat(formatProvider, format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void ErrorFormat(Exception exception, IFormatProvider formatProvider, String format, params Object[] args) {
|
||||
if (IsErrorEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Error, new SystemStringFormat(formatProvider, format, args), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void Fatal(String message) {
|
||||
if (IsFatalEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Fatal, message, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Fatal(Func<string> messageFactory) {
|
||||
if (IsFatalEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Fatal, messageFactory.Invoke(), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Fatal(String message, Exception exception) {
|
||||
if (IsFatalEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Fatal, message, exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void FatalFormat(String format, params Object[] args) {
|
||||
if (IsFatalEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Fatal, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void FatalFormat(Exception exception, String format, params Object[] args) {
|
||||
if (IsFatalEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Fatal, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void FatalFormat(IFormatProvider formatProvider, String format, params Object[] args) {
|
||||
if (IsFatalEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Fatal, new SystemStringFormat(formatProvider, format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void FatalFormat(Exception exception, IFormatProvider formatProvider, String format, params Object[] args) {
|
||||
if (IsFatalEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Fatal, new SystemStringFormat(formatProvider, format, args), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void Info(String message) {
|
||||
if (IsInfoEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Info, message, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Info(Func<string> messageFactory) {
|
||||
if (IsInfoEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Info, messageFactory.Invoke(), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Info(String message, Exception exception) {
|
||||
if (IsInfoEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Info, message, exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void InfoFormat(String format, params Object[] args) {
|
||||
if (IsInfoEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Info, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void InfoFormat(Exception exception, String format, params Object[] args) {
|
||||
if (IsInfoEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Info, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void InfoFormat(IFormatProvider formatProvider, String format, params Object[] args) {
|
||||
if (IsInfoEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Info, new SystemStringFormat(formatProvider, format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void InfoFormat(Exception exception, IFormatProvider formatProvider, String format, params Object[] args) {
|
||||
if (IsInfoEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Info, new SystemStringFormat(formatProvider, format, args), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void Warn(String message) {
|
||||
if (IsWarnEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Warn, message, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Warn(Func<string> messageFactory) {
|
||||
if (IsWarnEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Warn, messageFactory.Invoke(), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Warn(String message, Exception exception) {
|
||||
if (IsWarnEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Warn, message, exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void WarnFormat(String format, params Object[] args) {
|
||||
if (IsWarnEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Warn, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void WarnFormat(Exception exception, String format, params Object[] args) {
|
||||
if (IsWarnEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Warn, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void WarnFormat(IFormatProvider formatProvider, String format, params Object[] args) {
|
||||
if (IsWarnEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Warn, new SystemStringFormat(formatProvider, format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
public void WarnFormat(Exception exception, IFormatProvider formatProvider, String format, params Object[] args) {
|
||||
if (IsWarnEnabled) {
|
||||
AddExtendedThreadInfo();
|
||||
Logger.Log(declaringType, Level.Warn, new SystemStringFormat(formatProvider, format, args), exception);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use IsFatalEnabled instead")]
|
||||
public bool IsFatalErrorEnabled {
|
||||
get {
|
||||
return Logger.IsEnabledFor(Level.Fatal);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use DebugFormat instead")]
|
||||
public void Debug(string format, params object[] args) {
|
||||
if (IsDebugEnabled) {
|
||||
Logger.Log(declaringType, Level.Debug, string.Format(format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use ErrorFormat instead")]
|
||||
public void Error(string format, params object[] args) {
|
||||
if (IsErrorEnabled) {
|
||||
Logger.Log(declaringType, Level.Error, string.Format(format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use FatalFormat instead")]
|
||||
public void Fatal(string format, params object[] args) {
|
||||
if (IsFatalEnabled) {
|
||||
Logger.Log(declaringType, Level.Fatal, string.Format(format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use Fatal instead")]
|
||||
public void FatalError(string message) {
|
||||
if (IsFatalErrorEnabled) {
|
||||
Logger.Log(declaringType, Level.Fatal, message, null);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use FatalFormat instead")]
|
||||
public void FatalError(string format, params object[] args) {
|
||||
if (IsFatalErrorEnabled) {
|
||||
Logger.Log(declaringType, Level.Fatal, string.Format(format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use Fatal instead")]
|
||||
public void FatalError(string message, Exception exception) {
|
||||
if (IsFatalErrorEnabled) {
|
||||
Logger.Log(declaringType, Level.Fatal, message, exception);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use InfoFormat instead")]
|
||||
public void Info(string format, params object[] args) {
|
||||
if (IsInfoEnabled) {
|
||||
Logger.Log(declaringType, Level.Info, string.Format(format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use WarnFormat instead")]
|
||||
public void Warn(string format, params object[] args) {
|
||||
if (IsWarnEnabled) {
|
||||
Logger.Log(declaringType, Level.Warn, string.Format(format, args), null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,145 +1,145 @@
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Mvc.Filters;
|
||||
using Orchard.Security;
|
||||
|
||||
namespace Orchard.Mvc.AntiForgery {
|
||||
[UsedImplicitly]
|
||||
public class AntiForgeryAuthorizationFilter : FilterProvider, IAuthorizationFilter {
|
||||
private readonly IAuthenticationService _authenticationService;
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
|
||||
public AntiForgeryAuthorizationFilter(IAuthenticationService authenticationService, IExtensionManager extensionManager) {
|
||||
_authenticationService = authenticationService;
|
||||
_extensionManager = extensionManager;
|
||||
}
|
||||
|
||||
public void OnAuthorization(AuthorizationContext filterContext) {
|
||||
// If the request is not a POST or is anonymous, and the request doesn't have validation forced, return.
|
||||
if ((filterContext.HttpContext.Request.HttpMethod != "POST" ||
|
||||
_authenticationService.GetAuthenticatedUser() == null) && !ShouldValidateGet(filterContext)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsAntiForgeryProtectionEnabled(filterContext)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var validator = new ValidateAntiForgeryTokenAttribute();
|
||||
validator.OnAuthorization(filterContext);
|
||||
|
||||
if (filterContext.HttpContext is HackHttpContext)
|
||||
filterContext.HttpContext = ((HackHttpContext)filterContext.HttpContext).OriginalHttpContextBase;
|
||||
}
|
||||
|
||||
private bool IsAntiForgeryProtectionEnabled(AuthorizationContext context) {
|
||||
// POST is opt-out
|
||||
var attributes =
|
||||
(ValidateAntiForgeryTokenOrchardAttribute[])
|
||||
context.ActionDescriptor.GetCustomAttributes(typeof (ValidateAntiForgeryTokenOrchardAttribute), false);
|
||||
|
||||
if (attributes.Length > 0 && !attributes[0].Enabled) return false;
|
||||
|
||||
var currentModule = GetArea(context.RouteData);
|
||||
return !String.IsNullOrEmpty(currentModule)
|
||||
&& (_extensionManager.AvailableExtensions()
|
||||
.First(descriptor => String.Equals(descriptor.Id, currentModule, StringComparison.OrdinalIgnoreCase))
|
||||
.AntiForgery.Equals("enabled", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private static string GetArea(RouteData routeData) {
|
||||
if (routeData.Values.ContainsKey("area"))
|
||||
return routeData.Values["area"] as string;
|
||||
|
||||
return routeData.DataTokens["area"] as string ?? "";
|
||||
}
|
||||
|
||||
private static bool ShouldValidateGet(AuthorizationContext context) {
|
||||
const string tokenFieldName = "__RequestVerificationToken";
|
||||
|
||||
var attributes =
|
||||
(ValidateAntiForgeryTokenOrchardAttribute[])
|
||||
context.ActionDescriptor.GetCustomAttributes(typeof (ValidateAntiForgeryTokenOrchardAttribute), false);
|
||||
|
||||
if (attributes.Length > 0 && attributes[0].Enabled) {
|
||||
var request = context.HttpContext.Request;
|
||||
|
||||
//HAACK: (erikpo) If the token is in the querystring, put it in the form so MVC can validate it
|
||||
if (!string.IsNullOrEmpty(request.QueryString[tokenFieldName])) {
|
||||
context.HttpContext = new HackHttpContext(context.HttpContext, (HttpContext)context.HttpContext.Items["originalHttpContext"]);
|
||||
((HackHttpRequest)context.HttpContext.Request).AddFormValue(tokenFieldName, context.HttpContext.Request.QueryString[tokenFieldName]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#region HackHttpContext
|
||||
|
||||
private class HackHttpContext : HttpContextWrapper {
|
||||
private readonly HttpContextBase _originalHttpContextBase;
|
||||
private readonly HttpContext _originalHttpContext;
|
||||
private HttpRequestWrapper _request;
|
||||
|
||||
public HackHttpContext(HttpContextBase httpContextBase, HttpContext httpContext)
|
||||
: base(httpContext) {
|
||||
_originalHttpContextBase = httpContextBase;
|
||||
_originalHttpContext = httpContext;
|
||||
}
|
||||
|
||||
public HttpContextBase OriginalHttpContextBase {
|
||||
get { return _originalHttpContextBase; }
|
||||
}
|
||||
|
||||
public override HttpRequestBase Request
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_request == null)
|
||||
_request = new HackHttpRequest(_originalHttpContext.Request);
|
||||
|
||||
return _request;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region HackHttpRequest
|
||||
|
||||
private class HackHttpRequest : HttpRequestWrapper {
|
||||
private readonly HttpRequest _originalHttpRequest;
|
||||
private NameValueCollection _form;
|
||||
|
||||
public HackHttpRequest(HttpRequest httpRequest)
|
||||
: base(httpRequest) {
|
||||
_originalHttpRequest = httpRequest;
|
||||
}
|
||||
|
||||
public override NameValueCollection Form
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_form == null)
|
||||
_form = new NameValueCollection(_originalHttpRequest.Form);
|
||||
|
||||
return _form;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddFormValue(string key, string value) {
|
||||
Form.Add(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Mvc.Filters;
|
||||
using Orchard.Security;
|
||||
|
||||
namespace Orchard.Mvc.AntiForgery {
|
||||
[UsedImplicitly]
|
||||
public class AntiForgeryAuthorizationFilter : FilterProvider, IAuthorizationFilter {
|
||||
private readonly IAuthenticationService _authenticationService;
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
|
||||
public AntiForgeryAuthorizationFilter(IAuthenticationService authenticationService, IExtensionManager extensionManager) {
|
||||
_authenticationService = authenticationService;
|
||||
_extensionManager = extensionManager;
|
||||
}
|
||||
|
||||
public void OnAuthorization(AuthorizationContext filterContext) {
|
||||
// If the request is not a POST or is anonymous, and the request doesn't have validation forced, return.
|
||||
if ((filterContext.HttpContext.Request.HttpMethod != "POST" ||
|
||||
_authenticationService.GetAuthenticatedUser() == null) && !ShouldValidateGet(filterContext)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsAntiForgeryProtectionEnabled(filterContext)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var validator = new ValidateAntiForgeryTokenAttribute();
|
||||
validator.OnAuthorization(filterContext);
|
||||
|
||||
if (filterContext.HttpContext is HackHttpContext)
|
||||
filterContext.HttpContext = ((HackHttpContext)filterContext.HttpContext).OriginalHttpContextBase;
|
||||
}
|
||||
|
||||
private bool IsAntiForgeryProtectionEnabled(AuthorizationContext context) {
|
||||
// POST is opt-out
|
||||
var attributes =
|
||||
(ValidateAntiForgeryTokenOrchardAttribute[])
|
||||
context.ActionDescriptor.GetCustomAttributes(typeof (ValidateAntiForgeryTokenOrchardAttribute), false);
|
||||
|
||||
if (attributes.Length > 0 && !attributes[0].Enabled) return false;
|
||||
|
||||
var currentModule = GetArea(context.RouteData);
|
||||
return !String.IsNullOrEmpty(currentModule)
|
||||
&& (_extensionManager.AvailableExtensions()
|
||||
.First(descriptor => String.Equals(descriptor.Id, currentModule, StringComparison.OrdinalIgnoreCase))
|
||||
.AntiForgery.Equals("enabled", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private static string GetArea(RouteData routeData) {
|
||||
if (routeData.Values.ContainsKey("area"))
|
||||
return routeData.Values["area"] as string;
|
||||
|
||||
return routeData.DataTokens["area"] as string ?? "";
|
||||
}
|
||||
|
||||
private static bool ShouldValidateGet(AuthorizationContext context) {
|
||||
const string tokenFieldName = "__RequestVerificationToken";
|
||||
|
||||
var attributes =
|
||||
(ValidateAntiForgeryTokenOrchardAttribute[])
|
||||
context.ActionDescriptor.GetCustomAttributes(typeof (ValidateAntiForgeryTokenOrchardAttribute), false);
|
||||
|
||||
if (attributes.Length > 0 && attributes[0].Enabled) {
|
||||
var request = context.HttpContext.Request;
|
||||
|
||||
//HAACK: (erikpo) If the token is in the querystring, put it in the form so MVC can validate it
|
||||
if (!string.IsNullOrEmpty(request.QueryString[tokenFieldName])) {
|
||||
context.HttpContext = new HackHttpContext(context.HttpContext, (HttpContext)context.HttpContext.Items["originalHttpContext"]);
|
||||
((HackHttpRequest)context.HttpContext.Request).AddFormValue(tokenFieldName, context.HttpContext.Request.QueryString[tokenFieldName]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#region HackHttpContext
|
||||
|
||||
private class HackHttpContext : HttpContextWrapper {
|
||||
private readonly HttpContextBase _originalHttpContextBase;
|
||||
private readonly HttpContext _originalHttpContext;
|
||||
private HttpRequestWrapper _request;
|
||||
|
||||
public HackHttpContext(HttpContextBase httpContextBase, HttpContext httpContext)
|
||||
: base(httpContext) {
|
||||
_originalHttpContextBase = httpContextBase;
|
||||
_originalHttpContext = httpContext;
|
||||
}
|
||||
|
||||
public HttpContextBase OriginalHttpContextBase {
|
||||
get { return _originalHttpContextBase; }
|
||||
}
|
||||
|
||||
public override HttpRequestBase Request
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_request == null)
|
||||
_request = new HackHttpRequest(_originalHttpContext.Request);
|
||||
|
||||
return _request;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region HackHttpRequest
|
||||
|
||||
private class HackHttpRequest : HttpRequestWrapper {
|
||||
private readonly HttpRequest _originalHttpRequest;
|
||||
private NameValueCollection _form;
|
||||
|
||||
public HackHttpRequest(HttpRequest httpRequest)
|
||||
: base(httpRequest) {
|
||||
_originalHttpRequest = httpRequest;
|
||||
}
|
||||
|
||||
public override NameValueCollection Form
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_form == null)
|
||||
_form = new NameValueCollection(_originalHttpRequest.Form);
|
||||
|
||||
return _form;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddFormValue(string key, string value) {
|
||||
Form.Add(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,162 +1,162 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Mvc.Html;
|
||||
using System.Web.Routing;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.Mvc.Html {
|
||||
public static class ContentItemExtensions {
|
||||
|
||||
public static MvcHtmlString ItemDisplayText(this HtmlHelper html, IContent content) {
|
||||
return ItemDisplayText(html, content, true);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemDisplayText(this HtmlHelper html, IContent content, bool encode) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.DisplayText == null)
|
||||
return null;
|
||||
if (encode) {
|
||||
return MvcHtmlString.Create(html.Encode(metadata.DisplayText));
|
||||
} else {
|
||||
return MvcHtmlString.Create(metadata.DisplayText);
|
||||
}
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemDisplayLink(this HtmlHelper html, IContent content) {
|
||||
return ItemDisplayLink(html, null, content, null);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemDisplayLink(this HtmlHelper html, IContent content, object htmlAttributes) {
|
||||
return ItemDisplayLink(html, null, content, htmlAttributes);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemDisplayLink(this HtmlHelper html, string linkText, IContent content) {
|
||||
return ItemDisplayLink(html, linkText, content, null);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemDisplayLink(this HtmlHelper html, string linkText, IContent content, object htmlAttributes = null) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.DisplayRouteValues == null)
|
||||
return null;
|
||||
|
||||
return html.ActionLink(
|
||||
NonNullOrEmpty(linkText, metadata.DisplayText, "view"),
|
||||
Convert.ToString(metadata.DisplayRouteValues["action"]),
|
||||
metadata.DisplayRouteValues,
|
||||
new RouteValueDictionary(htmlAttributes));
|
||||
}
|
||||
|
||||
public static string ItemDisplayUrl(this UrlHelper urlHelper, IContent content) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.DisplayRouteValues == null)
|
||||
return null;
|
||||
|
||||
return urlHelper.Action(
|
||||
Convert.ToString(metadata.DisplayRouteValues["action"]),
|
||||
metadata.DisplayRouteValues);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemRemoveLink(this HtmlHelper html, IContent content) {
|
||||
return ItemRemoveLink(html, null, content, null);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemRemoveLink(this HtmlHelper html, string linkText, IContent content, object additionalRouteValues) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.RemoveRouteValues == null)
|
||||
return null;
|
||||
|
||||
return html.ActionLink(
|
||||
NonNullOrEmpty(linkText, metadata.DisplayText, "remove"),
|
||||
Convert.ToString(metadata.RemoveRouteValues["action"]),
|
||||
metadata.RemoveRouteValues.Merge(additionalRouteValues));
|
||||
}
|
||||
|
||||
public static string ItemRemoveUrl(this UrlHelper urlHelper, IContent content, object additionalRouteValues) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.RemoveRouteValues == null)
|
||||
return null;
|
||||
|
||||
return urlHelper.Action(
|
||||
Convert.ToString(metadata.RemoveRouteValues["action"]),
|
||||
metadata.RemoveRouteValues.Merge(additionalRouteValues));
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemEditLinkWithReturnUrl(this HtmlHelper html, string linkText, IContent content) {
|
||||
return html.ItemEditLink(linkText, content, new { ReturnUrl = html.ViewContext.HttpContext.Request.RawUrl });
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemEditLink(this HtmlHelper html, string linkText, IContent content) {
|
||||
return html.ItemEditLink(linkText, content, null);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemEditLink(this HtmlHelper html, string linkText, IContent content, object additionalRouteValues) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.EditorRouteValues == null)
|
||||
return null;
|
||||
|
||||
return html.ActionLink(
|
||||
NonNullOrEmpty(linkText, metadata.DisplayText, content.ContentItem.TypeDefinition.DisplayName),
|
||||
Convert.ToString(metadata.EditorRouteValues["action"]),
|
||||
metadata.EditorRouteValues.Merge(additionalRouteValues));
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemEditLink(this HtmlHelper html, string linkText, IContent content, object additionalRouteValues, object htmlAttributes) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.EditorRouteValues == null)
|
||||
return null;
|
||||
|
||||
return html.ActionLink(
|
||||
NonNullOrEmpty(linkText, metadata.DisplayText, content.ContentItem.TypeDefinition.DisplayName),
|
||||
Convert.ToString(metadata.EditorRouteValues["action"]),
|
||||
metadata.EditorRouteValues.Merge(additionalRouteValues),
|
||||
htmlAttributes);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemAdminLink(this HtmlHelper html, IContent content) {
|
||||
return ItemAdminLink(html, null, content);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemAdminLink(this HtmlHelper html, string linkText, IContent content) {
|
||||
return html.ItemAdminLink(linkText, content, null);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemAdminLink(this HtmlHelper html, string linkText, IContent content, object additionalRouteValues) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.AdminRouteValues == null)
|
||||
return null;
|
||||
|
||||
return html.ActionLink(
|
||||
NonNullOrEmpty(linkText, metadata.DisplayText, content.ContentItem.TypeDefinition.DisplayName),
|
||||
Convert.ToString(metadata.AdminRouteValues["action"]),
|
||||
metadata.AdminRouteValues.Merge(additionalRouteValues));
|
||||
}
|
||||
|
||||
public static string ItemEditUrl(this UrlHelper urlHelper, IContent content, object additionalRouteValues = null) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.EditorRouteValues == null)
|
||||
return null;
|
||||
|
||||
return urlHelper.Action(
|
||||
Convert.ToString(metadata.EditorRouteValues["action"]),
|
||||
metadata.EditorRouteValues.Merge(additionalRouteValues ?? new {}));
|
||||
}
|
||||
|
||||
public static string ItemAdminUrl(this UrlHelper urlHelper, IContent content, object additionalRouteValues = null) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
return metadata.AdminRouteValues == null ? null : urlHelper.RouteUrl(metadata.AdminRouteValues.Merge(additionalRouteValues ?? new { }));
|
||||
}
|
||||
|
||||
private static string NonNullOrEmpty(params string[] values) {
|
||||
foreach (var value in values) {
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemEditLink(this HtmlHelper html, IContent content) {
|
||||
return ItemEditLink(html, null, content);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Mvc.Html;
|
||||
using System.Web.Routing;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.Mvc.Html {
|
||||
public static class ContentItemExtensions {
|
||||
|
||||
public static MvcHtmlString ItemDisplayText(this HtmlHelper html, IContent content) {
|
||||
return ItemDisplayText(html, content, true);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemDisplayText(this HtmlHelper html, IContent content, bool encode) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.DisplayText == null)
|
||||
return null;
|
||||
if (encode) {
|
||||
return MvcHtmlString.Create(html.Encode(metadata.DisplayText));
|
||||
} else {
|
||||
return MvcHtmlString.Create(metadata.DisplayText);
|
||||
}
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemDisplayLink(this HtmlHelper html, IContent content) {
|
||||
return ItemDisplayLink(html, null, content, null);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemDisplayLink(this HtmlHelper html, IContent content, object htmlAttributes) {
|
||||
return ItemDisplayLink(html, null, content, htmlAttributes);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemDisplayLink(this HtmlHelper html, string linkText, IContent content) {
|
||||
return ItemDisplayLink(html, linkText, content, null);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemDisplayLink(this HtmlHelper html, string linkText, IContent content, object htmlAttributes = null) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.DisplayRouteValues == null)
|
||||
return null;
|
||||
|
||||
return html.ActionLink(
|
||||
NonNullOrEmpty(linkText, metadata.DisplayText, "view"),
|
||||
Convert.ToString(metadata.DisplayRouteValues["action"]),
|
||||
metadata.DisplayRouteValues,
|
||||
new RouteValueDictionary(htmlAttributes));
|
||||
}
|
||||
|
||||
public static string ItemDisplayUrl(this UrlHelper urlHelper, IContent content) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.DisplayRouteValues == null)
|
||||
return null;
|
||||
|
||||
return urlHelper.Action(
|
||||
Convert.ToString(metadata.DisplayRouteValues["action"]),
|
||||
metadata.DisplayRouteValues);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemRemoveLink(this HtmlHelper html, IContent content) {
|
||||
return ItemRemoveLink(html, null, content, null);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemRemoveLink(this HtmlHelper html, string linkText, IContent content, object additionalRouteValues) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.RemoveRouteValues == null)
|
||||
return null;
|
||||
|
||||
return html.ActionLink(
|
||||
NonNullOrEmpty(linkText, metadata.DisplayText, "remove"),
|
||||
Convert.ToString(metadata.RemoveRouteValues["action"]),
|
||||
metadata.RemoveRouteValues.Merge(additionalRouteValues));
|
||||
}
|
||||
|
||||
public static string ItemRemoveUrl(this UrlHelper urlHelper, IContent content, object additionalRouteValues) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.RemoveRouteValues == null)
|
||||
return null;
|
||||
|
||||
return urlHelper.Action(
|
||||
Convert.ToString(metadata.RemoveRouteValues["action"]),
|
||||
metadata.RemoveRouteValues.Merge(additionalRouteValues));
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemEditLinkWithReturnUrl(this HtmlHelper html, string linkText, IContent content) {
|
||||
return html.ItemEditLink(linkText, content, new { ReturnUrl = html.ViewContext.HttpContext.Request.RawUrl });
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemEditLink(this HtmlHelper html, string linkText, IContent content) {
|
||||
return html.ItemEditLink(linkText, content, null);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemEditLink(this HtmlHelper html, string linkText, IContent content, object additionalRouteValues) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.EditorRouteValues == null)
|
||||
return null;
|
||||
|
||||
return html.ActionLink(
|
||||
NonNullOrEmpty(linkText, metadata.DisplayText, content.ContentItem.TypeDefinition.DisplayName),
|
||||
Convert.ToString(metadata.EditorRouteValues["action"]),
|
||||
metadata.EditorRouteValues.Merge(additionalRouteValues));
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemEditLink(this HtmlHelper html, string linkText, IContent content, object additionalRouteValues, object htmlAttributes) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.EditorRouteValues == null)
|
||||
return null;
|
||||
|
||||
return html.ActionLink(
|
||||
NonNullOrEmpty(linkText, metadata.DisplayText, content.ContentItem.TypeDefinition.DisplayName),
|
||||
Convert.ToString(metadata.EditorRouteValues["action"]),
|
||||
metadata.EditorRouteValues.Merge(additionalRouteValues),
|
||||
htmlAttributes);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemAdminLink(this HtmlHelper html, IContent content) {
|
||||
return ItemAdminLink(html, null, content);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemAdminLink(this HtmlHelper html, string linkText, IContent content) {
|
||||
return html.ItemAdminLink(linkText, content, null);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemAdminLink(this HtmlHelper html, string linkText, IContent content, object additionalRouteValues) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.AdminRouteValues == null)
|
||||
return null;
|
||||
|
||||
return html.ActionLink(
|
||||
NonNullOrEmpty(linkText, metadata.DisplayText, content.ContentItem.TypeDefinition.DisplayName),
|
||||
Convert.ToString(metadata.AdminRouteValues["action"]),
|
||||
metadata.AdminRouteValues.Merge(additionalRouteValues));
|
||||
}
|
||||
|
||||
public static string ItemEditUrl(this UrlHelper urlHelper, IContent content, object additionalRouteValues = null) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.EditorRouteValues == null)
|
||||
return null;
|
||||
|
||||
return urlHelper.Action(
|
||||
Convert.ToString(metadata.EditorRouteValues["action"]),
|
||||
metadata.EditorRouteValues.Merge(additionalRouteValues ?? new {}));
|
||||
}
|
||||
|
||||
public static string ItemAdminUrl(this UrlHelper urlHelper, IContent content, object additionalRouteValues = null) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
return metadata.AdminRouteValues == null ? null : urlHelper.RouteUrl(metadata.AdminRouteValues.Merge(additionalRouteValues ?? new { }));
|
||||
}
|
||||
|
||||
private static string NonNullOrEmpty(params string[] values) {
|
||||
foreach (var value in values) {
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemEditLink(this HtmlHelper html, IContent content) {
|
||||
return ItemEditLink(html, null, content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user