vendredi 21 avril 2017

Asp.Net Cloud options for project (Pattern)

In my Asp.Net project I will create Factory pattern for download and upload and of course storage.Now my options are SFTP and Azure.I will select the option from webconfig like

  <add key="SelectedCloud" value="Azure" />

Shell I use always switch statement everywhere for selected cloud ?. I can not imagine I have not to much page in my project(6 or 7) that have cloud proccess. For example I will use in pge gridview onrowdatabound event :

 if (e.Row.RowType == DataControlRowType.DataRow)
        {
         //here the switch statemnt
            var item = (Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob)e.Row.DataItem;
            item.download
        }

     ** // or in page load or in my crud methods..

Pattern something like :

 public interface IBaseCloud
{

}

 public class CloudFactoryClass
{
    private readonly IBaseCloud _cloud;

    public CloudFactoryClass(CloudType ftpType)
    {
        if (ftpType == CloudType .Azure)
        {
            _ftp = new AzureHelper();
        }

        if (ftpType == FtpType.SFtp)
        {
            _ftp = new SFtpHelper();
        }

    }

    public CloudFactoryClass(CloudType ftpType, string host, string pass, string userName)
    {


     if (ftpType == CloudType .Azure)
        {
            _ftp = new AzureHelper(host, userName, pass);
        }

        if (ftpType == FtpType.SFtp)
        {
            _ftp = new SFtpHelper(host, pass,userName );
        }
    }

    public IBaseCloud GetICloud()
    {
        return _cloud;
    }
}

Aucun commentaire:

Enregistrer un commentaire