Skip to content

Commit

Permalink
Closes #26
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaCarroll committed Jul 12, 2022
1 parent 9213ba7 commit e93e3ef
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
18 changes: 10 additions & 8 deletions gisreporter_/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Reflection;
using System.Diagnostics;
using System.IO.Compression;
using Utilties;

namespace gisreporter_
{
Expand All @@ -24,7 +25,7 @@ class Program

static void Main(string[] args)
{
Version = 1.26;
Version = 1.27;


// Initialize global variables
Expand Down Expand Up @@ -110,7 +111,7 @@ private static void CheckWinlinkMessages(string path)
string suffix = "s";
if (mapItems.Count < 2) { suffix = ""; }

Console.WriteLine(String.Format("Sending {0} new message{1} to the server...", mapItems.Count, suffix));
Console.WriteLine(String.Format(Environment.NewLine + "Sending {0} new message{1} to the server...", mapItems.Count, suffix));

string json = JsonSerializer.Serialize(mapItems);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(gisReceiverUrl);
Expand All @@ -124,7 +125,7 @@ private static void CheckWinlinkMessages(string path)
try
{
res = (HttpWebResponse)req.GetResponse();
Console.WriteLine(" Server response: " + res.StatusDescription);
Console.WriteLine(" - Server response: " + res.StatusDescription);

if (res.StatusCode == HttpStatusCode.OK)
{
Expand Down Expand Up @@ -165,9 +166,10 @@ private static void ProcessFiles(string[] files)
{
if (mapItems.Count == 0)
{
Console.Write(Environment.NewLine);
Console.Write(Environment.NewLine + Environment.NewLine);
Console.WriteLine("New messages received...");
}
Console.WriteLine(String.Format(" - {0} received from {1} at {2}", msg.MessageSubject, msg.SendersCallsign, msg.DateTimeSent));
Console.WriteLine(String.Format(" - {0} received from {1} at {2}", msg.MessageSubject, msg.SendersCallsign, msg.DateTimeSent));
MapItem mapItem = msg.ToMapItem();
mapItems.Add(mapItem);
}
Expand Down Expand Up @@ -225,14 +227,14 @@ An updated version is available. Is is strongly recommended to update now.
Your version: " + Version + @"
New version: " + latestVersion + @"
Proceed with the update? (Y/N)
Proceed with the update? (Y/n)
*************************************************************
?: ");

string input = Console.ReadLine();
if (input.Trim().ToUpper() == "Y")
string input = Reader.ReadLine("n", 10000);
if ((input.Trim().ToUpper() == "Y") || (input.Trim() == ""))
{
// Find the zip file
int zipfileAssetIndex = -1;
Expand Down
46 changes: 45 additions & 1 deletion gisreporter_/Utilities.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.IO;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;

namespace Utilties
{
Expand Down Expand Up @@ -60,4 +62,46 @@ public static void ChangeLine(string fileName, string newText, int line_to_edit)
}

}
public class Reader
{
private static Thread inputThread;
private static AutoResetEvent getInput, gotInput;
private static string input;

static Reader()
{
getInput = new AutoResetEvent(false);
gotInput = new AutoResetEvent(false);
inputThread = new Thread(reader);
inputThread.IsBackground = true;
inputThread.Start();
}

private static void reader()
{
while (true)
{
getInput.WaitOne();
input = Console.ReadLine();
gotInput.Set();
}
}

// omit the parameter to read a line without a timeout
public static string ReadLine(string defaultValue, int timeOutMillisecs = Timeout.Infinite)
{
getInput.Set();
bool success = gotInput.WaitOne(timeOutMillisecs);
if (success)
{
return input;
}
else
{
//timed out
Console.WriteLine("N");
return defaultValue;
}
}
}
}

0 comments on commit e93e3ef

Please sign in to comment.