/// <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) { bool disable = ConfigurationManager.AppSettings[DisableVirtualPathProviderKey] != null && ConfigurationManager.AppSettings[DisableVirtualPathProviderKey] .Equals("true", StringComparison.InvariantCultureIgnoreCase); IFileSystem fileSystem = FileSystemProviderManager.Current.GetUnderlyingFileSystemProvider(Constants.DefaultMediaRoute); bool isAzureBlobFileSystem = fileSystem is AzureBlobFileSystem; if (!disable && isAzureBlobFileSystem) { AzureFileSystem azureFileSystem = ((AzureBlobFileSystem)fileSystem).FileSystem; // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression if (azureFileSystem.UseDefaultRoute) { FileSystemVirtualPathProvider.ConfigureMedia(Constants.DefaultMediaRoute); } else { FileSystemVirtualPathProvider.ConfigureMedia(azureFileSystem.ContainerName); } } base.ApplicationStarting(umbracoApplication, applicationContext); }
/// <summary> /// Returns a singleton instance of the <see cref="AzureFileSystem"/> class. /// </summary> /// <param name="containerName">The container name.</param> /// <param name="rootUrl">The root url.</param> /// <param name="connectionString">The connection string.</param> /// <param name="maxDays">The maximum number of days to cache blob items for in the browser.</param> /// <param name="useDefaultRoute">Whether to use the default "media" route in the url independent of the blob container.</param> /// <param name="usePrivateContainer">Whether to use private blob access (no direct access) or public (direct access possible, default) access.</param> /// <returns>The <see cref="AzureFileSystem"/></returns> public static AzureFileSystem GetInstance(string containerName, string rootUrl, string connectionString, string maxDays, string useDefaultRoute, string usePrivateContainer) { lock (Locker) { AzureFileSystem fileSystem = FileSystems.SingleOrDefault(fs => fs.ContainerName == containerName && fs.rootHostUrl == rootUrl); if (fileSystem == null) { int max; if (!int.TryParse(maxDays, out max)) { max = 365; } bool defaultRoute; if (!bool.TryParse(useDefaultRoute, out defaultRoute)) { defaultRoute = true; } bool privateContainer; if (!bool.TryParse(usePrivateContainer, out privateContainer)) { privateContainer = true; } BlobContainerPublicAccessType blobContainerPublicAccessType = privateContainer ? BlobContainerPublicAccessType.Off : BlobContainerPublicAccessType.Blob; fileSystem = new AzureFileSystem(containerName, rootUrl, connectionString, max, defaultRoute, blobContainerPublicAccessType); FileSystems.Add(fileSystem); } return(fileSystem); } }
/// <summary> /// Returns a singleton instance of the <see cref="AzureFileSystem"/> class. /// </summary> /// <param name="containerName">The container name.</param> /// <param name="rootUrl">The root url.</param> /// <param name="connectionString">The connection string.</param> /// <param name="maxDays">The maximum number of days to cache blob items for in the browser.</param> /// <returns>The <see cref="AzureFileSystem"/></returns> public static AzureFileSystem GetInstance(string containerName, string rootUrl, string connectionString, string maxDays) { lock (Locker) { if (fileSystem == null) { int max; if (!int.TryParse(maxDays, out max)) { max = 365; } fileSystem = new AzureFileSystem(containerName, rootUrl, connectionString, max); } return(fileSystem); } }
/// <summary> /// Initializes a new instance of the <see cref="AzureBlobFileSystem"/> class /// from values in application settings. /// </summary> /// <param name="alias">The alias of the provider</param> public AzureBlobFileSystem(string alias) { string connectionString = ConfigurationManager.AppSettings[$"{ConnectionStringKey}:{alias}"]; if (!string.IsNullOrWhiteSpace(connectionString)) { string rootUrl = ConfigurationManager.AppSettings[$"{RootUrlKey}:{alias}"]; if (string.IsNullOrWhiteSpace(rootUrl)) { throw new InvalidOperationException("Azure Storage Root URL is not defined in application settings. The " + RootUrlKey + " property was not defined or is empty."); } string containerName = ConfigurationManager.AppSettings[$"{ContainerNameKey}:{alias}"]; if (string.IsNullOrWhiteSpace(containerName)) { containerName = "media"; } string maxDays = ConfigurationManager.AppSettings[$"{MaxDaysKey}:{alias}"]; if (string.IsNullOrWhiteSpace(maxDays)) { maxDays = "365"; } string useDefaultRoute = ConfigurationManager.AppSettings[$"{UseDefaultRootKey}:{alias}"]; if (string.IsNullOrWhiteSpace(useDefaultRoute)) { useDefaultRoute = "true"; } string accessType = ConfigurationManager.AppSettings[$"{UsePrivateContainerKey}:{alias}"]; if (string.IsNullOrWhiteSpace(accessType)) { accessType = "true"; } this.FileSystem = AzureFileSystem.GetInstance(containerName, rootUrl, connectionString, maxDays, useDefaultRoute, accessType); } else { throw new InvalidOperationException("Unable to retrieve the Azure Storage configuration from the application settings. " + ConnectionStringKey + " was not defined or is empty."); } }
/// <summary> /// Initializes a new instance of the <see cref="AzureBlobFileSystem"/> class. /// </summary> /// <param name="containerName">The container name.</param> /// <param name="rootUrl">The root url.</param> /// <param name="connectionString">The connection string.</param> /// <param name="maxDays">The maximum number of days to cache blob items for in the browser.</param> /// <param name="useDefaultRoute">Whether to use the default "media" route in the url independent of the blob container.</param> /// <param name="usePrivateContainer">blob container can be private (no direct access) or public (direct access possible, default)</param> public AzureBlobFileSystem(string containerName, string rootUrl, string connectionString, string maxDays, string useDefaultRoute, string usePrivateContainer) { this.FileSystem = AzureFileSystem.GetInstance(containerName, rootUrl, connectionString, maxDays, useDefaultRoute, usePrivateContainer); }
/// <summary> /// Returns a singleton instance of the <see cref="AzureFileSystem"/> class. /// </summary> /// <param name="containerName">The container name.</param> /// <param name="rootUrl">The root url.</param> /// <param name="connectionString">The connection string.</param> /// <param name="maxDays">The maximum number of days to cache blob items for in the browser.</param> /// <returns>The <see cref="AzureFileSystem"/></returns> public static AzureFileSystem GetInstance(string containerName, string rootUrl, string connectionString, string maxDays) { lock (Locker) { if (fileSystem == null) { int max; if (!int.TryParse(maxDays, out max)) { max = 365; } fileSystem = new AzureFileSystem(containerName, rootUrl, connectionString, max); } return fileSystem; } }
/// <summary> /// Initializes a new instance of the <see cref="AzureBlobFileSystem"/> class. /// </summary> /// <param name="containerName">The container name.</param> /// <param name="rootUrl">The root url.</param> /// <param name="connectionString">The connection string.</param> /// <param name="maxDays">The maximum number of days to cache blob items for in the browser.</param> public AzureBlobFileSystem(string containerName, string rootUrl, string connectionString, string maxDays) { this.FileSystem = AzureFileSystem.GetInstance(containerName, rootUrl, connectionString, maxDays); }