Advertisement
Guest User

Untitled

a guest
May 15th, 2023
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.50 KB | None | 0 0
  1. using CMS;
  2. using CMS.Base;
  3. using CMS.DataEngine;
  4. using CMS.IO;
  5. using CMS.Helpers;
  6. using CMS.SiteProvider;
  7.  
  8. // Registers the custom module into the system
  9. [assembly: RegisterModule(typeof(Lummus.Custom.CustomAzureStorageModule))]
  10.  
  11. namespace Lummus.Custom
  12. {
  13.     public class CustomAzureStorageModule : Module
  14.     {
  15.         public CustomAzureStorageModule()
  16.             : base("CustomAzureStorageModule") { }
  17.  
  18.         protected override void OnInit()
  19.         {
  20.             base.OnInit();
  21.             var sites = SiteInfoProvider.GetSites();
  22.             // loop through all sites in this instance and create a new provider for each one
  23.             foreach (SiteInfo site in sites)
  24.             {
  25.                 // Creates a new StorageProvider instance for media files
  26.                 AbstractStorageProvider mediaProvider = CustomAzureStorageModule.CreateAzureStorageProvider();
  27.  
  28.                 // Maps a directory to the provider
  29.                 string path = string.Format("/{0}/media", site.SiteName);
  30.                 CMS.EventLog.EventLogProvider.LogEvent(CMS.EventLog.EventType.INFORMATION, "CustomAzureStorageModule", "OnInit", string.Format("Mapping {0} to Azure Storage", path));
  31.                 StorageHelper.MapStoragePath("~" + path, mediaProvider);
  32.  
  33.                 // Creates a new StorageProvider instance for files
  34.                 AbstractStorageProvider fileProvider = CustomAzureStorageModule.CreateAzureStorageProvider();
  35.  
  36.                 string filePath = string.Format("/{0}/files", site.SiteName);
  37.                 CMS.EventLog.EventLogProvider.LogEvent(CMS.EventLog.EventType.INFORMATION, "CustomAzureStorageModule", "OnInit", string.Format("Mapping {0} to Azure Storage", filePath));
  38.                 StorageHelper.MapStoragePath("~" + filePath, fileProvider);
  39.             }
  40.  
  41.         }
  42.  
  43.         public static AbstractStorageProvider CreateAzureStorageProvider()
  44.         {
  45.             // Creates a new StorageProvider instance
  46.             AbstractStorageProvider azureStorageProvider = new StorageProvider("Azure", "CMS.AzureStorage");
  47.  
  48.             // Specifies the target container
  49.             azureStorageProvider.CustomRootPath = ValidationHelper.GetString(SettingsHelper.AppSettings["CMSAzureRootContainer"], "");
  50.  
  51.             // Makes the container publicly accessible
  52.             azureStorageProvider.PublicExternalFolderObject = ValidationHelper.GetBoolean(SettingsHelper.AppSettings["CMSAzurePublicContainer"], false);
  53.  
  54.             return azureStorageProvider;
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement