public override Task <bool> SendNotificationAsync(PushNotificationItem notificationItem, object message, CancellationToken ct) { SmtpDeliveryProviderConfiguration cfg = (SmtpDeliveryProviderConfiguration)Configuration; bool sent = false; if (message is SerializableMailMessage smsg) { try { SmtpClient client = new SmtpClient() { Host = cfg.SmtpServer, Port = cfg.SmtpPort ?? 25, EnableSsl = cfg.EnableSsl ?? false }; if (!string.IsNullOrEmpty(cfg.SmtpUserName)) { client.Credentials = new NetworkCredential(cfg.SmtpUserName, cfg.SmtpPassword); } smsg.To.Add(new MailAddress(notificationItem.Destination.DestinationAddress, notificationItem.Destination.SubscriberName)); smsg.From = new MailAddress(cfg.SmtpFromAddress, cfg.SmtpFromDisplayName); client.Send(smsg); sent = true; } catch (Exception ex) { sent = false; //TODO: log this somewhere throw new Exception("", ex); } } return(Task.FromResult(sent)); }
public override async Task <bool> SendNotificationAsync(PushNotificationItem notificationItem, object message, CancellationToken ct) { var cfg = (SendGridDeliveryProviderConfiguration)Configuration; var sent = false; //implicit conversion operator MailMessage smsg = message as SerializableMailMessage; if (smsg != null) { try { var hView = smsg.AlternateViews.First(v => v.ContentType.MediaType == "text/html"); var tView = smsg.AlternateViews.First(v => v.ContentType.MediaType == "text/plain"); var sendGridMessage = new SendGridMessage { To = new[] { new MailAddress(notificationItem.Destination.DestinationAddress, notificationItem.Destination.SubscriberName) }, From = new MailAddress(cfg.FromAddress, cfg.FromDisplayName), Subject = smsg.Subject, Html = hView.ContentStream.ReadToString(), Text = tView.ContentStream.ReadToString() }; if (cfg.EnableClickTracking ?? false) { sendGridMessage.EnableClickTracking(); } if (cfg.EnableGravatar ?? false) { sendGridMessage.EnableGravatar(); } if (cfg.EnableOpenTracking ?? false) { sendGridMessage.EnableOpenTracking(); } if (cfg.SendToSink ?? false) { sendGridMessage.SendToSink(); } var transport = new Web(cfg.ApiKey); await transport.DeliverAsync(sendGridMessage); sent = true; } catch { sent = false; //TODO: log this somewhere } } return(sent); }
public override Task <object> GenerateMessageAsync(PushNotificationItem notificationItem, CancellationToken ct) { var memorydata = Convert.FromBase64String(notificationItem.MessageContent); using (var rs = new MemoryStream(memorydata)) { var sf = new BinaryFormatter(); return(Task.FromResult(sf.Deserialize(rs))); } }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { // Override point for customization after application launch. // If not required for your application you can safely delete this method Xamarin.IQKeyboardManager.SharedManager.ShouldResignOnTouchOutside = true; Xamarin.IQKeyboardManager.SharedManager.EnableAutoToolbar = true; ImageService.Instance.Config.SchedulerMaxParallelTasks = 6; var manager = BITHockeyManager.SharedHockeyManager; manager.Configure("8a31b849e71547c7b6137a87d58fdb09"); manager.StartManager(); Settings.AppID = ConstantsHelper.FB_ApplicationID; //"469763806538563"; Settings.DisplayName = ConstantsHelper.AppName; //"Fanword"; MixpanelTweaks.Register(typeof(AppTweaks)); Mixpanel.SharedInstanceWithToken(MIXPANEL_TOKEN); Mixpanel.SharedInstance.Track("Launch"); CrossPushNotifications.Current.Configure(ServiceApiBase.HubName, ServiceApiBase.AzureConnectionString, new[] { "fanword" }, 0); CrossPushNotifications.Current.PushNotificationClicked += (sender, e) => { if (UIApplication.SharedApplication.ApplicationState == UIApplicationState.Inactive && MainViewController.Instance?.NavigationController != null) { // clicked on notification from background var notification = (e as PushNotificationItem); Navigator.HandleNotificationTap(MainViewController.Instance.NavigationController, notification.MetaData, notification.Title, notification.Message); } else if (UIApplication.SharedApplication.ApplicationState == UIApplicationState.Active) { // Update badge MainViewController.Instance?.GetNotifications(); } else { // app closed ClickedNotification = (e as PushNotificationItem); } }; return(true); }
public async Task SendNotification(PushNotificationItem notification) { var users = dbService.GetUsers(); foreach (var token in users) { using (var fcm = new FireBaseSenderCore(_serverKey, token.UserId.ToString())) { await fcm.SendAsync(token.Token, new { notification = new { title = notification.Title, body = notification.Body }, }); } } }
public async Task SendReadyMessageAsync(PushNotificationItem notificationItem, int retryMax, int retryIntv, CancellationToken ct) { //do the meat var message = await GenerateMessageAsync(notificationItem, ct); var result = await SendNotificationAsync(notificationItem, message, ct); //if we're in a retry case, increment retry count if (notificationItem.DeliveryStatus == PushNotificationItemStatus.Retrying) { notificationItem.RetryCount++; } if (result) { //if sent, mark sent and remove schedule notificationItem.DeliveryStatus = PushNotificationItemStatus.Sent; notificationItem.ScheduledSendDate = null; } else { if (notificationItem.RetryCount <= retryMax) { //mark for retry, update schedule notificationItem.DeliveryStatus = PushNotificationItemStatus.Retrying; if (notificationItem.ScheduledSendDate != null) { notificationItem.ScheduledSendDate = notificationItem.ScheduledSendDate.Value.AddMinutes(retryIntv ^ notificationItem.RetryCount); } } else { //too many retry attempts, mark fail and clear schedule notificationItem.DeliveryStatus = PushNotificationItemStatus.Failed; notificationItem.ScheduledSendDate = null; } } }
public async Task Send(PushNotificationItem pushNotificationItem) { await pushNotificationService.SendNotification(pushNotificationItem); }
private static async Task SendNotificationMessageAsync(TdPushNotificationContext context, PushNotificationItem readyNote, CancellationToken ct) { var retryMax = context.TicketDeskPushNotificationSettings.RetryAttempts; var retryIntv = context.TicketDeskPushNotificationSettings.RetryIntervalMinutes; //find a provider for the notification destination type var provider = DeliveryProviders.FirstOrDefault(p => p.DestinationType == readyNote.Destination.DestinationType); if (provider == null) { //no provider readyNote.DeliveryStatus = PushNotificationItemStatus.NotAvailable; readyNote.ScheduledSendDate = null; } else { await provider.SendReadyMessageAsync(readyNote, retryMax, retryIntv, ct); } }
public abstract Task <bool> SendNotificationAsync(PushNotificationItem notificationItem, object message, CancellationToken ct);
public abstract Task <object> GenerateMessageAsync(PushNotificationItem notificationItem, CancellationToken ct);
public override async Task <bool> SendNotificationAsync(PushNotificationItem notificationItem, object message, CancellationToken ct) { var cfg = (SendGridDeliveryProviderConfiguration)Configuration; var sent = false; //implicit conversion operator MailMessage smsg = message as SerializableMailMessage; if (smsg != null) { try { var hView = smsg.AlternateViews.First(v => v.ContentType.MediaType == "text/html"); var tView = smsg.AlternateViews.First(v => v.ContentType.MediaType == "text/plain"); var sendGridMessage = new SendGridMessage { From = new EmailAddress(cfg.FromAddress, cfg.FromDisplayName), Subject = smsg.Subject, Contents = new List <Content>() { new Content("text/html", hView.ContentStream.ReadToString()), //new Content("text", tView.ContentStream.ReadToString()) }, Personalizations = new List <Personalization>() { new Personalization { Tos = new List <EmailAddress>() { new EmailAddress(notificationItem.Destination.DestinationAddress, notificationItem.Destination.SubscriberName) } } }, }; sendGridMessage.TrackingSettings = new TrackingSettings() { ClickTracking = new ClickTracking() }; if (cfg.EnableClickTracking ?? false) { sendGridMessage.TrackingSettings.ClickTracking.Enable = true;; } if (cfg.EnableGravatar ?? false) { //sendGridMessage.MailSettings.EnableGravatar(); } if (cfg.EnableOpenTracking ?? false) { sendGridMessage.TrackingSettings.OpenTracking.Enable = true;; } if (cfg.SendToSink ?? false) { //sendGridMessage.SendToSink(); } //var transport = new Web(cfg.ApiKey); //await transport.DeliverAsync(sendGridMessage); //sent = true; var sg = new SendGridClient(cfg.ApiKey); var response = await sg.SendEmailAsync(sendGridMessage); sent = true; } catch { sent = false; //TODO: log this somewhere } } return(sent); }