コード例 #1
0
        PageFile MatchItem(Item item, string url, UriSegmentParameterList urlSegmentParameters)
        {
            var matchResult = item.Match(url);
            if (matchResult.Success)
            {
                Item itemFound;
                if (string.IsNullOrEmpty(matchResult.NextUrlPart))
                {
                    // last segment found is not a file, so try to read the default (index) file
                    if (item.ItemType == ItemType.Directory)
                        itemFound = ((PageDirectory)item).IndexFile;
                    else if (item.ItemType == ItemType.PageFile)
                        itemFound = item;
                    else
                        throw new XrcException(string.Format("Item '{0}' is not supported.", item.ResourceLocation));
                }
                else if (item.ItemType == ItemType.Directory)
                    itemFound = MatchList((PageDirectory)item, matchResult.NextUrlPart, urlSegmentParameters);
                else
                    itemFound = null;

                if (itemFound != null && matchResult.IsParameter)
                    urlSegmentParameters.Add(matchResult.ParameterName, matchResult.ParameterValue);

                return (PageFile)itemFound;
            }

            return null;
        }
コード例 #2
0
ファイル: Item.cs プロジェクト: davideicardi/xrc
        public XrcUrl BuildUrl(UriSegmentParameterList segmentParameters = null)
        {
            string currentName = BuildSegmentUrl(segmentParameters);

            XrcUrl url;
            if (ItemType == ItemType.Directory)
            {
                if (Parent == null)
                    url = new XrcUrl(currentName);
                else
                    url = Parent.BuildUrl(segmentParameters).Append(currentName);

                url = url.AppendTrailingSlash();
            }
            else if (ItemType == ItemType.PageFile)
            {
                XrcUrl parentUrl;
                if (Parent == null)
                    parentUrl = new XrcUrl("~");
                else
                    parentUrl = Parent.BuildUrl(segmentParameters);

                if (((PageFile)this).IsIndex)
                    url = parentUrl;
                else
                    url = parentUrl.Append(currentName);
            }
            else
                throw new XrcException(string.Format("BuildUrl not supported on '{0}'.", ItemType));

            return url;
        }
コード例 #3
0
        public PageLocatorResult Locate(XrcUrl url)
        {
            if (url == null)
                throw new ArgumentNullException("url");

            var urlSegmentParameters = new UriSegmentParameterList();

            var matchItem = MatchItem(_pageStructure.GetRoot(), url.Path, urlSegmentParameters);

            if (matchItem == null)
                return null;

            return new PageLocatorResult(matchItem, urlSegmentParameters);
        }
コード例 #4
0
        Item MatchList(PageDirectory directory, string url, UriSegmentParameterList urlSegmentParameters)
        {
            var validFiles= directory.Files.Where(p => p.ItemType != ItemType.ConfigFile);
            var validItems = directory.Directories.Select(p => (Item)p).Union(validFiles)
                                .OrderBy(p => p.Priority);

            foreach (var item in validItems)
            {
                var match = MatchItem(item, url, urlSegmentParameters);
                if (match != null)
                    return match;
            }

            return null;
        }
コード例 #5
0
ファイル: Page.cs プロジェクト: davideicardi/xrc
        public Page(string resourceLocation, 
                    XrcUrl url,
                    PageActionList actions,
                    PageParameterList parameters,
                    ModuleDefinitionList modules,
                    UriSegmentParameterList urlSegmentsParameters,
					Configuration.IHostingConfig hostingConfig)
        {
            _actions = actions;
            _parameters = parameters;
            _modules = modules;
            _urlSegmentsParameters = urlSegmentsParameters;
            _url = url;
            _resourceLocation = resourceLocation;
            _hostingConfig = hostingConfig;
        }
コード例 #6
0
ファイル: PageLocatorResult.cs プロジェクト: davideicardi/xrc
 public PageLocatorResult(PageFile page, UriSegmentParameterList urlSegmentsParameters)
 {
     _page = page;
     _urlSegmentsParameters = urlSegmentsParameters;
 }
コード例 #7
0
        void SetLayout(PageDefinition pageDefinition, PageFile pageFile, UriSegmentParameterList uriParameters)
        {
            if (pageFile.IsSlot || pageFile.IsDefaultLayout)
                return;

            if (!pageDefinition.Actions.Contains("GET"))
                return;

            if (pageFile.DefaultLayoutFile == null)
                return;

            var action = pageDefinition.Actions["GET"];
            if (action != null && action.Layout == null)
                action.Layout = pageFile.DefaultLayoutFile.BuildUrl(uriParameters).ToString();
        }
コード例 #8
0
ファイル: Item.cs プロジェクト: davideicardi/xrc
        string BuildSegmentUrl(UriSegmentParameterList segmentParameters = null)
        {
            if (_parametricUriSegment != null)
             {
                 string paramValue;
                 if (segmentParameters == null || !_parametricUriSegment.IsParametric)
                     paramValue = Name;
                 else if (!segmentParameters.TryGetValue(_parametricUriSegment.ParameterName, out paramValue))
                     paramValue = Name;

                 return _parametricUriSegment.BuildSegmentUrl(paramValue);
             }
             else
                 return Name;
        }