Skip to content

Commit

Permalink
Target Net 5.0 + Fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlep committed Feb 3, 2021
1 parent 86115a1 commit 16db151
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions Pinger/Dataset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static void Write(Record record)
using (var csv = new CsvWriter(writer, config))
{
csv.WriteRecord(record);
csv.NextRecord();
}
}

Expand Down
2 changes: 1 addition & 1 deletion Pinger/Pinger.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>

Expand Down
29 changes: 24 additions & 5 deletions Pinger/PingerAppContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Pinger
{
public class PingerAppContext : ApplicationContext
{
private string AppVersion = "1.0";
private NotifyIcon trayIcon;
private Container components = new Container();

Expand All @@ -21,23 +22,41 @@ public PingerAppContext()

var menuItemSettings = new ToolStripMenuItem("Settings", null, (sender, e) =>
{
Process.Start(Settings.FileName);
var p = new Process();
p.StartInfo = new ProcessStartInfo(Settings.FileName)
{
UseShellExecute = true
};
p.Start();
});

var menuItemRestart = new ToolStripMenuItem("Restart", null, (sender, e) =>
{
Application.Restart();
});

var menuItemViewData = new ToolStripMenuItem("View data", null, (sender, e) =>
{
Process.Start(Dataset.FileName);
var p = new Process();
p.StartInfo = new ProcessStartInfo(Dataset.FileName)
{
UseShellExecute = true
};
p.Start();
});

contextMenu.Items.AddRange(new[] { menuItemViewData, menuItemSettings, menuItemExit });
contextMenu.Items.AddRange(new[] { menuItemViewData, menuItemSettings, menuItemRestart, menuItemExit });

trayIcon = new NotifyIcon(components)
{
ContextMenuStrip = contextMenu,
Icon = new System.Drawing.Icon("icon.ico"),
Text = "Pinger is collecting data!",
Visible = true
Text = $"Pinger is collecting data! - Version {AppVersion}",
Visible = true,
BalloonTipText = "Pinger as started collecting data!"
};

trayIcon.ShowBalloonTip(3000);
}
}
}
4 changes: 2 additions & 2 deletions Pinger/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Settings
public static readonly string FileName = Environment.CurrentDirectory + @"\settings.json";

public string host { get; set; } = "www.google.ca";
public int frequencyInSec { get; set; } = 3;
public int frequencyInSec { get; set; } = 60;

public static Settings Read()
{
Expand All @@ -18,7 +18,7 @@ public static Settings Read()

public static void Write(Settings settings)
{
File.WriteAllText(FileName, JsonSerializer.Serialize(settings));
File.WriteAllText(FileName, JsonSerializer.Serialize(settings, new JsonSerializerOptions { WriteIndented = true }));
}

public static void Init()
Expand Down

0 comments on commit 16db151

Please sign in to comment.