示例#1
0
        public virtual PathData ResolveUrl(Url url)
        {
            try
            {
                var path = parser.FindPath(url.RemoveDefaultDocument(Url.DefaultDocument).RemoveExtension(observedExtensions));

                path.CurrentItem = path.CurrentPage;

                if (draftRepository.Versions.TryParseVersion(url[PathData.VersionQueryKey], url["versionKey"], path))
                {
                    return(path);
                }

                string viewPreferenceParameter = url.GetQuery(WebExtensions.ViewPreferenceQueryString);
                if (viewPreferenceParameter == WebExtensions.DraftQueryValue && draftRepository.HasDraft(path.CurrentItem))
                {
                    var draft = draftRepository.Versions.GetVersion(path.CurrentPage);
                    path.TryApplyVersion(draft, url["versionKey"]);
                }

                return(path);
            }
            catch (Exception ex)
            {
                errorHandler.Notify(ex);
            }
            return(PathData.Empty);
        }
示例#2
0
        public void OtherStates_ArntDrafts(ContentState state)
        {
            var page = CreateOneItem <Items.NormalPage>(0, "page", null);

            persister.Save(page);

            var version = page.Clone(true);

            version.State     = state;
            version.VersionOf = page;

            var draft = repository.Save(version);

            drafts.HasDraft(page).ShouldBe(false);
            drafts.FindDrafts(page).ShouldBeEmpty();
        }
        public virtual PathData ResolveUrl(Url url)
        {
            // simple cache to help with multiple requests for same URL - PoC
            if ((lastUrl != null) && (lastUrl.Item1 == url.ToString()))
            {
                var result = lastUrl.Item2;
                lastUrl = null;
                return(result);
            }

            try
            {
                var path = parser.FindPath(url.RemoveDefaultDocument(Url.DefaultDocument).RemoveExtension(observedExtensions));

                path.CurrentItem = path.CurrentPage;

                if (draftRepository.Versions.TryParseVersion(url[PathData.VersionIndexQueryKey], url["versionKey"], path))
                {
                    lastUrl = new Tuple <string, PathData>(url, path);
                    return(path);
                }

                string viewPreferenceParameter = url.GetQuery(WebExtensions.ViewPreferenceQueryString);
                if (viewPreferenceParameter == WebExtensions.DraftQueryValue && draftRepository.HasDraft(path.CurrentItem))
                {
                    var draft = draftRepository.Versions.GetVersion(path.CurrentPage);
                    path.TryApplyVersion(draft, url["versionKey"]);
                }

                lastUrl = new Tuple <string, PathData>(url, path);
                return(path);
            }
            catch (Exception ex)
            {
                errorHandler.Notify(ex);
            }
            return(PathData.Empty);
        }