diff --git a/src/TumblThree/TumblThree.Applications/Crawler/TumblrBlogCrawler.cs b/src/TumblThree/TumblThree.Applications/Crawler/TumblrBlogCrawler.cs index 578752bc..5fe2a29d 100644 --- a/src/TumblThree/TumblThree.Applications/Crawler/TumblrBlogCrawler.cs +++ b/src/TumblThree/TumblThree.Applications/Crawler/TumblrBlogCrawler.cs @@ -418,6 +418,11 @@ private async Task CrawlPageAsync(int pageNumber) incompleteCrawl = true; HandleTimeoutException(timeoutException, Resources.Crawling); } + catch (FormatException formatException) + { + Logger.Error("TumblrBlogCrawler:CrawlPageAsync: {0}", formatException); + ShellService.ShowError(formatException, "{0}: {1}", Blog.Name, formatException.Message); + } catch (Exception e) { Logger.Error("TumblrBlogCrawler.CrawlPageAsync: {0}", e); @@ -436,24 +441,31 @@ private bool PostWithinTimeSpan(Post post) return true; } - long downloadFromUnixTime = 0; - long downloadToUnixTime = long.MaxValue; - if (!string.IsNullOrEmpty(Blog.DownloadFrom)) + try { - DateTime downloadFrom = DateTime.ParseExact(Blog.DownloadFrom, "yyyyMMdd", CultureInfo.InvariantCulture, - DateTimeStyles.None); - downloadFromUnixTime = new DateTimeOffset(downloadFrom).ToUnixTimeSeconds(); - } + long downloadFromUnixTime = 0; + long downloadToUnixTime = long.MaxValue; + if (!string.IsNullOrEmpty(Blog.DownloadFrom)) + { + DateTime downloadFrom = DateTime.ParseExact(Blog.DownloadFrom, "yyyyMMdd", CultureInfo.InvariantCulture, + DateTimeStyles.None); + downloadFromUnixTime = new DateTimeOffset(downloadFrom).ToUnixTimeSeconds(); + } - if (!string.IsNullOrEmpty(Blog.DownloadTo)) + if (!string.IsNullOrEmpty(Blog.DownloadTo)) + { + DateTime downloadTo = DateTime.ParseExact(Blog.DownloadTo, "yyyyMMdd", CultureInfo.InvariantCulture, + DateTimeStyles.None).AddDays(1); + downloadToUnixTime = new DateTimeOffset(downloadTo).ToUnixTimeSeconds(); + } + + long postTime = post.UnixTimestamp; + return downloadFromUnixTime <= postTime && postTime < downloadToUnixTime; + } + catch (System.FormatException) { - DateTime downloadTo = DateTime.ParseExact(Blog.DownloadTo, "yyyyMMdd", CultureInfo.InvariantCulture, - DateTimeStyles.None).AddDays(1); - downloadToUnixTime = new DateTimeOffset(downloadTo).ToUnixTimeSeconds(); + throw new FormatException(Resources.BlogValueHasWrongFormat); } - - long postTime = post.UnixTimestamp; - return downloadFromUnixTime <= postTime && postTime < downloadToUnixTime; } private bool CheckPostAge(TumblrApiJson response) diff --git a/src/TumblThree/TumblThree.Applications/Crawler/TumblrHiddenCrawler.cs b/src/TumblThree/TumblThree.Applications/Crawler/TumblrHiddenCrawler.cs index cac8a0ae..d4614cb0 100644 --- a/src/TumblThree/TumblThree.Applications/Crawler/TumblrHiddenCrawler.cs +++ b/src/TumblThree/TumblThree.Applications/Crawler/TumblrHiddenCrawler.cs @@ -245,6 +245,11 @@ private async Task CrawlPageAsync(int pageNumber) incompleteCrawl = true; HandleTimeoutException(timeoutException, Resources.Crawling); } + catch (FormatException formatException) + { + Logger.Error("TumblrHiddenCrawler.CrawlPageAsync: {0}", formatException); + ShellService.ShowError(formatException, "{0}: {1}", Blog.Name, formatException.Message); + } catch (Exception ex) { Logger.Error("TumblrHiddenCrawler.CrawlPageAsync: {0}", ex); @@ -307,24 +312,31 @@ private bool PostWithinTimeSpan(Post post) return true; } - long downloadFromUnixTime = 0; - long downloadToUnixTime = long.MaxValue; - if (!string.IsNullOrEmpty(Blog.DownloadFrom)) + try { - DateTime downloadFrom = DateTime.ParseExact(Blog.DownloadFrom, "yyyyMMdd", CultureInfo.InvariantCulture, - DateTimeStyles.None); - downloadFromUnixTime = new DateTimeOffset(downloadFrom).ToUnixTimeSeconds(); - } + long downloadFromUnixTime = 0; + long downloadToUnixTime = long.MaxValue; + if (!string.IsNullOrEmpty(Blog.DownloadFrom)) + { + DateTime downloadFrom = DateTime.ParseExact(Blog.DownloadFrom, "yyyyMMdd", CultureInfo.InvariantCulture, + DateTimeStyles.None); + downloadFromUnixTime = new DateTimeOffset(downloadFrom).ToUnixTimeSeconds(); + } - if (!string.IsNullOrEmpty(Blog.DownloadTo)) + if (!string.IsNullOrEmpty(Blog.DownloadTo)) + { + DateTime downloadTo = DateTime.ParseExact(Blog.DownloadTo, "yyyyMMdd", CultureInfo.InvariantCulture, + DateTimeStyles.None).AddDays(1); + downloadToUnixTime = new DateTimeOffset(downloadTo).ToUnixTimeSeconds(); + } + + long postTime = Convert.ToInt64(post.Timestamp); + return downloadFromUnixTime <= postTime && postTime < downloadToUnixTime; + } + catch (System.FormatException) { - DateTime downloadTo = DateTime.ParseExact(Blog.DownloadTo, "yyyyMMdd", CultureInfo.InvariantCulture, - DateTimeStyles.None).AddDays(1); - downloadToUnixTime = new DateTimeOffset(downloadTo).ToUnixTimeSeconds(); + throw new FormatException(Resources.BlogValueHasWrongFormat); } - - long postTime = Convert.ToInt64(post.Timestamp); - return downloadFromUnixTime <= postTime && postTime < downloadToUnixTime; } private async Task CheckIfLoggedInAsync() @@ -426,7 +438,7 @@ private async Task AddUrlsToDownloadListAsync(TumblrJson response, int crawlerNu Logger.Verbose("TumblrHiddenCrawler.AddUrlsToDownloadListAsync: {0}", e); } } - catch (Exception e) + catch (Exception e) when (!(e is FormatException)) { Logger.Error("TumblrHiddenCrawler.AddUrlsToDownloadListAsync: {0}", e); ShellService.ShowError(e, "{0}: Error parsing post!", Blog.Name); diff --git a/src/TumblThree/TumblThree.Applications/Crawler/TumblrLikedByCrawler.cs b/src/TumblThree/TumblThree.Applications/Crawler/TumblrLikedByCrawler.cs index 82ed8512..c979cd77 100644 --- a/src/TumblThree/TumblThree.Applications/Crawler/TumblrLikedByCrawler.cs +++ b/src/TumblThree/TumblThree.Applications/Crawler/TumblrLikedByCrawler.cs @@ -245,6 +245,11 @@ private async Task CrawlPageAsync(int crawlerNumber) ShellService.ShowError(limitExceededException, "{0}: {1}", Blog.Name, limitExceededException.Message); } } + catch (FormatException formatException) + { + Logger.Error("TumblrLikedByCrawler:CrawlPageAsync: {0}", formatException); + ShellService.ShowError(formatException, "{0}: {1}", Blog.Name, formatException.Message); + } catch (Exception e) { Logger.Error("TumblrLikedByCrawler:CrawlPageAsync: {0}", e); @@ -761,10 +766,16 @@ private bool CheckIfWithinTimespan(long pagination) return true; } - DateTime downloadFrom = DateTime.ParseExact(Blog.DownloadFrom, "yyyyMMdd", CultureInfo.InvariantCulture, - DateTimeStyles.None); - var dateTimeOffset = new DateTimeOffset(downloadFrom); - return pagination >= dateTimeOffset.ToUnixTimeSeconds(); + try + { + DateTime downloadFrom = DateTime.ParseExact(Blog.DownloadFrom, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None); + var dateTimeOffset = new DateTimeOffset(downloadFrom); + return pagination >= dateTimeOffset.ToUnixTimeSeconds(); + } + catch (System.FormatException) + { + throw new FormatException(Resources.BlogValueHasWrongFormat); + } } private async Task GetAlreadyExistingCrawlerDataFilesAsync() diff --git a/src/TumblThree/TumblThree.Applications/Crawler/TumblrSearchCrawler.cs b/src/TumblThree/TumblThree.Applications/Crawler/TumblrSearchCrawler.cs index a21ae96d..8d77f3dc 100644 --- a/src/TumblThree/TumblThree.Applications/Crawler/TumblrSearchCrawler.cs +++ b/src/TumblThree/TumblThree.Applications/Crawler/TumblrSearchCrawler.cs @@ -187,6 +187,11 @@ private async Task CrawlPageAsync() { HandleTimeoutException(timeoutException, Resources.Crawling); } + catch (FormatException formatException) + { + Logger.Error("TumblrSearchCrawler.CrawlPageAsync: {0}", formatException); + ShellService.ShowError(formatException, "{0}: {1}", Blog.Name, formatException.Message); + } catch (Exception e) { Logger.Error("TumblrSearchCrawler.CrawlPageAsync: {0}", e); @@ -288,7 +293,7 @@ private void DownloadPage(dynamic page) Logger.Verbose("TumblrSearchCrawler.DownloadPage: {0}", e); } } - catch (Exception ex) + catch (Exception ex) when (!(ex is FormatException)) { Logger.Error("TumblrSearchCrawler.DownloadMedia: {0}", ex); ShellService.ShowError(ex, "{0}: Error parsing post!", Blog.Name); @@ -299,7 +304,7 @@ private void DownloadPage(dynamic page) { HandleTimeoutException(timeoutException, Resources.Crawling); } - catch (Exception e) + catch (Exception e) when (!(e is FormatException)) { Logger.Error("TumblrSearchCrawler.DownloadPage: {0}", e); } @@ -366,10 +371,17 @@ private bool CheckIfWithinTimespan(long pagination) return true; } - DateTime downloadFrom = DateTime.ParseExact(Blog.DownloadFrom, "yyyyMMdd", CultureInfo.InvariantCulture, - DateTimeStyles.None); - var dateTimeOffset = new DateTimeOffset(downloadFrom); - return pagination >= dateTimeOffset.ToUnixTimeSeconds(); + try + { + DateTime downloadFrom = DateTime.ParseExact(Blog.DownloadFrom, "yyyyMMdd", CultureInfo.InvariantCulture, + DateTimeStyles.None); + var dateTimeOffset = new DateTimeOffset(downloadFrom); + return pagination >= dateTimeOffset.ToUnixTimeSeconds(); + } + catch (System.FormatException) + { + throw new FormatException(Resources.BlogValueHasWrongFormat); + } } private void DownloadText(dynamic dynPost, Post post) diff --git a/src/TumblThree/TumblThree.Applications/Crawler/TumblrTagSearchCrawler.cs b/src/TumblThree/TumblThree.Applications/Crawler/TumblrTagSearchCrawler.cs index 13f86433..910b8c04 100644 --- a/src/TumblThree/TumblThree.Applications/Crawler/TumblrTagSearchCrawler.cs +++ b/src/TumblThree/TumblThree.Applications/Crawler/TumblrTagSearchCrawler.cs @@ -159,9 +159,14 @@ private async Task CrawlPageAsync() { HandleTimeoutException(timeoutException, Resources.Crawling); } + catch (FormatException formatException) + { + Logger.Error("TumblrTagSearchCrawler.CrawlPageAsync: {0}", formatException); + ShellService.ShowError(formatException, "{0}: {1}", Blog.Name, formatException.Message); + } catch (Exception e) { - Logger.Error("CrawlPageAsync: {0}", e); + Logger.Error("TumblrTagSearchCrawler.CrawlPageAsync: {0}", e); } finally { @@ -222,7 +227,7 @@ private void DownloadMedia(TumblrTaggedSearchApi page) } } } - catch (Exception e) + catch (Exception e) when (!(e is FormatException)) { Logger.Error("DownloadMedia: {0}", e); } @@ -273,7 +278,7 @@ private void DownloadMedia(IList elements) } } } - catch (Exception e) + catch (Exception e) when (!(e is FormatException)) { Logger.Error("DownloadMedia: {0}", e); } @@ -286,10 +291,16 @@ private bool CheckIfWithinTimespan(long pagination) return true; } - DateTime downloadFrom = DateTime.ParseExact(Blog.DownloadFrom, "yyyyMMdd", CultureInfo.InvariantCulture, - DateTimeStyles.None); - var dateTimeOffset = new DateTimeOffset(downloadFrom); - return pagination >= dateTimeOffset.ToUnixTimeSeconds(); + try + { + DateTime downloadFrom = DateTime.ParseExact(Blog.DownloadFrom, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None); + var dateTimeOffset = new DateTimeOffset(downloadFrom); + return pagination >= dateTimeOffset.ToUnixTimeSeconds(); + } + catch (System.FormatException) + { + throw new FormatException(Resources.BlogValueHasWrongFormat); + } } private void DownloadMedia(Content content, Post post, int index) //String id, long timestamp, IList tags diff --git a/src/TumblThree/TumblThree.Applications/Crawler/TwitterCrawler.cs b/src/TumblThree/TumblThree.Applications/Crawler/TwitterCrawler.cs index ddb1a61a..e6345f02 100644 --- a/src/TumblThree/TumblThree.Applications/Crawler/TwitterCrawler.cs +++ b/src/TumblThree/TumblThree.Applications/Crawler/TwitterCrawler.cs @@ -638,6 +638,12 @@ private async Task CrawlPageAsync(int pageNo) retries++; Thread.Sleep(2000); } + catch (Exception e) when (e is FormatException) + { + Logger.Error("TwitterCrawler.CrawlPageAsync: {0}", e); + ShellService.ShowError(e, "{0}: {1}", Blog.Name, e.Message); + retries = 450; + } catch (Exception e) { Debug.WriteLine(e.ToString()); @@ -681,25 +687,32 @@ private bool PostWithinTimeSpan(Tweet post) return true; } - long downloadFromUnixTime = 0; - long downloadToUnixTime = long.MaxValue; - if (!string.IsNullOrEmpty(Blog.DownloadFrom)) + try { - DateTime downloadFrom = DateTime.ParseExact(Blog.DownloadFrom, "yyyyMMdd", CultureInfo.InvariantCulture, - DateTimeStyles.None); - downloadFromUnixTime = new DateTimeOffset(downloadFrom).ToUnixTimeSeconds(); - } + long downloadFromUnixTime = 0; + long downloadToUnixTime = long.MaxValue; + if (!string.IsNullOrEmpty(Blog.DownloadFrom)) + { + DateTime downloadFrom = DateTime.ParseExact(Blog.DownloadFrom, "yyyyMMdd", CultureInfo.InvariantCulture, + DateTimeStyles.None); + downloadFromUnixTime = new DateTimeOffset(downloadFrom).ToUnixTimeSeconds(); + } - if (!string.IsNullOrEmpty(Blog.DownloadTo)) + if (!string.IsNullOrEmpty(Blog.DownloadTo)) + { + DateTime downloadTo = DateTime.ParseExact(Blog.DownloadTo, "yyyyMMdd", CultureInfo.InvariantCulture, + DateTimeStyles.None).AddDays(1); + downloadToUnixTime = new DateTimeOffset(downloadTo).ToUnixTimeSeconds(); + } + + DateTime createdAt = DateTime.ParseExact(post.Legacy.CreatedAt, twitterDateTemplate, new CultureInfo("en-US")); + long postTime = ((DateTimeOffset)createdAt).ToUnixTimeSeconds(); + return downloadFromUnixTime <= postTime && postTime < downloadToUnixTime; + } + catch (System.FormatException) { - DateTime downloadTo = DateTime.ParseExact(Blog.DownloadTo, "yyyyMMdd", CultureInfo.InvariantCulture, - DateTimeStyles.None).AddDays(1); - downloadToUnixTime = new DateTimeOffset(downloadTo).ToUnixTimeSeconds(); + throw new FormatException(Resources.BlogValueHasWrongFormat); } - - DateTime createdAt = DateTime.ParseExact(post.Legacy.CreatedAt, twitterDateTemplate, new CultureInfo("en-US")); - long postTime = ((DateTimeOffset)createdAt).ToUnixTimeSeconds(); - return downloadFromUnixTime <= postTime && postTime < downloadToUnixTime; } private bool CheckPostAge(TimelineTweets response) @@ -772,7 +785,7 @@ private async Task AddUrlsToDownloadListAsync(List entries) Logger.Verbose("TwitterCrawler.AddUrlsToDownloadListAsync: {0}", e); } } - catch (Exception e) + catch (Exception e) when (!(e is FormatException)) { Logger.Error("TwitterCrawler.AddUrlsToDownloadListAsync: {0}", e); ShellService.ShowError(e, "{0}: Error parsing tweet!", Blog.Name); diff --git a/src/TumblThree/TumblThree.Applications/ErrorExceptions.cs b/src/TumblThree/TumblThree.Applications/ErrorExceptions.cs index 69485e9f..563cbb84 100644 --- a/src/TumblThree/TumblThree.Applications/ErrorExceptions.cs +++ b/src/TumblThree/TumblThree.Applications/ErrorExceptions.cs @@ -115,4 +115,18 @@ public APIException(string message, Exception innerException) : base(message, in protected APIException(SerializationInfo info, StreamingContext context) : base(info, context) { } } + + [Serializable] + public class FormatException : Exception + { + public FormatException(Exception innerException) : base(innerException?.Message, innerException) { } + + public FormatException() { } + + public FormatException(string message) : base(message) { } + + public FormatException(string message, Exception innerException) : base(message, innerException) { } + + protected FormatException(SerializationInfo info, StreamingContext context) : base(info, context) { } + } } diff --git a/src/TumblThree/TumblThree.Applications/Properties/Resources.Designer.cs b/src/TumblThree/TumblThree.Applications/Properties/Resources.Designer.cs index befe3894..dfc01f75 100644 --- a/src/TumblThree/TumblThree.Applications/Properties/Resources.Designer.cs +++ b/src/TumblThree/TumblThree.Applications/Properties/Resources.Designer.cs @@ -189,6 +189,15 @@ public static string BlogTypesOnceFinished { } } + /// + /// Looks up a localized string similar to A value entered on the details page has the wrong format.. + /// + public static string BlogValueHasWrongFormat { + get { + return ResourceManager.GetString("BlogValueHasWrongFormat", resourceCulture); + } + } + /// /// Looks up a localized string similar to Body: {0}. /// diff --git a/src/TumblThree/TumblThree.Applications/Properties/Resources.de.resx b/src/TumblThree/TumblThree.Applications/Properties/Resources.de.resx index fe5c5b43..ec4b39c0 100644 --- a/src/TumblThree/TumblThree.Applications/Properties/Resources.de.resx +++ b/src/TumblThree/TumblThree.Applications/Properties/Resources.de.resx @@ -507,4 +507,7 @@ Trotzdem fortfahren und schließen? Sie müssen sich bei x.com anmelden zum Laden von {0}. Dazu in den Einstellungen->Authentifizieren klicken. + + Ein auf der Detailseite eingegebener Wert hat das falsche Format. + \ No newline at end of file diff --git a/src/TumblThree/TumblThree.Applications/Properties/Resources.es.resx b/src/TumblThree/TumblThree.Applications/Properties/Resources.es.resx index fd1d4ca5..1edf2dbb 100644 --- a/src/TumblThree/TumblThree.Applications/Properties/Resources.es.resx +++ b/src/TumblThree/TumblThree.Applications/Properties/Resources.es.resx @@ -501,4 +501,7 @@ De lo contrario, debe cambiar al menos las entradas de ubicación "Descargar" y Debes iniciar sesión en x.com para descargar {0}. Vaya a Configuración-> Autenticar. + + Un valor ingresado en la página de detalles tiene el formato incorrecto. + \ No newline at end of file diff --git a/src/TumblThree/TumblThree.Applications/Properties/Resources.fr.resx b/src/TumblThree/TumblThree.Applications/Properties/Resources.fr.resx index a3928cad..40c7c593 100644 --- a/src/TumblThree/TumblThree.Applications/Properties/Resources.fr.resx +++ b/src/TumblThree/TumblThree.Applications/Properties/Resources.fr.resx @@ -519,4 +519,7 @@ Continuer à fermer quand même ? Vous devez vous connecter à x.com pour télécharger {0}. Accédez aux Paramètres-> Authentification. + + Une valeur saisie sur la page de détails a un format incorrect. + \ No newline at end of file diff --git a/src/TumblThree/TumblThree.Applications/Properties/Resources.resx b/src/TumblThree/TumblThree.Applications/Properties/Resources.resx index 49f52534..0a2ee2a8 100644 --- a/src/TumblThree/TumblThree.Applications/Properties/Resources.resx +++ b/src/TumblThree/TumblThree.Applications/Properties/Resources.resx @@ -538,4 +538,7 @@ Continue close anyway? You need to login to x.com for downloading {0}. Go to the Settings->Connection->Authenticate. + + A value entered on the details page has the wrong format. + \ No newline at end of file