/// <summary> /// Searches for a posted notification which has the specified tag and has not been deleted yet. /// </summary> /// <remarks> /// Load method should be called only for notifications, which have been posted using the NotificationManager.Post method. /// If two or more notifications share the same tag, the notification posted most recently is returned. /// </remarks> /// <param name="tag">Tag used to query.</param> /// <returns>Notification Object with specified tag.</returns> /// <exception cref="ArgumentException">Throwing the same exception when argument is invalid and when the tag does not exist is misleading.</exception> /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception> /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception> /// <example> /// <code> /// Notification notification = new Notification /// { /// Title = "title", /// Content = "content", /// Icon = "absolute icon path", /// Tag = "first notification" /// }; /// NotificationManager.Post(notification); /// /// // do someting /// /// Notification loadNotification = NotificationManager.Load("first notification"); /// </code> /// </example> /// <privilege>http://tizen.org/privilege/notification</privilege> /// <since_tizen> 3 </since_tizen> public static Notification Load(string tag) { IntPtr ptr = IntPtr.Zero; if (string.IsNullOrEmpty(tag)) { throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid parameter entered"); } ptr = Interop.Notification.Load(tag); if (ptr == IntPtr.Zero) { NotificationError ret = (NotificationError)Tizen.Internals.Errors.ErrorFacts.GetLastResult(); Log.Error(Notification.LogTag, "unable to load Notification : " + ret.ToString()); if (ret == NotificationError.DbError) { throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "the tag does not exist"); } else { throw NotificationErrorFactory.GetException(ret, "unable to load Notification"); } } Notification notification = new Notification { Handle = new NotificationSafeHandle(ptr, true) }.Build(); return(notification); }
public ErrorList AddError(string name, string notification) { NotificationError error = NotificationError.Create(name.EmptyStringIfNull(), notification); notificationsError.Add(error); return(this); }
/// <summary> /// Loads a notification template from the notification database. /// </summary> /// <param name="name">Template name.</param> /// <returns>Notification Object with inputted template name.</returns> /// <exception cref="ArgumentException">Throwing the same exception when argument is invalid and when the template does not exist is misleading.</exception> /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception> /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception> /// <example> /// <code> /// Notification notification = new Notification /// { /// Title = "title", /// Content = "content", /// Icon = "absolute icon path", /// Tag = "first notification" /// }; /// /// Notification.Accessory accessory = new Notification.Accessory /// { /// LedOption = AccessoryOption.On, /// VibrationOption = AccessoryOption.Custom, /// VibrationPath = "vibration absolute path" /// } /// notification.setAccessory(accessory); /// /// // do something /// /// NotificationManager.Post(notification); /// /// Notification.LockStyle style = new Notification.LockStyle /// { /// IconPath = "icon path", /// ThumbnailPath = "Thumbnail path" /// } /// notification.AddStyle(style); /// NotificationManager.SaveTemplate(notification, "firstTemplate"); /// Notification notificationTemplate = NotificationManager.LoadTemplate("firstTemplate"); /// </code> /// </example> /// <privilege>http://tizen.org/privilege/notification</privilege> /// <since_tizen> 3 </since_tizen> public static Notification LoadTemplate(string name) { IntPtr handle = IntPtr.Zero; if (string.IsNullOrEmpty(name)) { throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to load template"); } handle = Interop.Notification.LoadTemplate(name); if (handle == IntPtr.Zero) { NotificationError ret = (NotificationError)Tizen.Internals.Errors.ErrorFacts.GetLastResult(); if (ret == NotificationError.DbError) { throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "the name does not exist"); } else { throw NotificationErrorFactory.GetException(ret, "unable to create Notification from template"); } } Notification notification = new Notification { Handle = new NotificationSafeHandle(handle, true) }.Build(); return(notification); }
/// <summary> /// Posts a new notification. /// </summary> /// <param name="notification">Notification to post.</param> /// <exception cref="ArgumentException">Thrown when an argument is invalid.</exception> /// <exception cref="UnauthorizedAccessException">Thrown in case of a permission is denied.</exception> /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception> /// <example> /// <code> /// Notification notification = new Notification /// { /// Title = "title", /// Content = "content", /// Icon = "absolute icon path", /// Tag = "first notification" /// }; /// /// Notification.AccessorySet accessory = new Notification.AccessorySet /// { /// SoundOption = AccessoryOption.On, /// CanVibrate = true /// }; /// notification.Accessory = accessory; /// /// // do something /// /// NotificationManager.Post(notification); /// </code> /// </example> /// <privilege>http://tizen.org/privilege/notification</privilege> /// <since_tizen> 3 </since_tizen> public static void Post(Notification notification) { if (notification == null) { throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to post method"); } notification.Make(); if (ResponseEventHandler != null && ResponseEventHandler.GetInvocationList().Length > 0) { NotificationError ret = Interop.Notification.PostWithEventCallback(notification.Handle, responseEventCallback, IntPtr.Zero); if (ret != NotificationError.None) { throw NotificationErrorFactory.GetException(ret, "post notification with event callback failed"); } } else { NotificationError ret = Interop.Notification.Post(notification.Handle); if (ret != NotificationError.None) { throw NotificationErrorFactory.GetException(ret, "post notification failed"); } } int priv_id, group_id; Interop.Notification.GetID(notification.Handle, out group_id, out priv_id); notification.PrivID = priv_id; }
private static void BindLedToHandle(Notification notification) { NotificationError ret = NotificationError.None; Notification.AccessorySet accessory = notification.Accessory; ret = Interop.Notification.SetLed(notification.Handle, accessory.LedOption, 0); if (ret != NotificationError.None) { throw NotificationErrorFactory.GetException(ret, "unable to set led"); } ret = Interop.Notification.SetLedTimePeriod(notification.Handle, accessory.LedOnMillisecond, accessory.LedOffMillisecond); if (ret != NotificationError.None) { throw NotificationErrorFactory.GetException(ret, "unable to set led period"); } if (notification.Accessory.LedOption == AccessoryOption.Custom) { Color color = accessory.LedColor; ret = Interop.Notification.SetLed(notification.Handle, AccessoryOption.Custom, color.GetArgb()); if (ret != NotificationError.None) { throw NotificationErrorFactory.GetException(ret, "unable to set led color"); } } }
internal static void BindObject(Notification notification) { int flag; NotificationError ret = NotificationError.None; Notification.IndicatorStyle style = (Notification.IndicatorStyle)notification.GetStyle("Indicator"); Interop.Notification.GetApplist(notification.Handle, out flag); if (string.IsNullOrEmpty(style.SubText) == false) { ret = Interop.Notification.SetText(notification.Handle, NotificationText.FirstMainText, style.SubText, null, -1); if (ret != NotificationError.None) { throw NotificationErrorFactory.GetException(ret, "unable to set indicator text"); } flag |= (int)NotificationDisplayApplist.Ticker; } if (string.IsNullOrEmpty(style.IconPath) == false) { ret = Interop.Notification.SetImage(notification.Handle, NotificationImage.IconForIndicator, style.IconPath); if (ret != NotificationError.None) { throw NotificationErrorFactory.GetException(ret, "unable to set indicator image"); } flag |= (int)NotificationDisplayApplist.Indicator; } Interop.Notification.SetApplist(notification.Handle, flag); }
private void NotificationLoop(object input) { try { while (true) { try { var message = ReceiveEvent(); Active = true; if (!string.IsNullOrWhiteSpace(message)) { OnValueChanged(message); } } catch (Exception ex) { NotificationError?.Invoke(this, ex); } } } catch { // ignored } finally { Active = false; OnNotificationProcessStopped(); } }
/// <summary> /// Deletes a posted notification. /// </summary> /// <param name="notification">Notification to remove.</param> /// <exception cref="ArgumentException">Thrown when an argument is invalid.</exception> /// <exception cref="UnauthorizedAccessException">Thrown in case of a permission is denied.</exception> /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception> /// <example> /// <code> /// Notification notification = new Notification /// { /// Title = "title", /// Content = "content", /// Icon = "absolute icon path", /// Tag = "first notification" /// }; /// NotificationManager.Post(notification); /// /// // do something /// /// NotificationManager.Delete(notification); /// </code> /// </example> /// <privilege>http://tizen.org/privilege/notification</privilege> /// <pre> /// Post method should be called on the notification object. /// </pre> /// <since_tizen> 3 </since_tizen> public static void Delete(Notification notification) { if (notification == null || notification.Handle == null || notification.Handle.IsInvalid) { throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to post method"); } NotificationError ret = Interop.Notification.Delete(notification.Handle); if (ret != NotificationError.None) { throw NotificationErrorFactory.GetException(ret, "delete notification failed"); } }
private static void BindSoundToHandle(Notification notification) { Notification.AccessorySet accessory = notification.Accessory; if (accessory.SoundOption == AccessoryOption.Custom && string.IsNullOrEmpty(accessory.SoundPath)) { throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "If the option is set to Custom, the path must also be set."); } NotificationError ret = Interop.Notification.SetSound(notification.Handle, accessory.SoundOption, accessory.SoundPath); if (ret != NotificationError.None) { throw NotificationErrorFactory.GetException(ret, "unable to set sound"); } }
/// <summary> /// Saves a notification template to the notification database. /// </summary> /// <param name="notification">Notification to save as template.</param> /// <param name="name">Template name.</param> /// <exception cref="ArgumentException">Thrown when an argument is invalid.</exception> /// <exception cref="UnauthorizedAccessException">Thrown in case of a permission is denied.</exception> /// <exception cref="InvalidOperationException">Thrown when it can't be saved as a template.</exception> /// <example> /// <code> /// Notification notification = new Notification /// { /// Title = "title", /// Content = "content", /// Icon = "absolute icon path", /// Tag = "first notification" /// }; /// /// Notification.Accessory accessory = new Notification.Accessory /// { /// LedOption = AccessoryOption.On, /// VibrationOption = AccessoryOption.Custom, /// VibrationPath = "vibration absolute path" /// } /// notification.setAccessory(accessory); /// /// // do something /// /// NotificationManager.Post(notification); /// /// Notification.LockStyle style = new Notification.LockStyle /// { /// IconPath = "icon path", /// ThumbnailPath = "Thumbnail path" /// } /// notification.AddStyle(style); /// NotificationManager.SaveTemplate(notification, "firstTemplate"); /// </code> /// </example> /// <privilege>http://tizen.org/privilege/notification</privilege> /// <since_tizen> 3 </since_tizen> public static void SaveTemplate(Notification notification, string name) { if (notification == null || string.IsNullOrEmpty(name)) { throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to save template"); } notification.Make(); NotificationError ret = Interop.Notification.SaveTemplate(notification.Handle, name); if (ret != NotificationError.None) { throw NotificationErrorFactory.GetException(ret, "save as template failed"); } }
internal static Exception GetException(NotificationError ret, string msg, [CallerMemberName] string memberName = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0) { Log.Error(Notification.LogTag, memberName + " : " + lineNumber); switch (ret) { case NotificationError.InvalidParameter: Log.Error(Notification.LogTag, msg); return(new ArgumentException(ret + " error occurred.")); case NotificationError.PermissionDenied: throw new UnauthorizedAccessException("Permission denied (http://tizen.org/privilege/notification)"); default: Log.Error(Notification.LogTag, msg); return(new InvalidOperationException(ret + " error occurred.")); } }
public async Task <IActionResult> send([FromBody] EmailMetaData emd) { NotificationError e = new NotificationError(); Utility utility = new Utility(); bool isSent = false; //validate request if (!ModelState.IsValid) { var modelErrors = new List <NotificationError>(); var eD = new List <string>(); foreach (var modelState in ModelState.Values) { foreach (var modelError in modelState.Errors) { eD.Add(modelError.ErrorMessage); } } e.error = ((int)HttpStatusCode.BadRequest).ToString(); e.errorDetails = eD; return(BadRequest(e)); } try { emd.fromaddress = settings.Value.emailFromAddress; Smtp smtp = new Smtp() { enablessl = settings.Value.emailEnableSSL, host = settings.Value.emailHost, port = settings.Value.emailPort }; emd.protocol = smtp; isSent = await utility.SendMail(emd); } catch (Exception ex) { Console.Write(ex.ToString()); } return(CreatedAtAction("send", isSent)); }
private static void ResponseEventCallback(IntPtr ptr, int type, IntPtr userData) { IntPtr cloned; NotificationError ret = Interop.Notification.Clone(ptr, out cloned); if (ret != NotificationError.None) { Log.Error(Notification.LogTag, "Fail to clone notification : " + ret.ToString()); return; } NotificationResponseEventArgs eventArgs = new NotificationResponseEventArgs(); eventArgs.EventType = (NotificationResponseEventType)type; eventArgs.Notification = new Notification { Handle = new NotificationSafeHandle(cloned, true) }.Build(); ResponseEventHandler?.Invoke(null, eventArgs); }
/// <summary> /// Posts a new notification. /// </summary> /// <param name="notification">Notification to post.</param> /// <exception cref="ArgumentException">Thrown when an argument is invalid.</exception> /// <exception cref="UnauthorizedAccessException">Thrown in case of a permission is denied.</exception> /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception> /// <example> /// <code> /// Notification notification = new Notification /// { /// Title = "title", /// Content = "content", /// Icon = "absolute icon path", /// Tag = "first notification" /// }; /// /// Notification.AccessorySet accessory = new Notification.AccessorySet /// { /// SoundOption = AccessoryOption.On, /// CanVibrate = true /// }; /// notification.Accessory = accessory; /// /// // do something /// /// NotificationManager.Post(notification); /// </code> /// </example> /// <privilege>http://tizen.org/privilege/notification</privilege> /// <since_tizen> 3 </since_tizen> public static void Post(Notification notification) { if (notification == null) { throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to post method"); } notification.Make(); NotificationError ret = Interop.Notification.Post(notification.Handle); if (ret != NotificationError.None) { throw NotificationErrorFactory.GetException(ret, "post notification failed"); } int priv_id, group_id; Interop.Notification.GetID(notification.Handle, out group_id, out priv_id); notification.PrivID = priv_id; }
internal static void BindObject(Notification notification) { int flag; NotificationError ret = NotificationError.None; Notification.LockStyle style = (Notification.LockStyle)notification.GetStyle("Lock"); ret = Interop.Notification.SetImage(notification.Handle, NotificationImage.IconForLock, style.IconPath); if (ret != NotificationError.None) { throw NotificationErrorFactory.GetException(ret, "unable to set lock icon"); } ret = Interop.Notification.SetImage(notification.Handle, NotificationImage.ThumbnailForLock, style.ThumbnailPath); if (ret != NotificationError.None) { throw NotificationErrorFactory.GetException(ret, "unable to set lock thumbnail"); } Interop.Notification.GetApplist(notification.Handle, out flag); Interop.Notification.SetApplist(notification.Handle, flag | (int)NotificationDisplayApplist.Lock); }
internal static void BindObject(Notification notification) { int flag; int hidetime = 0; int deletetime = 0; NotificationError ret = NotificationError.None; Notification.ActiveStyle style = (Notification.ActiveStyle)notification.GetStyle("Active"); Interop.Notification.SetAutoRemove(notification.Handle, style.IsAutoRemove); style.GetRemoveTime(out hidetime, out deletetime); if (hidetime > 0) { Interop.Notification.SetHideTime(notification.Handle, hidetime); } if (deletetime > 0) { try { Interop.Notification.SetDeleteTime(notification.Handle, deletetime); } catch (TypeLoadException) { // To support in API version 3.0 style.SetRemoveTime(hidetime, 60); } } ret = Interop.Notification.SetImage(notification.Handle, NotificationImage.Background, style.BackgroundImage); if (ret != NotificationError.None) { throw NotificationErrorFactory.GetException(ret, "unable to set background Image"); } if (style.DefaultButton != ButtonIndex.None) { Interop.Notification.SetDefaultButton(notification.Handle, (int)style.DefaultButton + 1); } Interop.Notification.GetApplist(notification.Handle, out flag); Interop.Notification.SetApplist(notification.Handle, flag | (int)NotificationDisplayApplist.Active); foreach (Notification.ButtonAction button in style.GetButtonAction()) { button.Make(notification); } if (style.ReplyAction != null) { style.ReplyAction.Make(notification); } if (style.HiddenByUserAction != null) { Interop.Notification.SetExtensionAction(notification.Handle, NotificationEventType.HiddenByUser, style.HiddenByUserAction.SafeAppControlHandle); } if (style.HiddenByTimeoutAction != null) { Interop.Notification.SetExtensionAction(notification.Handle, NotificationEventType.HiddenByTimeout, style.HiddenByTimeoutAction.SafeAppControlHandle); } if (style.HiddenByExternalAction != null) { Interop.Notification.SetExtensionAction(notification.Handle, NotificationEventType.HiddenByExternal, style.HiddenByExternalAction.SafeAppControlHandle); } }
public NotificationErrorException(NotificationError notification) : base(notification.Message) { Notification = notification; }
private void ShowErrorNotification(string message) { NotificationError notification = new NotificationError(); notification.Show(message, Screen.FromControl(this)); }
public NotificationException(NotificationError error) : base(error.ToString()) { }