Skip to content

Commit

Permalink
Fix #325: Scheduler event doesn't show up if date period spans years
Browse files Browse the repository at this point in the history
  • Loading branch information
genemars committed Oct 21, 2018
1 parent e0db378 commit 2d64945
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 25 deletions.
3 changes: 3 additions & 0 deletions BaseFiles/Common/Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<Content Include="LICENSE_GPLV3.TXT">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="postinstall.lock">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="README.TXT">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
4 changes: 2 additions & 2 deletions BaseFiles/Common/html/ui/core/popup.cronwizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,8 @@ $$.getMonthCron = function(dateFrom, dateTo, dayOccur, monthOccur) {
cron = '* * '+(df!=1?'1-':'')+dt+' '+mt+' *';
cronItems.push(cron);
if (mf > mt || mt-mf > 1 || (mf == mt && dt < df)) {
var mfn = mf<11 ? mf+1 : 0;
var mtp = mt>0 ? mt-1 : 11;
var mfn = mf<12 ? mf+1 : 1;
var mtp = mt>1 ? mt-1 : 12;
cron = '* * * '+mfn+(mfn!=mtp?'-'+mtp:'')+' *';
cronItems.push(cron);
}
Expand Down
Empty file.
12 changes: 11 additions & 1 deletion HomeGenie.Tests/SchedulerServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ public void CronExpressionWithExcept(string expression)
DisplayOccurences(expression, occurences);
Assert.That(occurences.Count, Is.EqualTo(12));
}

[Test]
[TestCase("[ (* * 1-31 11 *) : (* * 1-15 1 *) : (* * * 12 *) ]")]
public void CronExpressionAcrossYears(string expression)
{
var occurences = _scheduler.GetScheduling(new DateTime(2018, 6, 1), new DateTime(2019, 6, 30), expression);

DisplayOccurences(expression, occurences);
Assert.That(occurences.Count, Is.EqualTo((30+31+15)*1440));
}

private static List<DateTime> GetOccurencesForDate(SchedulerService scheduler, DateTime date, string expression)
{
Expand All @@ -90,4 +100,4 @@ private void DisplayOccurences(string cronExpression, List<DateTime> occurences)
}
}
}
}
}
61 changes: 39 additions & 22 deletions HomeGenie/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,53 @@ static void Main(string[] args)

Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);

// Move MIG libraries from root folder to lib/mig
// TODO: find a better solution to this
string[] migFiles =
{
"MIG.HomeAutomation.dll",
"MIG.Protocols.dll",
"LibUsb.Common.dll",
"LibUsbDotNet.LibUsbDotNet.dll",
"XTenLib.dll",
"ZWaveLib.dll"
};
foreach (var f in migFiles)
PostInstallCheck();

_homegenie = new HomeGenieService();
do { System.Threading.Thread.Sleep(2000); } while (_isrunning);
}

private static void PostInstallCheck()
{
string postInstallLock = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "postinstall.lock");
if (File.Exists(postInstallLock))
{
string source = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, f);
if (!File.Exists(source)) continue;
// Move MIG interface plugins from root folder to lib/mig
// TODO: find a better solution to this
string[] migFiles =
{
"MIG.HomeAutomation.dll",
"MIG.Protocols.dll",
"LibUsb.Common.dll",
"LibUsbDotNet.LibUsbDotNet.dll",
"XTenLib.dll",
"ZWaveLib.dll"
};
foreach (var f in migFiles)
{
string source = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, f);
if (!File.Exists(source)) continue;
try
{
string dest = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "lib", "mig", f);
if (File.Exists(dest)) File.Delete(dest);
File.Move(source, dest);
}
catch (Exception e)
{
Console.WriteLine("{0}\n{1}\n", e.Message, e.StackTrace);
}
}
// TODO: place any other post-install stuff here
try
{
string dest = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "lib", "mig", f);
if (File.Exists(dest)) File.Delete(dest);
File.Move(source, dest);
File.Delete(postInstallLock);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
Console.WriteLine("{0}\n{1}\n", e.Message, e.StackTrace);
}
}

_homegenie = new HomeGenieService();
do { System.Threading.Thread.Sleep(2000); } while (_isrunning);
}

internal static void Quit(bool restartService)
Expand Down

0 comments on commit 2d64945

Please sign in to comment.