public HuaweiCloudSmsClient(HuaweiCloudSmsConfig config, Action <Exception> exceptionHandler = null) { _config = config ?? throw new ArgumentNullException(nameof(config)); _huaweiCloudAccount = config.Account ?? throw new ArgumentNullException(nameof(config.Account)); _proxy = WebApiClientCreator.Create(_config); var globalHandle = ExceptionHandleResolver.ResolveHandler(); globalHandle += exceptionHandler; _exceptionHandler = globalHandle; }
public static IHuaweiCloudSmsApis Create(HuaweiCloudSmsConfig config) { var handler = new HttpClientHandler(); handler.ServerCertificateCustomValidationCallback = delegate { return(true); }; var client = new HttpClient(handler); client.Timeout = TimeSpan.FromMilliseconds(config.TimeOut); client.BaseAddress = new Uri(ApiAddressHelper.GetGateway(config.RegionName)); var httpConfig = new HttpApiConfig(client); return(HttpApi.Create <IHuaweiCloudSmsApis>(httpConfig)); }
public HuaweiCloudSmsTests() { var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", false, true) .Build(); _config = configuration.GetSection("SMS:HuaweiCloud").Get <HuaweiCloudSmsConfig>(); SMS.Exceptions.ExceptionHandleResolver.SetHandler(e => { var sb = new StringBuilder(); sb.AppendLine(e.Message); sb.AppendLine(e.Source); sb.AppendLine(e.StackTrace); _messageIfError += sb.ToString(); }); _client = new HuaweiCloudSmsClient(_config, SMS.Exceptions.ExceptionHandleResolver.ResolveHandler()); }