Commit 320e32f4 by Sebastián Katzer

Do not schedule notifications old then 1 minute (Windows)

parent 404db4f3
...@@ -168,7 +168,21 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -168,7 +168,21 @@ namespace LocalNotificationProxy.LocalNotification
{ {
var xml = toast.GetXml(); var xml = toast.GetXml();
var at = this.Content.Date; var at = this.Content.Date;
var notification = new ScheduledToastNotification(xml, at); ScheduledToastNotification notification;
if (!at.HasValue)
{
return null;
}
try
{
notification = new ScheduledToastNotification(xml, at.Value);
}
catch
{
return null;
}
notification.Id = this.Content.Id; notification.Id = this.Content.Id;
notification.Tag = this.Options.Id.ToString(); notification.Tag = this.Options.Id.ToString();
......
...@@ -92,9 +92,9 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -92,9 +92,9 @@ namespace LocalNotificationProxy.LocalNotification
var p = this.ToArray(); var p = this.ToArray();
var today = DateTime.Today; var today = DateTime.Today;
p[2] = this.Day > 0 ? this.Day : today.Day; p[2] = this.DayIsVariable ? today.Day : this.Day;
p[3] = this.Month > 0 ? this.Month : today.Month; p[3] = this.MonthIsVariable ? today.Month : this.Month;
p[4] = this.Year > 0 ? this.Year : today.Year; p[4] = this.YearIsVariable ? today.Year : this.Year;
return new DateTime(p[4], p[3], p[2], p[1], p[0], 0); return new DateTime(p[4], p[3], p[2], p[1], p[0], 0);
} }
......
...@@ -47,14 +47,19 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -47,14 +47,19 @@ namespace LocalNotificationProxy.LocalNotification
foreach (Options options in notifications) foreach (Options options in notifications)
{ {
var builder = new Builder(options); var builder = new Builder(options);
ScheduledToastNotification toast;
do do
{ {
toast = builder.Build(); var toast = builder.Build();
if (toast != null)
{
ToastNotifier.AddToSchedule(toast); ToastNotifier.AddToSchedule(toast);
}
builder.MoveNext(); builder.MoveNext();
} while (builder.HasNext()); }
while (builder.HasNext());
} }
} }
......
...@@ -288,7 +288,7 @@ ...@@ -288,7 +288,7 @@
/// <summary> /// <summary>
/// Gets the date when to trigger the notification. /// Gets the date when to trigger the notification.
/// </summary> /// </summary>
public DateTime Date public DateTime? Date
{ {
get get
{ {
......
...@@ -61,7 +61,7 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -61,7 +61,7 @@ namespace LocalNotificationProxy.LocalNotification
/// <summary> /// <summary>
/// Gets the date when to trigger the notification. /// Gets the date when to trigger the notification.
/// </summary> /// </summary>
internal DateTime Date internal DateTime? Date
{ {
get get
{ {
...@@ -70,10 +70,30 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -70,10 +70,30 @@ namespace LocalNotificationProxy.LocalNotification
this.triggerDate = this.Every is Every ? this.GetRelDate() : this.GetFixDate(); this.triggerDate = this.Every is Every ? this.GetRelDate() : this.GetFixDate();
} }
if (!this.triggerDate.HasValue)
{
return null;
}
var date = this.GetNextTriggerDate(); var date = this.GetNextTriggerDate();
var minDate = DateTime.Now.AddSeconds(0.1); var minDate = DateTime.Now.AddSeconds(0.2);
return (date < minDate) ? minDate : date; if (!date.HasValue)
{
return null;
}
if (date >= minDate)
{
return date;
}
if ((minDate - date).Value.TotalMinutes <= 1)
{
return minDate;
}
return null;
} }
} }
...@@ -148,17 +168,22 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -148,17 +168,22 @@ namespace LocalNotificationProxy.LocalNotification
/// Gets the date when to trigger the notification. /// Gets the date when to trigger the notification.
/// </summary> /// </summary>
/// <returns>The first matching date specified by trigger.every</returns> /// <returns>The first matching date specified by trigger.every</returns>
private DateTime GetRelDate() private DateTime? GetRelDate()
{ {
var every = this.Every as Every; var every = this.Every as Every;
var date = every.ToDateTime(); var date = every.ToDateTime();
var now = DateTime.Now; var now = DateTime.Now;
if (date >= now || date.Year < now.Year) if (date >= now)
{ {
return date; return date;
} }
if (date.Year < now.Year)
{
return null;
}
if (date.Month < now.Month) if (date.Month < now.Month)
{ {
switch (every.Interval) switch (every.Interval)
...@@ -240,14 +265,14 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -240,14 +265,14 @@ namespace LocalNotificationProxy.LocalNotification
} }
} }
return date; return null;
} }
/// <summary> /// <summary>
/// Calculates the next trigger date by adding (interval * occurence) /// Calculates the next trigger date by adding (interval * occurence)
/// </summary> /// </summary>
/// <returns>The next valid trigger date</returns> /// <returns>The next valid trigger date</returns>
private DateTime GetNextTriggerDate() private DateTime? GetNextTriggerDate()
{ {
var every = this.Every is Every ? (this.Every as Every).Interval : this.Every; var every = this.Every is Every ? (this.Every as Every).Interval : this.Every;
var date = this.triggerDate.Value; var date = this.triggerDate.Value;
...@@ -285,7 +310,7 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -285,7 +310,7 @@ namespace LocalNotificationProxy.LocalNotification
} }
catch catch
{ {
return date; return null;
} }
} }
} }
......
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