Exemple #1
0
        // need to return something to LazyInitializer.EnsureInitialized
        // but it does not really matter what we return - here, null
        private object CreateWellKnownFileSystems()
        {
            var logger = _loggerFactory.CreateLogger <PhysicalFileSystem>();

            //TODO this is f****d, why do PhysicalFileSystem has a root url? Mvc views cannot be accessed by url!
            var macroPartialFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, logger, _hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.MacroPartials), _hostingEnvironment.ToAbsolute(Constants.SystemDirectories.MacroPartials));
            var partialViewsFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, logger, _hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.PartialViews), _hostingEnvironment.ToAbsolute(Constants.SystemDirectories.PartialViews));
            var scriptsFileSystem      = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, logger, _hostingEnvironment.MapPathWebRoot(_globalSettings.UmbracoScriptsPath), _hostingEnvironment.ToAbsolute(_globalSettings.UmbracoScriptsPath));
            var mvcViewsFileSystem     = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, logger, _hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.MvcViews), _hostingEnvironment.ToAbsolute(Constants.SystemDirectories.MvcViews));

            _macroPartialFileSystem = new ShadowWrapper(macroPartialFileSystem, _ioHelper, _hostingEnvironment, _loggerFactory, "macro-partials", IsScoped);
            _partialViewsFileSystem = new ShadowWrapper(partialViewsFileSystem, _ioHelper, _hostingEnvironment, _loggerFactory, "partials", IsScoped);
            _scriptsFileSystem      = new ShadowWrapper(scriptsFileSystem, _ioHelper, _hostingEnvironment, _loggerFactory, "scripts", IsScoped);
            _mvcViewsFileSystem     = new ShadowWrapper(mvcViewsFileSystem, _ioHelper, _hostingEnvironment, _loggerFactory, "views", IsScoped);

            if (_stylesheetsFileSystem == null)
            {
                var stylesheetsFileSystem = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, logger,
                                                                   _hostingEnvironment.MapPathWebRoot(_globalSettings.UmbracoCssPath),
                                                                   _hostingEnvironment.ToAbsolute(_globalSettings.UmbracoCssPath));

                _stylesheetsFileSystem = new ShadowWrapper(stylesheetsFileSystem, _ioHelper, _hostingEnvironment, _loggerFactory, "css", IsScoped);

                _shadowWrappers.Add(_stylesheetsFileSystem);
            }

            // TODO: do we need a lock here?
            _shadowWrappers.Add(_macroPartialFileSystem);
            _shadowWrappers.Add(_partialViewsFileSystem);
            _shadowWrappers.Add(_scriptsFileSystem);
            _shadowWrappers.Add(_mvcViewsFileSystem);

            return(null);
        }
Exemple #2
0
        /// <summary>
        /// Sets the stylesheet filesystem.
        /// </summary>
        /// <remarks>
        /// Be careful when using this, the root path and root url must be correct for this to work.
        /// </remarks>
        /// <param name="fileSystem">The <see cref="IFileSystem"/>.</param>
        /// <exception cref="ArgumentNullException">If the <paramref name="fileSystem"/> is <c>null</c></exception>
        /// <exception cref="InvalidOperationException">Throws exception if the StylesheetFileSystem has already been initialized.</exception>
        /// <exception cref="InvalidOperationException">Throws exception if full path can't be resolved successfully.</exception>
        public void SetStylesheetFilesystem(IFileSystem fileSystem)
        {
            if (fileSystem == null)
            {
                throw new ArgumentNullException(nameof(fileSystem));
            }

            if (_stylesheetsFileSystem != null)
            {
                throw new InvalidOperationException(
                          "The StylesheetFileSystem cannot be changed when it's already been initialized.");
            }

            // Verify that _rootUrl/_rootPath is correct
            // We have to do this because there's a tight coupling
            // to the VirtualPath we get with CodeFileDisplay from the frontend.
            try
            {
                var rootPath = fileSystem.GetFullPath("/css/");
            }
            catch (UnauthorizedAccessException exception)
            {
                throw new UnauthorizedAccessException(
                          "Can't register the stylesheet filesystem, "
                          + "this is most likely caused by using a PhysicalFileSystem with an incorrect "
                          + "rootPath/rootUrl. RootPath must be <installation folder>\\wwwroot\\css"
                          + " and rootUrl must be /css", exception);
            }

            _stylesheetsFileSystem = CreateShadowWrapperInternal(fileSystem, "css");
        }
Exemple #3
0
        public ICompletable Shadow()
        {
            if (Volatile.Read(ref _wkfsInitialized) == false)
            {
                EnsureWellKnownFileSystems();
            }

            var id = ShadowWrapper.CreateShadowId(_hostingEnvironment);

            return(new ShadowFileSystems(this, id)); // will invoke BeginShadow and EndShadow
        }
Exemple #4
0
        private ShadowWrapper CreateShadowWrapperInternal(IFileSystem filesystem, string shadowPath)
        {
            lock (_shadowLocker)
            {
                var wrapper = new ShadowWrapper(filesystem, _ioHelper, _hostingEnvironment, _loggerFactory, shadowPath, () => IsScoped());
                if (_shadowCurrentId != null)
                {
                    wrapper.Shadow(_shadowCurrentId);
                }

                _shadowWrappers.Add(wrapper);
                return(wrapper);
            }
        }
Exemple #5
0
 // Ctor for tests, allows you to set the various filesystems
 internal FileSystems(
     ILoggerFactory loggerFactory,
     IIOHelper ioHelper,
     IOptions <GlobalSettings> globalSettings,
     IHostingEnvironment hostingEnvironment,
     IFileSystem macroPartialFileSystem,
     IFileSystem partialViewsFileSystem,
     IFileSystem stylesheetFileSystem,
     IFileSystem scriptsFileSystem,
     IFileSystem mvcViewFileSystem) : this(loggerFactory, ioHelper, globalSettings, hostingEnvironment)
 {
     _macroPartialFileSystem = CreateShadowWrapperInternal(macroPartialFileSystem, "macro-partials");
     _partialViewsFileSystem = CreateShadowWrapperInternal(partialViewsFileSystem, "partials");
     _stylesheetsFileSystem  = CreateShadowWrapperInternal(stylesheetFileSystem, "css");
     _scriptsFileSystem      = CreateShadowWrapperInternal(scriptsFileSystem, "scripts");
     _mvcViewsFileSystem     = CreateShadowWrapperInternal(mvcViewFileSystem, "view");
     // Set initialized to true so the filesystems doesn't get overwritten.
     _wkfsInitialized = true;
 }