private async Task <bool> UserDeviceDeleteInternal(ExPostUserDeviceDelete userDeviceData) { Logging.Log.LogInfo($"UserDeviceDelete {userDeviceData.DeviceToken}"); using (var db = new Db()) { var data = db.TblUserDevices.Where(d => d.Device.DeviceToken == userDeviceData.DeviceToken); db.TblUserDevices.RemoveRange(data); try { var service = new MobileCenterNotification(Constants.MobileCenterNotification); if (data.Any()) { await service.RemoveDevice(data.First().Device.DeviceToken, data.First().Device.Plattform); } db.SaveChanges(); } catch (Exception e) { Logging.Log.LogWarning($"UserDeviceDelete SaveChanges: {e}"); return(false); } return(true); } }
/// <summary> /// Send Notification with an array of Devices /// </summary> /// <param name="title"></param> /// <param name="message"></param> /// <param name="devices"></param> /// <param name="payload"></param> /// <returns></returns> async public Task <bool> SendNotification(string title, string message, string[] devices = null, Dictionary <string, string> payload = null) { var notification = new MobileCenterNotification(); if (devices == null) { notification.Target = null; } else { notification.Target.Type = TargetType.Device; notification.Target.Devices = devices; } notification.Content.Title = title ?? ""; notification.Content.Body = message ?? ""; notification.Content.CustomData = payload; notification.Content.Name = devices == null ? $"Push to All devices - {title}" : devices.First(); foreach (var baseUrl in _platforms) { var url = $"{baseUrl}/push/notifications/"; var result = await Client.PostAsync <JObject>(url, notification); } return(true); }
async Task ExecuteSendPushNotificationCommand(string tag) { var id = await MobileCenter.GetInstallIdAsync(); var content = new NotificationContent(); var target = new NotificationTarget(); content.Body = "This is a test!"; content.Title = "push sent from mobile device"; target.Devices = new string[] { id.ToString() }; //if (!string.IsNullOrEmpty(tag)) //target.Audiences = new List<string>() { tag }; var push = new MobileCenterNotification(); push.Content = content; push.Target = target; push.Content.CustomData = new Dictionary <string, string>() { { "hello", "mahdi" } }; var httpclient = new HttpClient(); var jsonin = JsonConvert.SerializeObject(push); var res = await httpclient.PostAsync <string>("http://mobilecenterpush.azurewebsites.net/api/sendpush", push); }
public async Task <ExSaveDataResult> ClearUserDevices() { using (var db = new Db()) { var data = await db.TblUserDevices.ToListAsync(); db.TblUserDevices.RemoveRange(data); try { var service = new MobileCenterNotification(Constants.MobileCenterNotification); if (data.Any()) { foreach (var userDevice in data) { await service.RemoveDevice(userDevice.Device.DeviceToken, userDevice.Device.Plattform); } } db.SaveChanges(); } catch (Exception e) { Logging.Log.LogWarning($"UserDeviceDelete SaveChanges: {e}"); return(ExSaveDataResult.GetDefaultSaveError()); } return(ExSaveDataResult.GetDefaultSuccess()); } }
public async Task <ExSaveDataResult> NotificationTestAudience() { Logging.Log.LogInfo("NotificationTestAudience"); var service = new MobileCenterNotification(Constants.MobileCenterNotification); Task.Run(async() => await service.GetAudience(EnumPlattform.XamarinAndroid, "Testgruppe")); return(ExSaveDataResult.GetDefaultSuccess()); }
public bool NotificationSendBroadcast([FromBody] ExPostNotofication data) { Logging.Log.LogInfo($"NotificationSendBroadcast/{data.CampaignName}/{data.Body}/{data.Title}"); var service = new MobileCenterNotification(Constants.MobileCenterNotification); Task.Run(async() => await service.SendBroadcast(data.CampaignName, data.Body, data.Title, data.Data)); return(true); }
public async Task <ExSaveDataResult> NotificationSendToDevice([FromBody] ExPushNotificationData data) { using (Db db = new Db()) { var userDev = await db.TblUserDevices.FirstOrDefaultAsync(a => a.Id == data.DeviceId); if (userDev != null) { var service = new MobileCenterNotification(Constants.MobileCenterNotification); await service.Send("", data.Body, userDev.Device.Plattform, data.Title, null, new List <string> { userDev.Device.DeviceToken }); return(new ExSaveDataResult()); } return(new ExSaveDataResult()); } }