public JdCloudSmsClient(JdCloudSmsConfig config, Action <Exception> exceptionHandler = null) { _config = config ?? throw new ArgumentNullException(nameof(config)); _jdcloudAccount = config.Account ?? throw new ArgumentNullException(nameof(config.Account)); CredentialsProvider credentialsProvider = new StaticCredentialsProvider(_jdcloudAccount.AccessKey, _jdcloudAccount.SecretKey); _client = new SmsClient.DefaultBuilder() .CredentialsProvider(credentialsProvider) .HttpRequestConfig(new HttpRequestConfig(_config.Security ? Protocol.HTTPS : Protocol.HTTP, _config.RequestTimeout)) .Build(); var globalHandle = ExceptionHandleResolver.ResolveHandler(); globalHandle += exceptionHandler; _exceptionHandler = globalHandle; }
public JdCloudSmsTests() { var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", false, true) .Build(); _config = configuration.GetSection("SMS:JdCloud").Get <JdCloudSmsConfig>(); 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 JdCloudSmsClient(_config, SMS.Exceptions.ExceptionHandleResolver.ResolveHandler()); }
public static async Task <JdCloudSmsResult> SendAsync(SmsClient client, BatchSendRequest request, JdCloudSmsConfig config) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (request == null) { throw new ArgumentNullException(nameof(request)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } var asyncPolicy = Policy.HandleResult <JdCloudSmsResult>(r => !r.IsSuccess()) .RetryAsync(config.RetryTimes); return(await asyncPolicy.ExecuteAsync(() => CoreProcessAsync(client, request))); }