Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
NguyenDanPhuong committed Sep 18, 2016
1 parent a100cb8 commit a246315
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 1 deletion.
22 changes: 22 additions & 0 deletions MangaRipper.Core/Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace MangaRipper.Core
{
/// <summary>
/// Support download web page to string and image file to folder.
/// </summary>
public class Downloader
{
private static Logger logger = LogManager.GetCurrentClassLogger();
Expand All @@ -24,6 +27,11 @@ private HttpWebRequest CreateRequest(string url)
return request;
}

/// <summary>
/// Download single web page to string.
/// </summary>
/// <param name="url">The url to download</param>
/// <returns></returns>
public async Task<string> DownloadStringAsync(string url)
{
logger.Info("> DownloadStringAsync: {0}", url);
Expand All @@ -38,6 +46,13 @@ public async Task<string> DownloadStringAsync(string url)
}
}

/// <summary>
/// Download a list of web page.
/// </summary>
/// <param name="urls">List of url</param>
/// <param name="progress">Progress report callback</param>
/// <param name="cancellationToken">Cancellation control</param>
/// <returns></returns>
internal async Task<string> DownloadStringAsync(IEnumerable<string> urls, IProgress<int> progress, CancellationToken cancellationToken)
{
logger.Info("> DownloadStringAsync - Total: {0}", urls.Count());
Expand All @@ -55,6 +70,13 @@ internal async Task<string> DownloadStringAsync(IEnumerable<string> urls, IProgr
return sb.ToString();
}

/// <summary>
/// Download file and save to folder
/// </summary>
/// <param name="url">The url to download</param>
/// <param name="fileName">Save to filename</param>
/// <param name="cancellationToken">Cancellation control</param>
/// <returns></returns>
public async Task DownloadFileAsync(string url, string fileName, CancellationToken cancellationToken)
{
logger.Info("> DownloadFileAsync: {0} - {1}", url, fileName);
Expand Down
20 changes: 20 additions & 0 deletions MangaRipper.Core/Framework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@

namespace MangaRipper.Core
{
/// <summary>
/// The framework contains all services for this app.
/// When the app start, we have to call Init() to initilazation services.
/// </summary>
public class Framework
{
private static Logger logger = LogManager.GetCurrentClassLogger();
private static IList<IMangaService> services;
private static Worker worker;

/// <summary>
/// Initilaztion services.
/// </summary>
public static void Init()
{
logger.Info("> Framework.Init()");
Expand All @@ -24,16 +31,29 @@ public static void Init()
services.Add(new MangaShareService());
}

/// <summary>
/// Get all avaible services
/// </summary>
/// <returns></returns>
public static IEnumerable<IMangaService> GetServices()
{
return services.ToList().AsReadOnly();
}

/// <summary>
/// Get worker to download chapter.
/// </summary>
/// <returns></returns>
public static Worker GetWorker()
{
return worker;
}

/// <summary>
/// Find service base on inputed url.
/// </summary>
/// <param name="link"></param>
/// <returns></returns>
public static IMangaService GetService(string link)
{
IMangaService service = services.FirstOrDefault(s => s.Of(link));
Expand Down
29 changes: 28 additions & 1 deletion MangaRipper.Core/IMangaService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,40 @@
namespace MangaRipper.Core
{
/// <summary>
/// We have many manga services, each service support downloading from one site.
/// We have many manga services (web site), each service support finding chapters url and images url.
/// </summary>
public interface IMangaService
{
/// <summary>
/// The information of service
/// </summary>
/// <returns></returns>
SiteInformation GetInformation();

/// <summary>
/// Is a link is from this service.
/// If it's. We can use this service to fetch chapters and download
/// </summary>
/// <param name="link"></param>
/// <returns></returns>
bool Of(string link);

/// <summary>
/// Find all chapters inside a manga
/// </summary>
/// <param name="manga"></param>
/// <param name="progress"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IList<Chapter>> FindChapters(string manga, IProgress<int> progress, CancellationToken cancellationToken);

/// <summary>
/// Find all images inside a chapter.
/// </summary>
/// <param name="chapter"></param>
/// <param name="progress"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IList<string>> FindImanges(Chapter chapter, IProgress<int> progress, CancellationToken cancellationToken);
}
}
3 changes: 3 additions & 0 deletions MangaRipper.Core/MangaFoxService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace MangaRipper.Core
{
/// <summary>
/// Support find chapters, images from MangaFox
/// </summary>
class MangaFoxService : IMangaService
{
private static Logger logger = LogManager.GetCurrentClassLogger();
Expand Down
4 changes: 4 additions & 0 deletions MangaRipper.Core/MangaHereService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

namespace MangaRipper.Core
{

/// <summary>
/// Support find chapters and images from MangaHere
/// </summary>
class MangaHereService : IMangaService
{
private static Logger logger = LogManager.GetCurrentClassLogger();
Expand Down
3 changes: 3 additions & 0 deletions MangaRipper.Core/MangaReaderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

namespace MangaRipper.Core
{
/// <summary>
/// Support find chapters and images from MangaReader
/// </summary>
class MangaReaderService : IMangaService
{
private static Logger logger = LogManager.GetCurrentClassLogger();
Expand Down
4 changes: 4 additions & 0 deletions MangaRipper.Core/MangaShareService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

namespace MangaRipper.Core
{

/// <summary>
/// Support find chapters, images from MangaShare
/// </summary>
class MangaShareService : IMangaService
{
private static Logger logger = LogManager.GetCurrentClassLogger();
Expand Down
3 changes: 3 additions & 0 deletions MangaRipper.Core/SiteInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace MangaRipper.Core
{
/// <summary>
/// Contain information of a manga web site
/// </summary>
public class SiteInformation
{
public string Name { get; private set; }
Expand Down
19 changes: 19 additions & 0 deletions MangaRipper.Core/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace MangaRipper.Core
{
/// <summary>
/// Worker support download manga chapters on back ground thread.
/// </summary>
public class Worker
{
private static Logger logger = LogManager.GetCurrentClassLogger();
Expand All @@ -23,11 +26,21 @@ public Worker()
sema = new SemaphoreSlim(2);
}

/// <summary>
/// Stop download
/// </summary>
public void Cancel()
{
source.Cancel();
}

/// <summary>
/// Download a manga chapter.
/// </summary>
/// <param name="chapter">Chapter to download</param>
/// <param name="mangaLocalPath">Save chaper to this folder</param>
/// <param name="progress">Progress report callback</param>
/// <returns></returns>
public async Task DownloadChapter(Chapter chapter, string mangaLocalPath, IProgress<int> progress)
{
logger.Info("> DownloadChapter: {0} To: {1}", chapter.Link, mangaLocalPath);
Expand All @@ -53,6 +66,12 @@ await Task.Run(async () =>
});
}

/// <summary>
/// Find all chapters of a manga
/// </summary>
/// <param name="mangaPath">The url of manga</param>
/// <param name="progress">Progress report callback</param>
/// <returns></returns>
public async Task<IList<Chapter>> FindChapters(string mangaPath, IProgress<int> progress)
{
logger.Info("> FindChapters: {0}", mangaPath);
Expand Down

0 comments on commit a246315

Please sign in to comment.