public async Task <List <string> > GetRegistrationExcept(PushRegistration pushRegistration) { var registrations = new List <string>(); using (var conn = new SqlConnection(_connectionString)) { var sql = $"SELECT RegistrationId FROM PushNotificationRegistrations WHERE RegistrationId <> '{pushRegistration.RegistrationId}' AND AppId = '{pushRegistration.AppId}' AND UserId = '{pushRegistration.UserId}'"; using (var cmd = new SqlCommand(sql, conn)) { await conn.OpenAsync(); var reader = await cmd.ExecuteReaderAsync(); if (reader.HasRows) { while (await reader.ReadAsync()) { registrations.Add(reader[0].ToString()); } } } } return(registrations); }
public async Task CanGetAllowedAndDeniedReceivers() { ClearPushRegistrations(); var receiver1 = new PushRegistration { Allowed = true }; var receiver2 = new PushRegistration { Allowed = true }; var receiver3 = new PushRegistration { Allowed = false }; await _pushNotificationsService.InsertPushReceiver(receiver1); await _pushNotificationsService.InsertPushReceiver(receiver2); await _pushNotificationsService.InsertPushReceiver(receiver3); var allowed = await _pushNotificationsService.GetAllowedReceivers(); var denied = await _pushNotificationsService.GetDeniedReceivers(); Assert.AreEqual(2, allowed); Assert.AreEqual(1, denied); }
private async Task Clean(PushRegistration registration) { var registrationIds = await _dbRepo.GetRegistrationExcept(registration); foreach (var registrationId in registrationIds) { await _dbRepo.Delete(registrationId); await _nhRepo.Delete(registrationId); } }
public async Task <string> PostAsync([FromBody] PushRegistration registration) { #region input validation if (registration == null) { throw new ArgumentException("Check one or more of your arguments"); } if (string.IsNullOrEmpty(registration.AppId)) { throw new ArgumentException("Please provide a valid AppId"); } if (string.IsNullOrEmpty(registration.DeviceToken)) { throw new ArgumentException("Please provide a valid DeviceToken"); } if (registration.Platform == Platform.none) { throw new ArgumentException("Platform can only be iOS, Android or Windows"); } #endregion string registrationId = null; //registration.UserId = "*****@*****.**"; //registration.UserId = RequestContext.Principal.Identity.Name.ToLower(); if (registration.Tags == null) { registration.Tags = new List <string>(); } registration.Tags.Add($"UserId:{registration.UserId}"); AzureNotificationHub hub = await _dbRepo.GetAzureNotificationHubEndpoint(registration.AppId); if (string.IsNullOrEmpty(hub.Endpoint) && string.IsNullOrEmpty(hub.HubName)) { throw new Exception($"Unable to find an enpoint for appId = '{registration.AppId}'"); } _nhRepo = new NotificationHubRepository(hub.Endpoint, hub.HubName); registrationId = await _nhRepo.Upsert(registration); registration.RegistrationId = registrationId; var success = await _dbRepo.Upsert(registration); //await Clean(registration); return(registrationId); }
public async Task CanDeleteRegistration() { ClearPushRegistrations(); var toDelete = new PushRegistration(); await _pushNotificationsService.InsertPushReceiver(toDelete); Assert.AreEqual(1, _registrationRepository.Table.Count()); await _pushNotificationsService.DeletePushReceiver(toDelete); Assert.AreEqual(0, _registrationRepository.Table.Count()); }
public PushRegistrationDto(PushRegistration pushRegistration) { if (!String.IsNullOrEmpty(pushRegistration.AndroidSenderId)) { Add(AndroidSenderId, pushRegistration.AndroidSenderId); } if (!String.IsNullOrEmpty(pushRegistration.AndroidInstanceId)) { Add(AndroidInstanceId, pushRegistration.AndroidInstanceId); } if (!String.IsNullOrEmpty(pushRegistration.IOSToken)) { Add(IOSToken, pushRegistration.IOSToken); } }
public async Task CanGetRegistration() { ClearPushRegistrations(); var registration = new PushRegistration { Token = "CanGetRegistration" }; await _pushNotificationsService.InsertPushReceiver(registration); var actual = _registrationRepository.Table.Where(x => x.Token == "CanGetRegistration").First(); var found = await _pushNotificationsService.GetPushReceiver(actual.Id); Assert.AreEqual(actual.Token, found.Token); Assert.AreEqual(actual.Id, found.Id); }
public async Task <bool> Upsert(PushRegistration pushRegistration) { var success = false; var exists = await RegistrationExists(pushRegistration.RegistrationId); if (exists) { success = await Update(pushRegistration); } else { success = await Insert(pushRegistration); } return(success); }
public async Task CanUpdateRegistration() { ClearPushRegistrations(); var registration = new PushRegistration() { Token = "CanUpdateRegistrationToken" }; await _pushNotificationsService.InsertPushReceiver(registration); registration.Token = "CanUpdateRegistrationToken1"; await _pushNotificationsService.UpdatePushReceiver(registration); var found = _registrationRepository.Table.Where(x => x.Token == "CanUpdateRegistrationToken1"); Assert.AreEqual(1, found.Count()); }
public async Task <bool> Insert(PushRegistration pushRegistration) { var success = false; using (var conn = new SqlConnection(_connectionString)) { await conn.OpenAsync(); string sql = $"INSERT INTO PushNotificationRegistrations (RegistrationId, AppId, UserId, DeviceToken, Platform, Tags) VALUES ('{pushRegistration.RegistrationId}', '{pushRegistration.AppId}', '{pushRegistration.UserId}', '{pushRegistration.DeviceToken}', {(int)pushRegistration.Platform}, '{JsonConvert.SerializeObject(pushRegistration.Tags)}')"; using (var cmd = new SqlCommand(sql, conn)) { await cmd.ExecuteScalarAsync(); success = true; } } return(success); }
public async Task <bool> Update(PushRegistration pushRegistration) { var success = false; using (var conn = new SqlConnection(_connectionString)) { await conn.OpenAsync(); string sql = $"UPDATE PushNotificationRegistrations SET AppId = '{pushRegistration.AppId}', UserId = '{pushRegistration.UserId}', DeviceToken = '{pushRegistration.DeviceToken}', Platform = {(int)pushRegistration.Platform}, Tags = '{JsonConvert.SerializeObject(pushRegistration.Tags)}' WHERE RegistrationId = '{pushRegistration.RegistrationId}'"; using (var cmd = new SqlCommand(sql, conn)) { await cmd.ExecuteScalarAsync(); success = true; } } return(success); }
public async Task CanGetReceivers() { ClearPushRegistrations(); var receiver1 = new PushRegistration { Token = "CanGetReceivers1", Allowed = true }; var receiver2 = new PushRegistration { Token = "CanGetReceivers2", Allowed = true }; await _pushNotificationsService.InsertPushReceiver(receiver1); await _pushNotificationsService.InsertPushReceiver(receiver2); var found = await _pushNotificationsService.GetPushReceivers(); Assert.AreEqual(2, found.Count); Assert.AreEqual(true, found.Any(x => x.Token == "CanGetReceivers1")); Assert.AreEqual(true, found.Any(x => x.Token == "CanGetReceivers2")); }
public void CanGetPushReceiverByCustomerId() { ClearPushRegistrations(); var receiver1 = new PushRegistration { CustomerId = "CanGetPushReceiverByCustomerId1", Token = "CanGetPushReceiverByCustomerIdToken1" }; var receiver2 = new PushRegistration { CustomerId = "CanGetPushReceiverByCustomerId2", Token = "CanGetPushReceiverByCustomerIdToken2" }; _pushNotificationsService.InsertPushReceiver(receiver1); _pushNotificationsService.InsertPushReceiver(receiver2); var found = _pushNotificationsService.GetPushReceiverByCustomerId("CanGetPushReceiverByCustomerId1"); Assert.AreEqual("CanGetPushReceiverByCustomerIdToken1", found.Token); }
public async Task <string> Upsert(PushRegistration deviceUpdate) { RegistrationDescription desc = null; switch (deviceUpdate.Platform) { case Platform.Windows: desc = new WindowsRegistrationDescription(deviceUpdate.DeviceToken); break; case Platform.iOS: desc = new AppleRegistrationDescription(deviceUpdate.DeviceToken); break; case Platform.Android: desc = new GcmRegistrationDescription(deviceUpdate.DeviceToken); break; default: throw new ArgumentException("Wrong PushChannel"); } string registrationId = deviceUpdate.RegistrationId; if (string.IsNullOrEmpty(registrationId)) { registrationId = await _hub.CreateRegistrationIdAsync(); } desc.RegistrationId = registrationId; desc.Tags = new HashSet <string>(deviceUpdate.Tags); var registration = await _hub.CreateOrUpdateRegistrationAsync(desc); return(registrationId); }
/// <summary> /// Deletes push receiver /// </summary> /// <param name="model"></param> public virtual async Task DeletePushReceiver(PushRegistration registration) { await _pushRegistratiosnRepository.DeleteAsync(registration); await _eventPublisher.EntityDeleted(registration); }
private void Registration_Click(object sender, RoutedEventArgs e) { PushRegistration?.Invoke(); }
/// <summary> /// Updates push receiver /// </summary> /// <param name="registration"></param> public virtual void UpdatePushReceiver(PushRegistration registration) { _pushRegistratiosnRepository.Update(registration); _eventPublisher.EntityUpdated(registration); }
/// <summary> /// Inserts push receiver /// </summary> /// <param name="model"></param> public virtual void InsertPushReceiver(PushRegistration registration) { _pushRegistratiosnRepository.Insert(registration); _eventPublisher.EntityInserted(registration); }
public bool Update(PushRegistration pushDB) { var result = DBSet.Update(pushDB); return(_context.SaveChanges() > 0); }
public bool AddPushReg(PushRegistration pushReg) { var result = DBSet.Add(pushReg); return(_context.SaveChanges() > 0); }
/// <summary> /// Updates push receiver /// </summary> /// <param name="registration"></param> public virtual async Task UpdatePushReceiver(PushRegistration registration) { await _pushRegistratiosnRepository.UpdateAsync(registration); await _mediator.EntityUpdated(registration); }
/// <summary> /// Inserts push receiver /// </summary> /// <param name="model"></param> public virtual async Task InsertPushReceiver(PushRegistration registration) { await _pushRegistratiosnRepository.InsertAsync(registration); await _mediator.EntityInserted(registration); }