Ejemplo n.º 1
0
        public ActionResult IndexUnmanaged(AdminIndexOptions options, PagerParameters pagerParameters)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage aliases")))
            {
                return(new HttpUnauthorizedResult());
            }

            var pager = new Pager(Services.WorkContext.CurrentSite, pagerParameters);

            // default options
            if (options == null)
            {
                options = new AdminIndexOptions();
            }

            var aliases = _aliasHolder.GetMaps().SelectMany(x => x.GetAliases()).Where(x => !x.IsManaged);

            if (!String.IsNullOrWhiteSpace(options.Search))
            {
                var invariantSearch = options.Search.ToLowerInvariant();
                aliases = aliases.Where(x => x.Path.ToLowerInvariant().Contains(invariantSearch));
            }

            var pagerShape = Services.New.Pager(pager).TotalItemCount(aliases.Count());

            switch (options.Order)
            {
            case AliasOrder.Path:
                aliases = aliases.OrderBy(x => x.Path);
                break;
            }

            if (pager.PageSize != 0)
            {
                aliases = aliases.Skip(pager.GetStartIndex()).Take(pager.PageSize);
            }

            var model = new AdminIndexViewModel {
                Options      = options,
                Pager        = pagerShape,
                AliasEntries = aliases.Select(x => new AliasEntry()
                {
                    Alias = x, IsChecked = false
                }).ToList()
            };

            return(View(model));
        }
        public override void Build(BuildContext context)
        {
            var aliases = _aliasHolder.GetMaps().SelectMany(m => m.GetAliases()).Where(m => m.IsManaged == false).OrderBy(m => m.Path).ToList();

            if (!aliases.Any())
            {
                return;
            }

            var root = new XElement("Aliases");

            context.RecipeDocument.Element("Orchard").Add(root);

            foreach (var alias in aliases)
            {
                var aliasElement = new XElement("Alias", new XAttribute("Path", alias.Path));

                var routeValuesElement = new XElement("RouteValues");
                foreach (var routeValue in alias.RouteValues)
                {
                    routeValuesElement.Add(new XElement("Add", new XAttribute("Key", routeValue.Key), new XAttribute("Value", routeValue.Value)));
                }

                aliasElement.Add(routeValuesElement);
                root.Add(aliasElement);
            }
        }
Ejemplo n.º 3
0
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            var data = base.GetRouteData(httpContext);

            if (data == null)
            {
                return(null);
            }

            foreach (var key in data.Values.Keys)
            {
                if (!_constraintValues.Keys.Contains(key))
                {
                    continue;
                }

                var constrains = _constraintValues[key];
                var value      = (string)data.Values[key];
                if (!constrains.Contains(value, StringComparer.OrdinalIgnoreCase))
                {
                    return(null);
                }
            }

            var maps = _aliasHolder.GetMaps();

            foreach (var aliasMap in maps)
            {
                var       newRouteValues = new Dictionary <string, string>();
                AliasInfo aliasInfo;

                if (!aliasMap.TryGetAlias(_rewriteToUrl, out aliasInfo))
                {
                    continue;
                }

                foreach (var item in aliasInfo.RouteValues)
                {
                    newRouteValues.Add(item.Key, item.Value);
                }

                data.Values.Remove("area");
                newRouteValues.Merge(data.Values, true);
                data.Values.ReplaceWith(newRouteValues);
                data.DataTokens["area"] = newRouteValues["area"];
                return(data);
            }

            return(null);
        }
Ejemplo n.º 4
0
        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.OrderBy(x => x.Path))
            {
                var aliasElement = new XElement("Alias", new XAttribute("Path", aliasInfo.Path));

                var routeValuesElement = new XElement("RouteValues");
                foreach (var routeValue in aliasInfo.RouteValues.OrderBy(x => x.Key))
                {
                    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);
        }
Ejemplo n.º 5
0
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            var data = base.GetRouteData(httpContext);

            if (data == null)
            {
                return(null);
            }

            var prefix = (string)data.Values["prefix"];

            if (!_prefixValues.Contains(prefix))
            {
                return(null);
            }

            var newPath = (string)data.Values["path"];
            var maps    = _aliasHolder.GetMaps();

            foreach (var aliasMap in maps)
            {
                var       newRouteValues = new Dictionary <string, string>();
                AliasInfo aliasInfo;

                if (!aliasMap.TryGetAlias(newPath, out aliasInfo))
                {
                    continue;
                }
                foreach (var item in aliasInfo.RouteValues)
                {
                    newRouteValues.Add(item.Key, item.Value);
                }

                data.Values.Remove("area");

                newRouteValues.Merge(data.Values, true);
                data.Values.ReplaceWith(newRouteValues);
                data.Values[_prefixName] = prefix;
                data.DataTokens["area"]  = newRouteValues["area"];
                return(data);
            }

            return(null);
        }
Ejemplo n.º 6
0
        public static AliasInfo GetAlias(string requestPath, IAliasHolder aliasHolder)
        {
            var alias = GetClosestParentAlias(requestPath, aliasHolder.GetMap("Contents"), true);

            if (alias != null)
            {
                return(alias);
            }

            foreach (var map in aliasHolder.GetMaps())
            {
                alias = GetClosestParentAlias(requestPath, map, true);
                if (alias != null)
                {
                    return(alias);
                }
            }

            return(null);
        }
Ejemplo n.º 7
0
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            var data = base.GetRouteData(httpContext);

            if (data == null)
            {
                return(null);
            }

            var newPath = string.Join("/", _originalUrl);
            var maps    = _aliasHolder.GetMaps();


            foreach (var aliasMap in maps)
            {
                var       newRouteValues = new Dictionary <string, string>();
                AliasInfo aliasInfo;

                if (!aliasMap.TryGetAlias(newPath, out aliasInfo))
                {
                    continue;
                }

                foreach (var item in aliasInfo.RouteValues)
                {
                    newRouteValues.Add(item.Key, item.Value);
                }


                newRouteValues.Merge(data.Values, true);
                data.Values.ReplaceWith(newRouteValues);
                data.DataTokens["area"] = newRouteValues["area"];
                return(data);
            }


            return(null);
        }
Ejemplo n.º 8
0
        public IDictionary <string, string> Get(string path)
        {
            // All aliases are already in memory, and updated. We don't need to query the
            // database to lookup an alias by path.

            AliasInfo alias;

            // Optimized code path on Contents as it's the main provider of aliases
            if (_aliasHolder.GetMap("Contents").TryGetAlias(path, out alias))
            {
                return(alias.RouteValues);
            }

            foreach (var map in _aliasHolder.GetMaps())
            {
                if (map.TryGetAlias(path, out alias))
                {
                    return(alias.RouteValues);
                }
            }

            return(null);
        }