Пример #1
0
        public QiniuOSSService(IMemoryCache cache, OSSOptions options) : base(cache, options)
        {
            _mac    = new Mac(this.Options.AccessKey, this.Options.SecretKey);
            _config = new Config();
            _auth   = new Auth(_mac);
            _http   = new HttpManager();
            switch (this.Options.Region.ToLower())
            {
            case "cn_east":
                _config.Zone = Zone.ZONE_CN_East;
                break;

            case "cn_north":
                _config.Zone = Zone.ZONE_CN_North;
                break;

            case "cn_south":
                _config.Zone = Zone.ZONE_CN_South;
                break;

            case "us_north":
                _config.Zone = Zone.ZONE_US_North;
                break;

            case "asia_south":
                _config.Zone = Zone.ZONE_AS_Singapore;
                break;

            default:
                throw new InvalidOperationException("Incorrect regional configuration. Qiniu oss only supports the following regional configurations:CN_East(华东)/CN_South(华南)/CN_North(华北)/US_North(北美)/Asia_South(东南亚)");
            }
        }
        /// <summary>
        /// ╢сеДжцнд╪Чжп╪сть
        /// </summary>
        /// <param name="services"></param>
        /// <param name="name"></param>
        /// <param name="configuration"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static IServiceCollection AddOSSService(this IServiceCollection services, string name, string key)
        {
            ServiceProvider provider      = services.BuildServiceProvider();
            IConfiguration  configuration = provider.GetRequiredService <IConfiguration>();

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(IConfiguration));
            }
            provider.Dispose();

            IConfigurationSection section = configuration.GetSection(key);

            if (!section.Exists())
            {
                throw new Exception($"Config file not exist '{key}' section.");
            }
            OSSOptions options = section.Get <OSSOptions>();

            if (options == null)
            {
                throw new Exception($"Get OSS option from config file failed.");
            }
            return(services.AddOSSService(name, o =>
            {
                o.AccessKey = options.AccessKey;
                o.Endpoint = options.Endpoint;
                o.IsEnableCache = options.IsEnableCache;
                o.IsEnableHttps = options.IsEnableHttps;
                o.Provider = options.Provider;
                o.Region = options.Region;
                o.SecretKey = options.SecretKey;
                o.SessionToken = options.SessionToken;
            }));
        }
 public AliyunOSSService(OssClient client
                         , IEasyCachingProvider provider
                         , OSSOptions options)
 {
     this._client = client ?? throw new ArgumentNullException(nameof(OssClient));
     this._cache  = provider ?? throw new ArgumentNullException(nameof(IEasyCachingProvider));
     this.Options = options ?? throw new ArgumentNullException(nameof(OSSOptions));
 }
 public QCloudOSSService(CosXml client
                         , IEasyCachingProvider provider
                         , OSSOptions options)
 {
     this._client = client ?? throw new ArgumentNullException(nameof(CosXml));
     this._cache  = provider ?? throw new ArgumentNullException(nameof(IEasyCachingProvider));
     this.Options = options ?? throw new ArgumentNullException(nameof(OSSOptions));
 }
Пример #5
0
 public AliyunOSSService(IMemoryCache cache
                         , OSSOptions options) : base(cache, options)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options), "The OSSOptions can not null");
     }
     this._client = new OssClient(options.Endpoint, options.AccessKey, options.SecretKey);
 }
Пример #6
0
        public QCloudOSSService(IMemoryCache cache, OSSOptions options) : base(cache, options)
        {
            CosXmlConfig config = new CosXmlConfig.Builder()
                                  .IsHttps(options.IsEnableHttps)
                                  .SetRegion(options.Region)
                                  .SetDebugLog(false)
                                  .Build();
            QCloudCredentialProvider cosCredentialProvider = new DefaultQCloudCredentialProvider(options.AccessKey, options.SecretKey, 600);

            this._client = new CosXmlServer(config, cosCredentialProvider);
        }
Пример #7
0
        public HaweiOSSService(IMemoryCache cache, OSSOptions options) : base(cache, options)
        {
            string endPoint = options.Endpoint;

            //如果是不带协议的endpoint,添加协议
            if (!endPoint.StartsWith("http", StringComparison.OrdinalIgnoreCase))
            {
                endPoint = options.IsEnableHttps ? "https://" + endPoint : "http://" + endPoint;
            }
            _client = new ObsClient(Options.AccessKey, Options.SecretKey, new ObsConfig()
            {
                Endpoint = endPoint
            });
        }
Пример #8
0
        public MinioOSSService(IMemoryCache cache, OSSOptions options) : base(cache, options)
        {
            MinioClient client = new MinioClient()
                                 .WithEndpoint(options.Endpoint)
                                 .WithRegion(options.Region)
                                 .WithSessionToken(options.SessionToken)
                                 .WithCredentials(options.AccessKey, options.SecretKey);

            if (options.IsEnableHttps)
            {
                client = client.WithSSL();
            }
            this._client = client.Build();
        }
 public BaseOSSService(IMemoryCache cache, OSSOptions options)
 {
     this._cache  = cache ?? throw new ArgumentNullException(nameof(IMemoryCache));
     this.Options = options ?? throw new ArgumentNullException(nameof(OSSOptions));
 }