mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Merge
--HG-- branch : dev
This commit is contained in:
@@ -138,10 +138,12 @@ namespace Orchard.Setup {
|
|||||||
|
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
class SafeModeSiteWorkContextProvider : IWorkContextStateProvider {
|
class SafeModeSiteWorkContextProvider : IWorkContextStateProvider {
|
||||||
public T Get<T>(string name) {
|
public Func<T> Get<T>(string name) {
|
||||||
if (name == "CurrentSite")
|
if (name == "CurrentSite") {
|
||||||
return (T)(ISite) new SafeModeSite();
|
ISite safeModeSite = new SafeModeSite();
|
||||||
return default(T);
|
return () => (T)safeModeSite;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -97,10 +97,10 @@ namespace Orchard.Environment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override T GetState<T>(string name) {
|
public override T GetState<T>(string name) {
|
||||||
return (T)_state.GetOrAdd(name, x => GetStateInternal<T>(x));
|
return (T)_state.GetOrAdd(name, s => GetStateInternal<T>(s) == null ? default(T) : GetStateInternal<T>(s).Invoke());
|
||||||
}
|
}
|
||||||
|
|
||||||
private T GetStateInternal<T>(string name) {
|
private Func<T> GetStateInternal<T>(string name) {
|
||||||
return _workContextStateProviders.Select(wcsp => wcsp.Get<T>(name))
|
return _workContextStateProviders.Select(wcsp => wcsp.Get<T>(name))
|
||||||
.FirstOrDefault(value => !Equals(value, default(T)));
|
.FirstOrDefault(value => !Equals(value, default(T)));
|
||||||
}
|
}
|
||||||
|
@@ -11,7 +11,7 @@ namespace Orchard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface IWorkContextStateProvider : IDependency {
|
public interface IWorkContextStateProvider : IDependency {
|
||||||
T Get<T>(string name);
|
Func<T> Get<T>(string name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IWorkContextScope : IDisposable {
|
public interface IWorkContextScope : IDisposable {
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
namespace Orchard.Security {
|
using System;
|
||||||
|
|
||||||
|
namespace Orchard.Security {
|
||||||
public class CurrentUserWorkContext : IWorkContextStateProvider {
|
public class CurrentUserWorkContext : IWorkContextStateProvider {
|
||||||
private readonly IAuthenticationService _authenticationService;
|
private readonly IAuthenticationService _authenticationService;
|
||||||
|
|
||||||
@@ -6,10 +8,10 @@
|
|||||||
_authenticationService = authenticationService;
|
_authenticationService = authenticationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Get<T>(string name) {
|
public Func<T> Get<T>(string name) {
|
||||||
if (name == "CurrentUser")
|
if (name == "CurrentUser")
|
||||||
return (T)_authenticationService.GetAuthenticatedUser();
|
return () => (T)_authenticationService.GetAuthenticatedUser();
|
||||||
return default(T);
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
namespace Orchard.Settings {
|
using System;
|
||||||
|
|
||||||
|
namespace Orchard.Settings {
|
||||||
public class CurrentSiteWorkContext : IWorkContextStateProvider {
|
public class CurrentSiteWorkContext : IWorkContextStateProvider {
|
||||||
private readonly ISiteService _siteService;
|
private readonly ISiteService _siteService;
|
||||||
|
|
||||||
@@ -6,10 +8,12 @@
|
|||||||
_siteService = siteService;
|
_siteService = siteService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Get<T>(string name) {
|
public Func<T> Get<T>(string name) {
|
||||||
if (name == "CurrentSite")
|
if (name == "CurrentSite") {
|
||||||
return (T)_siteService.GetSiteSettings();
|
var siteSettings = _siteService.GetSiteSettings();
|
||||||
return default(T);
|
return () => (T)siteSettings;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
using ClaySharp.Implementation;
|
using System;
|
||||||
|
using ClaySharp.Implementation;
|
||||||
using Orchard.DisplayManagement;
|
using Orchard.DisplayManagement;
|
||||||
|
|
||||||
namespace Orchard.UI.Zones {
|
namespace Orchard.UI.Zones {
|
||||||
@@ -9,11 +10,12 @@ namespace Orchard.UI.Zones {
|
|||||||
_shapeFactory = shapeFactory;
|
_shapeFactory = shapeFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Get<T>(string name) {
|
public Func<T> Get<T>(string name) {
|
||||||
if (name == "Layout") {
|
if (name == "Layout") {
|
||||||
return (dynamic)_shapeFactory.Create("Layout", Arguments.Empty());
|
var layout = _shapeFactory.Create("Layout", Arguments.Empty());
|
||||||
|
return () => (T)layout;
|
||||||
}
|
}
|
||||||
return default(T);
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user