mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Cleanup
This commit is contained in:
@@ -8,27 +8,20 @@ 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 string _area;
|
||||
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);
|
||||
_area = area;
|
||||
_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.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 AliasInfo aliasInfo)
|
||||
{
|
||||
return _aliases.TryGetValue(virtualPath, out aliasInfo);
|
||||
@@ -46,8 +39,6 @@ namespace Orchard.Alias.Implementation.Map {
|
||||
if(info == null) {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
|
||||
//_aliases[info.Path] = info.RouteValues;
|
||||
_aliases[info.Path] = info;
|
||||
ExpandTree(_root, info.Path, info.RouteValues);
|
||||
}
|
||||
@@ -57,10 +48,8 @@ namespace Orchard.Alias.Implementation.Map {
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
public void Remove(AliasInfo info) {
|
||||
//IDictionary<string, string> values;
|
||||
AliasInfo aliasInfo;
|
||||
_aliases.TryRemove(info.Path, out aliasInfo);
|
||||
//_aliases.TryRemove(info.Path, out info);
|
||||
CollapseTree(_root, info.Path, info.RouteValues);
|
||||
}
|
||||
|
||||
|
@@ -110,7 +110,6 @@ namespace Orchard.Alias.Implementation.Storage {
|
||||
// Bulk updates might go wrong if we don't flush.
|
||||
_aliasRepository.Flush();
|
||||
var dict = ToDictionary(aliasRecord);
|
||||
//TODO:
|
||||
_aliasHolder.RemoveAlias(new AliasInfo() { Path = dict.Item1, Area = dict.Item2, RouteValues = dict.Item3, IsManaged = dict.Item6});
|
||||
}
|
||||
}
|
||||
|
@@ -30,8 +30,6 @@ namespace Orchard.Roles.Recipes.Builders {
|
||||
}
|
||||
|
||||
public override void Build(BuildContext context) {
|
||||
//var aliases = _aliasRecordepository.Table.ToList();
|
||||
|
||||
var aliases = _aliasHolder.GetMaps().SelectMany(m => m.GetAliases()).Where(m => m.IsManaged== false).ToList();
|
||||
|
||||
if (!aliases.Any())
|
||||
@@ -43,9 +41,7 @@ namespace Orchard.Roles.Recipes.Builders {
|
||||
foreach (var alias in aliases.OrderBy(x => x.Path))
|
||||
{
|
||||
var aliasElement = new XElement("Alias", new XAttribute("Path", alias.Path));
|
||||
//root.Add(
|
||||
// new XElement("Alias",
|
||||
// new XAttribute("Path", alias.Path)));
|
||||
|
||||
var routeValuesElement = new XElement("RouteValues");
|
||||
foreach (var routeValue in alias.RouteValues)
|
||||
{
|
||||
@@ -55,75 +51,7 @@ namespace Orchard.Roles.Recipes.Builders {
|
||||
aliasElement.Add(routeValuesElement);
|
||||
root.Add(aliasElement);
|
||||
}
|
||||
|
||||
//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)));
|
||||
//}
|
||||
|
||||
//root.Add(pathsElement);
|
||||
|
||||
//var rootElement = context.Document.Descendants("Orchard").FirstOrDefault();
|
||||
|
||||
//if (rootElement == null)
|
||||
//{
|
||||
// var ex = new OrchardException(T("Could not export this site's Aliases because the document passed via the Export Context did not contain a node called 'Orchard'. The document was malformed."));
|
||||
// Logger.Error(ex, ex.Message);
|
||||
// throw ex;
|
||||
//}
|
||||
|
||||
//rootElement.Add(xmlElement);
|
||||
}
|
||||
|
||||
//public void Exporting(ExportContext context)
|
||||
//{
|
||||
// if (!context.ExportOptions.CustomSteps.Contains("Aliases")) { return; }
|
||||
|
||||
// var xmlElement = new XElement("Aliases");
|
||||
|
||||
// var autoroutePaths = _contentManager.Query<AutoroutePart>().List().Select(p => p.Path);
|
||||
// var allAliasInfos = _aliasHolder.GetMaps().SelectMany(m => m.GetAliases()).ToList();
|
||||
|
||||
// //we need to remove any aliases that are autoroutes because the remote conent id may not sync up with the local content id. the autoroutes will be imported as part of the content import
|
||||
// var aliasInfosToExport = allAliasInfos.Where(ai => !autoroutePaths.Contains(ai.Path));
|
||||
|
||||
// foreach (var aliasInfo in aliasInfosToExport)
|
||||
// {
|
||||
// var aliasElement = new XElement("Alias", new XAttribute("Path", aliasInfo.Path));
|
||||
|
||||
// var routeValuesElement = new XElement("RouteValues");
|
||||
// foreach (var routeValue in aliasInfo.RouteValues)
|
||||
// {
|
||||
// routeValuesElement.Add(new XElement("Add", new XAttribute("Key", routeValue.Key), new XAttribute("Value", routeValue.Value)));
|
||||
// }
|
||||
|
||||
// aliasElement.Add(routeValuesElement);
|
||||
// xmlElement.Add(aliasElement);
|
||||
// }
|
||||
|
||||
// //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 allAliasInfos)
|
||||
// {
|
||||
// pathsElement.Add(new XElement("Add", new XAttribute("Path", aliasInfo.Path)));
|
||||
// }
|
||||
|
||||
// xmlElement.Add(pathsElement);
|
||||
|
||||
// var rootElement = context.Document.Descendants("Orchard").FirstOrDefault();
|
||||
|
||||
// if (rootElement == null)
|
||||
// {
|
||||
// var ex = new OrchardException(T("Could not export this site's Aliases because the document passed via the Export Context did not contain a node called 'Orchard'. The document was malformed."));
|
||||
// Logger.Error(ex, ex.Message);
|
||||
// throw ex;
|
||||
// }
|
||||
|
||||
// rootElement.Add(xmlElement);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -21,6 +21,16 @@ namespace Orchard.Alias.Recipes.Executors {
|
||||
get { return "Aliases"; }
|
||||
}
|
||||
|
||||
/*
|
||||
<Aliases>
|
||||
<Alias Path="Profile/Edit" Area="Custom.Profile">
|
||||
<RouteValues>
|
||||
<Add Key="area" Value="Custom.Profile" />
|
||||
<Add Key="controller" Value="Profile" />
|
||||
<Add Key="action" Value="Edit" />
|
||||
</RouteValues>
|
||||
</Alias>
|
||||
*/
|
||||
public override void Execute(RecipeExecutionContext context) {
|
||||
|
||||
foreach (var aliasElement in context.RecipeStep.Step.Elements()) {
|
||||
@@ -28,7 +38,6 @@ namespace Orchard.Alias.Recipes.Executors {
|
||||
|
||||
Logger.Information("Processing alias '{0}'.", aliasPath);
|
||||
|
||||
//var path = aliasElement.Attribute("Path").Value;
|
||||
var rvd = new RouteValueDictionary();
|
||||
|
||||
var routeValuesElement = aliasElement.Descendants("RouteValues").FirstOrDefault();
|
||||
@@ -48,60 +57,9 @@ namespace Orchard.Alias.Recipes.Executors {
|
||||
catch (Exception ex) {
|
||||
Logger.Error(ex, "Error while processing alias '{0}'.", aliasPath);
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
<Aliases>
|
||||
<Alias Path="Profile/Edit" Area="Custom.Profile">
|
||||
<RouteValues>
|
||||
<Add Key="area" Value="Custom.Profile" />
|
||||
<Add Key="controller" Value="Profile" />
|
||||
<Add Key="action" Value="Edit" />
|
||||
</RouteValues>
|
||||
</Alias>
|
||||
*/
|
||||
//Enable any features that are in the list, disable features that aren't in the list
|
||||
//public override void Execute(RecipeExecutionContext context)
|
||||
//{
|
||||
// if (!String.Equals(context.RecipeStep.Name, "Aliases", StringComparison.OrdinalIgnoreCase))
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// var aliasElements = context.RecipeStep.Step.Descendants("Alias");
|
||||
|
||||
// foreach (var aliasElement in aliasElements)
|
||||
// {
|
||||
// var path = aliasElement.Attribute("Path").Value;
|
||||
// var rvd = new RouteValueDictionary();
|
||||
|
||||
// var routeValuesElement = aliasElement.Descendants("RouteValues").FirstOrDefault();
|
||||
|
||||
// if (routeValuesElement != null)
|
||||
// {
|
||||
// foreach (var routeValue in routeValuesElement.Descendants("Add"))
|
||||
// {
|
||||
// rvd.Add(routeValue.Attribute("Key").Value, routeValue.Attribute("Value").Value);
|
||||
// }
|
||||
// }
|
||||
|
||||
// _aliasService.Set(path, rvd, "Custom");
|
||||
// }
|
||||
|
||||
// //remove all local pathys that are not present in the remote export
|
||||
// var allRemotePaths = recipeContext.RecipeStep.Step.XPathSelectElements("Paths/Add").Select(e => e.Attribute("Path").Value);
|
||||
// var allLocalPaths = _aliasService.List().Select(t => t.Item1).ToList();
|
||||
|
||||
// foreach (var path in allLocalPaths.Where(p => !allRemotePaths.Contains(p)))
|
||||
// {
|
||||
// _aliasService.Delete(path);
|
||||
// }
|
||||
|
||||
|
||||
// recipeContext.Executed = true;
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
@@ -25,9 +25,7 @@ namespace Orchard.Blogs.Routing {
|
||||
return false;
|
||||
}
|
||||
|
||||
//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;
|
||||
|
Reference in New Issue
Block a user