private IEnumerable <string> GetUserIds(NotificationRequest request, NotificationOption options) { if (request.SendToUserMode.HasValue) { switch (request.SendToUserMode.Value) { case SendToUserType.Admins: return(_userManager.Users.Where(i => i.Policy.IsAdministrator) .Select(i => i.Id.ToString("N"))); case SendToUserType.All: return(_userManager.Users.Select(i => i.Id.ToString("N"))); case SendToUserType.Custom: return(request.UserIds); default: throw new ArgumentException("Unrecognized SendToUserMode: " + request.SendToUserMode.Value); } } if (options != null && !string.IsNullOrWhiteSpace(request.NotificationType)) { var config = GetConfiguration(); return(_userManager.Users .Where(i => config.IsEnabledToSendToUser(request.NotificationType, i.Id.ToString("N"), i.Configuration)) .Select(i => i.Id.ToString("N"))); } return(request.UserIds); }
public static string ToEditorConfigString(this NotificationOption notificationOption) { if (notificationOption == NotificationOption.Silent) { return(nameof(NotificationOption.Silent).ToLowerInvariant()); } else { return(notificationOption.ToString().ToLowerInvariant()); } }
private static Notification GetNotification(Context ctx, int sessionId, NotificationOption not) { WorkshopDetail session = null; if (not.isWorkshop) { session = Services.Workshop.GetWorkshopFromBookingLocal(sessionId); } else { session = Services.Session.GetSession(sessionId); } var prefix = (not.isWorkshop) ? "" : "Session with "; Notification.Builder mBuilder = new Notification.Builder(ctx) .SetSmallIcon(Resource.Drawable.notificationIcon) .SetContentTitle(prefix + session.Title) .SetContentText(session.Time + " - " + session.DateHumanFriendly) .SetAutoCancel(true) .SetColor(ctx.Resources.GetColor(Resource.Color.primary)) .SetDefaults(NotificationDefaults.All) .SetStyle( new Notification.BigTextStyle().SetSummaryText(session.Title) .BigText(session.Time + " - " + session.DateHumanFriendly + System.Environment.NewLine + session.Room)); try { Looper.Prepare(); } catch (System.Exception ex) { } Intent resultIntent = new Intent(ctx, new ViewSessionActivity().Class); if (not.isWorkshop) { resultIntent = new Intent(ctx, new ViewWorkshopActivity().Class); } resultIntent.PutExtra("Id", sessionId); resultIntent.PutExtra("IsBooking", true); TaskStackBuilder stackBuilder = TaskStackBuilder.Create(ctx); stackBuilder.AddParentStack(new ViewWorkshopActivity().Class); stackBuilder.AddNextIntent(resultIntent); int identifier = (not.isWorkshop) ? 1 : 0; int notificationId = Integer.ParseInt(identifier + sessionId.ToString() + not.mins); PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(notificationId, PendingIntentFlags.UpdateCurrent); mBuilder.SetContentIntent(resultPendingIntent); return(mBuilder.Build()); }
private string GetDescription(NotificationRequest request, NotificationOption options) { var text = request.Description; // If empty, grab from options if (string.IsNullOrEmpty(text)) { if (!string.IsNullOrEmpty(request.NotificationType)) { if (options != null) { text = options.Description; } } } // If still empty, grab default if (string.IsNullOrEmpty(text)) { if (!string.IsNullOrEmpty(request.NotificationType)) { var info = GetNotificationTypes().FirstOrDefault(i => string.Equals(i.Type, request.NotificationType, StringComparison.OrdinalIgnoreCase)); if (info != null) { text = info.DefaultDescription; } } } text = text ?? string.Empty; foreach (var pair in request.Variables) { var token = "{" + pair.Key + "}"; text = text.Replace(token, pair.Value, StringComparison.OrdinalIgnoreCase); } return(text); }
/// <summary> /// Generates the final Toast options /// </summary> /// <returns>Notification options that are used to load the toast notifications</returns> public NotificationOption GenerateToastOption() { var notificationOption = new NotificationOption(); if (Status == NotificationStatus.Success) { notificationOption.ToastTitle = "Success!"; if (NotificationItem.GetType() == typeof(Product)) { notificationOption.ToastContent = $"Successfully added {(NotificationItem as Product).Title} to the Database"; } if (NotificationItem.GetType() == typeof(Customer)) { notificationOption.ToastContent = $"Successfully added {(NotificationItem as Customer).FirstName} to the Database"; } notificationOption.ToastCSS = "e-toast-success"; return(notificationOption); } if (Status == NotificationStatus.Failed) { notificationOption.ToastTitle = "Error!"; if (NotificationItem.GetType() == typeof(Product)) { notificationOption.ToastContent = $"There was an error adding {(NotificationItem as Product).Title} to the Database"; } if (NotificationItem.GetType() == typeof(Customer)) { notificationOption.ToastContent = $"There was an error adding {(NotificationItem as Customer).FirstName} to the Database"; } notificationOption.ToastCSS = "e-toast-error"; return(notificationOption); } // TODO :: Write code to inform there was an error with the notification return(notificationOption); }
private IDictionary <OptionKey, object> QualifyMethodAccessWithNotification(NotificationOption notification) => new Dictionary <OptionKey, object>() { { new OptionKey(CodeStyleOptions.QualifyMethodAccess, LanguageNames.CSharp), new CodeStyleOption <bool>(true, notification) } };
public static string ToEditorConfigString(this NotificationOption notificationOption) => notificationOption.Severity.ToEditorConfigString();
public void Add <T>(PerLanguageOption <CodeStyleOption <T> > option, T value, NotificationOption notification) => _options.Add(new OptionKey(option, _languageName), new CodeStyleOption <T>(value, notification));
public void Add <T>(Option <CodeStyleOption <T> > option, T value, NotificationOption notification) => _options.Add(new OptionKey(option), new CodeStyleOption <T>(value, notification));
private static PendingIntent GetPendingIntent(Context ctx, Notification notification, NotificationOption not, int sessionId) { // Creates an explicit intent for an Activity in your app Intent notificationIntent = new Intent(ctx, typeof(NotificationPublisher)); int identifier = (not.isWorkshop) ? 1 : 0; int notificationId = Integer.ParseInt(identifier + sessionId.ToString() + not.mins); notificationIntent.PutExtra(NotificationPublisher.NOTIFICATION_ID, notificationId); notificationIntent.PutExtra(NotificationPublisher.NOTIFICATION, notification); return(PendingIntent.GetBroadcast(ctx, notificationId, notificationIntent, PendingIntentFlags.UpdateCurrent)); }
private static void CreateAlarmManager(Context ctx, Notification notification, DateTime date, NotificationOption not, int sessionId) { DateTime dtBasis = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); AlarmManager alarmManager = (AlarmManager)ctx.GetSystemService(Context.AlarmService); alarmManager.Set(AlarmType.RtcWakeup, (long)date.ToUniversalTime().Subtract(dtBasis).TotalMilliseconds, GetPendingIntent(ctx, notification, not, sessionId)); }
private Task TestMissingAsyncWithOptionAndNotificationOption(string code, PerLanguageOption <CodeStyleOption <bool> > option, NotificationOption notification) { return(TestMissingAsync(code, options: Option(option, true, notification))); }
protected IDictionary <OptionKey, object> Option(IOption option, bool value, NotificationOption notification) => OptionsSet(Tuple.Create(option, value, notification));
public NotificationOptionViewModel(NotificationOption notification, ImageMoniker moniker) { Notification = notification; Name = notification.Name; Moniker = moniker; }
public static void Show(NotificationOption notification) { Execute.ToUiThread(() => { App.NotificationList?.Add(notification); }); }