private bool ConnectUsingPlugin(Plugin plugin, ServerCfg configuration) { Logger.Log(this, $"Connecting plugin: {plugin.ServerType}:{plugin.ServerName}"); var client = new ChatClient(plugin, configuration); // If the plugin loses connection, we need to dispose of all the state associated with it. plugin.OnConnectionLost += (_, __) => client.Dispose(); // When that's done, we can try reconnecting. plugin.OnConnectionLost += (message, exception) => HandleConnectionLoss(plugin.GetType(), configuration, message, exception); var result = client.Connect(); if (!result) { Logger.Log(this, $"Unable to connect to {plugin.ServerType}:{plugin.ServerName}", LogLevel.Error); return(false); } Logger.Log(this, "Plugin connection successful."); try { clients.Add(configuration.ServerName, client); } catch (ArgumentException) { Logger.Log(this, "Failed to add the chat server: a serverConfiguration with the same name already exists.", LogLevel.Error); plugin.Disconnect(); return(false); } return(true); }
private void TryConnect(ServerCfg server) { var intPlugins = Assembly.GetExecutingAssembly().GetTypes() .Where(type => typeof(Plugin).IsAssignableFrom(type) && !type.IsAbstract) .ToDictionary(type => type.GetCustomAttribute <ServerTypeAttribute>().ServerType); var extPlugins = new Dictionary <string, Type>(); if (Directory.Exists("plugins")) { extPlugins = Directory.GetFiles("plugins", "*.dll", SearchOption.TopDirectoryOnly) .Select(file => Assembly.LoadFile(Path.GetFullPath(file))) .SelectMany(asm => asm.GetExportedTypes() .Where(type => typeof(Plugin).IsAssignableFrom(type) && !type.IsAbstract)) .ToDictionary(type => type.GetCustomAttribute <ServerTypeAttribute>().ServerType); } Type pluginType; if (intPlugins.TryGetValue(server.ServerType, out pluginType) || extPlugins.TryGetValue(server.ServerType, out pluginType)) { chatClientManager.ConnectUsingPlugin(pluginType, server); } else { Logger.Log(this, $"Unable to connect to {server.ServerName}: no plugin of type {server.ServerType} found."); } }
internal ChatClient(Plugin plugin, ServerCfg configuration) { this.plugin = plugin; this.configuration = configuration; StatsDatabase = new StatsDatabaseManager(ConnectDatabase(configuration.Backend)); var handlers = new List <ChatClientEventHandler> { // This handler binds ChatUsers to database users and should therefore run first new BindHandler(), // Logs client events to stdout and optionally the log file new LogHandler(), // Generates statistics new StatsHandler(), // Performs channel-administrative actions new AdministrationHandler(), // Processes commands new CommandHandler() }; foreach (var handler in handlers) { handler.BindClient(this); handler.Initialise(); } var eventManager = new ChatClientEventManager(handlers); AttachEventHandlers(eventManager); }
public Connection(LogItemQueue logger, ServerCfg config) { m_Logger = logger; m_config = config; m_Logger.Push(LogLevel.WARNING, 0, "Client started"); m_Timer = new Timer(new TimerCallback(Tick), null, 1000, 100); }
private void HandleConnectionLoss(Type plugin, ServerCfg configuration, string reason, Exception ex) { if (reason == null) { if (ex == null) { Logger.Log(this, $"Connection to {configuration.ServerName} lost. Attempting to reconnect...", LogLevel.Error); } else { Logger.Log(this, $"Connection to {configuration.ServerName} lost ({ex.GetType()}: {ex.Message}) Attempting to reconnect...", LogLevel.Error); } } else { Logger.Log(this, $"Connection to {configuration.ServerName} lost ({reason}) Attempting to reconnect...", LogLevel.Warning); } if (ConnectUsingPlugin(plugin, configuration)) { Logger.Log(this, $"Successfully reconnected to {configuration.ServerName}.", LogLevel.Warning); } else { Logger.Log(this, $"Unable to reconnect to {configuration.ServerName}.", LogLevel.Error); } }
internal IrcPlugin(ServerCfg config) : base(config) { client = new IrcClient(); client.OnNetLibDebugLog += (sender, message) => Logger.Log(sender, "[NL#]" + message, LogLevel.Info); client.OnMessageReceived += MessageReceivedHandler; client.OnNickChange += NickChangeHandler; client.OnQuit += QuitHandler; }
public SlackPlugin(ServerCfg serverCfg) : base(serverCfg) { Capabilities.AllowsMultilineMessages = true; Capabilities.AtMention = true; Capabilities.SupportsSpecialCharacters = true; MessageFormatters.Add(new SlackMessagePreprocessor()); MessageFormatters.Add(new SlackMessageFormatter()); }
public CursePlugin(ServerCfg config) : base(config) { Capabilities.AllowsMultilineMessages = true; Capabilities.AtMention = true; MessageFormatters.Add(new CurseMessageFormatter()); loginCredentials = new NetworkCredential(config.Username, config.Password); client.MessageReceived += HandleMessage; client.WebsocketReconnected += () => Logger.Log(this, $"Websocket connction lost, but managed to reconnect.", LogLevel.Warning); }
public DiscordPlugin(ServerCfg cfg) : base(cfg) { client = new DiscordClient(); client.MessageReceived += (s, e) => { if (!e.Message.IsAuthor) { var user = ToChatUser(e.User); var channel = ToChatChannel(e.Channel); OnMessageReceived?.Invoke(new ChatMessage(e.Message.Timestamp, user, channel, e.Message.Text)); } }; }
public bool ConnectUsingPlugin(Type pluginType, ServerCfg configuration) { Plugin plugin; try { plugin = (Plugin)Activator.CreateInstance(pluginType, configuration); } catch (Exception e) { Logger.Log(this, $"Unable to connect to {configuration.ServerName}: An exception occured while creating the plugin ({e.GetType().Name}: {e.Message})"); return(false); } return(ConnectUsingPlugin(plugin, configuration)); }
private void Application_Startup(object sender, StartupEventArgs e) { IoC.SetupIoC();//IoC容器启用 ServerCfg.LoadServerSettings(); var clientInfoManager = IoC.Get <ClientInfoViewModel>(); clientInfoManager.GetPlayerInfo(); //获取本地的硬件信息 var log = IoC.Get <ILogWrite>(); log.WriteLog("程序启动"); var scheduleManager = IoC.Get <ProgramScheduleManager>(); MainView win = new MainView(scheduleManager); win.Show(); Application.Current.Exit += Current_Exit; }
public ProfileViewModel() { Profile = new ServerProfileNew("Server"); ServerCfg = Profile.ServerCfg; ServerCfg.ServerCfgContent = ServerCfg.ProcessFile(); }
public DingtekConnection(LogItemQueue logger, ServerCfg config) : base(logger, config) { m_Logger.Push(LogLevel.WARNING, 0, "Dingtek client started"); }
public void LoadServerCfg() { //ServerCfg = new ServerCfg { Hostname = name }; ServerCfg.ServerCfgContent = ServerCfg.ProcessFile(); }
public NagpurConnection(LogItemQueue logger, ServerCfg config) : base(logger, config) { m_Logger.Push(LogLevel.WARNING, 0, "Nagpur client started"); m_Logger.Push(LogLevel.WARNING, 0, "Nagpur Data Should Received"); }
public WialonIPSConnection(LogItemQueue logger, ServerCfg config) : base(logger, config) { m_Logger.Push(LogLevel.WARNING, 0, "Wialon client started"); }
public HttpJson(LogItemQueue logger, ServerCfg config) : base(logger, config) { m_Logger.Push(LogLevel.WARNING, 0, "HTTP/JSON client started"); ServicePointManager.DefaultConnectionLimit = 100; }
public ProfileViewModel(string name, Guid id) { Profile = new ServerProfileNew(name, id); ServerCfg = Profile.ServerCfg; ServerCfg.ServerCfgContent = ServerCfg.ProcessFile(); }
protected Plugin(ServerCfg config) { Configuration = config; }