Creating custom CloudStorage provider

To create a new Storage Provider, which will be used in CloudStorage plugin use ItPartner.Nop.Plugin.Misc.CloudStorage.CustomProvider project as source.

The process can be divided into 4 major steps:

  1. Set system name of your provider and path to it's dll.
    See CustomProviderPlugin.cs:

    public static readonly string PROVIDER_SYSTEM_NAME = "CustomProvider";
    public static readonly string PROVIDER_DIRECTORY_PATH = "~/Plugins/ItPartner.Misc.CloudStorage.CustomProvider/";
    
  2. Set you provider's initializator which is used to register and access you provider in CloudStorage plugin.
    See Services/CustomProviderServiceInitializer.cs:

    public class CustomProviderServiceInitializer : ICloudStorageProviderInitializer
    

    It should return instance of provider service for each storage type: pictures, downloads and content files:

    public ICloudStorageProviderService GetPictureProvider()
    {
        return _customeProviderPictureService;
    }
    
    public ICloudStorageProviderService GetDownloadProvider()
    {
        return _customeProviderDownloadService;
    }
    
    public ICloudStorageProviderService GetContentProvider()
    {
        return _customeProviderContentService; 
    }
    
  3. Change configuration model, view and controller's methods .
    On Controllers/CustomProviderController.cs:

    public ActionResult Configure()
    {
        var providerSettings = _settingService.LoadSetting<CustomProviderSettings>();
    
        var configurationModel = new ConfigurationModel()
        {
            ProviderSystemName = _customProviderServiceInitializer.GetSystemName(),
    
            AccountName = providerSettings.AccountName,
            AccountKey = providerSettings.AccountKey,
            ContainerName = providerSettings.ContainerName,
            CDN = providerSettings.CDN,
            UseCDN = providerSettings.UseCDN
        };
    
        return PartialView("~/Plugins/ItPartner.Misc.CloudStorage.CustomProvider/Views/CustomProvider/_ProviderSettings.cshtml",
            configurationModel);
    }
    

    Change the Models/ConfigurationModel.cs and Views/CustomProvider/_ProviderSettings.cshtml according to your settings

  4. Add logic to provider's service.
    On Services/CustomProviderService.cs:

    public override string InsertFile(string fileName, string contentType, byte[] binary)
    {
          //some of your code for inserting file in storage
    }
    
    public override bool IsFileExsit(string fileName)
    {
         //some of your code for checking the existence of file in storage
    }
    
    //...
    

    There is a point to create separate instances of provider service for each item type. For example, you can set different container names for pictures, downloads and files and make every provider service store container name in it. That will minimize the count of loading provider settings.

    private readonly string _container;
    

Please note that some methods like MoveFile, RenameFile, CreateDirectory and etc. are already implemented in abstract class BaseCloudStorageProviderService (you can see them in "Services/CustomProviderService.cs" called with base.ImplementedMethodName instead of throwing NotImplementedException). It was made for situations, when there is no correct method to move file for example. In that case we're going to download the whole file, upload it to another location and delete the old one. No doubt, that hurts perfomance and may have other difficulties, so if you have an oppotunity to implement it better without extra actions, override them!

Comments

Astounding distribute you share without a doubt i'm typical devotee of your site and that i look at this full distribute till stop and i truly like it extremely a decent arrangement. i as of late got here over your weblog and have been perusing along. I thought i'd leave my first comment. I don't perceive what to say other than that i've. The format is correct.  visit https://www.collegepaperwritingservices.com/secrets-behind-the-domination-of-us-universities-colleges-over-the-global-arena-of-higher-education.html

Leave your comment