Commit 8bbeabf0 by Sebastián Katzer

Refacture trigger code with support for weekday+weekOfMonth (Windows)

parent 21ef5695
...@@ -290,15 +290,15 @@ The properties depend on the trigger type. Not all of them are supported across ...@@ -290,15 +290,15 @@ The properties depend on the trigger type. Not all of them are supported across
| | every | Object | `minute` | x | x | x | | | every | Object | `minute` | x | x | x |
| | every | Object | `hour` | x | x | x | | | every | Object | `hour` | x | x | x |
| | every | Object | `day` | x | x | x | | | every | Object | `day` | x | x | x |
| | every | Object | `weekday` | x | x | | | every | Object | `weekday` | x | x | x |
| | every | Object | `weekdayOrdinal` | | x | | | every | Object | `weekdayOrdinal` | | x |
| | every | Object | `week` | x | x | x | | | every | Object | `week` | | x |
| | every | Object | `weekOfMonth` | x | x | | | every | Object | `weekOfMonth` | x | x | x |
| | every | Object | `month` | x | x | x | | | every | Object | `month` | x | x | x |
| | every | Object | `quarter` | | x | | | every | Object | `quarter` | | x |
| | every | Object | `year` | x | x | x | | | every | Object | `year` | x | x | x |
| | before | Date | | | | before | Date | |
| | after | Date | | x | x | | | after | Date | | x | x | x |
| Location | | Location |
| | center | Array | `[lat, long]` | | x | | | center | Array | `[lat, long]` | | x |
| | radius | Int | | | x | | | radius | Int | | | x |
......
...@@ -234,10 +234,11 @@ ...@@ -234,10 +234,11 @@
<!-- windows --> <!-- windows -->
<platform name="windows"> <platform name="windows">
<!--
<framework src="src/windows/lib.UW/x86/LocalNotificationProxy.winmd" target-dir="x86" arch="x86" custom="true"/> <framework src="src/windows/lib.UW/x86/LocalNotificationProxy.winmd" target-dir="x86" arch="x86" custom="true"/>
<framework src="src/windows/lib.UW/x64/LocalNotificationProxy.winmd" target-dir="x64" arch="x64" custom="true"/> <framework src="src/windows/lib.UW/x64/LocalNotificationProxy.winmd" target-dir="x64" arch="x64" custom="true"/>
<framework src="src/windows/lib.UW/ARM/LocalNotificationProxy.winmd" target-dir="ARM" arch="ARM" custom="true"/> <framework src="src/windows/lib.UW/ARM/LocalNotificationProxy.winmd" target-dir="ARM" arch="ARM" custom="true"/>
-->
<js-module src="src/windows/LocalNotificationProxy.js" name="LocalNotification.Proxy" > <js-module src="src/windows/LocalNotificationProxy.js" name="LocalNotification.Proxy" >
<merges target="" /> <merges target="" />
</js-module> </js-module>
......
...@@ -447,7 +447,7 @@ exports.parseOptions = function (obj) { ...@@ -447,7 +447,7 @@ exports.parseOptions = function (obj) {
* @return [ LocalNotification.Trigger ] * @return [ LocalNotification.Trigger ]
*/ */
exports.parseTrigger = function (obj) { exports.parseTrigger = function (obj) {
var trigger = new LocalNotification.Trigger(), var trigger = new LocalNotification.Toast.Trigger(),
spec = obj.trigger, val; spec = obj.trigger, val;
if (!spec) return trigger; if (!spec) return trigger;
...@@ -469,12 +469,12 @@ exports.parseTrigger = function (obj) { ...@@ -469,12 +469,12 @@ exports.parseTrigger = function (obj) {
* @return [ LocalNotification.Every|String ] * @return [ LocalNotification.Every|String ]
*/ */
exports.parseEvery = function (spec) { exports.parseEvery = function (spec) {
var every = new LocalNotification.Every(); var every = new LocalNotification.Toast.Every();
if (typeof spec !== 'object') return spec; if (typeof spec !== 'object') return spec;
for (var prop in every) { for (var prop in every) {
if (spec[prop]) every[prop] = parseInt(spec[prop]); if (spec.hasOwnProperty(prop)) every[prop] = parseInt(spec[prop]);
} }
return every; return every;
...@@ -494,10 +494,10 @@ exports.parseActions = function (obj) { ...@@ -494,10 +494,10 @@ exports.parseActions = function (obj) {
for (var action of obj.actions) { for (var action of obj.actions) {
if (!action.type || action.type == 'button') { if (!action.type || action.type == 'button') {
btn = new LocalNotification.Button(); btn = new LocalNotification.Toast.Button();
} else } else
if (action.type == 'input') { if (action.type == 'input') {
btn = new LocalNotification.Input(); btn = new LocalNotification.Toast.Input();
} }
for (var prop in btn) { for (var prop in btn) {
...@@ -518,7 +518,7 @@ exports.parseActions = function (obj) { ...@@ -518,7 +518,7 @@ exports.parseActions = function (obj) {
* @return [ LocalNotification.ProgressBar ] * @return [ LocalNotification.ProgressBar ]
*/ */
exports.parseProgressBar = function (obj) { exports.parseProgressBar = function (obj) {
var bar = new LocalNotification.ProgressBar(), var bar = new LocalNotification.Toast.ProgressBar(),
spec = obj.progressBar; spec = obj.progressBar;
if (!spec) return bar; if (!spec) return bar;
......
...@@ -27,12 +27,18 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -27,12 +27,18 @@ namespace LocalNotificationProxy.LocalNotification
internal class Builder internal class Builder
{ {
/// <summary> /// <summary>
/// The provided trigger request.
/// </summary>
private readonly Request request;
/// <summary>
/// Initializes a new instance of the <see cref="Builder"/> class. /// Initializes a new instance of the <see cref="Builder"/> class.
/// </summary> /// </summary>
/// <param name="options">Notification properties to set.</param> /// <param name="request">Trigger request.</param>
public Builder(Options options) public Builder(Request request)
{ {
this.Content = new Notification(options); this.request = request;
this.Content = new Notification(request.Options);
} }
/// <summary> /// <summary>
...@@ -46,11 +52,6 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -46,11 +52,6 @@ namespace LocalNotificationProxy.LocalNotification
private Options Options { get => this.Content.Options; } private Options Options { get => this.Content.Options; }
/// <summary> /// <summary>
/// Gets the trigger.
/// </summary>
private Trigger Trigger { get => this.Options.Trigger; }
/// <summary>
/// Build a toast notification specified by the options. /// Build a toast notification specified by the options.
/// </summary> /// </summary>
/// <returns>A fully configured toast notification instance.</returns> /// <returns>A fully configured toast notification instance.</returns>
...@@ -66,17 +67,6 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -66,17 +67,6 @@ namespace LocalNotificationProxy.LocalNotification
} }
/// <summary> /// <summary>
/// If there is at least one more toast variant to build.
/// </summary>
/// <returns>True if there are more toasts to build.</returns>
public bool HasNext() => this.Trigger.Count >= this.Trigger.Occurrence;
/// <summary>
/// Moves the flag to the next toast variant.
/// </summary>
public void MoveNext() => this.Trigger.Occurrence += this.HasNext() ? 1 : 0;
/// <summary>
/// Gets the initialize skeleton for a toast notification. /// Gets the initialize skeleton for a toast notification.
/// </summary> /// </summary>
/// <returns>Basic skeleton with sound, image and text.</returns> /// <returns>Basic skeleton with sound, image and text.</returns>
...@@ -167,7 +157,7 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -167,7 +157,7 @@ namespace LocalNotificationProxy.LocalNotification
private ScheduledToastNotification ConvertToastToNotification(ToastContent toast) private ScheduledToastNotification ConvertToastToNotification(ToastContent toast)
{ {
var xml = toast.GetXml(); var xml = toast.GetXml();
var at = this.Content.Date; var at = this.request.TriggerDate;
ScheduledToastNotification notification; ScheduledToastNotification notification;
if (!at.HasValue) if (!at.HasValue)
...@@ -188,7 +178,7 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -188,7 +178,7 @@ namespace LocalNotificationProxy.LocalNotification
notification.Tag = this.Options.Id.ToString(); notification.Tag = this.Options.Id.ToString();
notification.SuppressPopup = this.Options.Silent; notification.SuppressPopup = this.Options.Silent;
if (this.Trigger.Occurrence > 1) if (this.request.Occurrence > 1)
{ {
notification.Group = notification.Tag; notification.Group = notification.Tag;
} }
......
...@@ -46,7 +46,8 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -46,7 +46,8 @@ namespace LocalNotificationProxy.LocalNotification
{ {
foreach (Options options in notifications) foreach (Options options in notifications)
{ {
var builder = new Builder(options); var request = new Request(options);
var builder = new Builder(request);
do do
{ {
...@@ -58,9 +59,8 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -58,9 +59,8 @@ namespace LocalNotificationProxy.LocalNotification
} }
ToastNotifier.AddToSchedule(toast); ToastNotifier.AddToSchedule(toast);
builder.MoveNext();
} }
while (builder.HasNext()); while (request.MoveNext());
} }
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using global::LocalNotificationProxy.LocalNotification.Toast;
using Microsoft.Toolkit.Uwp.Notifications; using Microsoft.Toolkit.Uwp.Notifications;
using Windows.UI.Notifications; using Windows.UI.Notifications;
...@@ -286,17 +287,6 @@ ...@@ -286,17 +287,6 @@
} }
/// <summary> /// <summary>
/// Gets the date when to trigger the notification.
/// </summary>
public DateTime? Date
{
get
{
return this.Options.Trigger.Date;
}
}
/// <summary>
/// Gets the instance as an serialized xml element. /// Gets the instance as an serialized xml element.
/// </summary> /// </summary>
/// <returns>Element with all property values set as attributes.</returns> /// <returns>Element with all property values set as attributes.</returns>
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
namespace LocalNotificationProxy.LocalNotification namespace LocalNotificationProxy.LocalNotification
{ {
using global::LocalNotificationProxy.LocalNotification.Toast;
using Windows.Data.Xml.Dom; using Windows.Data.Xml.Dom;
public sealed class Options public sealed class Options
...@@ -68,7 +69,7 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -68,7 +69,7 @@ namespace LocalNotificationProxy.LocalNotification
/// <summary> /// <summary>
/// Gets or sets the notification trigger. /// Gets or sets the notification trigger.
/// </summary> /// </summary>
public Trigger Trigger { get; set; } public Toast.Trigger Trigger { get; set; }
/// <summary> /// <summary>
/// Gets or sets the notification user data. /// Gets or sets the notification user data.
...@@ -105,7 +106,7 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -105,7 +106,7 @@ namespace LocalNotificationProxy.LocalNotification
options.Id = int.Parse(node.GetAttribute("id")); options.Id = int.Parse(node.GetAttribute("id"));
options.Badge = int.Parse(node.GetAttribute("badge")); options.Badge = int.Parse(node.GetAttribute("badge"));
options.Trigger = Trigger.Parse(node.GetAttribute("trigger")); options.Trigger = Toast.Trigger.Parse(node.GetAttribute("trigger"));
if (node.GetAttributeNode("text") != null) if (node.GetAttributeNode("text") != null)
{ {
......
/*
* Apache 2.0 License
*
* Copyright (c) Sebastian Katzer 2017
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apache License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*/
namespace LocalNotificationProxy.LocalNotification
{
using System;
internal class Request
{
/// <summary>
/// The right trigger for the options
/// </summary>
private readonly Trigger.DateTrigger trigger;
/// <summary>
/// How often the trigger shall occur.
/// </summary>
private readonly int count;
/// <summary>
/// The trigger spec.
/// </summary>
private readonly Toast.Trigger spec;
/// <summary>
/// The current trigger date.
/// </summary>
private DateTime? triggerDate;
/// <summary>
/// Initializes a new instance of the <see cref="Request"/> class.
/// </summary>
/// <param name="options">The options spec.</param>
public Request(Options options)
{
this.Options = options;
this.spec = options.Trigger;
this.count = Math.Max(this.spec.Count, 1);
this.trigger = this.BuildTrigger();
this.triggerDate = this.trigger.GetNextTriggerDate(this.GetBaseDate());
}
/// <summary>
/// Gets the options spec.
/// </summary>
public Options Options { get; private set; }
/// <summary>
/// Gets the value of the internal occurrence counter.
/// </summary>
public int Occurrence { get => this.trigger.Occurrence; }
/// <summary>
/// Gets a value indicating whether there's one more trigger date to calculate.
/// </summary>
public bool HasNext { get => this.triggerDate.HasValue && this.Occurrence <= this.count; }
/// <summary>
/// Gets the current trigger date.
/// </summary>
public DateTime? TriggerDate
{
get
{
if (!this.triggerDate.HasValue)
{
return null;
}
var minDate = DateTime.Now.AddSeconds(0.2);
if (this.triggerDate >= minDate)
{
return this.triggerDate;
}
if ((minDate - this.triggerDate).Value.TotalMinutes <= 1)
{
return minDate;
}
return null;
}
}
/// <summary>
/// Moves the internal occurrence counter by one.
/// </summary>
/// <returns>false if it wasnt possible anymore to move ahead.</returns>
public bool MoveNext()
{
if (this.HasNext)
{
this.triggerDate = this.GetNextTriggerDate();
}
else
{
this.triggerDate = null;
}
return this.triggerDate.HasValue;
}
/// <summary>
/// Gets the next trigger date based on the current trigger date.
/// </summary>
/// <returns>null if there's no next one.</returns>
private DateTime? GetNextTriggerDate()
{
if (this.triggerDate.HasValue)
{
return this.trigger.GetNextTriggerDate(this.triggerDate.Value);
}
else
{
return null;
}
}
/// <summary>
/// Build the trigger specified in options.
/// </summary>
/// <returns>Configured trigger instance</returns>
private Trigger.DateTrigger BuildTrigger()
{
if (this.spec.Every is Toast.Every)
{
var matchers = this.GetMatchers();
var specials = this.GetSpecials();
return new Trigger.MatchTrigger(matchers, specials);
}
var unit = this.GetUnit();
var ticks = this.GetTicks();
return new Trigger.IntervalTrigger(ticks, unit);
}
/// <summary>
/// Gets the unit value.
/// </summary>
/// <returns>SECOND by default.</returns>
private Trigger.DateTrigger.Unit GetUnit()
{
var unit = "SECOND";
if (!string.IsNullOrEmpty(this.spec.Unit))
{
unit = this.spec.Unit;
}
else if (this.spec.Every is string)
{
unit = this.spec.Every as string;
}
return (Trigger.DateTrigger.Unit)Enum.Parse(
typeof(Trigger.DateTrigger.Unit), unit.ToUpper());
}
/// <summary>
/// Gets the tick value.
/// </summary>
/// <returns>Defaults to 0</returns>
private int GetTicks()
{
if (this.spec.At != 0)
{
return 0;
}
else if (this.spec.In != 0)
{
return this.spec.In;
}
else if (this.spec.Every is string)
{
return 1;
}
else if (this.spec.Every is double)
{
return Convert.ToInt32(this.spec.Every);
}
return 0;
}
/// <summary>
/// Gets an array of all date parts to construct a datetime instance.
/// </summary>
/// <returns>[min, hour, day, month, year]</returns>
private int?[] GetMatchers()
{
var every = this.spec.Every as Toast.Every;
return new int?[]
{
every.Minute, every.Hour, every.Day, every.Month, every.Year
};
}
/// <summary>
/// Gets an array of all date parts to construct a datetime instance.
/// </summary>
/// <returns>[weekday, weekdayOrdinal, weekOfMonth, quarter]</returns>
private int?[] GetSpecials()
{
var every = this.spec.Every as Toast.Every;
return new int?[]
{
every.Weekday, every.WeekdayOrdinal, every.WeekOfMonth, every.Quarter
};
}
/// <summary>
/// Gets the base date from where to calculate the next trigger date.
/// </summary>
/// <returns>Usually points to now</returns>
private DateTime GetBaseDate()
{
if (this.spec.At != 0)
{
return DateTimeOffset.FromUnixTimeMilliseconds(this.spec.At).LocalDateTime;
}
else if (this.spec.FirstAt != 0)
{
return DateTimeOffset.FromUnixTimeMilliseconds(this.spec.At).LocalDateTime;
}
else if (this.spec.After != 0)
{
return DateTimeOffset.FromUnixTimeMilliseconds(this.spec.After).LocalDateTime;
}
return DateTime.Now;
}
}
}
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
* limitations under the License. * limitations under the License.
*/ */
namespace LocalNotificationProxy.LocalNotification namespace LocalNotificationProxy.LocalNotification.Toast
{ {
public sealed class Button : IAction public sealed class Button : IAction
{ {
......
...@@ -19,14 +19,10 @@ ...@@ -19,14 +19,10 @@
* limitations under the License. * limitations under the License.
*/ */
namespace LocalNotificationProxy.LocalNotification namespace LocalNotificationProxy.LocalNotification.Toast
{ {
using System;
public sealed class Every public sealed class Every
{ {
private static readonly string[] Intervals = { null, "minute", "hour", "day", "month", "year" };
/// <summary> /// <summary>
/// Gets or sets the minute. /// Gets or sets the minute.
/// </summary> /// </summary>
...@@ -43,46 +39,38 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -43,46 +39,38 @@ namespace LocalNotificationProxy.LocalNotification
public int? Day { get; set; } public int? Day { get; set; }
/// <summary> /// <summary>
/// Gets or sets the month. /// Gets or sets the day of week.
/// </summary> /// </summary>
public int? Month { get; set; } public int? Weekday { get; set; }
/// <summary> /// <summary>
/// Gets or sets the year. /// Gets or sets the week of year.
/// </summary> /// </summary>
public int? Year { get; set; } public int? Week { get; set; }
/// <summary> /// <summary>
/// Gets the interval as a string representation. /// Gets or sets the day of ordinal week.
/// </summary> /// </summary>
/// <returns>year, month, ...</returns> public int? WeekdayOrdinal { get; set; }
internal string Interval { get => Intervals[Array.IndexOf(this.ToArray(), null) + 1]; }
/// <summary> /// <summary>
/// Converts the date time components into a datetime object. /// Gets or sets the week of month.
/// </summary> /// </summary>
/// <param name="now">The relative date to calculate the date from.</param> public int? WeekOfMonth { get; set; }
/// <returns>A datetime object</returns>
internal DateTime ToDateTime(DateTime now)
{
var p = this.ToArray();
p[0] = this.Minute.GetValueOrDefault(); /// <summary>
p[1] = this.Hour.GetValueOrDefault(); /// Gets or sets the month.
p[2] = this.Day.GetValueOrDefault(now.Day); /// </summary>
p[3] = this.Month.GetValueOrDefault(now.Month); public int? Month { get; set; }
p[4] = this.Year.GetValueOrDefault(now.Year);
return new DateTime(p[4].Value, p[3].Value, p[2].Value, p[1].Value, p[0].Value, 0); /// <summary>
} /// Gets or sets the quarter.
/// </summary>
public int? Quarter { get; set; }
/// <summary> /// <summary>
/// Gets an array of all date parts to construct a datetime instance. /// Gets or sets the year.
/// </summary> /// </summary>
/// <returns>[min, hour, day, month, year]</returns> public int? Year { get; set; }
private int?[] ToArray()
{
return new int?[] { this.Minute, this.Hour, this.Day, this.Month, this.Year };
}
} }
} }
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
* limitations under the License. * limitations under the License.
*/ */
namespace LocalNotificationProxy.LocalNotification namespace LocalNotificationProxy.LocalNotification.Toast
{ {
public interface IAction public interface IAction
{ {
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
* limitations under the License. * limitations under the License.
*/ */
namespace LocalNotificationProxy.LocalNotification namespace LocalNotificationProxy.LocalNotification.Toast
{ {
public sealed class Input : IAction public sealed class Input : IAction
{ {
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
* limitations under the License. * limitations under the License.
*/ */
namespace LocalNotificationProxy.LocalNotification namespace LocalNotificationProxy.LocalNotification.Toast
{ {
public sealed class ProgressBar public sealed class ProgressBar
{ {
......
/*
* Apache 2.0 License
*
* Copyright (c) Sebastian Katzer 2017
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apache License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*/
namespace LocalNotificationProxy.LocalNotification.Trigger
{
using System;
internal abstract class DateTrigger
{
/// <summary>
/// Default unit is SECOND
/// </summary>
public enum Unit : byte
{
NULL, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR
}
/// <summary>
/// Gets or sets the occurrence counter.
/// </summary>
public int Occurrence { get; protected set; } = 1;
/// <summary>
/// Gets the next trigger date.
/// </summary>
/// <param name="date">The date from where to calculate the next one.</param>
/// <returns>Null if there is no next trigger date.</returns>
public abstract DateTime? GetNextTriggerDate(DateTime date);
}
}
/*
* Apache 2.0 License
*
* Copyright (c) Sebastian Katzer 2017
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apache License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*/
namespace LocalNotificationProxy.LocalNotification.Trigger
{
using System;
internal class IntervalTrigger : DateTrigger
{
/// <summary>
/// The number of ticks per interval.
/// </summary>
private readonly int ticks;
/// <summary>
/// Initializes a new instance of the <see cref="IntervalTrigger"/> class.
/// </summary>
/// <param name="ticks">The number of ticks per interval.</param>
/// <param name="unit">The unit of the ticks.</param>
public IntervalTrigger(int ticks, Unit unit)
{
this.ticks = ticks;
this.Unit = unit;
}
/// <summary>
/// Gets the unit of the ticks
/// </summary>
internal new Unit Unit { get; private set; }
/// <summary>
/// Gets the next trigger date.
/// </summary>
/// <param name="date">The date from where to calculate the next one.</param>
/// <returns>Null if there is no next trigger date.</returns>
public override DateTime? GetNextTriggerDate(DateTime date)
{
this.Occurrence += 1;
return this.AddInterval(date);
}
/// <summary>
/// Adds the interval to the specified date.
/// </summary>
/// <param name="date">The date where to add the interval of ticks</param>
/// <returns>A new datetime instance</returns>
protected DateTime AddInterval(DateTime date)
{
switch (this.Unit)
{
case Unit.SECOND:
return date.AddSeconds(this.ticks);
case Unit.MINUTE:
return date.AddMinutes(this.ticks);
case Unit.HOUR:
return date.AddHours(this.ticks);
case Unit.DAY:
return date.AddDays(this.ticks);
case Unit.WEEK:
return date.AddDays(this.ticks * 7);
case Unit.MONTH:
return date.AddMonths(this.ticks);
case Unit.QUARTER:
return date.AddMonths(this.ticks * 3);
case Unit.YEAR:
return date.AddYears(this.ticks);
default:
return date;
}
}
}
}
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<DefaultLanguage>de-DE</DefaultLanguage> <DefaultLanguage>de-DE</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier> <TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.16299.0</TargetPlatformVersion> <TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.16299.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.16299.0</TargetPlatformMinVersion> <TargetPlatformMinVersion>10.0.15063.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion> <MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
...@@ -112,15 +112,19 @@ ...@@ -112,15 +112,19 @@
<ItemGroup> <ItemGroup>
<Compile Include="LocalNotificationProxy.cs" /> <Compile Include="LocalNotificationProxy.cs" />
<Compile Include="LocalNotification\Builder.cs" /> <Compile Include="LocalNotification\Builder.cs" />
<Compile Include="LocalNotification\Button.cs" /> <Compile Include="LocalNotification\Request.cs" />
<Compile Include="LocalNotification\Every.cs" /> <Compile Include="LocalNotification\Toast\Button.cs" />
<Compile Include="LocalNotification\Toast\Every.cs" />
<Compile Include="LocalNotification\Notification.cs" /> <Compile Include="LocalNotification\Notification.cs" />
<Compile Include="LocalNotification\IAction.cs" /> <Compile Include="LocalNotification\Toast\IAction.cs" />
<Compile Include="LocalNotification\Input.cs" /> <Compile Include="LocalNotification\Toast\Input.cs" />
<Compile Include="LocalNotification\Manager.cs" /> <Compile Include="LocalNotification\Manager.cs" />
<Compile Include="LocalNotification\Options.cs" /> <Compile Include="LocalNotification\Options.cs" />
<Compile Include="LocalNotification\ProgressBar.cs" /> <Compile Include="LocalNotification\Toast\ProgressBar.cs" />
<Compile Include="LocalNotification\Trigger.cs" /> <Compile Include="LocalNotification\Toast\Trigger.cs" />
<Compile Include="LocalNotification\Trigger\DateTrigger.cs" />
<Compile Include="LocalNotification\Trigger\IntervalTrigger.cs" />
<Compile Include="LocalNotification\Trigger\MatchTrigger.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
...@@ -137,6 +141,7 @@ ...@@ -137,6 +141,7 @@
<Name>Microsoft.Toolkit.Uwp.Notifications.UWP</Name> <Name>Microsoft.Toolkit.Uwp.Notifications.UWP</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup />
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' "> <PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion> <VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup> </PropertyGroup>
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' "> <PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess> <RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool> <RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">Z:\Documents\github\cordova-plugin-local-notifications\src\windows\Microsoft.Toolkit.Uwp.Notifications.UWP\project.lock.json</ProjectAssetsFile> <ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">Z:\Documents\github\cordova-plugin-local-notification\src\windows\Microsoft.Toolkit.Uwp.Notifications.UWP\project.lock.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot> <NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\katze\.nuget\packages\</NuGetPackageFolders> <NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\katze\.nuget\packages\;C:\Program Files (x86)\Microsoft SDKs\NuGetPackagesFallback\</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">ProjectJson</NuGetProjectStyle> <NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">ProjectJson</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">4.4.1</NuGetToolVersion> <NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">4.5.0</NuGetToolVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
...@@ -16,6 +16,6 @@ ...@@ -16,6 +16,6 @@
<Import Project="$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-x86\1.7.0\build\Microsoft.Net.Native.SharedLibrary-x86.props" Condition="Exists('$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-x86\1.7.0\build\Microsoft.Net.Native.SharedLibrary-x86.props')" /> <Import Project="$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-x86\1.7.0\build\Microsoft.Net.Native.SharedLibrary-x86.props" Condition="Exists('$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-x86\1.7.0\build\Microsoft.Net.Native.SharedLibrary-x86.props')" />
<Import Project="$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-x64\1.7.0\build\Microsoft.Net.Native.SharedLibrary-x64.props" Condition="Exists('$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-x64\1.7.0\build\Microsoft.Net.Native.SharedLibrary-x64.props')" /> <Import Project="$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-x64\1.7.0\build\Microsoft.Net.Native.SharedLibrary-x64.props" Condition="Exists('$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-x64\1.7.0\build\Microsoft.Net.Native.SharedLibrary-x64.props')" />
<Import Project="$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-arm\1.7.0\build\Microsoft.Net.Native.SharedLibrary-arm.props" Condition="Exists('$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-arm\1.7.0\build\Microsoft.Net.Native.SharedLibrary-arm.props')" /> <Import Project="$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-arm\1.7.0\build\Microsoft.Net.Native.SharedLibrary-arm.props" Condition="Exists('$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-arm\1.7.0\build\Microsoft.Net.Native.SharedLibrary-arm.props')" />
<Import Project="$(NuGetPackageRoot)microsoft.net.native.compiler\1.7.1\build\Microsoft.Net.Native.Compiler.props" Condition="Exists('$(NuGetPackageRoot)microsoft.net.native.compiler\1.7.1\build\Microsoft.Net.Native.Compiler.props')" /> <Import Project="$(NuGetPackageRoot)microsoft.net.native.compiler\1.7.3\build\Microsoft.Net.Native.Compiler.props" Condition="Exists('$(NuGetPackageRoot)microsoft.net.native.compiler\1.7.3\build\Microsoft.Net.Native.Compiler.props')" />
</ImportGroup> </ImportGroup>
</Project> </Project>
\ No newline at end of file
...@@ -7,6 +7,6 @@ ...@@ -7,6 +7,6 @@
<Import Project="$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-x86\1.7.0\build\Microsoft.Net.Native.SharedLibrary-x86.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-x86\1.7.0\build\Microsoft.Net.Native.SharedLibrary-x86.targets')" /> <Import Project="$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-x86\1.7.0\build\Microsoft.Net.Native.SharedLibrary-x86.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-x86\1.7.0\build\Microsoft.Net.Native.SharedLibrary-x86.targets')" />
<Import Project="$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-x64\1.7.0\build\Microsoft.Net.Native.SharedLibrary-x64.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-x64\1.7.0\build\Microsoft.Net.Native.SharedLibrary-x64.targets')" /> <Import Project="$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-x64\1.7.0\build\Microsoft.Net.Native.SharedLibrary-x64.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-x64\1.7.0\build\Microsoft.Net.Native.SharedLibrary-x64.targets')" />
<Import Project="$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-arm\1.7.0\build\Microsoft.Net.Native.SharedLibrary-arm.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-arm\1.7.0\build\Microsoft.Net.Native.SharedLibrary-arm.targets')" /> <Import Project="$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-arm\1.7.0\build\Microsoft.Net.Native.SharedLibrary-arm.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.net.native.sharedlibrary-arm\1.7.0\build\Microsoft.Net.Native.SharedLibrary-arm.targets')" />
<Import Project="$(NuGetPackageRoot)microsoft.net.native.compiler\1.7.1\build\Microsoft.Net.Native.Compiler.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.net.native.compiler\1.7.1\build\Microsoft.Net.Native.Compiler.targets')" /> <Import Project="$(NuGetPackageRoot)microsoft.net.native.compiler\1.7.3\build\Microsoft.Net.Native.Compiler.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.net.native.compiler\1.7.3\build\Microsoft.Net.Native.Compiler.targets')" />
</ImportGroup> </ImportGroup>
</Project> </Project>
\ No newline at end of file
{ {
"dependencies": { "dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "6.0.2", "Microsoft.NETCore.UniversalWindowsPlatform": "6.0.5",
"StyleCop.Analyzers": "1.0.2" "StyleCop.Analyzers": "1.0.2"
}, },
"frameworks": { "frameworks": {
......
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