private async void OnIrcClientConnectionStatusEvent(object sender, IrcClientConnectionStatusArgs args) { DebugHandler.TraceMessage("OnIrcClientConnectionStatusEvent called.", DebugSource.TASK, DebugType.ENTRY_EXIT); DebugHandler.TraceMessage(args.ToString(), DebugSource.TASK, DebugType.PARAMETERS); IsIrcConnected = args.Connected; try { JsonIrcInfo update = new JsonIrcInfo() { connected = args.Connected, channel = args.CurrentIrcSettings.Channels, server = args.CurrentIrcSettings.ServerAddress, user = args.CurrentIrcSettings.UserName, fullfilepath = args.CurrentIrcSettings.fullfilepath }; await WebSocketHandler.SendMessage(update.ToJson()); } catch (Exception e) { DebugHandler.TraceMessage(e.ToString(), DebugSource.TASK, DebugType.ERROR); JsonError error = new JsonError() { type = "irc_status_error", errormessage = "Error on sending irc status update to client.", errortype = "exception", exception = e.ToString() }; await WebSocketHandler.SendMessage(error.ToJson()); } }
public async Task GetCurrentIrcSettings() { DebugHandler.TraceMessage("GetCurrentIrcSettings Called.", DebugSource.TASK, DebugType.ENTRY_EXIT); IrcSettings = SettingsHandler.GetIrcSettings(); JsonIrcInfo info = new JsonIrcInfo() { channel = IrcSettings.Channels, server = IrcSettings.ServerAddress, user = IrcSettings.UserName, fullfilepath = IrcSettings.fullfilepath }; await WebSocketHandler.SendMessage(info.ToJson()); }
public async Task Disconnect() { DebugHandler.TraceMessage("Disconnect called.", DebugSource.TASK, DebugType.ENTRY_EXIT); bool succes = false; try { succes = IrcClientHandler.StopConnection(); JsonIrcInfo ircInfo = new JsonIrcInfo() { connected = !succes, channel = IrcSettings.Channels, server = IrcSettings.ServerAddress, user = IrcSettings.UserName, fullfilepath = IrcSettings.fullfilepath }; await WebSocketHandler.SendMessage(ircInfo.ToJson()); } catch (Exception e) { DebugHandler.TraceMessage(e.ToString(), DebugSource.TASK, DebugType.WARNING); succes = IrcClientHandler.StopConnection(); JsonIrcInfo ircInfo = new JsonIrcInfo() { connected = !succes, channel = IrcSettings.Channels, server = IrcSettings.ServerAddress, user = IrcSettings.UserName, fullfilepath = IrcSettings.fullfilepath }; await WebSocketHandler.SendMessage(ircInfo.ToJson()); JsonError error = new JsonError() { type = "irc_disconnect_error", errormessage = "Could not stop connection to irc server.", errortype = "exception", exception = e.ToString() }; await WebSocketHandler.SendMessage(error.ToJson()); } }
public async Task Connect(JObject ircJson = null) { DebugHandler.TraceMessage("Connect called", DebugSource.TASK, DebugType.ENTRY_EXIT); bool succes = false; try { if (ircJson == null) { string username = IrcSettings.UserName; if (username == "") { username = UtilityMethods.GenerateUsername(LittleWeebSettings.RandomUsernameLength); } IrcSettings.UserName = username; } else { DebugHandler.TraceMessage(ircJson.ToString(), DebugSource.TASK, DebugType.INFO); string username = ircJson.Value <string>("username"); if (username == "") { username = UtilityMethods.GenerateUsername(LittleWeebSettings.RandomUsernameLength); } IrcSettings.ServerAddress = ircJson.Value <string>("address"); IrcSettings.Channels = ircJson.Value <string>("channels"); IrcSettings.UserName = username; } succes = IrcClientHandler.StartConnection(IrcSettings); if (succes) { JsonIrcInfo ircInfo = new JsonIrcInfo() { connected = succes, channel = IrcSettings.Channels, server = IrcSettings.ServerAddress, user = IrcSettings.UserName, fullfilepath = IrcSettings.fullfilepath }; await WebSocketHandler.SendMessage(ircInfo.ToJson()); } else { JsonIrcInfo ircInfo = new JsonIrcInfo() { connected = succes, channel = IrcSettings.Channels, server = IrcSettings.ServerAddress, user = IrcSettings.UserName, fullfilepath = IrcSettings.fullfilepath }; await WebSocketHandler.SendMessage(ircInfo.ToJson()); } DebugHandler.TraceMessage("Started irc connection using the following settings: " + IrcSettings.ToString(), DebugSource.TASK, DebugType.INFO); SettingsHandler.WriteIrcSettings(IrcSettings); } catch (Exception e) { DebugHandler.TraceMessage(e.ToString(), DebugSource.TASK, DebugType.WARNING); JsonIrcInfo ircInfo = new JsonIrcInfo() { connected = succes, channel = IrcSettings.Channels, server = IrcSettings.ServerAddress, user = IrcSettings.UserName, fullfilepath = IrcSettings.fullfilepath }; await WebSocketHandler.SendMessage(ircInfo.ToJson()); JsonError error = new JsonError() { type = "irc_connect_error", errormessage = "Could not start connection to irc server.", errortype = "exception", exception = e.ToString() }; await WebSocketHandler.SendMessage(error.ToJson()); } IsIrcConnected = succes; }