Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Commit

Permalink
Remove recursion
Browse files Browse the repository at this point in the history
- Converts tail recursion to Iteration.
- Generally catches all exceptions from the downloader.
  • Loading branch information
johanneszab committed Jul 3, 2017
1 parent 9191c35 commit fa497d8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ TumblThree is the code rewrite of [TumblTwo](https://github.com/johanneszab/Tumb

### How To Build The Source Code To Help Further Developing: ###

* Download [Visual Studio](https://www.visualstudio.com/vs/community/). The minimum required version is Visual Studio 2015 (C# 6.0 feature support).
* Download [Visual Studio](https://www.visualstudio.com/vs/community/). The minimum required version is Visual Studio 2015 (C# 6.0 feature support). You also need _Blend for Visual Studio SDK for .NET_ which includes the System.Windows.Interactivity and Microsoft.Expression.Interactions dlls.
* Download the [source code as .zip file](https://github.com/johanneszab/TumblThree/archive/master.zip) or use the [GitHub Desktop](https://desktop.github.com/) and [checkout the code](https://github.com/johanneszab/TumblThree.git).
* Open the TumblThree.sln solution file in the src/ directory of the code.
* Build the Source once before editing anything. Build->Build Solution.
Expand Down
4 changes: 2 additions & 2 deletions src/TumblThree/SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

[assembly: ComVisible(false)]
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]
[assembly: AssemblyVersion("1.0.6.7")]
[assembly: AssemblyFileVersion("1.0.6.7")]
[assembly: AssemblyVersion("1.0.6.8")]
[assembly: AssemblyFileVersion("1.0.6.8")]
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,9 @@ protected virtual async Task<bool> DownloadBlogAsync(IProgress<DataModels.Downlo

trackedTasks.Add(new Func<Task>(async () =>
{
await DownloadPostAsync(progress, ct, downloadItem);
semaphoreSlim.Release();
try { await DownloadPostAsync(progress, ct, downloadItem); }
catch {}
finally { semaphoreSlim.Release(); }
})());
}
try { await Task.WhenAll(trackedTasks); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,31 +162,35 @@ private bool CheckIfLoggedIn(string document)

private async Task AddUrlsToDownloadList(string document, IProgress<DownloadProgress> progress, int crawlerNumber, CancellationToken ct, PauseToken pt)
{
if (ct.IsCancellationRequested)
while (true)
{
return;
}
if (pt.IsPaused)
{
pt.WaitWhilePausedWithResponseAsyc().Wait();
}
if (ct.IsCancellationRequested)
{
return;
}
if (pt.IsPaused)
{
pt.WaitWhilePausedWithResponseAsyc().Wait();
}

var tags = new List<string>();
if (!string.IsNullOrWhiteSpace(blog.Tags))
{
tags = blog.Tags.Split(',').Select(x => x.Trim()).ToList();
}
var tags = new List<string>();
if (!string.IsNullOrWhiteSpace(blog.Tags))
{
tags = blog.Tags.Split(',').Select(x => x.Trim()).ToList();
}

AddPhotoUrlToDownloadList(document, tags);
AddVideoUrlToDownloadList(document, tags);
AddPhotoUrlToDownloadList(document, tags);
AddVideoUrlToDownloadList(document, tags);

Interlocked.Increment(ref numberOfPagesCrawled);
UpdateProgressQueueInformation(progress, Resources.ProgressGetUrlShort, numberOfPagesCrawled);
crawlerNumber += shellService.Settings.ParallelScans;
document = await RequestDataAsync(blog.Url + "/page/" + crawlerNumber);
if (document.Contains("<div class=\"no_posts_found\">"))
return;
await AddUrlsToDownloadList(document, progress, crawlerNumber, ct, pt);
Interlocked.Increment(ref numberOfPagesCrawled);
UpdateProgressQueueInformation(progress, Resources.ProgressGetUrlShort, numberOfPagesCrawled);
crawlerNumber += shellService.Settings.ParallelScans;
document = await RequestDataAsync(blog.Url + "/page/" + crawlerNumber);
if (document.Contains("<div class=\"no_posts_found\">"))
{
return;
}
}
}

private void AddPhotoUrlToDownloadList(string document, IList<string> tags)
Expand Down

0 comments on commit fa497d8

Please sign in to comment.