当前位置: 首页>>代码示例>>C#>>正文


C# IDocumentSession.GetPublishedPages方法代码示例

本文整理汇总了C#中IDocumentSession.GetPublishedPages方法的典型用法代码示例。如果您正苦于以下问题:C# IDocumentSession.GetPublishedPages方法的具体用法?C# IDocumentSession.GetPublishedPages怎么用?C# IDocumentSession.GetPublishedPages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDocumentSession的用法示例。


在下文中一共展示了IDocumentSession.GetPublishedPages方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ResolvePath

        /// <summary>
        /// Resolves the path.
        /// </summary>
        /// <param name="routeData">The route data.</param>
        /// <param name="virtualUrl">The virtual URL.</param>
        /// <returns></returns>
        public IPathData ResolvePath(RouteData routeData, string virtualUrl)
        {
            // Set the default action to index
            _pathData.Action = UIRoute.DefaultAction;
            // Get an up to date document session from structuremap
            _session = _container.GetInstance<IDocumentSession>();

            // The requested url is for the start page with no action
            if (string.IsNullOrEmpty(virtualUrl) || string.Equals(virtualUrl, "/")) {
                _pageModel = _session.Query<IPageModel>()
                    .Customize(x => x.WaitForNonStaleResultsAsOfLastWrite())
                    .SingleOrDefault(x => x.Parent == null);
            } else {
                // Remove the trailing slash
                virtualUrl = VirtualPathUtility.RemoveTrailingSlash(virtualUrl).TrimStart(new[] { '/' });
                // The normal beahaviour should be to load the page based on the url
                _pageModel = _session.Query<IPageModel, PageByUrl>()
                    .Customize(x => x.WaitForNonStaleResultsAsOfLastWrite())
                    .FirstOrDefault(x => x.Metadata.Url == virtualUrl);
                // Try to load the page without the last segment of the url and set the last segment as action))
                if (_pageModel == null && virtualUrl.LastIndexOf("/") > 0) {
                    var index = virtualUrl.LastIndexOf("/");
                    var action = virtualUrl.Substring(index, virtualUrl.Length - index).Trim(new[] { '/' });
                    virtualUrl = virtualUrl.Substring(0, index).TrimStart(new[] { '/' });
                    _pageModel = _session.Query<IPageModel, PageByUrl>()
                        .Customize(x => x.WaitForNonStaleResultsAsOfLastWrite())
                        .FirstOrDefault(x => x.Metadata.Url == virtualUrl);
                    _pathData.Action = action;
                }
                // If the page model still is empty, let's try to resolve if the start page has an action named (virtualUrl)
                if (_pageModel == null) {
                    _pageModel = _session.Query<IPageModel>().SingleOrDefault(x => x.Parent == null);
                    if(_pageModel == null) {
                        return null;
                    }
                    var pageTypeAttribute = _pageModel.GetType().GetAttribute<PageTypeAttribute>();
                    object area;
                    _controllerName = _controllerMapper.GetControllerName(routeData.Values.TryGetValue("area", out area) ? typeof(PagesController) : pageTypeAttribute.ControllerType);
                    var action = virtualUrl.TrimStart(new[] { '/' });
                    if (!_controllerMapper.ControllerHasAction(_controllerName, action)) {
                        return null;
                    }
                    _pathData.Action = action;
                }
            }

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

            var controllerType = _pageModel.GetType().GetAttribute<PageTypeAttribute>().ControllerType;
            _pathData.Controller = controllerType != null ? _controllerMapper.GetControllerName(controllerType) : string.Format("{0}Controller", _pageModel.GetType().Name);
            _pathData.CurrentPage = _pageModel;
            _pathData.NavigationContext = _session.GetPublishedPages(_pageModel.Id);
            return _pathData;
        }
开发者ID:sriv,项目名称:BrickPile,代码行数:62,代码来源:PathResolver.cs


注:本文中的IDocumentSession.GetPublishedPages方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。