public IrcSettings GetIrcSettings() { DebugHandler.TraceMessage("GetIrcSettings called.", DebugSource.TASK, DebugType.ENTRY_EXIT); IrcSettings toReturn = new IrcSettings(); try { string settingsName = "IrcSettings.json"; if (File.Exists(Path.Combine(SettingsPath, settingsName))) { string settingsJson = ""; using (var fileStream = File.Open(Path.Combine(SettingsPath, settingsName), FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) { using (var streamReader = new StreamReader(fileStream)) { string readLine = ""; while ((readLine = streamReader.ReadLine()) != null) { settingsJson += readLine; } } } toReturn = JsonConvert.DeserializeObject <IrcSettings>(settingsJson); DebugHandler.TraceMessage("Returning read ircsettings: " + toReturn, DebugSource.TASK, DebugType.INFO); } } catch (Exception e) { DebugHandler.TraceMessage(e.ToString(), DebugSource.TASK, DebugType.WARNING); } return(toReturn); }
public DownloadWebSocketService( IWebSocketHandler webSocketHandler, IDirectoryHandler directoryHandler, IDownloadHandler downloadHandler, IFileHandler fileHandler, IFileHistoryHandler fileHistoryHandler, ISettingsHandler settingsHandler, IDebugHandler debugHandler) { debugHandler.TraceMessage("Constructor called.", DebugSource.CONSTRUCTOR, DebugType.ENTRY_EXIT); DebugHandler = debugHandler; WebSocketHandler = webSocketHandler; DirectoryHandler = directoryHandler; DownloadHandler = downloadHandler; FileHandler = fileHandler; FileHistoryHandler = fileHistoryHandler; SettingsHandler = settingsHandler; LastDownloadedInfo = new JsonDownloadInfo(); LittleWeebSettings = SettingsHandler.GetLittleWeebSettings(); IrcSettings = SettingsHandler.GetIrcSettings(); downloadHandler.OnDownloadUpdateEvent += OnDownloadUpdateEvent; }
public Task SetSettingsClasses( ISettingsHandler settingsHandler, IIrcClientHandler ircClientHandler, IFileHandler fileHandler, IDownloadHandler downloadHandler, IDirectoryWebSocketService directoryWebSocketService, IIrcWebSocketService ircWebSocketService ) { DebugHandler.TraceMessage("SetSettingsClasses Called.", DebugSource.TASK, DebugType.ENTRY_EXIT); SettingsHandler = settingsHandler; IrcClientHandler = ircClientHandler; DownloadHandler = downloadHandler; DirectoryWebSocketService = directoryWebSocketService; IrcWebSocketService = ircWebSocketService; WebSocketHandlerSettings = WebSocketHandler as ISettingsInterface; IrcClientHandlerSettings = ircClientHandler as ISettingsInterface; DebugHandlerSettings = DebugHandler as ISettingsInterface; FileHandlerSettings = fileHandler as ISettingsInterface; DownloadHandlerSettings = downloadHandler as ISettingsInterface; DirectoryWebSocketServiceSettings = directoryWebSocketService as ISettingsInterface; IrcWebSocketServiceSettings = ircWebSocketService as ISettingsInterface; LittleWeebSettings = settingsHandler.GetLittleWeebSettings(); IrcSettings = settingsHandler.GetIrcSettings(); SetAllIrcSettings(IrcSettings); SetAllLittleWeebSettings(LittleWeebSettings); return(Task.CompletedTask); }
public async Task SetIrcSettings(JObject jsonIrcSettings) { DebugHandler.TraceMessage("SetIrcSettings Called.", DebugSource.TASK, DebugType.ENTRY_EXIT); DebugHandler.TraceMessage(jsonIrcSettings.ToString(), DebugSource.TASK, DebugType.PARAMETERS); try { IrcSettings = SettingsHandler.GetIrcSettings(); IrcSettings.ServerAddress = jsonIrcSettings.Value <string>("address"); IrcSettings.Channels = jsonIrcSettings.Value <string>("channels"); IrcSettings.UserName = jsonIrcSettings.Value <string>("username"); IrcSettings.fullfilepath = jsonIrcSettings.Value <string>("fullfilepath"); IrcSettings.Port = jsonIrcSettings.Value <int>("port"); IrcSettings.Secure = jsonIrcSettings.Value <bool>("secure"); SetAllIrcSettings(IrcSettings); SettingsHandler.WriteIrcSettings(IrcSettings); await GetCurrentIrcSettings(); } catch (Exception e) { DebugHandler.TraceMessage(e.ToString(), DebugSource.TASK, DebugType.WARNING); JsonError jsonError = new JsonError { type = "set_irc_settings_error", errortype = "Exception", errormessage = "Failed to set irc settings.", exception = e.ToString() }; await WebSocketHandler.SendMessage(jsonError.ToJson()); } }
private void SetAllIrcSettings(IrcSettings settings) { DebugHandler.TraceMessage("SetAllIrcSettings Called.", DebugSource.TASK, DebugType.ENTRY_EXIT); DebugHandler.TraceMessage(settings.ToString(), DebugSource.TASK, DebugType.PARAMETERS); IrcClientHandlerSettings.SetIrcSettings(settings); FileHandlerSettings.SetIrcSettings(settings); DownloadHandlerSettings.SetIrcSettings(settings); DirectoryWebSocketServiceSettings.SetIrcSettings(settings); IrcWebSocketServiceSettings.SetIrcSettings(settings); }
public IrcClient( IOptions <IrcSettings> config, ILogger <IrcClient> logger) { _config = config.Value; _logger = logger; Connect(); _inputTask = StartInputHandler(); _outputTask = StartOutputHandler(); }
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 IrcWebSocketService(IWebSocketHandler webSocketHandler, IIrcClientHandler ircClientHandler, ISettingsHandler settingsHandler, IDebugHandler debugHandler) { debugHandler.TraceMessage("IrcWebSocketService Constructor called.", DebugSource.CONSTRUCTOR, DebugType.ENTRY_EXIT); SendMessageToWebSocketClient = false; IsIrcConnected = false; SettingsHandler = settingsHandler; IrcClientHandler = ircClientHandler; WebSocketHandler = webSocketHandler; DebugHandler = debugHandler; LittleWeebSettings = SettingsHandler.GetLittleWeebSettings(); IrcSettings = SettingsHandler.GetIrcSettings(); IrcClientHandler.OnIrcClientMessageEvent += OnIrcClientMessageEvent; IrcClientHandler.OnIrcClientConnectionStatusEvent += OnIrcClientConnectionStatusEvent; }
public IrcClientHandler(ISettingsHandler settingsHandler, IDebugHandler debugHandler) { debugHandler.TraceMessage("Constructor Called.", DebugSource.CONSTRUCTOR, DebugType.ENTRY_EXIT); SettingsHandler = settingsHandler; DebugHandler = debugHandler; IrcSettings = SettingsHandler.GetIrcSettings(); LittleWeebSettings = SettingsHandler.GetLittleWeebSettings(); IrcClient = new SimpleIRC(); IrcClient.SetCustomDownloadDir(IrcSettings.fullfilepath); IrcClient.IrcClient.OnUserListReceived += OnUserListUpdate; IrcClient.IrcClient.OnMessageReceived += OnMessage; IrcClient.IrcClient.OnDebugMessage += OnMessageDebug; IrcClient.DccClient.OnDccEvent += OnDownloadUpdate; IrcClient.DccClient.OnDccDebugMessage += OnDownloadUpdateDebug; }
public bool StartConnection(IrcSettings settings = null) { DebugHandler.TraceMessage("StartConnection Called.", DebugSource.TASK, DebugType.ENTRY_EXIT); try { if (settings != null) { DebugHandler.TraceMessage(settings.ToString(), DebugSource.TASK, DebugType.PARAMETERS); IrcSettings = settings; } IrcClient.SetupIrc(IrcSettings.ServerAddress, IrcSettings.UserName, IrcSettings.Channels, IrcSettings.Port, "", 3000, IrcSettings.Secure); Thread.Sleep(500); if (!IrcClient.StartClient()) { OnIrcClientConnectionStatusEvent?.Invoke(this, new IrcClientConnectionStatusArgs() { Connected = false, ChannelsAndUsers = null }); DebugHandler.TraceMessage("Irc client is could not connect!", DebugSource.TASK, DebugType.WARNING); return(false); } else { DebugHandler.TraceMessage("Irc client is succesfully connected!", DebugSource.TASK, DebugType.INFO); return(true); } } catch (Exception e) { DebugHandler.TraceMessage(e.ToString(), DebugSource.TASK, DebugType.ERROR); return(false); } }
public void WriteIrcSettings(IrcSettings ircSettings) { DebugHandler.TraceMessage("WriteIrcSettings Called.", DebugSource.TASK, DebugType.ENTRY_EXIT); DebugHandler.TraceMessage(ircSettings.ToString(), DebugSource.TASK, DebugType.PARAMETERS); try { string settingsName = "IrcSettings.json"; string settingsJson = JsonConvert.SerializeObject(ircSettings); if (!File.Exists(Path.Combine(SettingsPath, settingsName))) { using (var fileStream = File.Open(Path.Combine(SettingsPath, settingsName), FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite)) { using (var streamWriter = new StreamWriter(fileStream)) { streamWriter.Write(settingsJson); } } } else { using (var fileStream = File.Open(Path.Combine(SettingsPath, settingsName), FileMode.Truncate, FileAccess.ReadWrite, FileShare.ReadWrite)) { using (var streamWriter = new StreamWriter(fileStream)) { streamWriter.Write(settingsJson); } } } } catch (Exception e) { DebugHandler.TraceMessage(e.ToString(), DebugSource.TASK, DebugType.WARNING); } }
public void SetIrcSettings(IrcSettings settings) { DebugHandler.TraceMessage("SetIrcSettings called.", DebugSource.TASK, DebugType.ENTRY_EXIT); DebugHandler.TraceMessage(settings.ToString(), DebugSource.TASK, DebugType.PARAMETERS); IrcSettings = settings; }
public void SetIrcSettings(IrcSettings settings) { }