diff --git a/RhinoReminds/ClientListener.cs b/RhinoReminds/ClientListener.cs index aedab14..53e4cb0 100644 --- a/RhinoReminds/ClientListener.cs +++ b/RhinoReminds/ClientListener.cs @@ -15,10 +15,15 @@ using SBRL.Geometry; namespace RhinoReminds { + public class OnConnectedEventArgs : EventArgs { } + public delegate void OnConnectedHandler(object sender, OnConnectedEventArgs eventArgs); + public class ClientListener { public bool Debug { get; set; } = false; + public event OnConnectedHandler OnConnected; + public readonly string Jid; public string Username => Jid.Split('@')[0]; public string Hostname => Jid.Split('@')[1]; @@ -89,6 +94,7 @@ namespace RhinoReminds } Console.WriteLine($"[Rhino/Setup] Connected as {Jid}"); + OnConnected(this, new OnConnectedEventArgs()); return true; } @@ -109,7 +115,7 @@ namespace RhinoReminds { Console.Error.WriteLine($"[Error] {e.Reason}: {e.Exception}"); - if(!client.Connected) + if(!client.Connected || e.Exception is IOException) { Console.Error.WriteLine($"[Error/Handler] Reconnecting in {TimeSpan.FromSeconds(nextBackoffDelay).ToString()}."); Thread.Sleep(nextBackoffDelay * 1000); diff --git a/RhinoReminds/Program.cs b/RhinoReminds/Program.cs index b812492..5a13ccb 100644 --- a/RhinoReminds/Program.cs +++ b/RhinoReminds/Program.cs @@ -84,13 +84,16 @@ namespace RhinoReminds ReminderFilePath = settings.Filepath }; client.AllowedDomains.Add(settings.AllowedDomain); - // Connect to the server & start listening - Task clientListener = client.Start(); // Update the avatar if appropriate - if(settings.AvatarFilepath != string.Empty) - client.SetAvatar(settings.AvatarFilepath); + if (settings.AvatarFilepath != string.Empty) { + client.OnConnected += (object sender, OnConnectedEventArgs eventArgs) => { + client.SetAvatar(settings.AvatarFilepath); + Console.WriteLine($"[Program] Set avatar to '{settings.AvatarFilepath}'."); + }; + } + // Connect to the server & start listening // Make sure the program doesn't exit whilst we're connected - clientListener.Wait(); + client.Start().Wait(); } } } diff --git a/RhinoReminds/RhinoReminds.csproj b/RhinoReminds/RhinoReminds.csproj index bf2fddc..b851a2d 100644 --- a/RhinoReminds/RhinoReminds.csproj +++ b/RhinoReminds/RhinoReminds.csproj @@ -43,19 +43,19 @@ - ..\packages\Microsoft.Recognizers.Text.1.1.3\lib\net462\Microsoft.Recognizers.Definitions.dll + ..\packages\Microsoft.Recognizers.Text.1.1.4\lib\net462\Microsoft.Recognizers.Definitions.dll - ..\packages\Microsoft.Recognizers.Text.1.1.3\lib\net462\Microsoft.Recognizers.Text.dll + ..\packages\Microsoft.Recognizers.Text.1.1.4\lib\net462\Microsoft.Recognizers.Text.dll - ..\packages\Microsoft.Recognizers.Text.Number.1.1.3\lib\net462\Microsoft.Recognizers.Text.Number.dll + ..\packages\Microsoft.Recognizers.Text.Number.1.1.4\lib\net462\Microsoft.Recognizers.Text.Number.dll - ..\packages\Microsoft.Recognizers.Text.NumberWithUnit.1.1.3\lib\net462\Microsoft.Recognizers.Text.NumberWithUnit.dll + ..\packages\Microsoft.Recognizers.Text.NumberWithUnit.1.1.4\lib\net462\Microsoft.Recognizers.Text.NumberWithUnit.dll - ..\packages\Microsoft.Recognizers.Text.DateTime.1.1.3\lib\net462\Microsoft.Recognizers.Text.DateTime.dll + ..\packages\Microsoft.Recognizers.Text.DateTime.1.1.4\lib\net462\Microsoft.Recognizers.Text.DateTime.dll diff --git a/RhinoReminds/packages.config b/RhinoReminds/packages.config index e51b60d..c938836 100644 --- a/RhinoReminds/packages.config +++ b/RhinoReminds/packages.config @@ -1,9 +1,9 @@  - - - - + + + +