mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Extracted Updater for reuse.
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
<IISExpressWindowsAuthentication />
|
<IISExpressWindowsAuthentication />
|
||||||
<IISExpressUseClassicPipelineMode />
|
<IISExpressUseClassicPipelineMode />
|
||||||
<TargetFrameworkProfile />
|
<TargetFrameworkProfile />
|
||||||
|
<UseGlobalApplicationHostFile />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
@@ -9,6 +9,7 @@ using Orchard.ContentTypes.Events;
|
|||||||
using Orchard.ContentTypes.ViewModels;
|
using Orchard.ContentTypes.ViewModels;
|
||||||
using Orchard.Core.Contents.Extensions;
|
using Orchard.Core.Contents.Extensions;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
|
using Orchard.Mvc;
|
||||||
using Orchard.Utility.Extensions;
|
using Orchard.Utility.Extensions;
|
||||||
|
|
||||||
namespace Orchard.ContentTypes.Services {
|
namespace Orchard.ContentTypes.Services {
|
||||||
@@ -107,7 +108,7 @@ namespace Orchard.ContentTypes.Services {
|
|||||||
var partViewModel = part;
|
var partViewModel = part;
|
||||||
|
|
||||||
// enable updater to be aware of changing part prefix
|
// enable updater to be aware of changing part prefix
|
||||||
updater._prefix = secondHalf => String.Format("{0}.{1}", partViewModel.Prefix, secondHalf);
|
updater.Prefix = secondHalf => String.Format("{0}.{1}", partViewModel.Prefix, secondHalf);
|
||||||
|
|
||||||
// allow extensions to alter typePart configuration
|
// allow extensions to alter typePart configuration
|
||||||
typeBuilder.WithPart(partViewModel.PartDefinition.Name, typePartBuilder => {
|
typeBuilder.WithPart(partViewModel.PartDefinition.Name, typePartBuilder => {
|
||||||
@@ -125,7 +126,7 @@ namespace Orchard.ContentTypes.Services {
|
|||||||
var fieldViewModel = field;
|
var fieldViewModel = field;
|
||||||
|
|
||||||
// enable updater to be aware of changing field prefix
|
// enable updater to be aware of changing field prefix
|
||||||
updater._prefix = secondHalf =>
|
updater.Prefix = secondHalf =>
|
||||||
String.Format("{0}.{1}.{2}", fieldFirstHalf, fieldViewModel.Prefix, secondHalf);
|
String.Format("{0}.{1}.{2}", fieldFirstHalf, fieldViewModel.Prefix, secondHalf);
|
||||||
// allow extensions to alter partField configuration
|
// allow extensions to alter partField configuration
|
||||||
partBuilder.WithField(fieldViewModel.Name, partFieldBuilder => {
|
partBuilder.WithField(fieldViewModel.Name, partFieldBuilder => {
|
||||||
@@ -143,7 +144,7 @@ namespace Orchard.ContentTypes.Services {
|
|||||||
var fieldViewModel = field;
|
var fieldViewModel = field;
|
||||||
|
|
||||||
// enable updater to be aware of changing field prefix
|
// enable updater to be aware of changing field prefix
|
||||||
updater._prefix = secondHalf =>
|
updater.Prefix = secondHalf =>
|
||||||
string.Format("{0}.{1}", fieldViewModel.Prefix, secondHalf);
|
string.Format("{0}.{1}", fieldViewModel.Prefix, secondHalf);
|
||||||
|
|
||||||
// allow extensions to alter partField configuration
|
// allow extensions to alter partField configuration
|
||||||
@@ -370,23 +371,5 @@ namespace Orchard.ContentTypes.Services {
|
|||||||
|
|
||||||
return string.Format("{0}-{1}", name, version);
|
return string.Format("{0}-{1}", name, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Updater : IUpdateModel {
|
|
||||||
private readonly IUpdateModel _thunk;
|
|
||||||
|
|
||||||
public Updater(IUpdateModel thunk) {
|
|
||||||
_thunk = thunk;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Func<string, string> _prefix = x => x;
|
|
||||||
|
|
||||||
public bool TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) where TModel : class {
|
|
||||||
return _thunk.TryUpdateModel(model, _prefix(prefix), includeProperties, excludeProperties);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddModelError(string key, LocalizedString errorMessage) {
|
|
||||||
_thunk.AddModelError(_prefix(key), errorMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
28
src/Orchard/Mvc/Updater.cs
Normal file
28
src/Orchard/Mvc/Updater.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.Localization;
|
||||||
|
|
||||||
|
namespace Orchard.Mvc {
|
||||||
|
|
||||||
|
public class Updater : IUpdateModel {
|
||||||
|
private readonly IUpdateModel _thunk;
|
||||||
|
|
||||||
|
public Updater(IUpdateModel thunk) : this(thunk, x => x) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Updater(IUpdateModel thunk, Func<string, string> prefix) {
|
||||||
|
_thunk = thunk;
|
||||||
|
Prefix = prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Func<string, string> Prefix { get; set; }
|
||||||
|
|
||||||
|
public bool TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) where TModel : class {
|
||||||
|
return _thunk.TryUpdateModel(model, Prefix(prefix), includeProperties, excludeProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddModelError(string key, LocalizedString errorMessage) {
|
||||||
|
_thunk.AddModelError(Prefix(key), errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -150,6 +150,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Environment\Extensions\Helpers\ExtensionManagerExtensions.cs" />
|
<Compile Include="Environment\Extensions\Helpers\ExtensionManagerExtensions.cs" />
|
||||||
|
<Compile Include="Mvc\Updater.cs" />
|
||||||
<Compile Include="Recipes\Models\RecipeResult.cs" />
|
<Compile Include="Recipes\Models\RecipeResult.cs" />
|
||||||
<Compile Include="Recipes\Models\RecipeStepResult.cs" />
|
<Compile Include="Recipes\Models\RecipeStepResult.cs" />
|
||||||
<Compile Include="Recipes\Models\BuildContext.cs" />
|
<Compile Include="Recipes\Models\BuildContext.cs" />
|
||||||
|
Reference in New Issue
Block a user