Commit 0224f67c by Sebastián Katzer

Added query methods to get ids and options (Windows)

parent 703d40c8
......@@ -20,7 +20,7 @@
*/
var LocalNotification = LocalNotificationProxy.LocalNotification,
ActivationKind = Windows.ApplicationModel.Activation.ActivationKind;
ActivationKind = Windows.ApplicationModel.Activation.ActivationKind;
var impl = new LocalNotificationProxy.LocalNotificationProxy();
......@@ -108,7 +108,7 @@ exports.schedule = function (success, error, args) {
exports.ids = function (success, error) {
var ids = impl.ids() || [];
success(ids);
success(Array.from(ids));
};
/**
......@@ -122,7 +122,7 @@ exports.ids = function (success, error) {
exports.scheduledIds = function (success, error) {
var ids = impl.scheduledIds() || [];
success(ids);
success(Array.from(ids));
};
/**
......@@ -136,7 +136,65 @@ exports.scheduledIds = function (success, error) {
exports.triggeredIds = function (success, error) {
var ids = impl.triggeredIds() || [];
success(ids);
success(Array.from(ids));
};
/**
* Get a single notification by id.
*
* @param [ Function ] success Success callback
* @param [ Function ] error Error callback
* @param [ Array ] args Interface arguments
*
* @return [ Void ]
*/
exports.notification = function (success, error, args) {
var obj = impl.notification(args[0]);
success(obj);
};
/**
* List of (all) notifications.
*
* @param [ Function ] success Success callback
* @param [ Function ] error Error callback
* @param [ Array ] args Interface arguments
*
* @return [ Void ]
*/
exports.notifications = function (success, error, args) {
var objs = impl.notifications(args) || [];
success(Array.from(objs));
};
/**
* List of all scheduled notifications.
*
* @param [ Function ] success Success callback
* @param [ Function ] error Error callback
*
* @return [ Void ]
*/
exports.scheduledNotifications = function (success, error) {
var objs = impl.scheduledNotifications() || [];
success(Array.from(objs));
};
/**
* List of all triggered notifications.
*
* @param [ Function ] success Success callback
* @param [ Function ] error Error callback
*
* @return [ Void ]
*/
exports.triggeredNotifications = function (success, error) {
var objs = impl.triggeredNotifications() || [];
success(Array.from(objs));
};
/**
......
......@@ -93,15 +93,144 @@ namespace LocalNotificationProxy.LocalNotification
}
/// <summary>
/// Gets all notifications.
/// </summary>
/// <returns>A list of all triggered and scheduled notifications.</returns>
public List<Notification> GetAll()
{
return this.GetByType(Notification.Type.All);
}
/// <summary>
/// Gets all notifications of given type.
/// </summary>
/// <param name="type">The type of notification.</param>
/// <returns>A list of notifications.</returns>
public List<Notification> GetByType(Notification.Type type)
{
var notifications = new List<Notification>();
if (type == Notification.Type.All || type == Notification.Type.Scheduled)
{
var toasts = ToastNotifier.GetScheduledToastNotifications();
foreach (var toast in toasts)
{
notifications.Add(new Notification(toast));
}
}
if (type == Notification.Type.All || type == Notification.Type.Triggered)
{
var toasts = ToastNotificationManager.History.GetHistory();
foreach (var toast in toasts)
{
notifications.Add(new Notification(toast));
}
}
return notifications;
}
/// <summary>
/// Gets all notifications.
/// </summary>
/// <returns>A list of notification options instances.</returns>
public List<Options> GetOptions()
{
return this.GetOptionsByType(Notification.Type.All);
}
/// <summary>
/// Gets notifications specified by ID.
/// </summary>
/// <param name="ids">Optional list of IDs to find.</param>
/// <returns>A list of notification options instances.</returns>
public List<Options> GetOptions(int[] ids)
{
var options = new List<Options>();
foreach (var toast in this.Get(ids))
{
options.Add(toast.Options);
}
return options;
}
/// <summary>
/// Gets all notifications for given type.
/// </summary>
/// <param name="type">The type of notification.</param>
/// <returns>A list of notification options instances.</returns>
public List<Options> GetOptionsByType(Notification.Type type)
{
var options = new List<Options>();
var toasts = this.GetByType(type);
foreach (var toast in toasts)
{
options.Add(toast.Options);
}
return options;
}
/// <summary>
/// Gets the notifications specified by ID.
/// </summary>
/// <param name="ids">List of IDs to find.</param>
/// <returns>List of found notifications.</returns>
public List<Notification> Get(int[] ids)
{
var toasts = new List<Notification>();
foreach (var id in ids)
{
var toast = this.Get(id);
if (toast != null)
{
toasts.Add(toast);
}
}
return toasts;
}
/// <summary>
/// Gets the notification by ID.
/// </summary>
/// <param name="id">The ID of the notification to find.</param>
/// <returns>The found instance or null.</returns>
public Notification Get(int id)
{
return this.Get(id.ToString());
}
/// <summary>
/// Gets the notification by ID.
/// </summary>
/// <param name="id">The ID of the notification to find.</param>
/// <returns>The found instance or null.</returns>
private Notification Get(string id)
public Notification Get(string id)
{
foreach (var toast in ToastNotifier.GetScheduledToastNotifications())
var scheduled = ToastNotifier.GetScheduledToastNotifications();
foreach (var toast in scheduled)
{
if (toast.Tag == id)
{
return new Notification(toast);
}
}
var triggered = ToastNotificationManager.History.GetHistory();
foreach (var toast in triggered)
{
if (toast.Id == id)
if (toast.Tag == id)
{
return new Notification(toast);
}
......
......@@ -34,6 +34,16 @@
this.Options = Options.Parse(toast.Content.GetXml());
}
/// <summary>
/// Initializes a new instance of the <see cref="Notification"/> class.
/// </summary>
/// <param name="toast">The options as a toast object.</param>
public Notification(ToastNotification toast)
{
var xml = toast.Content.DocumentElement.GetAttribute("launch");
this.Options = Options.Parse(xml);
}
public enum Type
{
All, Scheduled, Triggered
......
......@@ -26,6 +26,9 @@ namespace LocalNotificationProxy
public sealed class LocalNotificationProxy
{
/// <summary>
/// Manager wrapps the native SDK methods.
/// </summary>
private Manager manager = new Manager();
/// <summary>
......@@ -72,5 +75,52 @@ namespace LocalNotificationProxy
{
return this.manager.GetIdsByType(Notification.Type.Triggered).ToArray();
}
#pragma warning disable SA1300 // Element must begin with upper-case letter
/// <summary>
/// Gets a single notifiation specified by id.
/// </summary>
/// <param name="id">The ID of the notification to find.</param>
/// <returns>List of options instances</returns>
public Options notification(int id)
{
var toast = this.manager.Get(id);
return toast != null ? toast.Options : null;
}
#pragma warning restore SA1300 // Element must begin with upper-case letter
/// <summary>
/// List of (all) notifiation specified by id.
/// </summary>
/// <param name="ids">Optional list of IDs to find.</param>
/// <returns>List of options instances</returns>
public Options[] Notifications([ReadOnlyArray] int[] ids)
{
if (ids == null || ids.Length == 0)
{
return this.manager.GetOptions().ToArray();
}
return this.manager.GetOptions(ids).ToArray();
}
/// <summary>
/// List of all scheduled notifiation.
/// </summary>
/// <returns>List of options instances</returns>
public Options[] ScheduledNotifications()
{
return this.manager.GetOptionsByType(Notification.Type.Scheduled).ToArray();
}
/// <summary>
/// List of all triggered notifiation.
/// </summary>
/// <returns>List of options instances</returns>
public Options[] TriggeredNotifications()
{
return this.manager.GetOptionsByType(Notification.Type.Triggered).ToArray();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment