private static bool ProcessFeed(FeedDefinition feed) { Console.WriteLine(feed.Name + "..."); try { using (var dl = new Downloader(feed)) { dl.Process(); } return(true); } catch (Exception ex) { feed.LatestError = ex.Message; while (ex != null) { Console.WriteLine(new string('-', 20)); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); ex = ex.InnerException; } } return(false); }
public Downloader(FeedDefinition feed) { this.feed = feed ?? throw new ArgumentNullException(nameof(feed)); this.baseDownloadPath = ConfigManager.Instance.GetCurrentConfig().BasePath; this.useSeparateFeedFolder = ConfigManager.Instance.GetCurrentConfig().UseSeparateFolders; var logpath = Path.Combine(this.baseDownloadPath, "__Logging"); EnsureFolderExists(logpath); logpath = Path.Combine(logpath, CleanupFilename(feed.Name) + ".txt"); this.logger = File.AppendText(logpath); this.logger.WriteLine(new string('=', 20) + " " + DateTime.Now.ToString(CultureInfo.CurrentCulture)); }
private static async Task <bool> ProcessFeed(FeedDefinition feed, DirectoryInfo basePath) { try { LoggerSingleton.Value.Log(LogLevel.Information, nameof(Program), $">> Starting on feed '{feed.Name}' from {feed.LatestDownload:yyyy-MM-dd}."); using (var dl = new Downloader(feed, basePath)) { await dl.Process(); } LoggerSingleton.Value.Log(LogLevel.Information, nameof(Program), $"<< Finished feed {feed.Name}. Up to date until {feed.LatestDownload:yyyy-MM-dd}."); return(true); } catch (Exception ex) { feed.LatestError = ex.Message; LoggerSingleton.Value.Log(LogLevel.Error, nameof(Program), nameof(ProcessFeed), ex); } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="Downloader"/> class. /// </summary> /// <param name="feed">The feed.</param> /// <param name="basePath">The base path.</param> /// <exception cref="ArgumentNullException">feed cannot be null.</exception> public Downloader(FeedDefinition feed, DirectoryInfo basePath) { this.feed = feed ?? throw new ArgumentNullException(nameof(feed)); this.baseDownloadPath = Path.Combine(basePath.FullName, "files"); }