Skip to content

Commit

Permalink
Tweaks and logging changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SirSparkles committed May 21, 2023
1 parent d1da91f commit e4646b6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion TVRename/App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private static void Main(string[] args)
{
// Already running
Logger.Warn("An instance is already running, exiting");
singleInstanceService.SendArgumentsToExistingInstance();
SingleInstanceService.SendArgumentsToExistingInstance();
return;
}

Expand Down
14 changes: 6 additions & 8 deletions TVRename/App/SingleInstanceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ namespace TVRename.App;

internal class SingleInstanceService
{
private const string localHost = "127.0.0.1";
private const int localPort = 19191;
private const string LOCAL_HOST = "127.0.0.1";
private const int LOCAL_PORT = 19191;
private readonly Action<string[]> onArgumentsReceived;
private static readonly NLog.Logger Log = NLog.LogManager.GetCurrentClassLogger();
// ReSharper disable once NotAccessedField.Local
private Semaphore? semaphore;
private readonly string semaphoreName = $"Global\\{Environment.MachineName}-myAppName{Assembly.GetExecutingAssembly().GetName().Version}-sid{Process.GetCurrentProcess().SessionId}";

Expand All @@ -37,14 +38,11 @@ internal bool IsFirstInstance()
}
}

public void SendArgumentsToExistingInstance()
{
Task.Run(SendArguments);
}
public static void SendArgumentsToExistingInstance() => Task.Run(SendArguments);

private void ListenForArguments()
{
TcpListener tcpListener = new(IPAddress.Parse(localHost), localPort);
TcpListener tcpListener = new(IPAddress.Parse(LOCAL_HOST), LOCAL_PORT);
try
{
tcpListener.Start();
Expand Down Expand Up @@ -85,7 +83,7 @@ private static void SendArguments()
{
try
{
using TcpClient tcpClient = new(localHost, localPort);
using TcpClient tcpClient = new(LOCAL_HOST, LOCAL_PORT);
using NetworkStream networkStream = tcpClient.GetStream();
string[] commandLineArgs = Environment.GetCommandLineArgs();
string message = commandLineArgs.Length > 1
Expand Down
5 changes: 5 additions & 0 deletions TVRename/Utility/BT/BEncodeLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ private BTItem ReadNext(System.IO.FileStream sr)
{
sr = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
}
catch (System.IO.IOException e)
{
Logger.Warn(e.Message);
return null;
}
catch (Exception e)
{
Logger.Error(e);
Expand Down
4 changes: 2 additions & 2 deletions TVRename/Utility/Helper/TimeHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ private static NtpClock GetClock()
{
Logger.Info($"Connected to NTP Server at UTC (based on local clock) {DateTime.UtcNow}");
ClockInstance = NtpClient.Default.Query();
Logger.Info($"Finished connecting to NTP Server at UTC (based on local clock) {DateTime.UtcNow}");
Logger.Info($"Finished connecting to NTP Server at UTC (based on local clock) {DateTime.UtcNow} - Offset = {ClockInstance.CorrectionOffset}");
if (ClockInstance.CorrectionOffset > 20.Seconds())
{
Logger.Error($"Discrepancy for systemtime of {DateTime.UtcNow} to {ClockInstance.UtcNow.UtcDateTime}");
Logger.Warn($"Discrepancy for systemtime of {DateTime.UtcNow} to {ClockInstance.UtcNow.UtcDateTime}");
}
}
return ClockInstance;
Expand Down

0 comments on commit e4646b6

Please sign in to comment.