Example #1
0
        /// <summary>
        /// Configures the virtual path provider.
        /// </summary>
        /// <param name="fileSystemAlias">
        ///     The FileSystem alias
        /// </param>
        /// <param name="pathPrefix">
        ///     The path prefix.
        /// </param>
        /// <typeparam name="TProviderTypeFilter">
        /// The provider type filter.
        /// </typeparam>
        /// <exception cref="ArgumentNullException">
        /// Thrown if <paramref name="pathPrefix"/> is null.
        /// </exception>
        public static void Configure <TProviderTypeFilter>(string fileSystemAlias, string pathPrefix = Constants.DefaultMediaRoute)
            where TProviderTypeFilter : SambaFileSystem
        {
            if (string.IsNullOrEmpty(pathPrefix))
            {
                throw new ArgumentNullException(nameof(pathPrefix));
            }

            var fileSystem = new Lazy <SambaFileSystem>(() =>
            {
                return((SambaFileSystem)FileSystemProviderManager.Current.GetUnderlyingFileSystemProvider(fileSystemAlias));
            });
            FileSystemVirtualPathProvider provider = new FileSystemVirtualPathProvider(pathPrefix, fileSystem);

            HostingEnvironment.RegisterVirtualPathProvider(provider);
        }
Example #2
0
        /// <summary>
        /// Overridable method to execute when All resolvers have been initialized but resolution is not
        /// frozen so they can be modified in this method
        /// </summary>
        /// <param name="umbracoApplication">The current <see cref="UmbracoApplicationBase"/></param>
        /// <param name="applicationContext">The Umbraco <see cref="ApplicationContext"/> for the current application.</param>
        protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            var configSection = this.GetFileSystemProvidersConfigSection();

            foreach (FileSystemProviderElement providerConfig in configSection.Providers)
            {
                var providerType = Type.GetType(providerConfig.Type);
                if (providerType == null || providerType.IsAssignableFrom(typeof(SambaFileSystem)) == false)
                {
                    continue;
                }

                var virtualPathProperty = providerConfig.Parameters[Constants.FileSystemConfiguration.VirtualPathRouteKey];
                if (virtualPathProperty == null || string.IsNullOrEmpty(virtualPathProperty.Value))
                {
                    continue;
                }

                FileSystemVirtualPathProvider.Configure <SambaFileSystem>(providerConfig.Alias, virtualPathProperty.Value);
            }

            base.ApplicationStarting(umbracoApplication, applicationContext);
        }