private static IPublishedContent FindContentByAlias(ContextualPublishedContentCache cache, int rootNodeId, string alias)
        {
            if (alias == null) throw new ArgumentNullException("alias");

            // the alias may be "foo/bar" or "/foo/bar"
            // there may be spaces as in "/foo/bar,  /foo/nil"
            // these should probably be taken care of earlier on

            alias = alias.TrimStart('/');
            var xpathBuilder = new StringBuilder();
            xpathBuilder.Append(XPathStringsDefinition.Root);

            if (rootNodeId > 0)
                xpathBuilder.AppendFormat(XPathStrings.DescendantDocumentById, rootNodeId);

            XPathVariable var = null;
            if (alias.Contains('\'') || alias.Contains('"'))
            {
                // use a var, as escaping gets ugly pretty quickly
                var = new XPathVariable("alias", alias);
                alias = "$alias";
            }
            xpathBuilder.AppendFormat(XPathStrings.DescendantDocumentByAlias, alias);

            var xpath = xpathBuilder.ToString();

            // note: it's OK if var is null, will be ignored
            return cache.GetSingleByXPath(xpath, var);
        }
        public void SetUp()
        {
            TestHelper.SetupLog4NetForTests();

            //create the app context
            ApplicationContext.Current = new ApplicationContext(false);

            _httpContextFactory = new FakeHttpContextFactory("~/Home");
            //ensure the StateHelper is using our custom context
            StateHelper.HttpContext = _httpContextFactory.HttpContext;

            UmbracoSettings.UseLegacyXmlSchema = false;
            var cache = new PublishedContentCache
            {
                GetXmlDelegate = (context, preview) =>
                {
                    var doc = new XmlDocument();
                    doc.LoadXml(GetXml());
                    return(doc);
                }
            };

            _umbracoContext = new UmbracoContext(
                _httpContextFactory.HttpContext,
                ApplicationContext.Current,
                new PublishedCaches(cache, new PublishedMediaCache()));

            _cache = _umbracoContext.ContentCache;
        }
Exemple #3
0
        public override void Initialize()
        {
            base.Initialize();

            _httpContextFactory = new FakeHttpContextFactory("~/Home");
            //ensure the StateHelper is using our custom context
            StateHelper.HttpContext = _httpContextFactory.HttpContext;

            var settings    = SettingsForTests.GenerateMockSettings();
            var contentMock = Mock.Get(settings.Content);

            contentMock.Setup(x => x.UseLegacyXmlSchema).Returns(false);
            SettingsForTests.ConfigureSettings(settings);
            _xml = new XmlDocument();
            _xml.LoadXml(GetXml());
            var cache = new PublishedContentCache
            {
                GetXmlDelegate = (context, preview) => _xml
            };

            _umbracoContext = new UmbracoContext(
                _httpContextFactory.HttpContext,
                ApplicationContext,
                new PublishedCaches(cache, new PublishedMediaCache(ApplicationContext)),
                new WebSecurity(_httpContextFactory.HttpContext, ApplicationContext));

            _cache = _umbracoContext.ContentCache;
        }
Exemple #4
0
        /// <summary>
        /// Initializes the <see cref="ExpiryRulesFromUmbraco" /> class.
        /// </summary>
        /// <param name="umbracoCache">The Umbraco content cache.</param>
        public ExpiryRulesFromUmbraco(ContextualPublishedContentCache umbracoCache)
        {
            _umbracoCache = umbracoCache ?? throw new ArgumentNullException(nameof(umbracoCache));
            _expiryRules  = _umbracoCache.GetAtRoot().FirstOrDefault(node => node.DocumentTypeAlias == "expiryRules");

            GetDocumentTypeRules();
            GetPageRules();
            GetDefaults();
        }
 /// <summary>
 /// Constructor used to return results from the caches
 /// </summary>
 /// <param name="contentCache"></param>
 /// <param name="mediaCache"></param>
 public PublishedContentQuery(ContextualPublishedContentCache contentCache, ContextualPublishedMediaCache mediaCache)
 {
     if (contentCache == null)
     {
         throw new ArgumentNullException("contentCache");
     }
     if (mediaCache == null)
     {
         throw new ArgumentNullException("mediaCache");
     }
     _contentCache = contentCache;
     _mediaCache   = mediaCache;
 }
        private static IPublishedContent FindContentByAlias(ContextualPublishedContentCache cache, int rootNodeId, string alias)
        {
            if (alias == null)
            {
                throw new ArgumentNullException("alias");
            }

            // the alias may be "foo/bar" or "/foo/bar"
            // there may be spaces as in "/foo/bar,  /foo/nil"
            // these should probably be taken care of earlier on

            alias = alias.TrimStart('/');
            var xpathBuilder = new StringBuilder();


            if (rootNodeId > 0)
            {
                xpathBuilder.AppendFormat(XPathStrings.DescendantDocumentById, rootNodeId);
            }
            else
            {
                xpathBuilder.Append(XPathStringsDefinition.Root);
            }


            XPathVariable var = null;

            if (alias.Contains('\'') || alias.Contains('"'))
            {
                // use a var, as escaping gets ugly pretty quickly
                var   = new XPathVariable("alias", alias);
                alias = "$alias";
            }
            xpathBuilder.AppendFormat(XPathStrings.DescendantDocumentByAlias, alias);

            var xpath = xpathBuilder.ToString();

            // note: it's OK if var is null, will be ignored
            return(cache.GetSingleByXPath(xpath, var));
        }
Exemple #7
0
        public override void Initialize()
        {
            base.Initialize();

            _httpContextFactory = new FakeHttpContextFactory("~/Home");
            //ensure the StateHelper is using our custom context
            StateHelper.HttpContext = _httpContextFactory.HttpContext;

            UmbracoSettings.UseLegacyXmlSchema = false;
            _xml = new XmlDocument();
            _xml.LoadXml(GetXml());
            var cache = new PublishedContentCache
            {
                GetXmlDelegate = (context, preview) => _xml
            };

            _umbracoContext = new UmbracoContext(
                _httpContextFactory.HttpContext,
                ApplicationContext.Current,
                new PublishedCaches(cache, new PublishedMediaCache()));

            _cache = _umbracoContext.ContentCache;
        }
        private IEnumerable <IPublishedContent> TypedDocumentsByXPath(XPathExpression xpath, XPathVariable[] vars, ContextualPublishedContentCache cache)
        {
            var doc = cache.GetByXPath(xpath, vars);

            return(doc);
        }
        private IPublishedContent TypedDocumentByXPath(string xpath, XPathVariable[] vars, ContextualPublishedContentCache cache)
        {
            var doc = cache.GetSingleByXPath(xpath, vars);

            return(doc);
        }
 public PublishedContentQuery(ContextualPublishedContentCache contentCache, ContextualPublishedMediaCache mediaCache)
 {
     _contentCache = contentCache;
     _mediaCache = mediaCache;
 }
		public void SetUp()
		{
			TestHelper.SetupLog4NetForTests();

            //create the app context 
            ApplicationContext.Current = new ApplicationContext(false);

			_httpContextFactory = new FakeHttpContextFactory("~/Home");
			//ensure the StateHelper is using our custom context
			StateHelper.HttpContext = _httpContextFactory.HttpContext;

			UmbracoSettings.UseLegacyXmlSchema = false;
            var cache = new PublishedContentCache
                {
                    GetXmlDelegate = (context, preview) =>
                        {
                            var doc = new XmlDocument();
                            doc.LoadXml(GetXml());
                            return doc;
                        }
                };

		    _umbracoContext = new UmbracoContext(
                _httpContextFactory.HttpContext,
                ApplicationContext.Current,
                new PublishedCaches(cache, new PublishedMediaCache()));

		    _cache = _umbracoContext.ContentCache;
		}
Exemple #12
0
        /// <summary>
        /// Gets a dynamic content identified by its unique identifier.
        /// </summary>
        /// <param name="cache">The contextual cache.</param>
        /// <param name="contentId">The content unique identifier.</param>
        /// <returns>The dynamic content, or null.</returns>
        public static dynamic GetDynamicById(this ContextualPublishedContentCache cache, int contentId)
        {
            var content = cache.GetById(contentId);

            return(content == null ? DynamicNull.Null : new DynamicPublishedContent(content).AsDynamic());
        }
        private Page GetPageFromUrl(Uri url, IUserService userService, IContentService contentService, ContextualPublishedContentCache contentCache)
        {
            var result      = new Page();
            var absoluteUrl = new Uri(Request.RequestUri, url);

            var match = Regex.Match(absoluteUrl.Fragment, "^#/content/content/edit/([0-9]+)$");

            if (match.Success)
            {
                var pageId = int.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture);
                var page   = contentService.GetById(pageId);
                if (page != null)
                {
                    result.NodeId = page.Id;
                    result.Name   = page.Name;

                    result.LastEditedDate = page.UpdateDate;
                    result.LastEditedBy   = GetUser(page.WriterId, userService);
                }
            }
            else
            {
                var page = contentCache.GetByRoute(absoluteUrl.AbsolutePath);
                if (page != null)
                {
                    result.NodeId = page.Id;
                    result.Url    = new Uri(page.UrlAbsolute());
                    result.Name   = page.Name;

                    result.LastEditedDate = page.UpdateDate;
                    result.LastEditedBy   = GetUser(page.WriterId, userService);
                }
            }


            return(result);
        }
        protected IPublishedContent FindContentByAlias(ContextualPublishedContentCache cache, int rootContentId, string alias)
        {
            Mandate.ParameterNotNullOrEmpty(alias, "alias");

            StringBuilder xpathBuilder             = new StringBuilder();
            bool          hideTopLevelNodeFromPath = GlobalSettings.HideTopLevelNodeFromPath;

            // Build xPath

            if (rootContentId == 0)
            {
                if (hideTopLevelNodeFromPath)
                {
                    xpathBuilder.Append(XPathStringsDefinition.RootDocuments);                     // first node is not in the url
                }
                else
                {
                    xpathBuilder.Append(XPathStringsDefinition.Root);
                }
            }
            else
            {
                xpathBuilder.Append(XPathStringsDefinition.Root);
                xpathBuilder.AppendFormat(XPathStringsDefinition.DescendantDocumentById, rootContentId);
                // always "hide top level" when there's a domain
            }

            // the alias may be "foo/bar" or "/foo/bar"
            // there may be spaces as in "/foo/bar,  /foo/nil"
            // these should probably be taken care of earlier on

            alias = alias.RemoveLeadingAndTrailingSlashAndBackslash();            // .TrimStart('/');
            string[] urlNames = alias.Split(SlashChar, StringSplitOptions.RemoveEmptyEntries);

            // We don't care about the level anymore because we do it by child anyway

            string urlName;

            for (int i = 0; i < urlNames.Length; i++)
            {
                urlName = urlNames[i].RemoveLeadingAndTrailingSlashAndBackslash();

                // If the top level nodes are hidden the level is +1

                /*if (GlobalSettings.HideTopLevelNodeFromPath)
                 * {
                 *      // First I thought this is problematic...
                 *      // because we do not know if the backend user has overridden the urls e.g.
                 *      // normal: /test1/test2 means that "/" is the first one (because of hide top level node from path)
                 *      // overridden /test/test1/test2 so "/" is NOT the first one ("/" is overridden to "test")
                 *      // but that's ok because we hide the textboxes in the root if it's HideTopLevelNodeFromPath
                 *      // because then it makes no sense he overrides the url if it's "/"
                 *
                 *      if (level == 1)
                 *      {
                 *              xPathBuilder.Append("/"); // Needs to be descendants because we start at level 2
                 *      }
                 *
                 *      level++;
                 * }*/

                xpathBuilder.AppendFormat(XPathStringsDefinition.ChildDocumentByUrlName,
                                          Core.Constants.Conventions.Content.UrlAlias,
                                          urlName);
            }

            //LogHelper.Info<ContentFinderByUrlAlias>("xPath: " + xpathBuilder.ToString());

            // xPath is like: /root//* [@isDoc and ((@urlName = 'frontpage' or langProperty = 'frontpage') and @level = 1)]/* [@isDoc and ((@urlName = 'textpage' or langProperty = 'textpage') and @level = 2)] ...
            return(cache.GetSingleByXPath(xpathBuilder.ToString() /*, aliasVariable*/));
        }
        public override void Initialize()
        {
            base.Initialize();

            _httpContextFactory = new FakeHttpContextFactory("~/Home");
            //ensure the StateHelper is using our custom context
            StateHelper.HttpContext = _httpContextFactory.HttpContext;

		    var settings = SettingsForTests.GetMockSettings();
		    var contentMock = Mock.Get(settings.Content);
            contentMock.Setup(x => x.UseLegacyXmlSchema).Returns(false);
		    SettingsForTests.ConfigureSettings(settings);
            _xml = new XmlDocument();
            _xml.LoadXml(GetXml());
            var cache = new PublishedContentCache
                {
                    GetXmlDelegate = (context, preview) => _xml
                };

		    _umbracoContext = new UmbracoContext(
                _httpContextFactory.HttpContext,
                ApplicationContext.Current,
                new PublishedCaches(cache, new PublishedMediaCache()),
                new WebSecurity(_httpContextFactory.HttpContext, ApplicationContext.Current));

		    _cache = _umbracoContext.ContentCache;
        }
 public PublishedContentStore(ContextualPublishedContentCache contentCache)
 {
     _contentCache = contentCache;
 }
        public override void Initialize()
        {
            base.Initialize();

            _httpContextFactory = new FakeHttpContextFactory("~/Home");
            //ensure the StateHelper is using our custom context
            StateHelper.HttpContext = _httpContextFactory.HttpContext;

			UmbracoSettings.UseLegacyXmlSchema = false;
            _xml = new XmlDocument();
            _xml.LoadXml(GetXml());
            var cache = new PublishedContentCache
                {
                    GetXmlDelegate = (context, preview) => _xml
                };

		    _umbracoContext = new UmbracoContext(
                _httpContextFactory.HttpContext,
                ApplicationContext.Current,
                new PublishedCaches(cache, new PublishedMediaCache()));

		    _cache = _umbracoContext.ContentCache;
        }
Exemple #18
0
        /// <summary>
        /// Gets a dynamic content resulting from an XPath query.
        /// </summary>
        /// <param name="cache">The contextual cache.</param>
        /// <param name="xpath">The XPath query.</param>
        /// <param name="vars">Optional XPath variables</param>
        /// <returns>The dynamic content, or null.</returns>
        public static dynamic GetDynamicSingleByXPath(this ContextualPublishedContentCache cache, XPathExpression xpath, params XPathVariable[] vars)
        {
            var content = cache.GetSingleByXPath(xpath, vars);

            return(content == null ? DynamicNull.Null : new DynamicPublishedContent(content).AsDynamic());
        }
 private IPublishedContent TypedDocumentByXPath(string xpath, XPathVariable[] vars, ContextualPublishedContentCache cache)
 {
     var doc = cache.GetSingleByXPath(xpath, vars);
     return doc;
 }
 public RedirectPublishedContentFinder(ContextualPublishedContentCache publishedCache)
 {
     this.publishedCache = publishedCache;
 }
Exemple #21
0
        /// <summary>
        /// Gets dynamic contents at root.
        /// </summary>
        /// <param name="cache">The contextual cache.</param>
        /// <returns>The dynamic contents.</returns>
        public static dynamic GetDynamicAtRoot(this ContextualPublishedContentCache cache)
        {
            var content = cache.GetAtRoot();

            return(new DynamicPublishedContentList(content.Select(c => new DynamicPublishedContent(c))));
        }
Exemple #22
0
        /// <summary>
        /// Gets dynamic contents resulting from an XPath query.
        /// </summary>
        /// <param name="cache">The contextual cache.</param>
        /// <param name="xpath">The XPath query.</param>
        /// <param name="vars">Optional XPath variables</param>
        /// <returns>The dynamic contents.</returns>
        public static dynamic GetDynamicByXPath(this ContextualPublishedContentCache cache, XPathExpression xpath, params XPathVariable[] vars)
        {
            var content = cache.GetByXPath(xpath, vars);

            return(new DynamicPublishedContentList(content.Select(c => new DynamicPublishedContent(c))));
        }
 private IEnumerable<IPublishedContent> TypedDocumentsByXPath(XPathExpression xpath, XPathVariable[] vars, ContextualPublishedContentCache cache)
 {
     var doc = cache.GetByXPath(xpath, vars);
     return doc;
 }