diff --git a/ISPChk/.config/dotnet-tools.json b/ISPChk/.config/dotnet-tools.json
new file mode 100644
index 0000000..4ab9494
--- /dev/null
+++ b/ISPChk/.config/dotnet-tools.json
@@ -0,0 +1,12 @@
+{
+ "version": 1,
+ "isRoot": true,
+ "tools": {
+ "dotnet-ef": {
+ "version": "5.0.2",
+ "commands": [
+ "dotnet-ef"
+ ]
+ }
+ }
+}
\ No newline at end of file
diff --git a/ISPChk/ISPChk.csproj b/ISPChk/ISPChk.csproj
index 9608c3c..615b32f 100644
--- a/ISPChk/ISPChk.csproj
+++ b/ISPChk/ISPChk.csproj
@@ -2,6 +2,7 @@
net5.0
+ 0f3cc2c5-5728-4cf6-b618-bda6124ebd51
diff --git a/ISPChk/NetworkTest.cs b/ISPChk/NetworkTest.cs
index 0f271fc..cb4a48f 100644
--- a/ISPChk/NetworkTest.cs
+++ b/ISPChk/NetworkTest.cs
@@ -15,11 +15,7 @@ namespace ISPChk
private ISPChkContext _context;
public NetworkTest() {
- var optionsBuilder = new DbContextOptionsBuilder();
- optionsBuilder.UseSqlite("Data Source=ispchk.db");
- _context = new ISPChkContext(optionsBuilder.Options);
- System.Diagnostics.Debug.WriteLine("NetworkTest instantiated.");
- _context.Database.EnsureCreated();
+ _context = CreateDbContext();
}
public async void LoadHostsFromDatabase()
@@ -31,10 +27,25 @@ namespace ISPChk
}
}
+ private ISPChkContext CreateDbContext()
+ {
+ var optionsBuilder = new DbContextOptionsBuilder();
+ optionsBuilder.UseSqlite("Data Source=ispchk.db");
+ var ctx = new ISPChkContext(optionsBuilder.Options);
+ System.Diagnostics.Debug.WriteLine("NetworkTest instantiated.");
+ ctx.Database.EnsureCreated();
+ return ctx;
+ }
+
private void StartPing(Host host)
{
var t = Task.Run(async () => {
+ // Do not use the outer context, not threadsafe?
+ var ctx = CreateDbContext();
+ var h = await ctx.Hosts.FindAsync(host.HostId);
+ ctx.Entry(h).Collection(hst => hst.PingItems).Load();
+
Ping pingSender = new Ping();
// Create a buffer of 32 bytes of data to be transmitted.
@@ -42,7 +53,7 @@ namespace ISPChk
byte[] buffer = Encoding.ASCII.GetBytes(data);
// Wait 10 seconds for a reply.
- int timeout = 5000;
+ int timeout = 3000;
// Set options for transmission:
// The data can go through 64 gateways or routers
@@ -54,12 +65,13 @@ namespace ISPChk
while (true)
{
+ int numPings = 5;
long min = timeout + 1;
long max = 0;
long avg = 0;
int successes = 0;
int failures = 0;
- for (var i = 0; i < 5; ++i)
+ for (var i = 0; i < numPings; ++i)
{
// Send the request.
PingReply reply = pingSender.Send(host.HostName, timeout, buffer, options);
@@ -89,12 +101,18 @@ namespace ISPChk
}
Thread.Sleep(500);
}
- avg = avg / successes;
+ if(successes > 0)
+ avg = avg / successes;
+ // FIXME: This is dirty but I don't want the graph to explode
+ if (min > timeout)
+ min = 0;
System.Diagnostics.Debug.WriteLine("min:" + min + " max:" + max + " avg:" + avg);
PingItem pi = new PingItem { Date = DateTimeOffset.UtcNow, Min = min, Max = max, Avg = avg, Failures = failures };
- host.PingItems.Add(pi);
- _context.SaveChanges();
- Thread.Sleep(5000);
+ h.PingItems.Add(pi);
+ ctx.SaveChanges();
+ // Throttle if everything is ok
+ if(successes == numPings)
+ Thread.Sleep(5000);
}
});
}
diff --git a/ISPChk/ispchk.db b/ISPChk/ispchk.db
index 0c73603..5499520 100644
Binary files a/ISPChk/ispchk.db and b/ISPChk/ispchk.db differ
diff --git a/ISPChk/ispchk.db-shm b/ISPChk/ispchk.db-shm
deleted file mode 100644
index 00b00ed..0000000
Binary files a/ISPChk/ispchk.db-shm and /dev/null differ
diff --git a/ISPChk/ispchk.db-wal b/ISPChk/ispchk.db-wal
deleted file mode 100644
index 9559866..0000000
Binary files a/ISPChk/ispchk.db-wal and /dev/null differ