/// <summary>
        /// Initializes a new instance of the <see cref="PublishedContentRequestEngine"/> class with a content request.
        /// </summary>
        /// <param name="webRoutingSection"></param>
        /// <param name="pcr">The content request.</param>
        public PublishedContentRequestEngine(
            IWebRoutingSection webRoutingSection,
            PublishedContentRequest pcr)
        {
            if (pcr == null)
            {
                throw new ArgumentException("pcr is null.");
            }
            if (webRoutingSection == null)
            {
                throw new ArgumentNullException("webRoutingSection");
            }

            _pcr = pcr;
            _webRoutingSection = webRoutingSection;

            _routingContext = pcr.RoutingContext;
            if (_routingContext == null)
            {
                throw new ArgumentException("pcr.RoutingContext is null.");
            }

            var umbracoContext = _routingContext.UmbracoContext;

            if (umbracoContext == null)
            {
                throw new ArgumentException("pcr.RoutingContext.UmbracoContext is null.");
            }
            if (umbracoContext.RoutingContext != _routingContext)
            {
                throw new ArgumentException("RoutingContext confusion.");
            }
            // no! not set yet.
            //if (umbracoContext.PublishedContentRequest != _pcr) throw new ArgumentException("PublishedContentRequest confusion.");
        }
Пример #2
0
 public TemplateRenderer(IUmbracoContextAccessor umbracoContextAccessor, IPublishedRouter publishedRouter, IFileService fileService, ILocalizationService textService, IWebRoutingSection webRoutingSection)
 {
     _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
     _publishedRouter        = publishedRouter ?? throw new ArgumentNullException(nameof(publishedRouter));
     _fileService            = fileService ?? throw new ArgumentNullException(nameof(fileService));
     _languageService        = textService ?? throw new ArgumentNullException(nameof(textService));
     _webRoutingSection      = webRoutingSection ?? throw new ArgumentNullException(nameof(webRoutingSection));
 }
Пример #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="umbracoContext"></param>
 /// <param name="routingSection"></param>
 /// <param name="getRolesForUser"></param>
 public PublishedContentRequestFactory(
     UmbracoContext umbracoContext,
     IWebRoutingSection routingSection,
     Func <string, IEnumerable <string> > getRolesForUser)
 {
     _getRolesForUser = getRolesForUser ?? throw new ArgumentNullException(nameof(getRolesForUser));
     _umbracoContext  = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext));
     _routingSection  = routingSection ?? throw new ArgumentNullException(nameof(routingSection));
 }
Пример #4
0
 internal static PublishedRouter CreatePublishedRouter(IWebRoutingSection webRoutingSection, IFactory container = null, ContentFinderCollection contentFinders = null)
 {
     return(new PublishedRouter(
                webRoutingSection,
                contentFinders ?? new ContentFinderCollection(Enumerable.Empty <IContentFinder>()),
                new TestLastChanceFinder(),
                new TestVariationContextAccessor(),
                container?.TryGetInstance <ServiceContext>() ?? ServiceContext.CreatePartial(),
                new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>())));
 }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PublishedRouter"/> class.
 /// </summary>
 public PublishedRouter(
     IWebRoutingSection webRoutingSection,
     ContentFinderCollection contentFinders,
     IContentLastChanceFinder contentLastChanceFinder,
     IVariationContextAccessor variationContextAccessor,
     ServiceContext services,
     IProfilingLogger proflog)
 {
     _webRoutingSection       = webRoutingSection ?? throw new ArgumentNullException(nameof(webRoutingSection));
     _contentFinders          = contentFinders ?? throw new ArgumentNullException(nameof(contentFinders));
     _contentLastChanceFinder = contentLastChanceFinder ?? throw new ArgumentNullException(nameof(contentLastChanceFinder));
     _services                 = services ?? throw new ArgumentNullException(nameof(services));
     _profilingLogger          = proflog ?? throw new ArgumentNullException(nameof(proflog));
     _variationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor));
     _logger = proflog;
 }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UrlProvider"/> class with an Umbraco context and a list of url providers.
        /// </summary>
        /// <param name="umbracoContext">The Umbraco context.</param>
        /// <param name="routingSettings"></param>
        /// <param name="urlProviders">The list of url providers.</param>
        public UrlProvider(UmbracoContext umbracoContext, IWebRoutingSection routingSettings, IEnumerable <IUrlProvider> urlProviders)
        {
            if (umbracoContext == null)
            {
                throw new ArgumentNullException("umbracoContext");
            }

            _umbracoContext = umbracoContext;
            _urlProviders   = urlProviders;

            var provider = UrlProviderMode.Auto;

            Mode = provider;

            if (Enum <UrlProviderMode> .TryParse(routingSettings.UrlProviderMode, out provider))
            {
                Mode = provider;
            }
        }
Пример #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UrlProvider"/> class with an Umbraco context and a list of url providers.
        /// </summary>
        /// <param name="umbracoContext">The Umbraco context.</param>
        /// <param name="routingSettings">Routing settings.</param>
        /// <param name="urlProviders">The list of url providers.</param>
        /// <param name="variationContextAccessor">The current variation accessor.</param>
        public UrlProvider(UmbracoContext umbracoContext, IWebRoutingSection routingSettings, IEnumerable <IUrlProvider> urlProviders, IVariationContextAccessor variationContextAccessor)
        {
            if (routingSettings == null)
            {
                throw new ArgumentNullException(nameof(routingSettings));
            }

            _umbracoContext           = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext));
            _urlProviders             = urlProviders;
            _variationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor));
            var provider = UrlProviderMode.Auto;

            Mode = provider;

            if (Enum <UrlProviderMode> .TryParse(routingSettings.UrlProviderMode, out provider))
            {
                Mode = provider;
            }
        }
Пример #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PublishedContentRequest"/> class with a specific Uri and routing context.
        /// </summary>
        /// <param name="uri">The request <c>Uri</c>.</param>
        /// <param name="routingContext">A routing context.</param>
        /// <param name="getRolesForLogin">A callback method to return the roles for the provided login name when required</param>
        /// <param name="routingConfig"></param>
        public PublishedContentRequest(Uri uri, RoutingContext routingContext, IWebRoutingSection routingConfig, Func <string, IEnumerable <string> > getRolesForLogin)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            if (routingContext == null)
            {
                throw new ArgumentNullException("routingContext");
            }

            Uri              = uri;
            RoutingContext   = routingContext;
            GetRolesForLogin = getRolesForLogin;

            _engine = new PublishedContentRequestEngine(
                routingConfig,
                this);

            RenderingEngine = RenderingEngine.Unknown;
        }
Пример #9
0
 public ContentFinderByIdPath(IWebRoutingSection webRoutingSection, ILogger logger)
 {
     _webRoutingSection = webRoutingSection ?? throw new System.ArgumentNullException(nameof(webRoutingSection));
     _logger            = logger ?? throw new System.ArgumentNullException(nameof(logger));
 }
Пример #10
0
 public static UmbracoContext GetUmbracoContext(ApplicationContext applicationContext   = null, IWebRoutingSection webRoutingSettings   = null, HttpContextBase httpContext = null, WebSecurity webSecurity = null,
                                                IUmbracoSettingsSection settingsSection = null, IEnumerable <IUrlProvider> urlProviders = null)
 {
     httpContext        = httpContext ?? new Mock <HttpContextBase>().Object;
     applicationContext = applicationContext ?? GetApplicationContext();
     return(UmbracoContext.EnsureContext(
                httpContext,
                applicationContext,
                webSecurity ?? GetWebSecurity(http: httpContext, application: applicationContext),
                settingsSection ?? Mock.Of <IUmbracoSettingsSection>(section => section.WebRouting == (webRoutingSettings ?? GetBasicWebRoutingSettings())),
                urlProviders ?? Enumerable.Empty <IUrlProvider>(),
                true));
 }
Пример #11
0
 public static PublishedContentRequest GetPublishedContentRequest(UmbracoContext context = null, string url = null, IWebRoutingSection routingSection = null, IEnumerable <string> rolesForLogic = null, IPublishedContent currentContent = null)
 {
     return(new PublishedContentRequest(new Uri(string.IsNullOrEmpty(url) ? "http://localhost/test" : url),
                                        (context ?? UmbracoContext.Current).RoutingContext,
                                        routingSection ?? GetBasicWebRoutingSettings(),
                                        s => rolesForLogic ?? Enumerable.Empty <string>())
     {
         PublishedContent = currentContent ?? Mock.Of <IPublishedContent>(publishedContent => publishedContent.Id == 12345)
     });
 }
Пример #12
0
 public static UrlProvider GetUmbracoUrlProvider(UmbracoContext context, IWebRoutingSection routingSection = null, IEnumerable <IUrlProvider> urlProviders = null)
 {
     return(new UrlProvider(context, routingSection ?? GetBasicWebRoutingSettings(UrlProviderMode.Auto), urlProviders ?? new[] { Mock.Of <IUrlProvider>() }));
 }
 public ContentFinderByIdPath(IWebRoutingSection webRoutingSection)
 {
     _webRoutingSection = webRoutingSection;
 }