Exemple #1
0
        public async Task <IEnumerable <string> > GetFilesAsync(Directory directory, CancellationToken cancellationToken)
        {
            this.logger.Info("Getting files for path: {value1}", directory.FullPath(Separator));
            var request = this.CreateRequest(directory.FullPath(Separator));

            request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
            using var cancellationRegister = cancellationToken.Register(() => request.Abort());

            using var response = await request.GetResponseAsync();

            await using var responseStream = response.GetResponseStream();

            if (responseStream != null)
            {
                using var streamReader = new StreamReader(responseStream);

                return((await streamReader.ReadToEndAsync().ConfigureAwait(false))
                       .Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries));
            }

            return(Array.Empty <string>());
        }
Exemple #2
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();
                        }
                    }
                }
                    );
            }