Beispiel #1
0
        public DownloadService(string host, int port, Func <IrcAnimeDbContext> getContext, IFtpClient ftpClient, Filesystem.Directory downloadDirectory, IModuleLogger moduleLogger)
        {
            this.logger             = moduleLogger.CreateSubLogger("Download-Service");
            this.requestedDownloads = new ConcurrentDictionary <string, CreateDownloaderContext>();
            this.downloadStatus     = new ConcurrentDictionary <string, DownloadProgress>();

            var ircClient = new IrcClient.Clients.IrcClient(
                (c) =>
            {
                c.MessageReceived += (m) => this.logger.Log(LogLevel.Debug, $"Received \"{m}\"");
                c.MessageSent     += (m) => this.logger.Log(LogLevel.Debug, $"Sent \"{m}\"");

                c.AddHandler(new IrcHandler(c));
                c.AddHandler(new CtcpHandler(c));
                c.AddHandler(
                    new DccHandler(c)
                {
                    FileReceived = (c) =>
                    {
                        this.logger.Info($"Received incoming filedownload '{c.Filename}'");
                        if (this.requestedDownloads.TryGetValue(c.Filename, out var context))
                        {
                            context.Downloader = c;
                            context.ManualResetEvent.Set();
                        }
                    }
                }
                    );
            }
Beispiel #2
0
        public async Task Load(IDatabaseConnector databaseConnector, IFtpClient ftpClient, Directory moduleDirectory, IModuleLogger moduleLogger)
        {
            this.connectionString =
                await databaseConnector.GetDatabaseConnectionStringAsync(Guid.Parse(Id), DatabasePassword);

            this.moduleDirectory   = moduleDirectory;
            this.downloadDirectory = new Directory("Files", moduleDirectory);

            using (var context = this.GetContext())
            {
                await context.Database.EnsureCreatedAsync();
            }

            this.searchService   = new SearchService(moduleLogger.CreateSubLogger("Search-Service"));
            this.downloadService = new DownloadService("irc.rizon.net", 6667, this.GetContext, ftpClient, downloadDirectory, moduleLogger);

            this.GrpcServices = new[] { IrcAnimeService.BindService(new IrcAnimeImplementation(this.searchService, this.downloadService, this.GetContext, ftpClient, downloadDirectory, moduleLogger.CreateSubLogger("GRPC-Implementation"))), };

            moduleLogger.Log(NLog.LogLevel.Info, "IrcAnime loaded successfully");
        }