public async Task Ensure_Client_Caching_Works_With_Jwt() { var service = BoostrapApnsService(); var jwtOpt1 = new ApnsJwtOptions() { KeyId = "1234567890", TeamId = "1234567890", BundleId = "bundleid1", CertContent = _certs.P8CertData }; var jwtOpt2 = new ApnsJwtOptions() { KeyId = "1234567890", TeamId = "1234567890", BundleId = "bundleid2", CertContent = _certs.P8CertData }; var firstPush = ApplePush.CreateContentAvailable().AddToken("token"); var secondPush = ApplePush.CreateAlert(new ApplePushAlert(null, "body")).AddToken("token"); var thirdPush = ApplePush.CreateAlert(new ApplePushAlert(null, "body")).AddToken("token"); var fourthPush = ApplePush.CreateContentAvailable().AddToken("token"); await service.SendPush(firstPush, jwtOpt1); await service.SendPush(secondPush, jwtOpt1); await service.SendPush(thirdPush, jwtOpt2); await service.SendPush(fourthPush, jwtOpt2); Assert.Equal(2, ((IDictionary)service.GetType().GetField("_cachedJwtClients", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(service)).Count); }
ApnsJwtOptions CreateStubJwt() { var jwt = new ApnsJwtOptions() { BundleId = "bundle", CertContent = _certs.P8CertData, KeyId = "key", TeamId = "team" }; return(jwt); }
public IApnsClient CreateUsingJwt(ApnsJwtOptions options, bool useSandbox = false) { var client = ApnsClient.CreateUsingJwt(_httpClientFactory.CreateClient("dotAPNS"), options); if (useSandbox) { client.UseSandbox(); } return(client); }
public void CreateUsingJwt_Using_Cert_Path_Succeeds() { var jwtOpt = new ApnsJwtOptions() { BundleId = "bundle", CertFilePath = _certs.P8CertPath, KeyId = "key", TeamId = "team" }; var client = ApnsClient.CreateUsingJwt(new HttpClient(), jwtOpt); }
public IApnsClient CreateUsingJwt(ApnsJwtOptions options, bool useSandbox = false, bool disableServerCertValidation = false) { var httpClient = _httpClientFactory.CreateClient(disableServerCertValidation ? "dotAPNS_DisableCerverCertValidation" : "dotAPNS"); var client = ApnsClient.CreateUsingJwt(httpClient, options); if (useSandbox) { client.UseSandbox(); } return(client); }
public Task <ApnsResponse> SendPush(ApplePush push, ApnsJwtOptions jwtOptions) { var client = GetOrCreateCached(jwtOptions); try { return(client.Send(push)); } catch { _cachedJwtClients.TryRemove(jwtOptions.BundleId, out _); throw; } }
public Task <ApnsResponse> SendPush(ApplePush push, ApnsJwtOptions jwtOptions, bool useSandbox = false) { string clientCacheId = (useSandbox ? "s_" : "") + jwtOptions.BundleId; var client = _cachedJwtClients.GetOrAdd(clientCacheId, _ => _apnsClientFactory.CreateUsingJwt(jwtOptions, useSandbox)); try { return(client.Send(push)); } catch { _cachedJwtClients.TryRemove(clientCacheId, out _); throw; } }
public async Task <List <ApnsResponse> > SendPushes(IReadOnlyCollection <ApplePush> pushes, ApnsJwtOptions jwtOptions, bool useSandbox = false) { string clientCacheId = (useSandbox ? "s_" : "") + jwtOptions.BundleId; var client = _cachedJwtClients.GetOrAdd(clientCacheId, _ => _apnsClientFactory.CreateUsingJwt(jwtOptions, useSandbox)); var result = new List <ApnsResponse>(pushes.Count); try { foreach (var push in pushes) { result.Add(await client.Send(push)); } return(result); } catch { _cachedJwtClients.TryRemove(clientCacheId, out _); throw; } }
public IApnsClient CreateUsingJwt(ApnsJwtOptions options) => ApnsClient.CreateUsingJwt(_httpClientFactory.CreateClient("dotAPNS"), options);
public async Task <List <ApnsResponse> > SendPushes(IReadOnlyCollection <ApplePush> pushes, ApnsJwtOptions jwtOptions) { var client = GetOrCreateCached(jwtOptions); var result = new List <ApnsResponse>(pushes.Count); try { foreach (var push in pushes) { result.Add(await client.Send(push)); } return(result); } catch { _cachedJwtClients.TryRemove(jwtOptions.BundleId, out _); throw; } }