// initializes a new instance of the UmbracoContext class // internal for unit tests // otherwise it's used by EnsureContext above // warn: does *not* manage setting any IUmbracoContextAccessor internal UmbracoContext(HttpContextBase httpContext, IPublishedSnapshotService publishedSnapshotService, WebSecurity webSecurity, IUmbracoSettingsSection umbracoSettings, IEnumerable <IUrlProvider> urlProviders, IGlobalSettings globalSettings, IVariationContextAccessor variationContextAccessor) { if (httpContext == null) { throw new ArgumentNullException(nameof(httpContext)); } if (publishedSnapshotService == null) { throw new ArgumentNullException(nameof(publishedSnapshotService)); } if (webSecurity == null) { throw new ArgumentNullException(nameof(webSecurity)); } if (umbracoSettings == null) { throw new ArgumentNullException(nameof(umbracoSettings)); } if (urlProviders == null) { throw new ArgumentNullException(nameof(urlProviders)); } VariationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor)); _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); // ensure that this instance is disposed when the request terminates, though we *also* ensure // this happens in the Umbraco module since the UmbracoCOntext is added to the HttpContext items. // // also, it *can* be returned by the container with a PerRequest lifetime, meaning that the // container *could* also try to dispose it. // // all in all, this context may be disposed more than once, but DisposableObject ensures that // it is ok and it will be actually disposed only once. httpContext.DisposeOnPipelineCompleted(this); ObjectCreated = DateTime.Now; UmbracoRequestId = Guid.NewGuid(); HttpContext = httpContext; Security = webSecurity; // beware - we cannot expect a current user here, so detecting preview mode must be a lazy thing _publishedSnapshot = new Lazy <IPublishedSnapshot>(() => publishedSnapshotService.CreatePublishedSnapshot(PreviewToken)); // set the urls... // NOTE: The request will not be available during app startup so we can only set this to an absolute URL of localhost, this // is a work around to being able to access the UmbracoContext during application startup and this will also ensure that people // 'could' still generate URLs during startup BUT any domain driven URL generation will not work because it is NOT possible to get // the current domain during application startup. // see: http://issues.umbraco.org/issue/U4-1890 // OriginalRequestUrl = GetRequestFromContext()?.Url ?? new Uri("http://localhost"); CleanedUmbracoUrl = UriUtility.UriToUmbraco(OriginalRequestUrl); UrlProvider = new UrlProvider(this, umbracoSettings.WebRouting, urlProviders, variationContextAccessor); }
public DataTypeCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IdkMap idkMap) : base(appCaches, serializer) { _publishedSnapshotService = publishedSnapshotService; _publishedModelFactory = publishedModelFactory; _idkMap = idkMap; }
public PreviewApiController(Lazy <IContentResolver> contentResolver, IPublishedSnapshotService publishedSnapshotService, IUserService userService, IContentService contentService) { _contentResolver = contentResolver; _publishedSnapshotService = publishedSnapshotService; _userService = userService; _contentService = contentService; }
public ContentTypeCacheRefresher(AppCaches appCaches, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IdkMap idkMap) : base(appCaches) { _publishedSnapshotService = publishedSnapshotService; _publishedModelFactory = publishedModelFactory; _idkMap = idkMap; }
public UmbracoInjectedModule( IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, IPublishedSnapshotService publishedSnapshotService, IUserService userService, UrlProviderCollection urlProviders, IRuntimeState runtime, ILogger logger, IPublishedRouter publishedRouter, IVariationContextAccessor variationContextAccessor, IUmbracoContextFactory umbracoContextFactory) { _combinedRouteCollection = new Lazy <RouteCollection>(CreateRouteCollection); _globalSettings = globalSettings; _umbracoContextAccessor = umbracoContextAccessor; _publishedSnapshotService = publishedSnapshotService; _userService = userService; _urlProviders = urlProviders; _runtime = runtime; _logger = logger; _publishedRouter = publishedRouter; _variationContextAccessor = variationContextAccessor; _umbracoContextFactory = umbracoContextFactory; }
public PreviewController(UmbracoFeatures features, IGlobalSettings globalSettings, IPublishedSnapshotService publishedSnapshotService, UmbracoContext umbracoContext) { _features = features; _globalSettings = globalSettings; _publishedSnapshotService = publishedSnapshotService; _umbracoContext = umbracoContext; }
public LanguageCacheRefresher( AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IEventAggregator eventAggregator, ICacheRefresherNotificationFactory factory) : base(appCaches, serializer, eventAggregator, factory) =>
/// <summary> /// Sets the published snapshot service. /// </summary> /// <param name="builder">The builder.</param> /// <param name="service">A published snapshot service.</param> public static IUmbracoBuilder SetPublishedSnapshotService( this IUmbracoBuilder builder, IPublishedSnapshotService service) { builder.Services.AddUnique(service); return(builder); }
public ContentCacheRefresher(CacheHelper cacheHelper, IPublishedSnapshotService publishedSnapshotService, IdkMap idkMap, IDomainService domainService) : base(cacheHelper) { _publishedSnapshotService = publishedSnapshotService; _idkMap = idkMap; _domainService = domainService; }
// initializes a new instance of the UmbracoContext class // internal for unit tests // otherwise it's used by EnsureContext above // warn: does *not* manage setting any IUmbracoContextAccessor internal UmbracoContext( IPublishedSnapshotService publishedSnapshotService, UmbracoRequestPaths umbracoRequestPaths, IHostingEnvironment hostingEnvironment, UriUtility uriUtility, ICookieManager cookieManager, IHttpContextAccessor httpContextAccessor) { if (publishedSnapshotService == null) { throw new ArgumentNullException(nameof(publishedSnapshotService)); } _uriUtility = uriUtility; _hostingEnvironment = hostingEnvironment; _cookieManager = cookieManager; _httpContextAccessor = httpContextAccessor; ObjectCreated = DateTime.Now; UmbracoRequestId = Guid.NewGuid(); _umbracoRequestPaths = umbracoRequestPaths; // beware - we cannot expect a current user here, so detecting preview mode must be a lazy thing _publishedSnapshot = new Lazy <IPublishedSnapshot>(() => publishedSnapshotService.CreatePublishedSnapshot(PreviewToken)); }
/// <summary> /// Initializes a new instance of the <see cref="PublishedSnapshotRebuilder" /> class. /// </summary> public PublishedSnapshotRebuilder( IPublishedSnapshotService publishedSnapshotService, DistributedCache distributedCache) { _publishedSnapshotService = publishedSnapshotService; _distributedCache = distributedCache; }
/// <summary> /// Initializes a new instance of the <see cref="PublishedSnapshotServiceEventHandler" /> class. /// </summary> public PublishedSnapshotServiceEventHandler( IPublishedSnapshotService publishedSnapshotService, INuCacheContentService publishedContentService) { _publishedSnapshotService = publishedSnapshotService; _publishedContentService = publishedContentService; }
public ContentCacheRefresher(AppCaches appCaches, IPublishedSnapshotService publishedSnapshotService, IdkMap idkMap, IDomainService domainService) : base(appCaches) { _publishedSnapshotService = publishedSnapshotService; _idkMap = idkMap; _domainService = domainService; }
public ContentTypeCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IdkMap idkMap, IContentTypeCommonRepository contentTypeCommonRepository) : base(appCaches, serializer) { _publishedSnapshotService = publishedSnapshotService; _publishedModelFactory = publishedModelFactory; _idkMap = idkMap; _contentTypeCommonRepository = contentTypeCommonRepository; }
public NuCacheStatusController(IPublishedSnapshotService publishedSnapshotService) { if (publishedSnapshotService == null) { throw new ArgumentNullException(nameof(publishedSnapshotService)); } _publishedSnapshotService = publishedSnapshotService; }
/// <summary> /// Initializes a new instance of the <see cref="PublishedSnapshotCacheStatusController"/> class. /// </summary> public PublishedSnapshotCacheStatusController( IPublishedSnapshotService publishedSnapshotService, IPublishedSnapshotStatus publishedSnapshotStatus, DistributedCache distributedCache) { _publishedSnapshotService = publishedSnapshotService ?? throw new ArgumentNullException(nameof(publishedSnapshotService)); _publishedSnapshotStatus = publishedSnapshotStatus; _distributedCache = distributedCache; }
public PublishedSnapshotServiceEventHandler( IRuntimeState runtime, IPublishedSnapshotService publishedSnapshotService, INuCacheContentService publishedContentService, IContentService contentService, IMediaService mediaService) : this(publishedSnapshotService, publishedContentService) { }
/// <summary> /// Refreshes the publish snapshot service and if there are published changes ensures that partial view caches are /// refreshed too /// </summary> /// <param name="service"></param> /// <param name="appCaches"></param> /// <param name="payloads"></param> internal static void NotifyPublishedSnapshotService(IPublishedSnapshotService service, AppCaches appCaches, JsonPayload[] payloads) { service.Notify(payloads, out _, out var publishedChanged); if (payloads.Any(x => x.ChangeTypes.HasType(TreeChangeTypes.RefreshAll)) || publishedChanged) { // when a public version changes appCaches.ClearPartialViewCache(); } }
public XmlDataIntegrityController(IPublishedSnapshotService publishedSnapshotService) { if (publishedSnapshotService == null) { throw new ArgumentNullException(nameof(publishedSnapshotService)); } _publishedSnapshotService = publishedSnapshotService as PublishedSnapshotService; if (_publishedSnapshotService == null) { throw new NotSupportedException("Unsupported IPublishedSnapshotService, only the Xml one is supported."); } }
/// <summary> /// Initializes a new instance of the <see cref="UmbracoContextFactory"/> class. /// </summary> public UmbracoContextFactory(IUmbracoContextAccessor umbracoContextAccessor, IPublishedSnapshotService publishedSnapshotService, IVariationContextAccessor variationContextAccessor, IDefaultCultureAccessor defaultCultureAccessor, IUmbracoSettingsSection umbracoSettings, IGlobalSettings globalSettings, UrlProviderCollection urlProviders, IUserService userService) { _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); _publishedSnapshotService = publishedSnapshotService ?? throw new ArgumentNullException(nameof(publishedSnapshotService)); _variationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor)); _defaultCultureAccessor = defaultCultureAccessor ?? throw new ArgumentNullException(nameof(defaultCultureAccessor)); _umbracoSettings = umbracoSettings ?? throw new ArgumentNullException(nameof(umbracoSettings)); _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); _urlProviders = urlProviders ?? throw new ArgumentNullException(nameof(urlProviders)); _userService = userService ?? throw new ArgumentNullException(nameof(userService)); }
public MediaCacheRefresher( AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IIdKeyMap idKeyMap, IEventAggregator eventAggregator, ICacheRefresherNotificationFactory factory) : base(appCaches, serializer, eventAggregator, factory) { _publishedSnapshotService = publishedSnapshotService; _idKeyMap = idKeyMap; }
/// <summary> /// Ensures that there is a "current" UmbracoContext. /// </summary> /// <param name="umbracoContextAccessor"></param> /// <param name="httpContext">An http context.</param> /// <param name="publishedSnapshotService">A published snapshot service.</param> /// <param name="webSecurity">A security helper.</param> /// <param name="umbracoSettings">The umbraco settings.</param> /// <param name="urlProviders">Some url providers.</param> /// <param name="globalSettings"></param> /// <param name="replace">A value indicating whether to replace the existing context.</param> /// <returns>The "current" UmbracoContext.</returns> /// <remarks> /// fixme - this needs to be clarified /// /// If <paramref name="replace"/> is true then the "current" UmbracoContext is replaced /// with a new one even if there is one already. See <see cref="WebRuntimeComponent"/>. Has to do with /// creating a context at startup and not being able to access httpContext.Request at that time, so /// the OriginalRequestUrl remains unspecified until <see cref="UmbracoModule"/> replaces the context. /// /// This *has* to be done differently! /// /// See http://issues.umbraco.org/issue/U4-1890, http://issues.umbraco.org/issue/U4-1717 /// /// </remarks> // used by // UmbracoModule BeginRequest (since it's a request it has an UmbracoContext) // in BeginRequest so *late* ie *after* the HttpApplication has started (+ init? check!) // WebRuntimeComponent (and I'm not quite sure why) // -> because an UmbracoContext seems to be required by UrlProvider to get the "current" published snapshot? // note: at startup not sure we have an HttpContext.Current // at startup not sure we have an httpContext.Request => hard to tell "current" url // should we have a post-boot event of some sort for ppl that *need* ?! // can we have issues w/ routing context? // and tests // can .ContentRequest be null? of course! public static UmbracoContext EnsureContext( IUmbracoContextAccessor umbracoContextAccessor, HttpContextBase httpContext, IPublishedSnapshotService publishedSnapshotService, WebSecurity webSecurity, IUmbracoSettingsSection umbracoSettings, IEnumerable <IUrlProvider> urlProviders, IGlobalSettings globalSettings, IVariationContextAccessor variationContextAccessor, bool replace = false) { if (umbracoContextAccessor == null) { throw new ArgumentNullException(nameof(umbracoContextAccessor)); } if (httpContext == null) { throw new ArgumentNullException(nameof(httpContext)); } if (publishedSnapshotService == null) { throw new ArgumentNullException(nameof(publishedSnapshotService)); } if (webSecurity == null) { throw new ArgumentNullException(nameof(webSecurity)); } if (umbracoSettings == null) { throw new ArgumentNullException(nameof(umbracoSettings)); } if (urlProviders == null) { throw new ArgumentNullException(nameof(urlProviders)); } if (globalSettings == null) { throw new ArgumentNullException(nameof(globalSettings)); } // if there is already a current context, return if not replacing var current = umbracoContextAccessor.UmbracoContext; if (current != null && replace == false) { return(current); } // create & assign to accessor, dispose existing if any umbracoContextAccessor.UmbracoContext?.Dispose(); return(umbracoContextAccessor.UmbracoContext = new UmbracoContext(httpContext, publishedSnapshotService, webSecurity, umbracoSettings, urlProviders, globalSettings, variationContextAccessor)); }
public PreviewController( UmbracoFeatures features, IGlobalSettings globalSettings, IPublishedSnapshotService publishedSnapshotService, IUmbracoContextAccessor umbracoContextAccessor, ILocalizationService localizationService) { _features = features; _globalSettings = globalSettings; _publishedSnapshotService = publishedSnapshotService; _umbracoContextAccessor = umbracoContextAccessor; _localizationService = localizationService; }
/// <summary> /// Initializes a new instance of the <see cref="PublishedSnapshotServiceEventHandler"/> class. /// </summary> public PublishedSnapshotServiceEventHandler( IRuntimeState runtime, IPublishedSnapshotService publishedSnapshotService, INuCacheContentService publishedContentService, IContentService contentService, IMediaService mediaService) { _runtime = runtime; _publishedSnapshotService = publishedSnapshotService; _publishedContentService = publishedContentService; _contentService = contentService; _mediaService = mediaService; }
public PreviewController( UmbracoFeatures features, IGlobalSettings globalSettings, IPublishedSnapshotService publishedSnapshotService, IUmbracoContextAccessor umbracoContextAccessor, ILocalizationService localizationService) : this(features, globalSettings, publishedSnapshotService, umbracoContextAccessor, localizationService, Current.IconService) { }
protected override void Initialize() // FIXME: should NOT be here! { base.Initialize(); DefaultCultureAccessor = new TestDefaultCultureAccessor(); CreateAndInitializeDatabase(); // ensure we have a PublishedSnapshotService if (PublishedSnapshotService == null) { PublishedSnapshotService = CreatePublishedSnapshotService(); } }
public ContentTypeCacheRefresher( AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IIdKeyMap idKeyMap, IContentTypeCommonRepository contentTypeCommonRepository, IEventAggregator eventAggregator, ICacheRefresherNotificationFactory factory) : base(appCaches, serializer, eventAggregator, factory) { _publishedSnapshotService = publishedSnapshotService; _publishedModelFactory = publishedModelFactory; _idKeyMap = idKeyMap; _contentTypeCommonRepository = contentTypeCommonRepository; }
/// <summary> /// Initializes a new instance of the <see cref="UmbracoContextFactory"/> class. /// </summary> public UmbracoContextFactory( IUmbracoContextAccessor umbracoContextAccessor, IPublishedSnapshotService publishedSnapshotService, UmbracoRequestPaths umbracoRequestPaths, IHostingEnvironment hostingEnvironment, UriUtility uriUtility, ICookieManager cookieManager, IHttpContextAccessor httpContextAccessor) { _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); _publishedSnapshotService = publishedSnapshotService ?? throw new ArgumentNullException(nameof(publishedSnapshotService)); _umbracoRequestPaths = umbracoRequestPaths ?? throw new ArgumentNullException(nameof(umbracoRequestPaths)); _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); _uriUtility = uriUtility ?? throw new ArgumentNullException(nameof(uriUtility)); _cookieManager = cookieManager ?? throw new ArgumentNullException(nameof(cookieManager)); _httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor)); }
public WebRuntimeComponent( IUmbracoContextAccessor umbracoContextAccessor, SurfaceControllerTypeCollection surfaceControllerTypes, UmbracoApiControllerTypeCollection apiControllerTypes, IPublishedSnapshotService publishedSnapshotService, IUserService userService, IUmbracoSettingsSection umbracoSettings, IGlobalSettings globalSettings, IVariationContextAccessor variationContextAccessor, UrlProviderCollection urlProviders) { _umbracoContextAccessor = umbracoContextAccessor; _surfaceControllerTypes = surfaceControllerTypes; _apiControllerTypes = apiControllerTypes; _publishedSnapshotService = publishedSnapshotService; _userService = userService; _umbracoSettings = umbracoSettings; _globalSettings = globalSettings; _variationContextAccessor = variationContextAccessor; _urlProviders = urlProviders; }
public PreviewController( UmbracoFeatures features, IOptionsSnapshot <GlobalSettings> globalSettings, IPublishedSnapshotService publishedSnapshotService, IBackOfficeSecurityAccessor backofficeSecurityAccessor, ILocalizationService localizationService, IHostingEnvironment hostingEnvironment, ICookieManager cookieManager, IRuntimeMinifier runtimeMinifier, ICompositeViewEngine viewEngines, IUmbracoContextAccessor umbracoContextAccessor) { _features = features; _globalSettings = globalSettings.Value; _publishedSnapshotService = publishedSnapshotService; _backofficeSecurityAccessor = backofficeSecurityAccessor; _localizationService = localizationService; _hostingEnvironment = hostingEnvironment; _cookieManager = cookieManager; _runtimeMinifier = runtimeMinifier; _viewEngines = viewEngines; _umbracoContextAccessor = umbracoContextAccessor; }