From 16db151176a6b7064937126146f4f1fcb5539043 Mon Sep 17 00:00:00 2001 From: davidlep Date: Wed, 3 Feb 2021 17:46:58 -0500 Subject: [PATCH] Target Net 5.0 + Fix issues --- Pinger/Dataset.cs | 1 + Pinger/Pinger.csproj | 2 +- Pinger/PingerAppContext.cs | 29 ++++++++++++++++++++++++----- Pinger/Settings.cs | 4 ++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Pinger/Dataset.cs b/Pinger/Dataset.cs index 7bdfda2..4ca46da 100644 --- a/Pinger/Dataset.cs +++ b/Pinger/Dataset.cs @@ -31,6 +31,7 @@ public static void Write(Record record) using (var csv = new CsvWriter(writer, config)) { csv.WriteRecord(record); + csv.NextRecord(); } } diff --git a/Pinger/Pinger.csproj b/Pinger/Pinger.csproj index dd26878..2b93f7a 100644 --- a/Pinger/Pinger.csproj +++ b/Pinger/Pinger.csproj @@ -2,7 +2,7 @@ WinExe - netcoreapp3.1 + net5.0-windows true diff --git a/Pinger/PingerAppContext.cs b/Pinger/PingerAppContext.cs index 4fb728b..203daca 100644 --- a/Pinger/PingerAppContext.cs +++ b/Pinger/PingerAppContext.cs @@ -6,6 +6,7 @@ namespace Pinger { public class PingerAppContext : ApplicationContext { + private string AppVersion = "1.0"; private NotifyIcon trayIcon; private Container components = new Container(); @@ -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); } } } diff --git a/Pinger/Settings.cs b/Pinger/Settings.cs index 35d9673..4302444 100644 --- a/Pinger/Settings.cs +++ b/Pinger/Settings.cs @@ -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() { @@ -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()