mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 03:25:23 +08:00
Export and import works
This commit is contained in:
@@ -140,7 +140,7 @@ namespace Orchard.Alias.Controllers {
|
||||
}
|
||||
|
||||
try {
|
||||
_aliasService.Set(aliasPath, routePath, "Custom");
|
||||
_aliasService.Set(aliasPath, routePath, "Custom",false);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
Services.TransactionManager.Cancel();
|
||||
@@ -204,7 +204,7 @@ namespace Orchard.Alias.Controllers {
|
||||
}
|
||||
|
||||
try {
|
||||
_aliasService.Set(aliasPath, routePath, "Custom");
|
||||
_aliasService.Set(aliasPath, routePath, "Custom",false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@@ -5,8 +5,8 @@ using System.Web.Routing;
|
||||
namespace Orchard.Alias {
|
||||
public interface IAliasService : IDependency {
|
||||
RouteValueDictionary Get(string aliasPath);
|
||||
void Set(string aliasPath, RouteValueDictionary routeValues, string aliasSource);
|
||||
void Set(string aliasPath, string routePath, string aliasSource);
|
||||
void Set(string aliasPath, RouteValueDictionary routeValues, string aliasSource, bool isManaged);
|
||||
void Set(string aliasPath, string routePath, string aliasSource, bool isManaged);
|
||||
void Delete(string aliasPath);
|
||||
void Delete(string aliasPath, string aliasSource);
|
||||
/// <summary>
|
||||
@@ -18,8 +18,8 @@ namespace Orchard.Alias {
|
||||
IEnumerable<string> Lookup(RouteValueDictionary routeValues);
|
||||
IEnumerable<string> Lookup(string routePath);
|
||||
|
||||
void Replace(string aliasPath, RouteValueDictionary routeValues, string aliasSource);
|
||||
void Replace(string aliasPath, string routePath, string aliasSource);
|
||||
void Replace(string aliasPath, RouteValueDictionary routeValues, string aliasSource, bool isManaged);
|
||||
void Replace(string aliasPath, string routePath, string aliasSource, bool isManaged);
|
||||
|
||||
IEnumerable<Tuple<string, RouteValueDictionary>> List();
|
||||
IEnumerable<Tuple<string, RouteValueDictionary, string>> List(string sourceStartsWith);
|
||||
|
@@ -29,12 +29,14 @@ namespace Orchard.Alias.Implementation {
|
||||
var virtualPath = httpContext.Request.AppRelativeCurrentExecutionFilePath.Substring(2) + httpContext.Request.PathInfo;
|
||||
|
||||
// Attempt to lookup RouteValues in the alias map
|
||||
IDictionary<string, string> routeValues;
|
||||
//IDictionary<string, string> routeValues;
|
||||
AliasInfo aliasInfo;
|
||||
// TODO: Might as well have the lookup in AliasHolder...
|
||||
if (_aliasMap.TryGetAlias(virtualPath, out routeValues)) {
|
||||
if (_aliasMap.TryGetAlias(virtualPath, out aliasInfo))
|
||||
{
|
||||
// Construct RouteData from the route values
|
||||
var data = new RouteData(this, _routeHandler);
|
||||
foreach (var routeValue in routeValues) {
|
||||
foreach (var routeValue in aliasInfo.RouteValues) {
|
||||
var key = routeValue.Key;
|
||||
if (key.EndsWith("-"))
|
||||
data.Values.Add(key.Substring(0, key.Length - 1), routeValue.Value);
|
||||
|
@@ -31,18 +31,20 @@ namespace Orchard.Alias.Implementation {
|
||||
return _aliasStorage.Get(aliasPath).ToRouteValueDictionary();
|
||||
}
|
||||
|
||||
public void Set(string aliasPath, RouteValueDictionary routeValues, string aliasSource) {
|
||||
public void Set(string aliasPath, RouteValueDictionary routeValues, string aliasSource, bool isManaged) {
|
||||
_aliasStorage.Set(
|
||||
aliasPath,
|
||||
ToDictionary(routeValues),
|
||||
aliasSource);
|
||||
aliasSource,
|
||||
isManaged);
|
||||
}
|
||||
|
||||
public void Set(string aliasPath, string routePath, string aliasSource) {
|
||||
public void Set(string aliasPath, string routePath, string aliasSource, bool isManaged) {
|
||||
_aliasStorage.Set(
|
||||
aliasPath.TrimStart('/'),
|
||||
ToDictionary(routePath),
|
||||
aliasSource);
|
||||
aliasSource,
|
||||
isManaged);
|
||||
}
|
||||
|
||||
public void Delete(string aliasPath) {
|
||||
@@ -71,15 +73,16 @@ namespace Orchard.Alias.Implementation {
|
||||
return Lookup(ToDictionary(routePath).ToRouteValueDictionary());
|
||||
}
|
||||
|
||||
public void Replace(string aliasPath, RouteValueDictionary routeValues, string aliasSource) {
|
||||
public void Replace(string aliasPath, RouteValueDictionary routeValues, string aliasSource, bool isManaged) {
|
||||
foreach (var lookup in Lookup(routeValues).Where(path => path != aliasPath)) {
|
||||
Delete(lookup, aliasSource);
|
||||
}
|
||||
Set(aliasPath, routeValues, aliasSource);
|
||||
Set(aliasPath, routeValues, aliasSource, isManaged);
|
||||
}
|
||||
|
||||
public void Replace(string aliasPath, string routePath, string aliasSource) {
|
||||
Replace(aliasPath, ToDictionary(routePath).ToRouteValueDictionary(), aliasSource);
|
||||
public void Replace(string aliasPath, string routePath, string aliasSource, bool isManaged)
|
||||
{
|
||||
Replace(aliasPath, ToDictionary(routePath).ToRouteValueDictionary(), aliasSource, isManaged);
|
||||
}
|
||||
|
||||
public IEnumerable<string> Lookup(RouteValueDictionary routeValues) {
|
||||
|
@@ -5,5 +5,6 @@ namespace Orchard.Alias.Implementation.Holder {
|
||||
public string Area { get; set; }
|
||||
public string Path { get; set; }
|
||||
public IDictionary<string, string> RouteValues { get; set; }
|
||||
public bool IsManaged { get; set; }
|
||||
}
|
||||
}
|
@@ -9,21 +9,29 @@ using System.Collections.Concurrent;
|
||||
namespace Orchard.Alias.Implementation.Map {
|
||||
public class AliasMap {
|
||||
private readonly string _area;
|
||||
private readonly ConcurrentDictionary<string, IDictionary<string, string>> _aliases;
|
||||
private readonly Node _root;
|
||||
//private readonly ConcurrentDictionary<string, IDictionary<string, string>> _aliases;
|
||||
private readonly ConcurrentDictionary<string, AliasInfo> _aliases;
|
||||
private readonly Node _root;
|
||||
|
||||
public AliasMap(string area) {
|
||||
_area = area;
|
||||
_aliases = new ConcurrentDictionary<string, IDictionary<string, string>>(StringComparer.OrdinalIgnoreCase);
|
||||
//_aliases = new ConcurrentDictionary<string, IDictionary<string, string>>(StringComparer.OrdinalIgnoreCase);
|
||||
_aliases = new ConcurrentDictionary<string, AliasInfo>(StringComparer.OrdinalIgnoreCase);
|
||||
_root = new Node();
|
||||
//_isManaged = isManaged;
|
||||
}
|
||||
|
||||
public IEnumerable<AliasInfo> GetAliases() {
|
||||
return _aliases.Select(x => new AliasInfo {Area = _area, Path = x.Key, RouteValues = x.Value});
|
||||
return _aliases.Select(x => new AliasInfo { Area = _area, Path = x.Key, RouteValues = x.Value.RouteValues, IsManaged = x.Value.IsManaged });
|
||||
}
|
||||
|
||||
public bool TryGetAlias(string virtualPath, out IDictionary<string, string> routeValues) {
|
||||
return _aliases.TryGetValue(virtualPath, out routeValues);
|
||||
//public bool TryGetAlias(string virtualPath, out IDictionary<string, string> routeValues) {
|
||||
// return _aliases.TryGetValue(virtualPath, out routeValues);
|
||||
//}
|
||||
|
||||
public bool TryGetAlias(string virtualPath, out AliasInfo aliasInfo)
|
||||
{
|
||||
return _aliases.TryGetValue(virtualPath, out aliasInfo);
|
||||
}
|
||||
|
||||
public Tuple<IDictionary<string, object>, string> Locate(RouteValueDictionary routeValues) {
|
||||
@@ -39,7 +47,8 @@ namespace Orchard.Alias.Implementation.Map {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
|
||||
_aliases[info.Path] = info.RouteValues;
|
||||
//_aliases[info.Path] = info.RouteValues;
|
||||
_aliases[info.Path] = info;
|
||||
ExpandTree(_root, info.Path, info.RouteValues);
|
||||
}
|
||||
|
||||
@@ -48,8 +57,10 @@ namespace Orchard.Alias.Implementation.Map {
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
public void Remove(AliasInfo info) {
|
||||
IDictionary<string,string> values;
|
||||
_aliases.TryRemove(info.Path, out values);
|
||||
//IDictionary<string, string> values;
|
||||
AliasInfo aliasInfo;
|
||||
_aliases.TryRemove(info.Path, out aliasInfo);
|
||||
//_aliases.TryRemove(info.Path, out info);
|
||||
CollapseTree(_root, info.Path, info.RouteValues);
|
||||
}
|
||||
|
||||
|
@@ -10,15 +10,15 @@ using Orchard.Validation;
|
||||
|
||||
namespace Orchard.Alias.Implementation.Storage {
|
||||
public interface IAliasStorage : IDependency {
|
||||
void Set(string path, IDictionary<string, string> routeValues, string source);
|
||||
void Set(string path, IDictionary<string, string> routeValues, string source, bool isManaged);
|
||||
IDictionary<string, string> Get(string aliasPath);
|
||||
void Remove(Expression<Func<AliasRecord, bool>> filter);
|
||||
void Remove(string path);
|
||||
void Remove(string path, string aliasSource);
|
||||
void RemoveBySource(string aliasSource);
|
||||
IEnumerable<Tuple<string, string, IDictionary<string, string>, string, int>> List(Expression<Func<AliasRecord, bool>> predicate);
|
||||
IEnumerable<Tuple<string, string, IDictionary<string, string>, string, int>> List();
|
||||
IEnumerable<Tuple<string, string, IDictionary<string, string>, string, int>> List(string sourceStartsWith);
|
||||
IEnumerable<Tuple<string, string, IDictionary<string, string>, string, int, bool>> List(Expression<Func<AliasRecord, bool>> predicate);
|
||||
IEnumerable<Tuple<string, string, IDictionary<string, string>, string, int, bool>> List();
|
||||
IEnumerable<Tuple<string, string, IDictionary<string, string>, string, int, bool>> List(string sourceStartsWith);
|
||||
}
|
||||
|
||||
public class AliasStorage : IAliasStorage {
|
||||
@@ -31,7 +31,7 @@ namespace Orchard.Alias.Implementation.Storage {
|
||||
_aliasHolder = aliasHolder;
|
||||
}
|
||||
|
||||
public void Set(string path, IDictionary<string, string> routeValues, string source) {
|
||||
public void Set(string path, IDictionary<string, string> routeValues, string source, bool isManaged) {
|
||||
if (path == null) {
|
||||
throw new ArgumentNullException("path");
|
||||
}
|
||||
@@ -66,6 +66,7 @@ namespace Orchard.Alias.Implementation.Storage {
|
||||
|
||||
aliasRecord.RouteValues = values.ToString();
|
||||
aliasRecord.Source = source;
|
||||
aliasRecord.IsManaged = isManaged;
|
||||
if (aliasRecord.Action.Id == 0 || aliasRecord.Id == 0) {
|
||||
if (aliasRecord.Action.Id == 0) {
|
||||
_actionRepository.Create(aliasRecord.Action);
|
||||
@@ -78,7 +79,7 @@ namespace Orchard.Alias.Implementation.Storage {
|
||||
}
|
||||
// Transform and push into AliasHolder
|
||||
var dict = ToDictionary(aliasRecord);
|
||||
_aliasHolder.SetAlias(new AliasInfo { Path = dict.Item1, Area = dict.Item2, RouteValues = dict.Item3 });
|
||||
_aliasHolder.SetAlias(new AliasInfo { Path = dict.Item1, Area = dict.Item2, RouteValues = dict.Item3, IsManaged = dict.Item6 });
|
||||
}
|
||||
|
||||
public IDictionary<string, string> Get(string path) {
|
||||
@@ -109,15 +110,17 @@ namespace Orchard.Alias.Implementation.Storage {
|
||||
// Bulk updates might go wrong if we don't flush.
|
||||
_aliasRepository.Flush();
|
||||
var dict = ToDictionary(aliasRecord);
|
||||
_aliasHolder.RemoveAlias(new AliasInfo() { Path = dict.Item1, Area = dict.Item2, RouteValues = dict.Item3 });
|
||||
//TODO:
|
||||
_aliasHolder.RemoveAlias(new AliasInfo() { Path = dict.Item1, Area = dict.Item2, RouteValues = dict.Item3, IsManaged = dict.Item6});
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Tuple<string, string, IDictionary<string, string>, string, int>> List() {
|
||||
public IEnumerable<Tuple<string, string, IDictionary<string, string>, string, int, bool>> List()
|
||||
{
|
||||
return List((Expression<Func<AliasRecord, bool>>)null);
|
||||
}
|
||||
|
||||
public IEnumerable<Tuple<string, string, IDictionary<string, string>, string, int>> List(Expression<Func<AliasRecord, bool>> predicate) {
|
||||
public IEnumerable<Tuple<string, string, IDictionary<string, string>, string, int, bool>> List(Expression<Func<AliasRecord, bool>> predicate) {
|
||||
var table = _aliasRepository.Table;
|
||||
|
||||
if (predicate != null) {
|
||||
@@ -127,11 +130,13 @@ namespace Orchard.Alias.Implementation.Storage {
|
||||
return table.OrderBy(a => a.Id).Select(ToDictionary).ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<Tuple<string, string, IDictionary<string, string>, string, int>> List(string sourceStartsWith) {
|
||||
public IEnumerable<Tuple<string, string, IDictionary<string, string>, string, int, bool>> List(string sourceStartsWith)
|
||||
{
|
||||
return List(a => a.Source.StartsWith(sourceStartsWith));
|
||||
}
|
||||
|
||||
private static Tuple<string, string, IDictionary<string, string>, string, int> ToDictionary(AliasRecord aliasRecord) {
|
||||
private static Tuple<string, string, IDictionary<string, string>, string, int, bool> ToDictionary(AliasRecord aliasRecord)
|
||||
{
|
||||
IDictionary<string, string> routeValues = new Dictionary<string, string>();
|
||||
if (aliasRecord.Action.Area != null) {
|
||||
routeValues.Add("area", aliasRecord.Action.Area);
|
||||
@@ -147,7 +152,7 @@ namespace Orchard.Alias.Implementation.Storage {
|
||||
routeValues.Add(attr.Name.LocalName, attr.Value);
|
||||
}
|
||||
}
|
||||
return Tuple.Create(aliasRecord.Path, aliasRecord.Action.Area, routeValues, aliasRecord.Source, aliasRecord.Id);
|
||||
return Tuple.Create(aliasRecord.Path, aliasRecord.Action.Area, routeValues, aliasRecord.Source, aliasRecord.Id, aliasRecord.IsManaged);
|
||||
}
|
||||
}
|
||||
}
|
@@ -34,7 +34,7 @@ namespace Orchard.Alias.Implementation.Updater {
|
||||
// update the last processed id
|
||||
if (aliases.Any()) {
|
||||
_cursor.Cursor = aliases.Last().Item5;
|
||||
_aliasHolder.SetAliases(aliases.Select(alias => new AliasInfo { Path = alias.Item1, Area = alias.Item2, RouteValues = alias.Item3 }));
|
||||
_aliasHolder.SetAliases(aliases.Select(alias => new AliasInfo { Path = alias.Item1, Area = alias.Item2, RouteValues = alias.Item3, IsManaged = alias.Item6 }));
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
@@ -20,5 +20,14 @@ namespace Orchard.Alias {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int UpdateFrom1()
|
||||
{
|
||||
SchemaBuilder.AlterTable("AliasRecord",
|
||||
table => table
|
||||
.AddColumn<bool>("IsManaged", column => column.WithDefault(false))
|
||||
);
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -32,7 +32,7 @@ namespace Orchard.Roles.Recipes.Builders {
|
||||
public override void Build(BuildContext context) {
|
||||
//var aliases = _aliasRecordepository.Table.ToList();
|
||||
|
||||
var aliases = _aliasHolder.GetMaps().SelectMany(m => m.GetAliases()).ToList();
|
||||
var aliases = _aliasHolder.GetMaps().SelectMany(m => m.GetAliases()).Where(m => m.IsManaged== false).ToList();
|
||||
|
||||
if (!aliases.Any())
|
||||
return;
|
||||
@@ -57,13 +57,13 @@ namespace Orchard.Roles.Recipes.Builders {
|
||||
}
|
||||
|
||||
//add a collection of all the alias paths in this site so that the importing site can remove aliases that don't exist remotely
|
||||
var pathsElement = new XElement("Paths");
|
||||
foreach (var aliasInfo in aliases)
|
||||
{
|
||||
pathsElement.Add(new XElement("Add", new XAttribute("Path", aliasInfo.Path)));
|
||||
}
|
||||
//var pathsElement = new XElement("Paths");
|
||||
//foreach (var aliasInfo in aliases)
|
||||
//{
|
||||
// pathsElement.Add(new XElement("Add", new XAttribute("Path", aliasInfo.Path)));
|
||||
//}
|
||||
|
||||
root.Add(pathsElement);
|
||||
//root.Add(pathsElement);
|
||||
|
||||
//var rootElement = context.Document.Descendants("Orchard").FirstOrDefault();
|
||||
|
||||
|
@@ -18,7 +18,7 @@ namespace Orchard.Alias.Recipes.Executors {
|
||||
}
|
||||
|
||||
public override string Name {
|
||||
get { return "Alias"; }
|
||||
get { return "Aliases"; }
|
||||
}
|
||||
|
||||
public override void Execute(RecipeExecutionContext context) {
|
||||
@@ -42,10 +42,10 @@ namespace Orchard.Alias.Recipes.Executors {
|
||||
}
|
||||
}
|
||||
|
||||
_aliasService.Set(aliasPath, rvd, "Custom");
|
||||
//_aliasService.Set(aliasPath, rvd, "Custom",false);
|
||||
|
||||
try {
|
||||
_aliasService.Set(aliasPath, rvd, "Custom");
|
||||
_aliasService.Set(aliasPath, rvd, "Custom", false);
|
||||
//var role = _roleService.GetRoleByName(roleName);
|
||||
//if (role == null) {
|
||||
// _roleService.CreateRole(roleName);
|
||||
|
@@ -5,5 +5,6 @@
|
||||
public virtual ActionRecord Action { get; set; }
|
||||
public virtual string RouteValues { get; set; }
|
||||
public virtual string Source { get; set; }
|
||||
public virtual bool IsManaged { get; set; }
|
||||
}
|
||||
}
|
@@ -12,6 +12,7 @@ namespace Orchard.Alias.ViewModels {
|
||||
public class AliasEntry {
|
||||
public AliasInfo Alias { get; set; }
|
||||
public bool IsChecked { get; set; }
|
||||
public bool IsManaged { get; set; }
|
||||
}
|
||||
public class AdminIndexOptions {
|
||||
public string Search { get; set; }
|
||||
|
@@ -96,7 +96,7 @@ namespace Orchard.Autoroute.Services {
|
||||
|
||||
public void PublishAlias(AutoroutePart part) {
|
||||
var displayRouteValues = _contentManager.GetItemMetadata(part).DisplayRouteValues;
|
||||
_aliasService.Replace(part.DisplayAlias, displayRouteValues, AliasSource);
|
||||
_aliasService.Replace(part.DisplayAlias, displayRouteValues, AliasSource, true);
|
||||
_routeEvents.Routed(part, part.DisplayAlias);
|
||||
}
|
||||
|
||||
|
@@ -37,18 +37,20 @@ namespace Orchard.Blogs.Routing {
|
||||
return false;
|
||||
}
|
||||
|
||||
IDictionary<string, string> routeValues;
|
||||
if (!_aliasHolder.GetMap("Orchard.Blogs").TryGetAlias(path, out routeValues)) {
|
||||
//IDictionary<string, string> routeValues;
|
||||
AliasInfo aliasInfo;
|
||||
if (!_aliasHolder.GetMap("Orchard.Blogs").TryGetAlias(path, out aliasInfo))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var isBlog =
|
||||
//routeValues.ContainsKey("area") &&
|
||||
//routeValues["area"] == "Orchard.Blogs" &&
|
||||
routeValues.ContainsKey("controller") &&
|
||||
routeValues["controller"] == "Blog" &&
|
||||
routeValues.ContainsKey("action") &&
|
||||
routeValues["action"] == "Item"
|
||||
aliasInfo.RouteValues.ContainsKey("controller") &&
|
||||
aliasInfo.RouteValues["controller"] == "Blog" &&
|
||||
aliasInfo.RouteValues.ContainsKey("action") &&
|
||||
aliasInfo.RouteValues["action"] == "Item"
|
||||
;
|
||||
|
||||
return isBlog;
|
||||
|
@@ -25,18 +25,21 @@ namespace Orchard.Blogs.Routing {
|
||||
return false;
|
||||
}
|
||||
|
||||
IDictionary<string, string> routeValues;
|
||||
if (!_aliasHolder.GetMap("Orchard.Blogs").TryGetAlias(path, out routeValues)) {
|
||||
//IDictionary<string, string> routeValues;
|
||||
AliasInfo aliasInfo;
|
||||
//if (!_aliasHolder.GetMap("Orchard.Blogs").TryGetAlias(path, out routeValues)) {
|
||||
if (!_aliasHolder.GetMap("Orchard.Blogs").TryGetAlias(path, out aliasInfo))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var isBlog =
|
||||
//routeValues.ContainsKey("area") &&
|
||||
//routeValues["area"] == "Orchard.Blogs" &&
|
||||
routeValues.ContainsKey("controller") &&
|
||||
routeValues["controller"] == "Blog" &&
|
||||
routeValues.ContainsKey("action") &&
|
||||
routeValues["action"] == "Item"
|
||||
aliasInfo.RouteValues.ContainsKey("controller") &&
|
||||
aliasInfo.RouteValues["controller"] == "Blog" &&
|
||||
aliasInfo.RouteValues.ContainsKey("action") &&
|
||||
aliasInfo.RouteValues["action"] == "Item"
|
||||
;
|
||||
|
||||
return isBlog;
|
||||
|
Reference in New Issue
Block a user