Skip to content

Commit

Permalink
Added "ping now" functionality; some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
MrShoenel committed Aug 8, 2013
1 parent 2ccf590 commit cc28b68
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,43 @@ protected Timer InitializeTimer(TimeSpan interval)
var timer = new Timer(interval.TotalMilliseconds);
timer.Elapsed += (s, e) =>
{
if (settings.DriveSettings.Any(ds => ds.Ping))
{
this.SwitchToWorkingIcon();
}

foreach (var d in settings.DriveSettings.Where(ds => ds.Ping))
{
var guid = Guid.NewGuid().ToString();
try
{
File.WriteAllText(d.DriveInfo.Name + guid, guid);
File.Delete(d.DriveInfo.Name + guid);
}
catch { }
}
this.PingDrives();
};
timer.Start();

return timer;
}

private void PingDrives()
{
if (settings.DriveSettings.Any(ds => ds.Ping))
{
this.SwitchToWorkingIcon();
}

foreach (var ds in settings.DriveSettings)
{
var guid = Guid.NewGuid().ToString();
try
{
File.WriteAllText(ds.DriveInfo.Name + guid, guid);
File.Delete(ds.DriveInfo.Name + guid);
}
catch { }
}
}

protected void CreateTrayOptions()
{
var pingNowItem = new MenuItem("Ping now");
pingNowItem.Click += (s, e) =>
{
this.PingDrives();
};

trayMenu.MenuItems.Add(pingNowItem);
trayMenu.MenuItems.Add("-");

var drivesMenu = new MenuItem("Ping Drives");
var drives = DriveInfo.GetDrives();

Expand Down

0 comments on commit cc28b68

Please sign in to comment.