private void CreateWellKnownFileSystems() { var macroPartialFileSystem = new PhysicalFileSystem(SystemDirectories.MacroPartials); var partialViewsFileSystem = new PhysicalFileSystem(SystemDirectories.PartialViews); var macroScriptsFileSystem = new PhysicalFileSystem(SystemDirectories.MacroScripts); var userControlsFileSystem = new PhysicalFileSystem(SystemDirectories.UserControls); var stylesheetsFileSystem = new PhysicalFileSystem(SystemDirectories.Css); var scriptsFileSystem = new PhysicalFileSystem(SystemDirectories.Scripts); var xsltFileSystem = new PhysicalFileSystem(SystemDirectories.Xslt); var masterPagesFileSystem = new PhysicalFileSystem(SystemDirectories.Masterpages); var mvcViewsFileSystem = new PhysicalFileSystem(SystemDirectories.MvcViews); var javaScriptLibraryFileSystem = new PhysicalFileSystem(Path.Combine(SystemDirectories.Umbraco, "lib")); _macroPartialFileSystem = new ShadowWrapper(macroPartialFileSystem, "Views/MacroPartials", ScopeProvider); _partialViewsFileSystem = new ShadowWrapper(partialViewsFileSystem, "Views/Partials", ScopeProvider); _macroScriptsFileSystem = new ShadowWrapper(macroScriptsFileSystem, "macroScripts", ScopeProvider); _userControlsFileSystem = new ShadowWrapper(userControlsFileSystem, "usercontrols", ScopeProvider); _stylesheetsFileSystem = new ShadowWrapper(stylesheetsFileSystem, "css", ScopeProvider); _scriptsFileSystem = new ShadowWrapper(scriptsFileSystem, "scripts", ScopeProvider); _xsltFileSystem = new ShadowWrapper(xsltFileSystem, "xslt", ScopeProvider); _masterPagesFileSystem = new ShadowWrapper(masterPagesFileSystem, "masterpages", ScopeProvider); _mvcViewsFileSystem = new ShadowWrapper(mvcViewsFileSystem, "Views", ScopeProvider); _javaScriptLibraryFileSystem = new ShadowWrapper(javaScriptLibraryFileSystem, "Lib", ScopeProvider); // filesystems obtained from GetFileSystemProvider are already wrapped and do not need to be wrapped again MediaFileSystem = GetFileSystemProvider <MediaFileSystem>(); }
// need to return something to LazyInitializer.EnsureInitialized // but it does not really matter what we return - here, null private object CreateWellKnownFileSystems() { var macroPartialFileSystem = new PhysicalFileSystem(SystemDirectories.MacroPartials); var partialViewsFileSystem = new PhysicalFileSystem(SystemDirectories.PartialViews); var stylesheetsFileSystem = new PhysicalFileSystem(SystemDirectories.Css); var scriptsFileSystem = new PhysicalFileSystem(SystemDirectories.Scripts); var masterPagesFileSystem = new PhysicalFileSystem(SystemDirectories.Masterpages); var mvcViewsFileSystem = new PhysicalFileSystem(SystemDirectories.MvcViews); _macroPartialFileSystem = new ShadowWrapper(macroPartialFileSystem, "Views/MacroPartials", IsScoped); _partialViewsFileSystem = new ShadowWrapper(partialViewsFileSystem, "Views/Partials", IsScoped); _stylesheetsFileSystem = new ShadowWrapper(stylesheetsFileSystem, "css", IsScoped); _scriptsFileSystem = new ShadowWrapper(scriptsFileSystem, "scripts", IsScoped); _masterPagesFileSystem = new ShadowWrapper(masterPagesFileSystem, "masterpages", IsScoped); _mvcViewsFileSystem = new ShadowWrapper(mvcViewsFileSystem, "Views", IsScoped); // fixme locking? _shadowWrappers.Add(_macroPartialFileSystem); _shadowWrappers.Add(_partialViewsFileSystem); _shadowWrappers.Add(_stylesheetsFileSystem); _shadowWrappers.Add(_scriptsFileSystem); _shadowWrappers.Add(_masterPagesFileSystem); _shadowWrappers.Add(_mvcViewsFileSystem); return(null); }
// note // shadowing is thread-safe, but entering and exiting shadow mode is not, and there is only one // global shadow for the entire application, so great care should be taken to ensure that the // application is *not* doing anything else when using a shadow. internal ICompletable Shadow() { if (Volatile.Read(ref _wkfsInitialized) == false) { EnsureWellKnownFileSystems(); } var id = ShadowWrapper.CreateShadowId(); return(new ShadowFileSystems(this, id)); // will invoke BeginShadow and EndShadow }
private ShadowWrapper CreateShadowWrapper(IFileSystem filesystem, string shadowPath) { lock (_shadowLocker) { var wrapper = new ShadowWrapper(filesystem, shadowPath, IsScoped); if (_shadowCurrentId != null) { wrapper.Shadow(_shadowCurrentId); } _shadowWrappers.Add(wrapper); return(wrapper); } }
/// <summary> /// Gets a strongly-typed filesystem. /// </summary> /// <typeparam name="TFileSystem">The type of the filesystem.</typeparam> /// <param name="fallback">A fallback creator for the inner filesystem.</param> /// <returns>A strongly-typed filesystem of the specified type.</returns> /// <remarks> /// <para>The fallback creator is used only if nothing is configured.</para> /// <para>Ideally, this should cache the instances, but that would break backward compatibility, so we /// only do it for our own MediaFileSystem - for everything else, it's the responsibility of the caller /// to ensure that they maintain singletons. This is important for singletons, as each filesystem maintains /// its own shadow and having multiple instances would lead to inconsistencies.</para> /// <para>Note that any filesystem created by this method *after* shadowing begins, will *not* be /// shadowing (and an exception will be thrown by the ShadowWrapper).</para> /// </remarks> public TFileSystem GetFileSystemProvider <TFileSystem>(Func <IFileSystem> fallback) where TFileSystem : FileSystemWrapper { var alias = GetFileSystemAlias <TFileSystem>(); return((TFileSystem)_filesystems.GetOrAdd(alias, _ => { // gets the inner fs, create the strongly-typed fs wrapping the inner fs, register & return // so we are double-wrapping here // could be optimized by having FileSystemWrapper inherit from ShadowWrapper, maybe var innerFs = GetUnderlyingFileSystemNoCache(alias, fallback); var shadowWrapper = new ShadowWrapper(innerFs, "typed/" + alias, ScopeProvider); var fs = (IFileSystem2)Activator.CreateInstance(typeof(TFileSystem), shadowWrapper); _wrappers.Add(shadowWrapper); // keeping a reference to the wrapper return fs; })); }
internal ICompletable Shadow(Guid id) { var typed = _wrappers.ToArray(); var wrappers = new ShadowWrapper[typed.Length + 9]; var i = 0; while (i < typed.Length) { wrappers[i] = typed[i++]; } wrappers[i++] = _macroPartialFileSystem; wrappers[i++] = _macroScriptsFileSystem; wrappers[i++] = _partialViewsFileSystem; wrappers[i++] = _stylesheetsFileSystem; wrappers[i++] = _scriptsFileSystem; wrappers[i++] = _userControlsFileSystem; wrappers[i++] = _xsltFileSystem; wrappers[i++] = _masterPagesFileSystem; wrappers[i] = _mvcViewsFileSystem; return(new ShadowFileSystems(id, wrappers)); }
// need to return something to LazyInitializer.EnsureInitialized // but it does not really matter what we return - here, null private object CreateWellKnownFileSystems() { var macroPartialFileSystem = new PhysicalFileSystem(SystemDirectories.MacroPartials); var partialViewsFileSystem = new PhysicalFileSystem(SystemDirectories.PartialViews); var stylesheetsFileSystem = new PhysicalFileSystem(SystemDirectories.Css); var scriptsFileSystem = new PhysicalFileSystem(SystemDirectories.Scripts); var mvcViewsFileSystem = new PhysicalFileSystem(SystemDirectories.MvcViews); _macroPartialFileSystem = new ShadowWrapper(macroPartialFileSystem, "macro-partials", IsScoped); _partialViewsFileSystem = new ShadowWrapper(partialViewsFileSystem, "partials", IsScoped); _stylesheetsFileSystem = new ShadowWrapper(stylesheetsFileSystem, "css", IsScoped); _scriptsFileSystem = new ShadowWrapper(scriptsFileSystem, "scripts", IsScoped); _mvcViewsFileSystem = new ShadowWrapper(mvcViewsFileSystem, "views", IsScoped); // TODO: do we need a lock here? _shadowWrappers.Add(_macroPartialFileSystem); _shadowWrappers.Add(_partialViewsFileSystem); _shadowWrappers.Add(_stylesheetsFileSystem); _shadowWrappers.Add(_scriptsFileSystem); _shadowWrappers.Add(_mvcViewsFileSystem); return(null); }