Commit 320e32f4 by Sebastián Katzer

Do not schedule notifications old then 1 minute (Windows)

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