Exemple #1
0
        public void Initialize()
        {
            //日志函数
            void LogAction(string tag, string message)
            {
                if (tag.Equals("error", StringComparison.CurrentCultureIgnoreCase))
                {
                    Logger.Error(message);
                }
                else
                {
                    Logger.Debug(message);
                }
            }

            #region 配置存储程序
            switch (AppConfiguration["StorageProvider:Type"])
            {
            case "LocalStorageProvider":
            {
                var config = GetConfigFromConfigOrSettingsByKey <LocalStorageConfig>("LocalStorageProvider").Result;

                if (config != null)
                {
                    if (!config.RootPath.Contains(":"))
                    {
                        var hostingEnvironment = IocManager.Resolve <IWebHostEnvironment>();
                        config.RootPath = Path.Combine(hostingEnvironment.WebRootPath, config.RootPath);
                    }
                }
                if (!Directory.Exists(config.RootPath))
                {
                    Directory.CreateDirectory(config.RootPath);
                }

                StorageProvider = new LocalStorageProvider(config);
                break;
            }

            case "AliyunOssStorageProvider":
            {
                var aliyunOssConfig = GetConfigFromConfigOrSettingsByKey <AliyunOssConfig>("AliyunOssStorageProvider").Result;;
                StorageProvider = new AliyunOssStorageProvider(aliyunOssConfig);
                break;
            }

            case "TencentCosStorageProvider":
            {
                var config = GetConfigFromConfigOrSettingsByKey <TencentCosConfig>("TencentCosStorageProvider").Result;;
                StorageProvider = new TencentStorageProvider(config);
                break;
            }

            default:
                break;
            }
            #endregion
        }
Exemple #2
0
        public TencentStorageTests()
        {
            var cosConfig = new TencentCosConfig
            {
                //这里使用自己的腾讯云相关配置
                //AppId = "",
                //SecretId = "",
                //SecretKey = "",
                //BucketName = "test",
                //Region = "ap-chengdu"
            };

            if (cosConfig.AppId == null)
            {
                cosConfig = ConfigHelper.LoadConfig <TencentCosConfig>("TencentStorage");
            }
            var tencentStorage = new TencentStorageProvider(cosConfig);

            StorageProvider = tencentStorage;
        }
        public TencentStorageTests()
        {
            var cosConfig = new TencentCosConfig
            {
                //这里使用自己的腾讯云相关配置
                AppId      = "",
                SecretId   = "",
                SecretKey  = "",
                BucketName = "test",
                Region     = "ap-chengdu"
            };

            //如果没填,尝试从配置文件加载
            if (string.IsNullOrWhiteSpace(cosConfig.AppId))
            {
                cosConfig = ConfigHelper.LoadConfig <TencentCosConfig>("TencentStorage");
            }
            var tencentStorage = new TencentStorageProvider(cosConfig);

            StorageProvider = tencentStorage;
        }