From c9209f14a746fd8d60bd01cbeed337d384c45b27 Mon Sep 17 00:00:00 2001 From: Cesxhin Date: Mon, 29 May 2023 21:01:07 +0200 Subject: [PATCH 01/15] update dockerfile and move file only used for notify by references --- Dockerfile | 3 +- DockerfileArm32v7 | 3 +- .../Cesxhin.AnimeManga.Application.csproj | 26 + .../Consumers/NotifyConsumer.cs | 4 +- .../Cesxhin.AnimeManga.NotifyService.csproj | 5 +- .../Program.cs | 4 +- .../CheckManager/Interfaces/IUpdate.cs | 7 - .../CheckManager/Interfaces/IUpgrade.cs | 7 - .../CheckManager/UpdateBook.cs | 187 ------ .../CheckManager/UpdateVideo.cs | 179 ------ .../CheckManager/UpgradeBook.cs | 214 ------- .../CheckManager/UpgradeVideo.cs | 228 ------- .../Consumers/ConversionConsumer.cs | 212 ------- .../Consumers/DeleteBookConsumer.cs | 48 -- .../Consumers/DeleteVideoConsumer.cs | 43 -- .../Consumers/DownloadBookConsumer.cs | 202 ------- .../Consumers/DownloadVideoConsumer.cs | 556 ------------------ .../Controllers/IGeneralControllerBase.cs | 35 -- .../Repositories/IAccountRepository.cs | 18 - .../IChapterRegisterRepository.cs | 8 - .../Repositories/IChapterRepository.cs | 10 - .../Repositories/IDescriptionRepository.cs | 9 - .../IEpisodeRegisterRepository.cs | 8 - .../Repositories/IEpisodeRepository.cs | 10 - .../Repositories/IGeneralNameRepository.cs | 22 - .../IGeneralObjectRegisterRepository.cs | 19 - .../Repositories/IGeneralObjectRepository.cs | 23 - .../IProgressChapterRepository.cs | 12 - .../IProgressEpisodeRepository.cs | 12 - .../Interfaces/Services/IAccountService.cs | 18 - .../Services/IChapterRegisterService.cs | 8 - .../Interfaces/Services/IChapterService.cs | 8 - .../Services/IDescriptionBookService.cs | 9 - .../Services/IDescriptionVideoService.cs | 9 - .../Services/IEpisodeRegisterService.cs | 8 - .../Interfaces/Services/IEpisodeService.cs | 8 - .../Services/IGeneralNameService.cs | 24 - .../Interfaces/Services/IGeneralObject.cs | 23 - .../Services/IGeneralObjectRegister.cs | 19 - .../Services/IProgressChapterService.cs | 14 - .../Services/IProgressEpisodeService.cs | 14 - .../Services/AccountService.cs | 109 ---- .../Services/ChapterRegisterService.cs | 85 --- .../Services/ChapterService.cs | 99 ---- .../Services/DescriptionBookService.cs | 278 --------- .../Services/DescriptionVideoService.cs | 286 --------- .../Services/EpisodeRegisterService.cs | 76 --- .../Services/EpisodeService.cs | 95 --- .../Services/ProgressChapterService.cs | 42 -- .../Services/ProgressEpisodeService.cs | 42 -- .../Models/WatchList.cs | 2 + .../Cesxhin.AnimeManga.Modules.csproj} | 5 - .../CronJob/HealthJob.cs | 8 +- .../CronJob/SpaceDiskJob.cs | 8 +- .../Exceptions/ApiConflictException.cs | 2 +- .../Exceptions/ApiGenericException.cs | 2 +- .../Exceptions/ApiNotAuthorizeException.cs | 2 +- .../Exceptions/ApiNotFoundException.cs | 2 +- .../Generic/Api.cs | 4 +- .../Generic/ConvertGeneric.cs | 2 +- .../Generic/Hash.cs | 2 +- .../HtmlAgilityPack/RipperBookGeneric.cs | 6 +- .../HtmlAgilityPack/RipperSchema.cs | 4 +- .../HtmlAgilityPack/RipperVideoGeneric.cs | 6 +- .../NlogManager/NLogConsole.cs | 2 +- .../NlogManager/NLogManager.cs | 2 +- .../Parallel/ParallelManager.cs | 4 +- .../Proxy/ProxyManagement.cs | 2 +- .../Schema/SchemaControl.cs | 2 +- .../Cesxhin.AnimeManga.Persistence.csproj | 19 - .../Repositories/AccountRepository.cs | 155 ----- .../Repositories/ChapterRegisterRepository.cs | 136 ----- .../Repositories/ChapterRepository.cs | 219 ------- .../Repositories/DescriptionRepository.cs | 187 ------ .../Repositories/EpisodeRegisterRepository.cs | 141 ----- .../Repositories/EpisodeRepository.cs | 228 ------- .../Repositories/ProgressChapterRepository.cs | 91 --- .../Repositories/ProgressEpisodeRepository.cs | 91 --- 78 files changed, 69 insertions(+), 4653 deletions(-) create mode 100644 src/Cesxhin.AnimeManga.Application/Cesxhin.AnimeManga.Application.csproj rename src/{references => }/Cesxhin.AnimeManga.Application/Consumers/NotifyConsumer.cs (94%) delete mode 100644 src/references/Cesxhin.AnimeManga.Application/CheckManager/Interfaces/IUpdate.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/CheckManager/Interfaces/IUpgrade.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/CheckManager/UpdateBook.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/CheckManager/UpdateVideo.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/CheckManager/UpgradeBook.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/CheckManager/UpgradeVideo.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Consumers/ConversionConsumer.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Consumers/DeleteBookConsumer.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Consumers/DeleteVideoConsumer.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Consumers/DownloadBookConsumer.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Consumers/DownloadVideoConsumer.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Controllers/IGeneralControllerBase.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IAccountRepository.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IChapterRegisterRepository.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IChapterRepository.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IDescriptionRepository.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IEpisodeRegisterRepository.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IEpisodeRepository.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IGeneralNameRepository.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IGeneralObjectRegisterRepository.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IGeneralObjectRepository.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IProgressChapterRepository.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IProgressEpisodeRepository.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IAccountService.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IChapterRegisterService.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IChapterService.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IDescriptionBookService.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IDescriptionVideoService.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IEpisodeRegisterService.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IEpisodeService.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IGeneralNameService.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IGeneralObject.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IGeneralObjectRegister.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IProgressChapterService.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IProgressEpisodeService.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Services/AccountService.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Services/ChapterRegisterService.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Services/ChapterService.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Services/DescriptionBookService.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Services/DescriptionVideoService.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Services/EpisodeRegisterService.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Services/EpisodeService.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Services/ProgressChapterService.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Application/Services/ProgressEpisodeService.cs rename src/references/{Cesxhin.AnimeManga.Application/Cesxhin.AnimeManga.Application.csproj => Cesxhin.AnimeManga.Modules/Cesxhin.AnimeManga.Modules.csproj} (81%) rename src/references/{Cesxhin.AnimeManga.Application => Cesxhin.AnimeManga.Modules}/CronJob/HealthJob.cs (82%) rename src/references/{Cesxhin.AnimeManga.Application => Cesxhin.AnimeManga.Modules}/CronJob/SpaceDiskJob.cs (87%) rename src/references/{Cesxhin.AnimeManga.Application => Cesxhin.AnimeManga.Modules}/Exceptions/ApiConflictException.cs (85%) rename src/references/{Cesxhin.AnimeManga.Application => Cesxhin.AnimeManga.Modules}/Exceptions/ApiGenericException.cs (85%) rename src/references/{Cesxhin.AnimeManga.Application => Cesxhin.AnimeManga.Modules}/Exceptions/ApiNotAuthorizeException.cs (85%) rename src/references/{Cesxhin.AnimeManga.Application => Cesxhin.AnimeManga.Modules}/Exceptions/ApiNotFoundException.cs (85%) rename src/references/{Cesxhin.AnimeManga.Application => Cesxhin.AnimeManga.Modules}/Generic/Api.cs (98%) rename src/references/{Cesxhin.AnimeManga.Application => Cesxhin.AnimeManga.Modules}/Generic/ConvertGeneric.cs (88%) rename src/references/{Cesxhin.AnimeManga.Application => Cesxhin.AnimeManga.Modules}/Generic/Hash.cs (94%) rename src/references/{Cesxhin.AnimeManga.Application => Cesxhin.AnimeManga.Modules}/HtmlAgilityPack/RipperBookGeneric.cs (98%) rename src/references/{Cesxhin.AnimeManga.Application => Cesxhin.AnimeManga.Modules}/HtmlAgilityPack/RipperSchema.cs (99%) rename src/references/{Cesxhin.AnimeManga.Application => Cesxhin.AnimeManga.Modules}/HtmlAgilityPack/RipperVideoGeneric.cs (97%) rename src/references/{Cesxhin.AnimeManga.Application => Cesxhin.AnimeManga.Modules}/NlogManager/NLogConsole.cs (98%) rename src/references/{Cesxhin.AnimeManga.Application => Cesxhin.AnimeManga.Modules}/NlogManager/NLogManager.cs (95%) rename src/references/{Cesxhin.AnimeManga.Application => Cesxhin.AnimeManga.Modules}/Parallel/ParallelManager.cs (97%) rename src/references/{Cesxhin.AnimeManga.Application => Cesxhin.AnimeManga.Modules}/Proxy/ProxyManagement.cs (98%) rename src/references/{Cesxhin.AnimeManga.Application => Cesxhin.AnimeManga.Modules}/Schema/SchemaControl.cs (99%) delete mode 100644 src/references/Cesxhin.AnimeManga.Persistence/Cesxhin.AnimeManga.Persistence.csproj delete mode 100644 src/references/Cesxhin.AnimeManga.Persistence/Repositories/AccountRepository.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Persistence/Repositories/ChapterRegisterRepository.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Persistence/Repositories/ChapterRepository.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Persistence/Repositories/DescriptionRepository.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Persistence/Repositories/EpisodeRegisterRepository.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Persistence/Repositories/EpisodeRepository.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Persistence/Repositories/ProgressChapterRepository.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Persistence/Repositories/ProgressEpisodeRepository.cs diff --git a/Dockerfile b/Dockerfile index e7dea84..5d54c9a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,8 @@ FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build WORKDIR /src COPY ["src/Cesxhin.AnimeManga.NotifyService/", "./Cesxhin.AnimeManga.NotifyService/"] -COPY ["src/references/Cesxhin.AnimeManga.Application/", "./references/Cesxhin.AnimeManga.Application/"] +COPY ["src/Cesxhin.AnimeManga.Application/", "./Cesxhin.AnimeManga.Application/"] +COPY ["src/references/Cesxhin.AnimeManga.Modules/", "./references/Cesxhin.AnimeManga.Modules/"] COPY ["src/references/Cesxhin.AnimeManga.Domain/", "./references/Cesxhin.AnimeManga.Domain/"] RUN dotnet restore "./Cesxhin.AnimeManga.NotifyService/Cesxhin.AnimeManga.NotifyService.csproj" diff --git a/DockerfileArm32v7 b/DockerfileArm32v7 index 095742f..8a6f1ca 100644 --- a/DockerfileArm32v7 +++ b/DockerfileArm32v7 @@ -7,7 +7,8 @@ FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim-arm32v7 AS build WORKDIR /src COPY ["src/Cesxhin.AnimeManga.NotifyService/", "./Cesxhin.AnimeManga.NotifyService/"] -COPY ["src/references/Cesxhin.AnimeManga.Application/", "./references/Cesxhin.AnimeManga.Application/"] +COPY ["src/Cesxhin.AnimeManga.Application/", "./Cesxhin.AnimeManga.Application/"] +COPY ["src/references/Cesxhin.AnimeManga.Modules/", "./references/Cesxhin.AnimeManga.Modules/"] COPY ["src/references/Cesxhin.AnimeManga.Domain/", "./references/Cesxhin.AnimeManga.Domain/"] RUN dotnet restore "./Cesxhin.AnimeManga.NotifyService/Cesxhin.AnimeManga.NotifyService.csproj" diff --git a/src/Cesxhin.AnimeManga.Application/Cesxhin.AnimeManga.Application.csproj b/src/Cesxhin.AnimeManga.Application/Cesxhin.AnimeManga.Application.csproj new file mode 100644 index 0000000..f57acfd --- /dev/null +++ b/src/Cesxhin.AnimeManga.Application/Cesxhin.AnimeManga.Application.csproj @@ -0,0 +1,26 @@ + + + + net5.0 + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/references/Cesxhin.AnimeManga.Application/Consumers/NotifyConsumer.cs b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyConsumer.cs similarity index 94% rename from src/references/Cesxhin.AnimeManga.Application/Consumers/NotifyConsumer.cs rename to src/Cesxhin.AnimeManga.Application/Consumers/NotifyConsumer.cs index e423e25..cecfad9 100644 --- a/src/references/Cesxhin.AnimeManga.Application/Consumers/NotifyConsumer.cs +++ b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyConsumer.cs @@ -1,5 +1,5 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.NlogManager; +using Cesxhin.AnimeManga.Modules.Exceptions; +using Cesxhin.AnimeManga.Modules.NlogManager; using Cesxhin.AnimeManga.Domain.DTO; using Discord.Webhook; using MassTransit; diff --git a/src/Cesxhin.AnimeManga.NotifyService/Cesxhin.AnimeManga.NotifyService.csproj b/src/Cesxhin.AnimeManga.NotifyService/Cesxhin.AnimeManga.NotifyService.csproj index 2e33436..ab56eaa 100644 --- a/src/Cesxhin.AnimeManga.NotifyService/Cesxhin.AnimeManga.NotifyService.csproj +++ b/src/Cesxhin.AnimeManga.NotifyService/Cesxhin.AnimeManga.NotifyService.csproj @@ -1,4 +1,4 @@ - + net5.0 @@ -14,6 +14,7 @@ - + + diff --git a/src/Cesxhin.AnimeManga.NotifyService/Program.cs b/src/Cesxhin.AnimeManga.NotifyService/Program.cs index 7f3a8a6..d55f00a 100644 --- a/src/Cesxhin.AnimeManga.NotifyService/Program.cs +++ b/src/Cesxhin.AnimeManga.NotifyService/Program.cs @@ -1,6 +1,6 @@ using Cesxhin.AnimeManga.Application.Consumers; -using Cesxhin.AnimeManga.Application.CronJob; -using Cesxhin.AnimeManga.Application.Generic; +using Cesxhin.AnimeManga.Modules.CronJob; +using Cesxhin.AnimeManga.Modules.Generic; using MassTransit; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; diff --git a/src/references/Cesxhin.AnimeManga.Application/CheckManager/Interfaces/IUpdate.cs b/src/references/Cesxhin.AnimeManga.Application/CheckManager/Interfaces/IUpdate.cs deleted file mode 100644 index 8cf3379..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/CheckManager/Interfaces/IUpdate.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Cesxhin.AnimeManga.Application.CheckManager.Interfaces -{ - public interface IUpdate - { - void ExecuteUpdate(); - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/CheckManager/Interfaces/IUpgrade.cs b/src/references/Cesxhin.AnimeManga.Application/CheckManager/Interfaces/IUpgrade.cs deleted file mode 100644 index bfe73e0..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/CheckManager/Interfaces/IUpgrade.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Cesxhin.AnimeManga.Application.CheckManager.Interfaces -{ - public interface IUpgrade - { - void ExecuteUpgrade(); - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/CheckManager/UpdateBook.cs b/src/references/Cesxhin.AnimeManga.Application/CheckManager/UpdateBook.cs deleted file mode 100644 index 6378d5d..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/CheckManager/UpdateBook.cs +++ /dev/null @@ -1,187 +0,0 @@ -using Cesxhin.AnimeManga.Application.CheckManager.Interfaces; -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Generic; -using Cesxhin.AnimeManga.Application.NlogManager; -using Cesxhin.AnimeManga.Application.Parallel; -using Cesxhin.AnimeManga.Domain.DTO; -using MassTransit; -using Newtonsoft.Json.Linq; -using NLog; -using System; -using System.Collections.Generic; -using System.IO; - -namespace Cesxhin.AnimeManga.Application.CheckManager -{ - public class UpdateBook : IUpdate - { - //interface - private readonly IBus _publishEndpoint; - - //log - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - //env - private readonly string _folder = Environment.GetEnvironmentVariable("BASE_PATH") ?? "/"; - private readonly JObject schemas = JObject.Parse(Environment.GetEnvironmentVariable("SCHEMA")); - - //Instance Parallel - private readonly ParallelManager parallel = new(); - - //Istance Api - private readonly Api bookApi = new(); - private readonly Api chapterApi = new(); - private readonly Api chapterRegisterApi = new(); - - //download api - private List listBook = null; - - public UpdateBook(IBus publicEndpoint) - { - _publishEndpoint = publicEndpoint; - } - - public void ExecuteUpdate() - { - _logger.Info($"Start update book"); - - foreach (var item in schemas) - { - var schema = schemas.GetValue(item.Key).ToObject(); - if (schema.GetValue("type").ToString() == "book") - { - try - { - var query = new Dictionary() - { - ["nameCfg"] = item.Key - }; - - listBook = bookApi.GetMore("/book/all", query).GetAwaiter().GetResult(); - } - catch (ApiNotFoundException ex) - { - _logger.Error($"Not found get all, details error: {ex.Message}"); - } - catch (ApiGenericException ex) - { - _logger.Fatal($"Error generic get all, details error: {ex.Message}"); - } - - //if exists listManga - if (listBook != null && listBook.Count > 0) - { - var tasks = new List>(); - //step one check file - foreach (var book in listBook) - { - - //foreach chapters - foreach (var chapter in book.Chapters) - { - tasks.Add(new Func(() => Checkchapter(book, chapter, chapterApi, chapterRegisterApi))); - } - } - parallel.AddTasks(tasks); - parallel.Start(); - parallel.WhenCompleted(); - parallel.ClearList(); - } - } - - } - - _logger.Info($"End update book"); - } - - private object Checkchapter(GenericBookDTO book, ChapterDTO chapter, Api chapterApi, Api chapterRegisterApi) - { - var chapterRegister = book.ChapterRegister.Find(e => e.ChapterId == chapter.ID); - if (chapterRegister == null) - { - _logger.Warn($"not found chapterRegister by chapter id: {chapter.ID}"); - return null; - } - - for (int i = 0; i < chapterRegister.ChapterPath.Length; i++) - { - _logger.Debug($"check {chapterRegister.ChapterPath[i]}"); - - //check integry file - if (chapter.StateDownload == null || chapter.StateDownload == "failed" || (chapter.StateDownload == "completed" && chapterRegister.ChapterHash == null)) - { - ConfirmStartDownload(chapter, chapterApi); - } - else if ((!File.Exists(chapterRegister.ChapterPath[i]) && chapter.StateDownload != "pending")) - { - var found = false; - string newHash; - - foreach (string file in Directory.EnumerateFiles(_folder, "*.png", SearchOption.AllDirectories)) - { - newHash = Hash.GetHash(file); - if (newHash == chapterRegister.ChapterHash[i]) - { - _logger.Info($"I found file (chapter id: {chapter.ID}) that was move, now update information"); - - //update - chapterRegister.ChapterPath[i] = file; - try - { - chapterRegisterApi.PutOne("/chapter/register", chapterRegister).GetAwaiter().GetResult(); - - _logger.Info($"Ok update chapter id: {chapter.ID} that was move"); - - //return - found = true; - } - catch (ApiNotFoundException ex) - { - _logger.Error($"Not found chapterRegister id: {chapterRegister.ChapterId} for update information, details: {ex.Message}"); - } - catch (ApiConflictException ex) - { - _logger.Error($"Error conflict put chapterRegister, details error: {ex.Message}"); - } - catch (ApiGenericException ex) - { - _logger.Fatal($"Error generic put chapterRegister, details error: {ex.Message}"); - } - - break; - } - } - - //if not found file - if (found == false) - ConfirmStartDownload(chapter, chapterApi); - } - } - - return null; - } - - private async void ConfirmStartDownload(ChapterDTO chapter, Api chapterApi) - { - //set pending to - chapter.StateDownload = "pending"; - - try - { - //set change status - await chapterApi.PutOne("/book/statusDownload", chapter); - - await _publishEndpoint.Publish(chapter); - _logger.Info($"this file ({chapter.NameManga} volume: {chapter.CurrentVolume} chapter: {chapter.CurrentChapter}) does not exists, sending message to DownloadService"); - } - catch (ApiNotFoundException ex) - { - _logger.Error($"Impossible update chapter becouse not found chapter id: {chapter.ID}, details: {ex.Message}"); - } - catch (ApiGenericException ex) - { - _logger.Fatal($"Error update chapter, details error: {ex.Message}"); - } - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/CheckManager/UpdateVideo.cs b/src/references/Cesxhin.AnimeManga.Application/CheckManager/UpdateVideo.cs deleted file mode 100644 index 70e52a6..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/CheckManager/UpdateVideo.cs +++ /dev/null @@ -1,179 +0,0 @@ -using Cesxhin.AnimeManga.Application.CheckManager.Interfaces; -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Generic; -using Cesxhin.AnimeManga.Application.NlogManager; -using Cesxhin.AnimeManga.Application.Parallel; -using Cesxhin.AnimeManga.Domain.DTO; -using MassTransit; -using Newtonsoft.Json.Linq; -using NLog; -using System; -using System.Collections.Generic; -using System.IO; - -namespace Cesxhin.AnimeManga.Application.CheckManager -{ - public class UpdateVideo : IUpdate - { - //interface - private readonly IBus _publishEndpoint; - - //log - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - //env - private readonly string _folder = Environment.GetEnvironmentVariable("BASE_PATH") ?? "/"; - private readonly JObject schemas = JObject.Parse(Environment.GetEnvironmentVariable("SCHEMA")); - - //Instance Parallel - private readonly ParallelManager parallel = new(); - - //Istance Api - private readonly Api videoApi = new(); - private readonly Api episodeApi = new(); - private readonly Api episodeRegisterApi = new(); - - //download api - private List listVideo = null; - - public UpdateVideo(IBus publicEndpoint) - { - _publishEndpoint = publicEndpoint; - } - - public void ExecuteUpdate() - { - _logger.Info($"Start update video"); - foreach (var item in schemas) - { - var schema = schemas.GetValue(item.Key).ToObject(); - if (schema.GetValue("type").ToString() == "video") - { - try - { - var query = new Dictionary() - { - ["nameCfg"] = item.Key - }; - - listVideo = videoApi.GetMore("/video/all", query).GetAwaiter().GetResult(); - } - catch (ApiNotFoundException ex) - { - _logger.Error($"Not found get all, details error: {ex.Message}"); - } - catch (ApiGenericException ex) - { - _logger.Fatal($"Error generic get all, details error: {ex.Message}"); - } - - //if exists listAnime - if (listVideo != null) - { - var tasks = new List>(); - //step one check file - foreach (var video in listVideo) - { - //foreach episodes - foreach (var episode in video.Episodes) - { - tasks.Add(new Func(() => CheckEpisode(video, episode, episodeApi, episodeRegisterApi))); - } - } - parallel.AddTasks(tasks); - parallel.Start(); - parallel.WhenCompleted(); - parallel.ClearList(); - } - } - } - _logger.Info($"End update anime"); - } - - private object CheckEpisode(GenericVideoDTO video, EpisodeDTO episode, Api episodeApi, Api episodeRegisterApi) - { - var episodeRegister = video.EpisodesRegister.Find(e => e.EpisodeId == episode.ID); - if (episodeRegister == null) - { - _logger.Warn($"not found episodeRegister by episode id: {episode.ID}"); - return null; - } - - _logger.Debug($"check {episodeRegister.EpisodePath}"); - - //check integry file - if (episode.StateDownload == null || episode.StateDownload == "failed" || (episode.StateDownload == "completed" && episodeRegister.EpisodeHash == null)) - { - ConfirmStartDownload(episode, episodeApi); - } - else if (!File.Exists(episodeRegister.EpisodePath) && episode.StateDownload == "completed") - { - var found = false; - string newHash; - foreach (string file in Directory.EnumerateFiles(_folder, "*.mp4", SearchOption.AllDirectories)) - { - newHash = Hash.GetHash(file); - if (newHash == episodeRegister.EpisodeHash) - { - _logger.Info($"I found file (episode id: {episode.ID}) that was move, now update information"); - - //update - episodeRegister.EpisodePath = file; - try - { - episodeRegisterApi.PutOne("/episode/register", episodeRegister).GetAwaiter().GetResult(); - - _logger.Info($"Ok update episode id: {episode.ID} that was move"); - - //return - found = true; - } - catch (ApiNotFoundException ex) - { - _logger.Error($"Not found episodeRegister id: {episodeRegister.EpisodeId} for update information, details: {ex.Message}"); - } - catch (ApiConflictException ex) - { - _logger.Error($"Error conflict put episodeRegister, details error: {ex.Message}"); - } - catch (ApiGenericException ex) - { - _logger.Fatal($"Error generic put episodeRegister, details error: {ex.Message}"); - } - - break; - } - } - - //if not found file - if (found == false) - ConfirmStartDownload(episode, episodeApi); - } - - return null; - } - - private async void ConfirmStartDownload(EpisodeDTO episode, Api episodeApi) - { - //set pending to - episode.StateDownload = "pending"; - - try - { - //set change status - await episodeApi.PutOne("/video/statusDownload", episode); - - await _publishEndpoint.Publish(episode); - _logger.Info($"this file ({episode.VideoId} episode: {episode.NumberEpisodeCurrent}) does not exists, sending message to DownloadService"); - } - catch (ApiNotFoundException ex) - { - _logger.Error($"Impossible update episode becouse not found episode id: {episode.ID}, details: {ex.Message}"); - } - catch (ApiGenericException ex) - { - _logger.Fatal($"Error update episode, details error: {ex.Message}"); - } - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/CheckManager/UpgradeBook.cs b/src/references/Cesxhin.AnimeManga.Application/CheckManager/UpgradeBook.cs deleted file mode 100644 index 48d3475..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/CheckManager/UpgradeBook.cs +++ /dev/null @@ -1,214 +0,0 @@ -using Cesxhin.AnimeManga.Application.CheckManager.Interfaces; -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Generic; -using Cesxhin.AnimeManga.Application.HtmlAgilityPack; -using Cesxhin.AnimeManga.Application.NlogManager; -using Cesxhin.AnimeManga.Domain.DTO; -using MassTransit; -using Newtonsoft.Json.Linq; -using NLog; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace Cesxhin.AnimeManga.Application.CheckManager -{ - public class UpgradeBook : IUpgrade - { - //log - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - //variables - private readonly string _folder = Environment.GetEnvironmentVariable("BASE_PATH") ?? "/"; - private readonly JObject schemas = JObject.Parse(Environment.GetEnvironmentVariable("SCHEMA")); - - //list - private List listGenerics = new(); - private List listChapterRegister; - private List blacklist; - - //api - private readonly Api genericApi = new(); - private readonly Api descriptionApi = new(); - private readonly Api chapterApi = new(); - private readonly Api chapterRegisterApi = new(); - - //rabbit - private readonly IBus _publishEndpoint; - - public UpgradeBook(IBus publishEndpoint) - { - _publishEndpoint = publishEndpoint; - } - - public void ExecuteUpgrade() - { - _logger.Info($"Start upgrade book"); - foreach (var item in schemas) - { - var schema = schemas.GetValue(item.Key).ToObject(); - if (schema.GetValue("type").ToString() == "book") - { - try - { - var query = new Dictionary() - { - ["nameCfg"] = item.Key - }; - - listGenerics = genericApi.GetMore("/book/all", query).GetAwaiter().GetResult(); - } - catch (ApiNotFoundException ex) - { - _logger.Error($"not found, details: " + ex.Message); - } - - //step check on website if the anime is still active - foreach (var list in listGenerics) - { - var book = JObject.Parse(list.Book); - - //get list episodes by name - List checkChapters = null; - List listChaptersAdd = null; - - var urlPage = (string)book.GetValue("url_page"); - var name_id = (string)book.GetValue("name_id"); - - _logger.Info($"Check description for book: {name_id}"); - - var bookMerge = book.DeepClone().ToObject(); - var description = RipperBookGeneric.GetDescriptionBook(schema, urlPage, item.Key); - - bookMerge.Merge(description); - - foreach(var field in bookMerge) - { - if (!book.ContainsKey(field.Key) || (string)book[field.Key] != (string)bookMerge[field.Key]) - { - _logger.Info($"Upgrade description of book: {name_id}"); - - //insert to db - try - { - descriptionApi.PutOne("/book", bookMerge).GetAwaiter().GetResult(); - } - catch (Exception ex) - { - _logger.Fatal($"Error generic put description, details error: {ex.Message}"); - } - - break; - } - } - - _logger.Info($"End check description for book: {name_id}"); - - _logger.Info($"Check new episodes for book: {urlPage}"); - - //check new episode - checkChapters = RipperBookGeneric.GetChapters(schema, urlPage, name_id, item.Key); - - //check if null - if (checkChapters == null) - { - _logger.Error($"Can't download with this url, {urlPage}"); - continue; - } - - listChaptersAdd = new(checkChapters); - blacklist = new(); - - foreach (var checkChapter in checkChapters) - { - foreach (var chapter in list.Chapters) - { - if (chapter.CurrentChapter == checkChapter.CurrentChapter) - { - blacklist.Add(list.ChapterRegister.Find(e => e.ChapterId == chapter.ID)); - listChaptersAdd.Remove(checkChapter); - break; - } - } - } - - if (listChaptersAdd.Count > 0) - { - _logger.Info($"There are new chapters ({listChaptersAdd.Count}) of {name_id}"); - - //insert to db - listChaptersAdd = chapterApi.PostMore("/chapters", listChaptersAdd).GetAwaiter().GetResult(); - - //create episodeRegister - listChapterRegister = new(); - - string pathDefault = null; - List paths = new(); - - if (blacklist.Count > 0) - pathDefault = Path.GetDirectoryName(blacklist.FirstOrDefault().ChapterPath.First()); - - foreach (var chapter in listChaptersAdd) - { - //use path how others episodesRegisters - for (int i = 0; i <= chapter.NumberMaxImage; i++) - { - if (pathDefault != null) - { - paths.Add($"{pathDefault}/{chapter.NameManga}/Volume {chapter.CurrentVolume}/Chapter {chapter.CurrentChapter}/{chapter.NameManga} s{chapter.CurrentVolume}c{chapter.CurrentChapter}n{i}.png"); - } - else //default - { - paths.Add($"{_folder}/{chapter.NameManga}/Volume {chapter.CurrentVolume}/Chapter {chapter.CurrentChapter}/{chapter.NameManga} s{chapter.CurrentVolume}c{chapter.CurrentChapter}n{i}.png"); - } - } - - listChapterRegister.Add(new ChapterRegisterDTO - { - ChapterId = chapter.ID, - ChapterPath = paths.ToArray() - }); - - paths.Clear(); - } - - chapterRegisterApi.PostMore("/chapters/registers", listChapterRegister).GetAwaiter(); - - //create message for notify - string message = $"💽UpgradeService say: \nAdd new chapter of {name_id}\n"; - - listChaptersAdd.Sort(delegate (ChapterDTO p1, ChapterDTO p2) { return p1.CurrentChapter.CompareTo(p2.CurrentChapter); }); - foreach (var episodeNotify in listChaptersAdd) - { - message += $"- {episodeNotify.ID} Chapter: {episodeNotify.CurrentChapter}\n"; - } - - try - { - var messageNotify = new NotifyDTO - { - Message = message, - Image = (string)book.GetValue("cover") - }; - _publishEndpoint.Publish(messageNotify).GetAwaiter().GetResult(); - } - catch (Exception ex) - { - _logger.Error($"Cannot send message rabbit, details: {ex.Message}"); - } - - - _logger.Info($"Done upgrade! of {name_id}"); - } - //clear resource - listChaptersAdd.Clear(); - } - } - } - - - _logger.Info($"End upgrade book"); - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/CheckManager/UpgradeVideo.cs b/src/references/Cesxhin.AnimeManga.Application/CheckManager/UpgradeVideo.cs deleted file mode 100644 index 8515eaa..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/CheckManager/UpgradeVideo.cs +++ /dev/null @@ -1,228 +0,0 @@ -using Cesxhin.AnimeManga.Application.CheckManager.Interfaces; -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Generic; -using Cesxhin.AnimeManga.Application.HtmlAgilityPack; -using Cesxhin.AnimeManga.Application.NlogManager; -using Cesxhin.AnimeManga.Domain.DTO; -using MassTransit; -using Newtonsoft.Json.Linq; -using NLog; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace Cesxhin.AnimeManga.Application.CheckManager -{ - public class UpgradeVideo : IUpgrade - { - //log - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - //variables - private readonly string _folder = Environment.GetEnvironmentVariable("BASE_PATH") ?? "/"; - private readonly JObject schemas = JObject.Parse(Environment.GetEnvironmentVariable("SCHEMA")); - - //list - private List listGenerics = new(); - private List listEpisodeRegister; - private List blacklist; - - //api - private readonly Api genericApi = new(); - private readonly Api descriptionApi = new(); - private readonly Api episodeApi = new(); - private readonly Api episodeRegisterApi = new(); - - //rabbit - private readonly IBus _publishEndpoint; - - public UpgradeVideo(IBus publishEndpoint) - { - _publishEndpoint = publishEndpoint; - } - - public void ExecuteUpgrade() - { - _logger.Info($"Start upgrade video"); - foreach (var item in schemas) - { - var schema = schemas.GetValue(item.Key).ToObject(); - if (schema.GetValue("type").ToString() == "video") - { - try - { - var query = new Dictionary() - { - ["nameCfg"] = item.Key - }; - - listGenerics = genericApi.GetMore("/video/all", query).GetAwaiter().GetResult(); - } - catch (ApiNotFoundException ex) - { - _logger.Error($"not found, details: " + ex.Message); - } - catch (ApiGenericException ex) - { - _logger.Fatal($"Error generic get all, details error: {ex.Message}"); - } - - //step check on website if the anime is still active - foreach (var list in listGenerics) - { - var video = JObject.Parse(list.Video); - - //get list episodes by name - List checkEpisodes = null; - List listEpisodesAdd = null; - - string name_id = (string)video.GetValue("name_id"); - string urlPage = (string)video.GetValue("url_page"); - - - _logger.Info($"Check description for Video: {name_id}"); - - var videoMerge = video.DeepClone().ToObject(); - var description = RipperVideoGeneric.GetDescriptionVideo(schema, urlPage, item.Key); - - videoMerge.Merge(description); - - foreach (var field in videoMerge) - { - if (!video.ContainsKey(field.Key) || (string)video[field.Key] != (string)videoMerge[field.Key]) - { - _logger.Info($"Upgrade description of video: {name_id}"); - - //insert to db - try - { - descriptionApi.PutOne("/video", videoMerge).GetAwaiter().GetResult(); - } - catch (Exception ex) - { - _logger.Fatal($"Error generic put description, details error: {ex.Message}"); - } - - break; - } - } - - _logger.Info($"End check description for video: {name_id}"); - - _logger.Info($"Check new episodes for video: {name_id}"); - - //check new episode - checkEpisodes = RipperVideoGeneric.GetEpisodes(schema, urlPage, name_id, item.Key); - - //check if null - if (checkEpisodes == null) - { - _logger.Error($"Can't download with this url, {urlPage}"); - continue; - } - - listEpisodesAdd = new(checkEpisodes); - blacklist = new(); - - foreach (var checkEpisode in checkEpisodes) - { - foreach (var episode in list.Episodes) - { - if (episode.NumberEpisodeCurrent == checkEpisode.NumberEpisodeCurrent) - { - blacklist.Add(list.EpisodesRegister.Find(e => e.EpisodeId == episode.ID)); - listEpisodesAdd.Remove(checkEpisode); - break; - } - } - } - - if (listEpisodesAdd.Count > 0) - { - _logger.Info($"There are new episodes ({listEpisodesAdd.Count}) of {name_id}"); - - //insert to db - try - { - listEpisodesAdd = episodeApi.PostMore("/episodes", listEpisodesAdd).GetAwaiter().GetResult(); - } - catch (ApiGenericException ex) - { - _logger.Fatal($"Error generic post episodes, details error: {ex.Message}"); - } - - //create episodeRegister - listEpisodeRegister = new(); - - string pathDefault = null; - string path = null; - - if (blacklist.Count > 0) - pathDefault = Path.GetDirectoryName(blacklist.FirstOrDefault().EpisodePath); - - foreach (var episode in listEpisodesAdd) - { - path = ""; - //use path how others episodesRegisters - if (pathDefault != null) - { - path = $"{pathDefault}/{episode.VideoId} s{episode.NumberSeasonCurrent.ToString("D2")}e{episode.NumberEpisodeCurrent.ToString("D2")}.mp4"; - } - else //default - { - path = $"{_folder}/{episode.VideoId}/Season {episode.NumberSeasonCurrent.ToString("D2")}/{episode.VideoId} s{episode.NumberSeasonCurrent.ToString("D2")}e{episode.NumberEpisodeCurrent.ToString("D2")}.mp4"; - } - - listEpisodeRegister.Add(new EpisodeRegisterDTO - { - EpisodeId = episode.ID, - EpisodePath = path - }); - } - - try - { - episodeRegisterApi.PostMore("/episodes/registers", listEpisodeRegister).GetAwaiter(); - } - catch (ApiGenericException ex) - { - _logger.Fatal($"Error generic post registers, details error: {ex.Message}"); - } - - //create message for notify - string message = $"💽UpgradeService say: \nAdd new episode of {name_id}\n"; - - listEpisodesAdd.Sort(delegate (EpisodeDTO p1, EpisodeDTO p2) { return p1.NumberEpisodeCurrent.CompareTo(p2.NumberEpisodeCurrent); }); - foreach (var episodeNotify in listEpisodesAdd) - { - message += $"- {episodeNotify.VideoId} Episode: {episodeNotify.NumberEpisodeCurrent}\n"; - } - - try - { - var messageNotify = new NotifyDTO - { - Message = message, - Image = (string)video.GetValue("cover") - }; - _publishEndpoint.Publish(messageNotify).GetAwaiter().GetResult(); - } - catch (Exception ex) - { - _logger.Error($"Cannot send message rabbit, details: {ex.Message}"); - } - - - _logger.Info($"Done upgrade! of {name_id}"); - } - //clear resource - listEpisodesAdd.Clear(); - } - } - } - - _logger.Info($"End upgrade video"); - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Consumers/ConversionConsumer.cs b/src/references/Cesxhin.AnimeManga.Application/Consumers/ConversionConsumer.cs deleted file mode 100644 index 5501c5b..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Consumers/ConversionConsumer.cs +++ /dev/null @@ -1,212 +0,0 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Generic; -using Cesxhin.AnimeManga.Application.NlogManager; -using Cesxhin.AnimeManga.Domain.DTO; -using FFMpegCore; -using FFMpegCore.Enums; -using MassTransit; -using NLog; -using System; -using System.Collections.Generic; -using System.IO; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Consumers -{ - public class ConversionConsumer : IConsumer - { - //nlog - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - //temp - private string pathTemp = Environment.GetEnvironmentVariable("PATH_TEMP") ?? "D:\\TestVideo\\temp"; - - //env - private readonly string MAX_THREAD = Environment.GetEnvironmentVariable("MAX_THREAD") ?? "2"; - public Task Consume(ConsumeContext context) - { - try - { - var message = context.Message; - - Api episodeApi = new(); - Api episodeRegisterApi = new(); - - EpisodeDTO episode = null; - EpisodeRegisterDTO episodeRegister = null; - //episode - try - { - episode = episodeApi.GetOne($"/episode/id/{message.ID}").GetAwaiter().GetResult(); - } - catch (ApiNotFoundException ex) - { - _logger.Error($"Not found episodeRegister, details error: {ex.Message}"); - } - catch (ApiGenericException ex) - { - _logger.Fatal($"Impossible error generic get episodeRegister, details error: {ex.Message}"); - - } - - //episodeRegister - try - { - episodeRegister = episodeRegisterApi.GetOne($"/episode/register/episodeid/{episode.ID}").GetAwaiter().GetResult(); - } - catch (ApiNotFoundException ex) - { - _logger.Error($"Not found episodeRegister, details error: {ex.Message}"); - } - catch (ApiGenericException ex) - { - _logger.Fatal($"Impossible error generic get episodeRegister, details error: {ex.Message}"); - } - - //check - if (episode == null) - { - _logger.Fatal($"Get episode ID: {message.ID} not exitis"); - return null; - } - - - _logger.Info($"Start conversion episode ID: {message.ID}"); - - var fileTemp = $"{pathTemp}/joined-{Path.GetFileName(message.FilePath)}.ts"; - - if (!File.Exists(fileTemp)) - { - //read all bytes - List buffer = new(); - foreach (var path in message.Paths) - { - buffer.Add(File.ReadAllBytes(path)); - } - - //join bytes - using (var file = new FileStream(fileTemp, FileMode.OpenOrCreate, FileAccess.Write)) - { - foreach (var data in buffer) - file.Write(data); - } - - //destroy - buffer.Clear(); - - //delete old files - foreach (var path in message.Paths) - File.Delete(path); - } - - //send status api - episode.StateDownload = "conversioning"; - episode.PercentualDownload = 0; - SendStatusDownloadAPIAsync(episode, episodeApi); - - //convert ts to mp4 - var tempMp4 = $"{pathTemp}/{Path.GetFileName(message.FilePath)}"; - - var mediaInfo = FFProbe.Analyse(fileTemp); - - try - { - var process = FFMpegArguments - .FromFileInput(fileTemp) - .OutputToFile(tempMp4, true, options => options - .UsingThreads(int.Parse(MAX_THREAD)) - .WithVideoCodec(VideoCodec.LibX264) - .WithAudioCodec(AudioCodec.Aac) - .WithVideoFilters(filterOptions => filterOptions - .Scale(VideoSize.FullHd)) - .WithFastStart()) - .NotifyOnError((outLine) => - { - if (outLine != null) - { - if (outLine.Contains("frame=")) - { - if (DateTime.Now.Second % 5 == 0) - { - var lastFrame = outLine.Split("fps")[0].Split("=")[1].Trim(); - var percentual = Math.Round(decimal.Parse(lastFrame) / ((decimal)mediaInfo.Duration.TotalSeconds * (decimal)mediaInfo.VideoStreams[0].FrameRate) * 100); - episode.PercentualDownload = (int)percentual; - - _logger.Debug($"episode ID: {episode.ID} percentual: {episode.PercentualDownload}"); - SendStatusDownloadAPIAsync(episode, episodeApi); - } - } - } - }) - .ProcessSynchronously(); - } - catch (Exception ex) - { - _logger.Error($"Impossible conversion ID: {episode.ID}, details: {ex}"); - episode.StateDownload = "failed"; - SendStatusDownloadAPIAsync(episode, episodeApi); - return Task.CompletedTask; - } - - if (episode.StateDownload == "failed") - return Task.CompletedTask; - - File.Move(tempMp4, message.FilePath, true); - - //delete old file - File.Delete(fileTemp); - - - - //get hash and update - _logger.Info($"start calculate hash of episode id: {episode.ID}"); - string hash = Hash.GetHash(episodeRegister.EpisodePath); - _logger.Info($"end calculate hash of episode id: {episode.ID}"); - - episodeRegister.EpisodeHash = hash; - - try - { - episodeRegisterApi.PutOne("/episode/register", episodeRegister).GetAwaiter().GetResult(); - } - catch (ApiNotFoundException ex) - { - _logger.Error($"Not found episodeRegister id: {episodeRegister.EpisodeId}, details error: {ex.Message}"); - } - catch (ApiGenericException ex) - { - _logger.Fatal($"Error generic put episodeRegister, details error: {ex.Message}"); - } - - //send status api - episode.StateDownload = "completed"; - episode.PercentualDownload = 100; - SendStatusDownloadAPIAsync(episode, episodeApi); - - return Task.CompletedTask; - } - catch (Exception ex) - { - _logger.Error($"Error generic, details {ex.Message}"); - } - - return null; - } - - private void SendStatusDownloadAPIAsync(EpisodeDTO episode, Api episodeApi) - { - try - { - episodeApi.PutOne("/video/statusDownload", episode).GetAwaiter().GetResult(); - } - catch (ApiNotFoundException ex) - { - _logger.Error($"Not found episode id: {episode.ID}, details: {ex.Message}"); - } - catch (ApiGenericException ex) - { - _logger.Error($"Error generic api, details: {ex.Message}"); - } - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Consumers/DeleteBookConsumer.cs b/src/references/Cesxhin.AnimeManga.Application/Consumers/DeleteBookConsumer.cs deleted file mode 100644 index c6b1970..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Consumers/DeleteBookConsumer.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Generic; -using Cesxhin.AnimeManga.Application.NlogManager; -using Cesxhin.AnimeManga.Domain.DTO; -using MassTransit; -using NLog; -using System; -using System.Collections.Generic; -using System.IO; -using System.Threading; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Consumers -{ - public class DeleteBookConsumer : IConsumer - { - //nlog - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - public Task Consume(ConsumeContext context) - { - var chapterRegister = context.Message; - - foreach (var singlePath in chapterRegister.ChapterPath) - { - try - { - File.Delete(singlePath); - _logger.Info($"Delete success! {singlePath}"); - } - catch (FileNotFoundException ex) - { - _logger.Warn($"File not found: {singlePath}, details: {ex}"); - } - catch (DirectoryNotFoundException ex) - { - _logger.Warn($"File not found: {singlePath}, details: {ex}"); - } - catch (Exception ex) - { - _logger.Error($"Error generic of file {singlePath}, details: {ex}"); - } - } - - return Task.CompletedTask; - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Consumers/DeleteVideoConsumer.cs b/src/references/Cesxhin.AnimeManga.Application/Consumers/DeleteVideoConsumer.cs deleted file mode 100644 index 969488c..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Consumers/DeleteVideoConsumer.cs +++ /dev/null @@ -1,43 +0,0 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Generic; -using Cesxhin.AnimeManga.Application.NlogManager; -using Cesxhin.AnimeManga.Domain.DTO; -using MassTransit; -using NLog; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Consumers -{ - public class DeleteVideoConsumer : IConsumer - { - //nlog - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - public Task Consume(ConsumeContext context) - { - var episodeRegister = context.Message; - - try - { - File.Delete(episodeRegister.EpisodePath); - _logger.Info($"Delete success! {episodeRegister.EpisodePath}"); - } - catch (FileNotFoundException ex) - { - _logger.Warn($"File not found: {episodeRegister.EpisodePath}, details: {ex.Message}"); - } - catch (Exception ex) - { - _logger.Error($"Error generic of file {episodeRegister.EpisodeId}, details: {ex.Message}"); - } - - return Task.CompletedTask; - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Consumers/DownloadBookConsumer.cs b/src/references/Cesxhin.AnimeManga.Application/Consumers/DownloadBookConsumer.cs deleted file mode 100644 index 917d869..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Consumers/DownloadBookConsumer.cs +++ /dev/null @@ -1,202 +0,0 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Generic; -using Cesxhin.AnimeManga.Application.HtmlAgilityPack; -using Cesxhin.AnimeManga.Application.NlogManager; -using Cesxhin.AnimeManga.Application.Parallel; -using Cesxhin.AnimeManga.Domain.DTO; -using MassTransit; -using NLog; -using System; -using System.Collections.Generic; -using System.IO; -using System.Threading; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Consumers -{ - public class DownloadBookConsumer : IConsumer - { - //nlog - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - //Instance Parallel - private readonly ParallelManager parallel = new(); - - //api - private readonly Api chapterApi = new(); - private readonly Api chapterRegisterApi = new(); - - //download - private readonly int MAX_DELAY = int.Parse(Environment.GetEnvironmentVariable("MAX_DELAY") ?? "5"); - private readonly int DELAY_RETRY_ERROR = int.Parse(Environment.GetEnvironmentVariable("DELAY_RETRY_ERROR") ?? "10000"); - - - public Task Consume(ConsumeContext context) - { - //get body - var chapter = context.Message; - - //chapterRegister - ChapterRegisterDTO chapterRegister = null; - try - { - chapterRegister = chapterRegisterApi.GetOne($"/chapter/register/chapterid/{chapter.ID}").GetAwaiter().GetResult(); - } - catch (ApiNotFoundException ex) - { - _logger.Error($"Not found episodeRegister, details error: {ex.Message}"); - } - catch (ApiGenericException ex) - { - _logger.Fatal($"Impossible error generic get episodeRegister, details error: {ex.Message}"); - } - - //chapter - ChapterDTO chapterVerify = null; - try - { - chapterVerify = chapterApi.GetOne($"/chapter/id/{chapter.ID}").GetAwaiter().GetResult(); - } - catch (ApiNotFoundException ex) - { - _logger.Error($"Not found episodeRegister, details error: {ex.Message}"); - } - catch (ApiGenericException ex) - { - _logger.Fatal($"Impossible error generic get episodeRegister, details error: {ex.Message}"); - } - - //check duplication messages - if (chapterVerify != null && chapterVerify.StateDownload == "pending") - { - _logger.Info($"Start download manga {chapter.NameManga} of volume {chapter.CurrentVolume} chapter {chapter.CurrentChapter}"); - - //create empty file - for (int i = 0; i <= chapter.NumberMaxImage; i++) - { - //check directory - var pathWithoutFile = Path.GetDirectoryName(chapterRegister.ChapterPath[i]); - if (Directory.Exists(pathWithoutFile) == false) - Directory.CreateDirectory(pathWithoutFile); - - File.WriteAllBytes(chapterRegister.ChapterPath[i], new byte[0]); - } - - //set start download - chapter.StateDownload = "downloading"; - SendStatusDownloadAPIAsync(chapter); - - //set parallel - var tasks = new List>(); - - //step one check file - for (int i = 0; i <= chapter.NumberMaxImage; i++) - { - var currentImage = i; - var path = chapterRegister.ChapterPath[currentImage]; - tasks.Add(new Func(() => Download(chapter, path, currentImage))); - } - parallel.AddTasks(tasks); - parallel.Start(); - - while (!parallel.CheckFinish()) - { - //send status download - chapter.PercentualDownload = parallel.PercentualCompleted(); - SendStatusDownloadAPIAsync(chapter); - Thread.Sleep(3000); - } - } - - var result = parallel.GetResultAndClear(); - - if (result.Contains("failed")) - { - //send failed download - chapter.StateDownload = "failed"; - chapter.PercentualDownload = 0; - SendStatusDownloadAPIAsync(chapter); - - _logger.Error($"failed download {chapter.ID} v{chapter.CurrentVolume}-c{chapter.CurrentChapter}"); - return Task.CompletedTask; - } - - //get hash and update - _logger.Info($"start calculate hash of chapter id: {chapter.ID}"); - List listHash = new(); - for (int i = 0; i <= chapter.NumberMaxImage; i++) - { - listHash.Add(Hash.GetHash(chapterRegister.ChapterPath[i])); - } - _logger.Info($"end calculate hash of episode id: {chapter.ID}"); - - chapterRegister.ChapterHash = listHash.ToArray(); - - try - { - chapterRegisterApi.PutOne("/chapter/register", chapterRegister).GetAwaiter().GetResult(); - } - catch (ApiNotFoundException ex) - { - _logger.Error($"Not found episodeRegister id: {chapterRegister.ChapterId}, details error: {ex.Message}"); - } - catch (ApiGenericException ex) - { - _logger.Fatal($"Error generic put episodeRegister, details error: {ex.Message}"); - } - - //end download - chapter.PercentualDownload = 100; - chapter.StateDownload = "completed"; - SendStatusDownloadAPIAsync(chapter); - - _logger.Info($"Done download manga {chapter.NameManga} of volume {chapter.CurrentVolume} chapter {chapter.CurrentChapter}"); - return Task.CompletedTask; - } - - private string Download(ChapterDTO chapter, string path, int currentImage) - { - byte[] imgBytes; - int timeout = 0; - while (true) - { - imgBytes = RipperBookGeneric.GetImagePage(chapter.UrlPage, currentImage, chapter); - - if (timeout >= MAX_DELAY) - { - _logger.Error($"Failed download, details: {chapter.UrlPage}"); - return "failed"; - } - else if (imgBytes == null) - { - _logger.Warn($"The attempts remains: {MAX_DELAY - timeout} for {chapter.UrlPage}"); - Task.Delay(DELAY_RETRY_ERROR); - timeout++; - } - else - break; - - } - - File.WriteAllBytes(path, imgBytes); - - return "done"; - } - - private void SendStatusDownloadAPIAsync(ChapterDTO chapter) - { - try - { - chapterApi.PutOne("/book/statusDownload", chapter).GetAwaiter().GetResult(); - } - catch (ApiNotFoundException ex) - { - _logger.Error($"Not found episode id: {chapter.ID}, details: {ex.Message}"); - } - catch (ApiGenericException ex) - { - _logger.Error($"Error generic api, details: {ex.Message}"); - } - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Consumers/DownloadVideoConsumer.cs b/src/references/Cesxhin.AnimeManga.Application/Consumers/DownloadVideoConsumer.cs deleted file mode 100644 index 9502897..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Consumers/DownloadVideoConsumer.cs +++ /dev/null @@ -1,556 +0,0 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Generic; -using Cesxhin.AnimeManga.Application.NlogManager; -using Cesxhin.AnimeManga.Application.Parallel; -using Cesxhin.AnimeManga.Application.Proxy; -using Cesxhin.AnimeManga.Domain.DTO; -using Cesxhin.AnimeManga.Domain.Models; -using MassTransit; -using NLog; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.IO; -using System.Linq; -using System.Net; -using System.Threading; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Consumers -{ - public class DownloadVideoConsumer : IConsumer - { - //nlog - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - //parallel - private readonly ParallelManager parallel = new(); - - //temp - private string pathTemp = Environment.GetEnvironmentVariable("PATH_TEMP") ?? "D:\\TestVideo\\temp"; - - //download - private readonly int MAX_DELAY = int.Parse(Environment.GetEnvironmentVariable("MAX_DELAY") ?? "5"); - private readonly int DELAY_RETRY_ERROR = int.Parse(Environment.GetEnvironmentVariable("DELAY_RETRY_ERROR") ?? "10000"); - - public Task Consume(ConsumeContext context) - { - //get body - var episode = context.Message; - - //api - Api episodeRegisterApi = new(); - Api videoApi = new(); - Api episodeApi = new(); - - EpisodeRegisterDTO episodeRegister = null; - EpisodeDTO episodeVerify = null; - - //episodeRegister - try - { - episodeRegister = episodeRegisterApi.GetOne($"/episode/register/episodeid/{episode.ID}").GetAwaiter().GetResult(); - } - catch (ApiNotFoundException ex) - { - _logger.Error($"Not found episodeRegister, details error: {ex.Message}"); - } - catch (ApiGenericException ex) - { - _logger.Fatal($"Impossible error generic get episodeRegister, details error: {ex.Message}"); - } - - //episode - try - { - episodeVerify = episodeApi.GetOne($"/episode/id/{episode.ID}").GetAwaiter().GetResult(); - } - catch (ApiNotFoundException ex) - { - _logger.Error($"Not found episodeRegister, details error: {ex.Message}"); - } - catch (ApiGenericException ex) - { - _logger.Fatal($"Impossible error generic get episodeRegister, details error: {ex.Message}"); - } - - //check duplication messages - if (episodeVerify != null && episodeVerify.StateDownload == "pending") - { - //paths - var directoryPath = Path.GetDirectoryName(episodeRegister.EpisodePath); - var filePathTemp = Path.GetFullPath($"{pathTemp}/{Path.GetFileName(episodeRegister.EpisodePath)}"); - - //check directory - if (!Directory.Exists(directoryPath)) - Directory.CreateDirectory(directoryPath); - - if (!Directory.Exists(Path.GetDirectoryName(filePathTemp))) - Directory.CreateDirectory(Path.GetDirectoryName(filePathTemp)); - - //check type url - if (episode.UrlVideo != null) - { - //api - Api episodeDTOApi = new(); - - //url with file - using (var client = new MyWebClient()) - { - //set proxy - var ip = ProxyManagement.GetAllIP(); - - //task - client.DownloadProgressChanged += client_DownloadProgressChanged(filePathTemp, episode); - client.DownloadFileCompleted += client_DownloadFileCompleted(filePathTemp, episode); - - //setup - int timeout = 0; - - //send api failed download - episode.StateDownload = "downloading"; - episode.PercentualDownload = 0; - SendStatusDownloadAPIAsync(episode, episodeDTOApi); - - do - { - if (ProxyManagement.EnableProxy() && ip.Any()) - { - client.Proxy = new WebProxy(new Uri(ip.First())); - ip.Remove(ip.First()); - } - else - client.Proxy = null; - - - if (timeout >= MAX_DELAY) - { - //send api failed download - episode.StateDownload = "failed"; - SendStatusDownloadAPIAsync(episode, episodeDTOApi); - - _logger.Error($"Failed download, details: {episode.UrlVideo}"); - return null; - } - - - _logger.Info("try download: " + episode.UrlVideo); - try - { - Dictionary query = new() - { - ["nameCfg"] = episode.nameCfg - }; - var video = videoApi.GetOne($"/video/name/{episode.VideoId}", query).GetAwaiter().GetResult(); - - //setup client - client.Timeout = 60000; //? check - - //start download - client.DownloadFileTaskAsync(new Uri(episode.UrlVideo), filePathTemp).ConfigureAwait(false).GetAwaiter().GetResult(); - - File.Move(filePathTemp, episodeRegister.EpisodePath, true); - break; - } - catch (ApiNotFoundException ex) - { - _logger.Error($"Not found anime so can't set headers referer for download, details: {ex.Message}"); - } - catch (WebException ex) - { - _logger.Error($"{ex.Message}, failed download {episode.UrlVideo}"); - - if (client.Proxy == null) - { - //reset ip - ip = ProxyManagement.GetAllIP(); - - //set timeout - timeout++; - - _logger.Warn($"The attempts remains: {MAX_DELAY - timeout} for {episode.UrlVideo}"); - Thread.Sleep(DELAY_RETRY_ERROR); - } - else - { - if (ip.Any()) - _logger.Warn($"Failed download, try change proxy: {ip.First()}"); - else - _logger.Warn($"Failed all proxy, try use local network"); - Thread.Sleep(1000); - } - } - catch (Exception ex) - { - _logger.Fatal($"Error download with url easy, details error: {ex.Message}"); - timeout = MAX_DELAY; - } - } while (true); - - } - - //get hash and update - _logger.Info($"start calculate hash of episode id: {episode.ID}"); - string hash = Hash.GetHash(episodeRegister.EpisodePath); - _logger.Info($"end calculate hash of episode id: {episode.ID}"); - - episodeRegister.EpisodeHash = hash; - - try - { - episodeRegisterApi.PutOne("/episode/register", episodeRegister).GetAwaiter().GetResult(); - } - catch (ApiNotFoundException ex) - { - _logger.Error($"Not found episodeRegister id: {episodeRegister.EpisodeId}, details error: {ex.Message}"); - } - catch (ApiGenericException ex) - { - _logger.Fatal($"Error generic put episodeRegister, details error: {ex.Message}"); - } - - //download finish download - episode.StateDownload = "completed"; - episode.PercentualDownload = 100; - SendStatusDownloadAPIAsync(episode, episodeApi); - } - else - { - //url stream - try - { - Download(episode, filePathTemp, episodeRegister.EpisodePath, context); - } - catch (Exception ex) - { - _logger.Fatal($"Error download with url stream, details error: {ex.Message}"); - } - } - } - - _logger.Info($"Completed task download episode id: {episode.ID}"); - return Task.CompletedTask; - } - - //download url with files stream - private async void Download(EpisodeDTO episode, string filePathTemp, string filePath, ConsumeContext context) - { - //timeout if not response one resource and close with status failed - int timeoutFile = 0; - - //api - Api episodeDTOApi = new(); - - while (true) - { - if (timeoutFile >= 10) - { - //send api failed download - episode.StateDownload = "failed"; - SendStatusDownloadAPIAsync(episode, episodeDTOApi); - - throw new Exception($"{filePathTemp} impossible open file, contact administrator please"); - } - - try - { - //create file and save to end operation - List buffer = new(); - List> tasks = new(); - - _logger.Info($"start download {episode.VideoId} s{episode.NumberSeasonCurrent}-e{episode.NumberEpisodeCurrent}"); - - //change by pending to downloading - episode.StateDownload = "downloading"; - SendStatusDownloadAPIAsync(episode, episodeDTOApi); - - for (int numberFrame = episode.startNumberBuffer; numberFrame < episode.endNumberBuffer; numberFrame++) - { - var numberFrameSave = numberFrame; - tasks.Add(new Func(() => { return DownloadBuffParallel(episode, numberFrameSave, filePathTemp, episodeDTOApi); })); - } - - parallel.AddTasks(tasks); - parallel.Start(); - - while (!parallel.CheckFinish()) - { - //send status download - episode.PercentualDownload = parallel.PercentualCompleted(); - SendStatusDownloadAPIAsync(episode, episodeDTOApi); - - if (parallel.checkError(null)) - { - parallel.Kill(); - } - - Thread.Sleep(3000); - } - - buffer = parallel.GetResultAndClear(); - - if (buffer.Contains(null)) - { - //send end download - episode.StateDownload = "failed"; - episode.PercentualDownload = 0; - SendStatusDownloadAPIAsync(episode, episodeDTOApi); - - _logger.Error($"failed download {episode.VideoId} s{episode.NumberSeasonCurrent}-e{episode.NumberEpisodeCurrent}"); - return; - } - - buffer.Sort(delegate (EpisodeBuffer p1, EpisodeBuffer p2) { return p1.Id.CompareTo(p2.Id); }); - - List paths = new(); - - foreach (var singleBuffer in buffer) - { - using (var fsBuffer = new FileStream(singleBuffer.Path, FileMode.OpenOrCreate, FileAccess.Write)) - { - fsBuffer.Write(singleBuffer.Data); - paths.Add(singleBuffer.Path); - } - } - - _logger.Info($"end download {episode.VideoId} s{episode.NumberSeasonCurrent}-e{episode.NumberEpisodeCurrent}"); - - //send end download - episode.StateDownload = "wait conversion"; - episode.PercentualDownload = 100; - SendStatusDownloadAPIAsync(episode, episodeDTOApi); - - //send message to ConversionService; - try - { - var conversionDTO = new ConversionDTO - { - ID = episode.ID, - Paths = paths, - FilePath = filePath - }; - - await context.Publish(conversionDTO); - } - catch (Exception ex) - { - _logger.Error($"Cannot send message rabbit, details: {ex.Message}"); - } - - return; - } - catch (IOException ex) - { - _logger.Error($"{filePathTemp} can't open, details: {ex.Message}"); - timeoutFile++; - } - catch (Exception ex) - { - _logger.Fatal($"{filePathTemp} can't open, details: {ex.Message}"); - } - } - } - - private EpisodeBuffer DownloadBuffParallel(EpisodeDTO episode, int numberFrame, string filePath, Api episodeDTOApi) - { - string url = $"{episode.BaseUrl}/{episode.Resolution}/{episode.Resolution}-{numberFrame.ToString("D3")}.ts"; - Uri uri = new Uri(url); - - //setup - int timeout = 0; - - //download frame - using (var client = new MyWebClient()) - { - client.Timeout = 60000; //? check - - //set proxy - var ip = ProxyManagement.GetAllIP(); - - do - { - if(ProxyManagement.EnableProxy() && ip.Any()) - { - client.Proxy = new WebProxy(new Uri(ip.First())); - ip.Remove(ip.First()); - } - else - client.Proxy = null; - - if (timeout >= MAX_DELAY) - { - //send api failed download - episode.StateDownload = "failed"; - SendStatusDownloadAPIAsync(episode, episodeDTOApi); - - _logger.Error($"Failed download, details: {url}"); - - //delete file - //fs.Close(); - if (File.Exists(filePath)) - { - File.Delete(filePath); - _logger.Warn($"The file is deleted {filePath}"); - } - return null; - } - - try - { - var data = client.DownloadData(uri); - return new EpisodeBuffer - { - Id = numberFrame, - Data = data, - Path = $"{pathTemp}/{episode.ID}-{episode.Resolution}-{numberFrame.ToString("D3")}.ts", - }; - } - catch(WebException ex) - { - _logger.Error($"{ex.Message}, failed download {url}"); - - if (client.Proxy == null) - { - //reset ip - ip = ProxyManagement.GetAllIP(); - - //set timeout - timeout++; - - _logger.Warn($"The attempts remains: {MAX_DELAY - timeout} for {url}"); - Thread.Sleep(DELAY_RETRY_ERROR); - } - else - { - if (ip.Any()) - _logger.Warn($"Failed download, try change proxy: {ip.First()}"); - else - _logger.Warn($"Failed all proxy, try use local network"); - Thread.Sleep(1000); - } - } - catch (Exception ex) - { - _logger.Fatal($"Error generic, details : {ex.Message}"); - return null; - } - } while (true); - } - } - - private DownloadProgressChangedEventHandler client_DownloadProgressChanged(string filePath, EpisodeDTO episode) - { - //change by pending to downloading - episode.StateDownload = "downloading"; - - int lastTriggerTime = 0; - int intervalCheck; - - //api - Api episodeDTO = new(); - - try - { - Action action = (sender, e) => - { - //print progress - _logger.Debug(e.ProgressPercentage + "% | " + e.BytesReceived + " bytes out of " + e.TotalBytesToReceive + " bytes retrieven of the file: " + filePath); - - //send only one data every 3 seconds - intervalCheck = DateTime.Now.Second; - if (lastTriggerTime > intervalCheck) - lastTriggerTime = 3; - - if (intervalCheck % 3 == 0 && (intervalCheck - lastTriggerTime) >= 3) - { - lastTriggerTime = DateTime.Now.Second; - - //send status download - episode.PercentualDownload = e.ProgressPercentage; - SendStatusDownloadAPIAsync(episode, episodeDTO); - } - }; - return new DownloadProgressChangedEventHandler(action); - } - catch (Exception ex) - { - _logger.Error(ex.Message); - } - return null; - - } - private AsyncCompletedEventHandler client_DownloadFileCompleted(string filePath, EpisodeDTO episode) - { - try - { - //api - Api episodeDTO = new(); - - //recive response action - Action action = (sender, e) => - { - if (e.Error != null) - { - _logger.Error($"Interrupt download file {filePath}"); - _logger.Error(e.Error); - - if (File.Exists(filePath)) - { - try - { - File.Delete(filePath); - _logger.Warn($"The file is deleted {filePath}"); - } - catch (IOException ex) - { - _logger.Error($"cannot delete file {filePath}, details error:{ex.Message}"); - } - } - /*//send failed download - episode.StateDownload = "failed"; - SendStatusDownloadAPIAsync(episode, episodeDTO);*/ - } - else - { - _logger.Info($"Download completed! {filePath}"); - } - }; - return new AsyncCompletedEventHandler(action); - } - catch (Exception ex) - { - _logger.Error(ex); - } - return null; - } - - private void SendStatusDownloadAPIAsync(EpisodeDTO episode, Api episodeApi) - { - try - { - episodeApi.PutOne("/video/statusDownload", episode).GetAwaiter().GetResult(); - } - catch (ApiNotFoundException ex) - { - _logger.Error($"Not found episode id: {episode.ID}, details: {ex.Message}"); - } - catch (ApiGenericException ex) - { - _logger.Error($"Error generic api, details: {ex.Message}"); - } - } - } - - //custom WebClient for set Timeout - public class MyWebClient : WebClient - { - public int? Timeout { get; set; } - - protected override WebRequest GetWebRequest(Uri uri) - { - WebRequest webRequest = base.GetWebRequest(uri); - webRequest.Timeout = (int)Timeout; - return webRequest; - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Controllers/IGeneralControllerBase.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Controllers/IGeneralControllerBase.cs deleted file mode 100644 index ef8ffd2..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Controllers/IGeneralControllerBase.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Controllers -{ - public interface IGeneralControllerBase - { - //get - public Task GetInfoAll(string nameCfg, string username); - public Task GetInfoByName(string nameCfg, string name, string username); - public Task GetMostInfoByName(string nameCfg, string name, string username); - public Task GetAll(string nameCfg, string username); - public Task GetObjectByName(string name); - public Task GetObjectById(string id); - public Task GetObjectRegisterByObjectId(string id); - public Task GetListSearchByName(string nameCfg, string name); - public Task GetStateProgress(string name, string username, string nameCfg); - - //put - public Task PutInfo(string nameCfg, I infoClass); - public Task UpdateInfo(string content); - public Task PutObject(O objectClass); - public Task PutObjects(List objectsClass); - public Task PutObjectsRegisters(List objectsRegistersClass); - public Task UpdateObjectRegister(R objectRegisterClass); - public Task RedownloadObjectByUrlPage(string id); - public Task DownloadInfoByUrlPage(D objectsClass); - public Task PutUpdateStateDownload(O objectClass); - public Task PutStateProgress(E objectClass); - - //delete - public Task DeleteInfo(string nameCfg, string id); - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IAccountRepository.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IAccountRepository.cs deleted file mode 100644 index 8b02ca2..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IAccountRepository.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Cesxhin.AnimeManga.Domain.Models; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Repositories -{ - public interface IAccountRepository - { - public Task CreateAccount(Auth auth); - public Task FindAccountByUsername(string username); - - //whitelist generic - public Task> GetListWatchListByUsername(string username); - public Task InsertWhiteList(WatchList whiteList); - public Task DeleteWhiteList(WatchList whiteList); - public Task WhiteListCheckByName(string name); - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IChapterRegisterRepository.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IChapterRegisterRepository.cs deleted file mode 100644 index dbb1c89..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IChapterRegisterRepository.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Cesxhin.AnimeManga.Domain.Models; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Repositories -{ - public interface IChapterRegisterRepository : IGeneralObjectRegisterRepository - { - } -} \ No newline at end of file diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IChapterRepository.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IChapterRepository.cs deleted file mode 100644 index 7129947..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IChapterRepository.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Cesxhin.AnimeManga.Domain.Models; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Repositories -{ - public interface IChapterRepository : IGeneralObjectRepository - { - public Task DeleteByNameAsync(string id); - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IDescriptionRepository.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IDescriptionRepository.cs deleted file mode 100644 index d8b649c..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IDescriptionRepository.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Newtonsoft.Json.Linq; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Repositories -{ - public interface IDescriptionRepository : IGeneralNameRepository - { - - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IEpisodeRegisterRepository.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IEpisodeRegisterRepository.cs deleted file mode 100644 index 98ab7f3..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IEpisodeRegisterRepository.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Cesxhin.AnimeManga.Domain.Models; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Repositories -{ - public interface IEpisodeRegisterRepository : IGeneralObjectRegisterRepository - { - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IEpisodeRepository.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IEpisodeRepository.cs deleted file mode 100644 index 1d86b29..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IEpisodeRepository.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Cesxhin.AnimeManga.Domain.Models; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Repositories -{ - public interface IEpisodeRepository : IGeneralObjectRepository - { - public Task DeleteByNameAsync(string id); - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IGeneralNameRepository.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IGeneralNameRepository.cs deleted file mode 100644 index 537bb44..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IGeneralNameRepository.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Repositories -{ - public interface IGeneralNameRepository - { - //get - Task> GetNameAllAsync(string nameCfg); - Task GetNameByNameAsync(string nameCfg, string name); - Task> GetMostNameByNameAsync(string nameCfg, string name); - - //Insert - Task InsertNameAsync(string nameCfg, TGeneralName generalName); - - //Update - Task UpdateNameAsync(string nameCfg, TGeneralName generalName); - - //delete - Task DeleteNameAsync(string nameCfg, string id); - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IGeneralObjectRegisterRepository.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IGeneralObjectRegisterRepository.cs deleted file mode 100644 index c71d4b8..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IGeneralObjectRegisterRepository.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Repositories -{ - public interface IGeneralObjectRegisterRepository - { - //get - Task GetObjectRegisterByObjectId(string id); - Task> GetObjectsRegistersByListObjectId(List listObjects); - - //insert - Task> InsertObjectsRegisterAsync(List objectRegister); - Task InsertObjectRegisterAsync(T objectRegister); - - //put - Task UpdateObjectRegisterAsync(T objectRegister); - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IGeneralObjectRepository.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IGeneralObjectRepository.cs deleted file mode 100644 index b8cec89..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IGeneralObjectRepository.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Repositories -{ - public interface IGeneralObjectRepository - { - //get - Task GetObjectByIDAsync(string id); - Task> GetObjectsByNameAsync(string nameGeneral); - - //insert - Task> InsertObjectsAsync(List objectsGeneral); - Task InsertObjectAsync(T objectGeneral); - - //update - Task UpdateStateDownloadAsync(T objectGeneral); - - //reset - Task ResetStatusDownloadObjectByIdAsync(T objectGeneral); - Task> ResetStatusDownloadObjectsByIdAsync(List objectsGeneral); - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IProgressChapterRepository.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IProgressChapterRepository.cs deleted file mode 100644 index 5a555f0..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IProgressChapterRepository.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Cesxhin.AnimeManga.Domain.Models; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Repositories -{ - public interface IProgressChapterRepository - { - public Task UpdateProgress(ProgressChapter progress); - public Task CheckProgress(string name, string username, string nameCfg); - public Task CreateProgress(ProgressChapter progress); - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IProgressEpisodeRepository.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IProgressEpisodeRepository.cs deleted file mode 100644 index 6c413ad..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Repositories/IProgressEpisodeRepository.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Cesxhin.AnimeManga.Domain.Models; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Repositories -{ - public interface IProgressEpisodeRepository - { - public Task UpdateProgress(ProgressEpisode progress); - public Task CheckProgress(string name, string username, string nameCfg); - public Task CreateProgress(ProgressEpisode progress); - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IAccountService.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IAccountService.cs deleted file mode 100644 index c8f11b0..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IAccountService.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Cesxhin.AnimeManga.Domain.DTO; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Services -{ - public interface IAccountService - { - public Task Login(string username, string password); - public Task CreateAccount(string username, string password); - - //whitelist generic - public Task> GetListWatchListByUsername(string username); - public Task InsertWatchList(WatchListDTO whiteListDTO); - public Task DeleteWatchList(WatchListDTO whiteListDTO); - public Task WatchListCheckByName(string name); - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IChapterRegisterService.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IChapterRegisterService.cs deleted file mode 100644 index 6196df2..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IChapterRegisterService.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Cesxhin.AnimeManga.Domain.DTO; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Services -{ - public interface IChapterRegisterService : IGeneralObjectRegister - { - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IChapterService.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IChapterService.cs deleted file mode 100644 index b3a07b8..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IChapterService.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Cesxhin.AnimeManga.Domain.DTO; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Services -{ - public interface IChapterService : IGeneralObject - { - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IDescriptionBookService.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IDescriptionBookService.cs deleted file mode 100644 index aa60034..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IDescriptionBookService.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Cesxhin.AnimeManga.Domain.DTO; -using Newtonsoft.Json.Linq; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Services -{ - public interface IDescriptionBookService : IGeneralNameService - { - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IDescriptionVideoService.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IDescriptionVideoService.cs deleted file mode 100644 index c460181..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IDescriptionVideoService.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Cesxhin.AnimeManga.Domain.DTO; -using Newtonsoft.Json.Linq; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Services -{ - public interface IDescriptionVideoService : IGeneralNameService - { - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IEpisodeRegisterService.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IEpisodeRegisterService.cs deleted file mode 100644 index 0067900..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IEpisodeRegisterService.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Cesxhin.AnimeManga.Domain.DTO; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Services -{ - public interface IEpisodeRegisterService : IGeneralObjectRegister - { - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IEpisodeService.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IEpisodeService.cs deleted file mode 100644 index 5757c3d..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IEpisodeService.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Cesxhin.AnimeManga.Domain.DTO; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Services -{ - public interface IEpisodeService : IGeneralObject - { - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IGeneralNameService.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IGeneralNameService.cs deleted file mode 100644 index 70c94ea..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IGeneralNameService.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Services -{ - public interface IGeneralNameService - { - //get - Task> GetNameAllAsync(string nameCfg, string username); - Task GetNameByNameAsync(string nameCfg, string name, string username); - Task> GetMostNameByNameAsync(string nameCfg, string name, string username); - Task> GetNameAllWithAllAsync(string nameCfg, string username); - Task> GetNameAllOnlyWatchListAsync(string nameCfg, string username); - - //insert - Task InsertNameAsync(string nameCfg, TGeneralNameDTO anime); - - //update - Task UpdateNameAsync(string nameCfg, TGeneralNameDTO anime); - - //delete - Task DeleteNameByIdAsync(string nameCfg, string id); - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IGeneralObject.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IGeneralObject.cs deleted file mode 100644 index f19fc2d..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IGeneralObject.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Services -{ - public interface IGeneralObject - { - //get - Task GetObjectByIDAsync(string id); - Task> GetObjectsByNameAsync(string name); - - //insert - Task> InsertObjectsAsync(List generalObjects); - Task InsertObjectAsync(TObjectDTO generalObject); - - //update - Task UpdateStateDownloadAsync(TObjectDTO generalObject); - - //reset - Task ResetStatusDownloadObjectByIdAsync(TObjectDTO generalObject); - Task> ResetStatusMultipleDownloadObjectByIdAsync(string name); - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IGeneralObjectRegister.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IGeneralObjectRegister.cs deleted file mode 100644 index 2c70119..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IGeneralObjectRegister.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Services -{ - public interface IGeneralObjectRegister - { - //get - Task GetObjectRegisterByObjectId(string id); - Task> GetObjectsRegistersByListObjectId(List objectDTOs); - - //insert - Task InsertObjectRegisterAsync(TObjectRegisterDTO objectGeneralRegister); - Task> InsertObjectsRegistersAsync(List objectGeneralRegister); - - //put - Task UpdateObjectRegisterAsync(TObjectRegisterDTO objectGeneralRegister); - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IProgressChapterService.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IProgressChapterService.cs deleted file mode 100644 index f0d1178..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IProgressChapterService.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Cesxhin.AnimeManga.Domain.DTO; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Services -{ - public interface IProgressChapterService - { - //get - public Task GetProgressByName(string name, string username, string nameCfg); - - //update - public Task UpdateProgress(ProgressChapterDTO progress); - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IProgressEpisodeService.cs b/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IProgressEpisodeService.cs deleted file mode 100644 index b7ef3f7..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Interfaces/Services/IProgressEpisodeService.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Cesxhin.AnimeManga.Domain.DTO; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Interfaces.Services -{ - public interface IProgressEpisodeService - { - //get - public Task GetProgressByName(string name, string username, string nameCfg); - - //update - public Task UpdateProgress(ProgressEpisodeDTO progress); - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Services/AccountService.cs b/src/references/Cesxhin.AnimeManga.Application/Services/AccountService.cs deleted file mode 100644 index 5f091eb..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Services/AccountService.cs +++ /dev/null @@ -1,109 +0,0 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Interfaces.Repositories; -using Cesxhin.AnimeManga.Application.Interfaces.Services; -using Cesxhin.AnimeManga.Domain.DTO; -using Cesxhin.AnimeManga.Domain.Models; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Services -{ - public class AccountService : IAccountService - { - public readonly IAccountRepository _accountRepository; - public AccountService(IAccountRepository accountRepository) - { - _accountRepository = accountRepository; - } - - private static bool ValidPassword(string password, string hasedPassword) - { - return BCrypt.Net.BCrypt.Verify(password, hasedPassword); - } - - private static string CryptPasword(string password) - { - return BCrypt.Net.BCrypt.HashPassword(password); - } - - public async Task CreateAccount(string username, string password) - { - try - { - await _accountRepository.FindAccountByUsername(username); - throw new ApiConflictException("Conflict CreateAccount"); - } - catch (ApiNotFoundException) - { - var auth = new Auth - { - Username = username, - Password = password - }; - - auth.Password = CryptPasword(auth.Password); - var authResult = await _accountRepository.CreateAccount(auth); - - return AuthDTO.AuthToAuthDTO(authResult); - } - } - - public async Task Login(string username, string password) - { - Auth findUser; - try - { - findUser = await _accountRepository.FindAccountByUsername(username); - } - catch (ApiNotFoundException) - { - throw new ApiNotAuthorizeException("Not Authorize Login"); - } - - if (findUser != null && ValidPassword(password, findUser.Password)) - return AuthDTO.AuthToAuthDTO(findUser); - else - throw new ApiNotAuthorizeException("Not Authorize Login"); - - } - - public async Task InsertWatchList(WatchListDTO whiteListDTO) - { - try - { - await _accountRepository.WhiteListCheckByName(whiteListDTO.Name); - throw new ApiConflictException("Conflict InsertWatchList"); - } - catch (ApiNotFoundException) - { - var result = await _accountRepository.InsertWhiteList(WatchList.WatchListDTOToWatchList(whiteListDTO)); - return WatchListDTO.WatchListToWatchListDTO(result); - } - } - - public async Task DeleteWatchList(WatchListDTO whiteListDTO) - { - var result = await _accountRepository.DeleteWhiteList(WatchList.WatchListDTOToWatchList(whiteListDTO)); - return WatchListDTO.WatchListToWatchListDTO(result); - } - - public async Task WatchListCheckByName(string name) - { - return await _accountRepository.WhiteListCheckByName(name); - } - - public async Task> GetListWatchListByUsername(string username) - { - var result = await _accountRepository.GetListWatchListByUsername(username); - - var resultArray = new List(); - - foreach (var item in result) - { - resultArray.Add(WatchListDTO.WatchListToWatchListDTO(item)); - } - - return resultArray; - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Services/ChapterRegisterService.cs b/src/references/Cesxhin.AnimeManga.Application/Services/ChapterRegisterService.cs deleted file mode 100644 index d0b787d..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Services/ChapterRegisterService.cs +++ /dev/null @@ -1,85 +0,0 @@ -using Cesxhin.AnimeManga.Application.Interfaces.Repositories; -using Cesxhin.AnimeManga.Application.Interfaces.Services; -using Cesxhin.AnimeManga.Domain.DTO; -using Cesxhin.AnimeManga.Domain.Models; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Services -{ - public class ChapterRegisterService : IChapterRegisterService - { - //interfaces - private readonly IChapterRegisterRepository _chapterRegisterRepository; - - public ChapterRegisterService(IChapterRegisterRepository chapterRegisterRepository) - { - _chapterRegisterRepository = chapterRegisterRepository; - } - - //get chapterRegister by chapter id - public async Task GetObjectRegisterByObjectId(string id) - { - var chapterRegister = await _chapterRegisterRepository.GetObjectRegisterByObjectId(id); - return ChapterRegisterDTO.ChapterRegisterToChapterRegisterDTO(chapterRegister); - } - - public async Task> GetObjectsRegistersByListObjectId(List listChapterDTO) - { - List listChapter = new(); - - foreach (var chapterDTO in listChapterDTO) - { - listChapter.Add(Chapter.ChapterDTOToChapter(chapterDTO)); - } - - var rs = await _chapterRegisterRepository.GetObjectsRegistersByListObjectId(listChapter); - - - List listChapterRegisterDTO = new(); - - foreach (var chapterRegister in rs.ToList()) - { - listChapterRegisterDTO.Add(ChapterRegisterDTO.ChapterRegisterToChapterRegisterDTO(chapterRegister)); - } - - return listChapterRegisterDTO; - } - - //insert chapterRegister - public async Task InsertObjectRegisterAsync(ChapterRegisterDTO chapterRegister) - { - var result = await _chapterRegisterRepository.InsertObjectRegisterAsync(ChapterRegister.ChapterRegisterDTOToChapterRegister(chapterRegister)); - return ChapterRegisterDTO.ChapterRegisterToChapterRegisterDTO(result); - } - - //insert list chapterRegister - public async Task> InsertObjectsRegistersAsync(List chaptersRegisters) - { - List chapterRegistersConvert = new(); - foreach (var chapter in chaptersRegisters) - { - chapterRegistersConvert.Add(ChapterRegister.ChapterRegisterDTOToChapterRegister(chapter)); - } - - var resultChapters = await _chapterRegisterRepository.InsertObjectsRegisterAsync(chapterRegistersConvert); - - - List chapterRegistersDTOConvert = new(); - foreach (var chapter in resultChapters) - { - chapterRegistersDTOConvert.Add(ChapterRegisterDTO.ChapterRegisterToChapterRegisterDTO(chapter)); - } - - return chapterRegistersDTOConvert; - } - - //Update chapterRegister - public async Task UpdateObjectRegisterAsync(ChapterRegisterDTO chapterRegister) - { - var chapterResult = await _chapterRegisterRepository.UpdateObjectRegisterAsync(ChapterRegister.ChapterRegisterDTOToChapterRegister(chapterRegister)); - return ChapterRegisterDTO.ChapterRegisterToChapterRegisterDTO(chapterResult); - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Services/ChapterService.cs b/src/references/Cesxhin.AnimeManga.Application/Services/ChapterService.cs deleted file mode 100644 index 054774c..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Services/ChapterService.cs +++ /dev/null @@ -1,99 +0,0 @@ -using Cesxhin.AnimeManga.Application.Interfaces.Repositories; -using Cesxhin.AnimeManga.Application.Interfaces.Services; -using Cesxhin.AnimeManga.Domain.DTO; -using Cesxhin.AnimeManga.Domain.Models; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Services -{ - public class ChapterService : IChapterService - { - //interfaces - private readonly IChapterRepository _chapterRepository; - - public ChapterService(IChapterRepository chapterRepository) - { - _chapterRepository = chapterRepository; - } - - //get chapter by id - public async Task GetObjectByIDAsync(string id) - { - var rs = await _chapterRepository.GetObjectByIDAsync(id); - return ChapterDTO.ChapterToChapterDTO(rs); - } - - //get chapters by name - public async Task> GetObjectsByNameAsync(string name) - { - var listChapter = await _chapterRepository.GetObjectsByNameAsync(name); - - List chapters = new(); - foreach (var chapter in listChapter) - { - chapters.Add(ChapterDTO.ChapterToChapterDTO(chapter)); - } - - return chapters; - } - - //insert one chapter - public async Task InsertObjectAsync(ChapterDTO chapter) - { - var chapterResult = await _chapterRepository.InsertObjectAsync(Chapter.ChapterDTOToChapter(chapter)); - return ChapterDTO.ChapterToChapterDTO(chapterResult); - } - - //insert chapters - public async Task> InsertObjectsAsync(List chapters) - { - List chaptersConvert = new(); - foreach (var chapter in chapters) - { - chaptersConvert.Add(Chapter.ChapterDTOToChapter(chapter)); - } - - var resultChapters = await _chapterRepository.InsertObjectsAsync(chaptersConvert); - - List chaptersDTOConvert = new(); - foreach (var chapter in resultChapters) - { - chaptersDTOConvert.Add(ChapterDTO.ChapterToChapterDTO(chapter)); - } - - return chaptersDTOConvert; - } - - //reset manual - public async Task ResetStatusDownloadObjectByIdAsync(ChapterDTO chapter) - { - var rs = await _chapterRepository.ResetStatusDownloadObjectByIdAsync(Chapter.ChapterDTOToChapter(chapter)); - return ChapterDTO.ChapterToChapterDTO(rs); - } - - //reset automatic - public async Task> ResetStatusMultipleDownloadObjectByIdAsync(string name) - { - var listChapters = await _chapterRepository.GetObjectsByNameAsync(name); - - var resultChapters = await _chapterRepository.ResetStatusDownloadObjectsByIdAsync(listChapters.ToList()); - - List chaptersDTOConvert = new(); - foreach (var chapter in resultChapters) - { - chaptersDTOConvert.Add(ChapterDTO.ChapterToChapterDTO(chapter)); - } - - return chaptersDTOConvert; - } - - //update PercentualState - public async Task UpdateStateDownloadAsync(ChapterDTO chapter) - { - var chapterResult = await _chapterRepository.UpdateStateDownloadAsync(Chapter.ChapterDTOToChapter(chapter)); - return ChapterDTO.ChapterToChapterDTO(chapterResult); - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Services/DescriptionBookService.cs b/src/references/Cesxhin.AnimeManga.Application/Services/DescriptionBookService.cs deleted file mode 100644 index 7ab73ba..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Services/DescriptionBookService.cs +++ /dev/null @@ -1,278 +0,0 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Interfaces.Repositories; -using Cesxhin.AnimeManga.Application.Interfaces.Services; -using Cesxhin.AnimeManga.Application.NlogManager; -using Cesxhin.AnimeManga.Domain.DTO; -using Newtonsoft.Json.Linq; -using NLog; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Services -{ - public class DescriptionBookService : IDescriptionBookService - { - //log - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - //interfaces - private readonly IDescriptionRepository _descriptionRepository; - private readonly IChapterRepository _chapterRepository; - private readonly IChapterRegisterRepository _chapterRegisterRepository; - private readonly IAccountService _accountService; - - public DescriptionBookService(IAccountService accountService, IDescriptionRepository descriptionRepository, IChapterRepository chapterRepository, IChapterRegisterRepository chapterRegisterRepository) - { - _descriptionRepository = descriptionRepository; - _chapterRepository = chapterRepository; - _chapterRegisterRepository = chapterRegisterRepository; - _accountService = accountService; - } - - public async Task DeleteNameByIdAsync(string nameCfg, string name) - { - //get episodes - var episodes = await _chapterRepository.GetObjectsByNameAsync(name); - - foreach (var episode in episodes) - { - if (!(episode.StateDownload == "completed" || episode.StateDownload == null)) - throw new ApiConflictException("Conflict DeleteNameByIdAsync"); - } - - try - { - await _descriptionRepository.DeleteNameAsync(nameCfg, name); - } - catch (ApiNotFoundException) - { - _logger.Warn($"I tried delete description book name: {name} nameCfg: {nameCfg}"); - } - - try - { - await _chapterRepository.DeleteByNameAsync(name); - } - catch (ApiNotFoundException) - { - _logger.Warn($"I tried delete chapters name: {name} nameCfg: {nameCfg}"); - } - - return name; - } - - public async Task> GetMostNameByNameAsync(string nameCfg, string name, string username) - { - var result = await _descriptionRepository.GetMostNameByNameAsync(nameCfg, name); - - try - { - var watchList = await _accountService.GetListWatchListByUsername(username); - result.ForEach(item => - { - var filterWatchList = watchList.Where((singleWatchList) => - { - if (singleWatchList.Name == item["name_id"].ToString() && singleWatchList.NameCfg == item["nameCfg"].ToString()) - return true; - return false; - }); - - if (filterWatchList.Count() > 0) - item["watchList"] = true; - else - item["watchList"] = false; - }); - } - catch (ApiNotFoundException) { } - - return result; - } - - public async Task> GetNameAllAsync(string nameCfg, string username) - { - var result = await _descriptionRepository.GetNameAllAsync(nameCfg); - - try - { - var watchList = await _accountService.GetListWatchListByUsername(username); - - result.ForEach(item => - { - var filterWatchList = watchList.Where((singleWatchList) => - { - if (singleWatchList.Name == item["name_id"].ToString() && singleWatchList.NameCfg == item["nameCfg"].ToString()) - return true; - return false; - }); - - if (filterWatchList.Count() > 0) - item["watchList"] = true; - else - item["watchList"] = false; - }); - } - catch (ApiNotFoundException) { } - - return result; - } - - public async Task> GetNameAllOnlyWatchListAsync(string nameCfg, string username) - { - var watchList = await _accountService.GetListWatchListByUsername(username); - - var result = new List(); - JObject resultFind; - - foreach (var watch in watchList) - { - if (watch.NameCfg == nameCfg) - { - try - { - resultFind = await _descriptionRepository.GetNameByNameAsync(watch.NameCfg, watch.Name); - - if (resultFind != null) - result.Add(resultFind); - } - catch (ApiNotFoundException) { } - } - } - - result.ForEach(item => - { - var filterWatchList = watchList.Where((singleWatchList) => - { - if (singleWatchList.Name == item["name_id"].ToString() && singleWatchList.NameCfg == item["nameCfg"].ToString()) - return true; - return false; - }); - - if (filterWatchList.Count() > 0) - item["watchList"] = true; - else - item["watchList"] = false; - }); - - return result; - } - - public async Task> GetNameAllWithAllAsync(string nameCfg, string username) - { - List listGenericDTO = new(); - List listEpisodeDTO = new(); - List listEpisodeRegisterDTO = new(); - - var listDescriptions = await _descriptionRepository.GetNameAllAsync(nameCfg); - - try - { - var watchList = await _accountService.GetListWatchListByUsername(username); - - listDescriptions.ForEach(item => - { - var filterWatchList = watchList.Where((singleWatchList) => - { - if (singleWatchList.Name == item["name_id"].ToString() && singleWatchList.NameCfg == item["nameCfg"].ToString()) - return true; - return false; - }); - - if (filterWatchList.Count() > 0) - item["watchList"] = true; - else - item["watchList"] = false; - }); - } - catch (ApiNotFoundException) { } - - //anime - foreach (var description in listDescriptions) - { - var episodes = await _chapterRepository.GetObjectsByNameAsync(description.GetValue("name_id").ToString()); - - //episodes - foreach (var episode in episodes) - { - var episodeRegister = await _chapterRegisterRepository.GetObjectRegisterByObjectId(episode.ID); - - listEpisodeRegisterDTO.Add(ChapterRegisterDTO.ChapterRegisterToChapterRegisterDTO(episodeRegister)); - listEpisodeDTO.Add(ChapterDTO.ChapterToChapterDTO(episode)); - } - - listGenericDTO.Add(new GenericBookDTO - { - Book = description.ToString(), - Chapters = listEpisodeDTO, - ChapterRegister = listEpisodeRegisterDTO - }); - - //reset - listEpisodeDTO = new(); - listEpisodeRegisterDTO = new(); - } - - return listGenericDTO; - } - - public async Task GetNameByNameAsync(string nameCfg, string name, string username) - { - var result = await _descriptionRepository.GetNameByNameAsync(nameCfg, name); - - try - { - var watchList = await _accountService.GetListWatchListByUsername(username); - - var filterWatchList = watchList.Where((singleWatchList) => - { - if (singleWatchList.Name == result["name_id"].ToString() && singleWatchList.NameCfg == result["nameCfg"].ToString()) - return true; - return false; - }); - - if (filterWatchList.Count() > 0) - result["watchList"] = true; - else - result["watchList"] = false; - } - catch (ApiNotFoundException) { } - - return result; - } - - public async Task InsertNameAsync(string nameCfg, JObject description) - { - if (description.ContainsKey("name_id")) - { - try - { - await _descriptionRepository.GetNameByNameAsync(nameCfg, description.GetValue("name_id").ToString()); - throw new ApiConflictException(); - } - catch (ApiNotFoundException) - { - return await _descriptionRepository.InsertNameAsync(nameCfg, description); - } - } - else - { - _logger.Error("Not found field 'name_id' of book"); - throw new ApiNotFoundException("Not found field 'name_id' of book"); - } - } - - public async Task UpdateNameAsync(string nameCfg, JObject description) - { - if (description.ContainsKey("name_id")) - { - await _descriptionRepository.GetNameByNameAsync(nameCfg, description.GetValue("name_id").ToString()); - return await _descriptionRepository.UpdateNameAsync(nameCfg, description); - } - else - { - _logger.Error("Not found field 'name_id' of book"); - throw new ApiNotFoundException("Not found field 'name_id' of book"); - } - } - } -} \ No newline at end of file diff --git a/src/references/Cesxhin.AnimeManga.Application/Services/DescriptionVideoService.cs b/src/references/Cesxhin.AnimeManga.Application/Services/DescriptionVideoService.cs deleted file mode 100644 index 42aa551..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Services/DescriptionVideoService.cs +++ /dev/null @@ -1,286 +0,0 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Interfaces.Repositories; -using Cesxhin.AnimeManga.Application.Interfaces.Services; -using Cesxhin.AnimeManga.Application.NlogManager; -using Cesxhin.AnimeManga.Domain.DTO; -using Newtonsoft.Json.Linq; -using NLog; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Services -{ - public class DescriptionVideoService : IDescriptionVideoService - { - //log - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - //interfaces - private readonly IDescriptionRepository _descriptionRepository; - private readonly IEpisodeRepository _episodeRepository; - private readonly IEpisodeRegisterRepository _episodeRegisterRepository; - private readonly IAccountService _accountService; - - public DescriptionVideoService(IAccountService accountService, IDescriptionRepository descriptionRepository, IEpisodeRepository episodeRepository, IEpisodeRegisterRepository episodeRegisterRepository) - { - _descriptionRepository = descriptionRepository; - _episodeRepository = episodeRepository; - _episodeRegisterRepository = episodeRegisterRepository; - _accountService = accountService; - } - public async Task DeleteNameByIdAsync(string nameCfg, string name) - { - //get episodes - var episodes = await _episodeRepository.GetObjectsByNameAsync(name); - - foreach (var episode in episodes) - { - if (!(episode.StateDownload == "completed" || episode.StateDownload == null)) - throw new ApiConflictException(); - } - - try - { - await _descriptionRepository.DeleteNameAsync(nameCfg, name); - } - catch (ApiNotFoundException) - { - _logger.Warn($"I tried delete description video name: {name} nameCfg: {nameCfg}"); - } - - try - { - await _episodeRepository.DeleteByNameAsync(name); - } - catch (ApiNotFoundException) - { - _logger.Warn($"I tried delete episodes name: {name} nameCfg: {nameCfg}"); - } - - return name; - } - - public async Task> GetMostNameByNameAsync(string nameCfg, string name, string username) - { - var result = await _descriptionRepository.GetMostNameByNameAsync(nameCfg, name); - - try - { - var watchList = await _accountService.GetListWatchListByUsername(username); - - result.ForEach(item => - { - var filterWatchList = watchList.Where((singleWatchList) => - { - if (singleWatchList.Name == item["name_id"].ToString() && singleWatchList.NameCfg == item["nameCfg"].ToString()) - return true; - return false; - }); - - if (filterWatchList.Count() > 0) - item["watchList"] = true; - else - item["watchList"] = false; - }); - } - catch (ApiNotFoundException) { } - - return result; - } - - public async Task> GetNameAllAsync(string nameCfg, string username) - { - var result = await _descriptionRepository.GetNameAllAsync(nameCfg); - - try - { - var watchList = await _accountService.GetListWatchListByUsername(username); - - result.ForEach(item => - { - var filterWatchList = watchList.Where((singleWatchList) => - { - if (singleWatchList.Name == item["name_id"].ToString() && singleWatchList.NameCfg == item["nameCfg"].ToString()) - return true; - return false; - }); - - if (filterWatchList.Count() > 0) - item["watchList"] = true; - else - item["watchList"] = false; - }); - } - catch (ApiNotFoundException) { } - - return result; - } - - public async Task> GetNameAllOnlyWatchListAsync(string nameCfg, string username) - { - var watchList = await _accountService.GetListWatchListByUsername(username); - - var result = new List(); - JObject resultFind; - - foreach (var watch in watchList) - { - if (watch.NameCfg == nameCfg) - { - try - { - resultFind = await _descriptionRepository.GetNameByNameAsync(watch.NameCfg, watch.Name); - - if (resultFind != null) - result.Add(resultFind); - } - catch (ApiNotFoundException) { } - } - } - - result.ForEach(item => - { - var filterWatchList = watchList.Where((singleWatchList) => - { - if (singleWatchList.Name == item["name_id"].ToString() && singleWatchList.NameCfg == item["nameCfg"].ToString()) - return true; - return false; - }); - - if (filterWatchList.Count() > 0) - item["watchList"] = true; - else - item["watchList"] = false; - }); - - return result; - } - - public async Task> GetNameAllWithAllAsync(string nameCfg, string username) - { - List listGenericDTO = new(); - - List listEpisodeDTO = new(); - List listEpisodeRegisterDTO = new(); - - var listDescriptions = await _descriptionRepository.GetNameAllAsync(nameCfg); - - try - { - var watchList = await _accountService.GetListWatchListByUsername(username); - - listDescriptions.ForEach(item => - { - var filterWatchList = watchList.Where((singleWatchList) => - { - if (singleWatchList.Name == item["name_id"].ToString() && singleWatchList.NameCfg == item["nameCfg"].ToString()) - return true; - return false; - }); - - if (filterWatchList.Any()) - item["watchList"] = true; - else - item["watchList"] = false; - }); - } - catch (ApiNotFoundException) { } - - //anime - foreach (var description in listDescriptions) - { - var episodes = await _episodeRepository.GetObjectsByNameAsync(description.GetValue("name_id").ToString()); - - //episodes - foreach (var episode in episodes) - { - var episodeRegister = await _episodeRegisterRepository.GetObjectRegisterByObjectId(episode.ID); - - listEpisodeRegisterDTO.Add(EpisodeRegisterDTO.EpisodeRegisterToEpisodeRegisterDTO(episodeRegister)); - listEpisodeDTO.Add(EpisodeDTO.EpisodeToEpisodeDTO(episode)); - } - - var objectAll = JObject.FromObject(new - { - description, - listEpisodeDTO, - listEpisodeRegisterDTO - }); - - listGenericDTO.Add(new GenericVideoDTO() - { - Video = description.ToString(), - Episodes = listEpisodeDTO, - EpisodesRegister = listEpisodeRegisterDTO - }); - - //reset - listEpisodeDTO = new(); - listEpisodeRegisterDTO = new(); - } - - return listGenericDTO; - } - - public async Task GetNameByNameAsync(string nameCfg, string name, string username) - { - var result = await _descriptionRepository.GetNameByNameAsync(nameCfg, name); - - try - { - var watchList = await _accountService.GetListWatchListByUsername(username); - - var filterWatchList = watchList.Where((singleWatchList) => - { - if (singleWatchList.Name == result["name_id"].ToString() && singleWatchList.NameCfg == result["nameCfg"].ToString()) - return true; - return false; - }); - - if (filterWatchList.Count() > 0) - result["watchList"] = true; - else - result["watchList"] = false; - } - catch (ApiNotFoundException) { } - - return result; - } - - public async Task InsertNameAsync(string nameCfg, JObject description) - { - if (description.ContainsKey("name_id")) - { - try - { - await _descriptionRepository.GetNameByNameAsync(nameCfg, description.GetValue("name_id").ToString()); - throw new ApiConflictException(); - } - catch (ApiNotFoundException) - { - return await _descriptionRepository.InsertNameAsync(nameCfg, description); - } - } - else - { - _logger.Error("Not found field 'name_id' of video"); - throw new ApiConflictException("Not found field 'name_id' of video"); - } - } - - public async Task UpdateNameAsync(string nameCfg, JObject description) - { - if (description.ContainsKey("name_id")) - { - await _descriptionRepository.GetNameByNameAsync(nameCfg, description.GetValue("name_id").ToString()); - return await _descriptionRepository.UpdateNameAsync(nameCfg, description); - } - else - { - _logger.Error("Not found field 'name_id' of video"); - throw new ApiConflictException("Not found field 'name_id' of video"); - } - } - } -} \ No newline at end of file diff --git a/src/references/Cesxhin.AnimeManga.Application/Services/EpisodeRegisterService.cs b/src/references/Cesxhin.AnimeManga.Application/Services/EpisodeRegisterService.cs deleted file mode 100644 index 86626ed..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Services/EpisodeRegisterService.cs +++ /dev/null @@ -1,76 +0,0 @@ -using Cesxhin.AnimeManga.Application.Interfaces.Repositories; -using Cesxhin.AnimeManga.Application.Interfaces.Services; -using Cesxhin.AnimeManga.Domain.DTO; -using Cesxhin.AnimeManga.Domain.Models; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Services -{ - public class EpisodeRegisterService : IEpisodeRegisterService - { - //interfaces - private readonly IEpisodeRegisterRepository _episodeRegisterRepository; - - public EpisodeRegisterService(IEpisodeRegisterRepository episodeRegisterRepository) - { - _episodeRegisterRepository = episodeRegisterRepository; - } - - //get episodeRegister by episode id - public async Task GetObjectRegisterByObjectId(string id) - { - var episodeRegister = await _episodeRegisterRepository.GetObjectRegisterByObjectId(id); - return EpisodeRegisterDTO.EpisodeRegisterToEpisodeRegisterDTO(episodeRegister); - } - - public async Task> GetObjectsRegistersByListObjectId(List listEpisodeDTO) - { - List listEpisode = new(); - - foreach(var episodeDTO in listEpisodeDTO) - { - listEpisode.Add(Episode.EpisodeDTOToEpisode(episodeDTO)); - } - - var rs = await _episodeRegisterRepository.GetObjectsRegistersByListObjectId(listEpisode); - - - List listEpisodeRegisterDTO = new(); - - foreach (var episodeRegister in rs.ToList()) - { - listEpisodeRegisterDTO.Add(EpisodeRegisterDTO.EpisodeRegisterToEpisodeRegisterDTO(episodeRegister)); - } - - return listEpisodeRegisterDTO; - } - - //insert episodeRegister - public async Task InsertObjectRegisterAsync(EpisodeRegisterDTO episodeRegister) - { - var rs = await _episodeRegisterRepository.InsertObjectRegisterAsync(EpisodeRegister.EpisodeRegisterToEpisodeRegisterDTO(episodeRegister)); - return EpisodeRegisterDTO.EpisodeRegisterToEpisodeRegisterDTO(rs); - } - - //insert list episodeRegister - public async Task> InsertObjectsRegistersAsync(List episodesRegistersDTO) - { - List resultEpisodes = new(); - foreach (var episode in episodesRegistersDTO) - { - var episodeResult = await _episodeRegisterRepository.InsertObjectRegisterAsync(EpisodeRegister.EpisodeRegisterToEpisodeRegisterDTO(episode)); - resultEpisodes.Add(EpisodeRegisterDTO.EpisodeRegisterToEpisodeRegisterDTO(episodeResult)); - } - return resultEpisodes; - } - - //Update episodeRegister - public async Task UpdateObjectRegisterAsync(EpisodeRegisterDTO episodeRegister) - { - var rs = await _episodeRegisterRepository.UpdateObjectRegisterAsync(EpisodeRegister.EpisodeRegisterToEpisodeRegisterDTO(episodeRegister)); - return EpisodeRegisterDTO.EpisodeRegisterToEpisodeRegisterDTO(rs); - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Services/EpisodeService.cs b/src/references/Cesxhin.AnimeManga.Application/Services/EpisodeService.cs deleted file mode 100644 index 06a24df..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Services/EpisodeService.cs +++ /dev/null @@ -1,95 +0,0 @@ -using Cesxhin.AnimeManga.Application.Interfaces.Repositories; -using Cesxhin.AnimeManga.Application.Interfaces.Services; -using Cesxhin.AnimeManga.Domain.DTO; -using Cesxhin.AnimeManga.Domain.Models; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Services -{ - public class EpisodeService : IEpisodeService - { - //interfaces - private readonly IEpisodeRepository _episodeRepository; - - public EpisodeService(IEpisodeRepository episodeRepository) - { - _episodeRepository = episodeRepository; - } - - //get episode by id - public async Task GetObjectByIDAsync(string id) - { - var episode = await _episodeRepository.GetObjectByIDAsync(id); - return EpisodeDTO.EpisodeToEpisodeDTO(episode); - } - - //get episodes by name - public async Task> GetObjectsByNameAsync(string name) - { - var listEpisode = await _episodeRepository.GetObjectsByNameAsync(name); - - List episodes = new(); - foreach (var episode in listEpisode) - { - episodes.Add(EpisodeDTO.EpisodeToEpisodeDTO(episode)); - } - - return episodes; - } - - //insert one episode - public async Task InsertObjectAsync(EpisodeDTO episode) - { - var episodeResult = await _episodeRepository.InsertObjectAsync(Episode.EpisodeDTOToEpisode(episode)); - return EpisodeDTO.EpisodeToEpisodeDTO(episodeResult); - } - - //insert episodes - public async Task> InsertObjectsAsync(List episodes) - { - List resultEpisodes = new(); - foreach (var episode in episodes) - { - var episodeResult = await _episodeRepository.InsertObjectAsync(Episode.EpisodeDTOToEpisode(episode)); - resultEpisodes.Add(EpisodeDTO.EpisodeToEpisodeDTO(episodeResult)); - } - return resultEpisodes; - } - - //reset StatusDownload to null - public async Task ResetStatusDownloadObjectByIdAsync(EpisodeDTO episode) - { - var episodeResult = await _episodeRepository.ResetStatusDownloadObjectByIdAsync(Episode.EpisodeDTOToEpisode(episode)); - return EpisodeDTO.EpisodeToEpisodeDTO(episodeResult); - } - - //reset all state - public async Task> ResetStatusMultipleDownloadObjectByIdAsync(string name) - { - var listEpisodes = await _episodeRepository.GetObjectsByNameAsync(name); - - var resultEpisodes = await _episodeRepository.ResetStatusDownloadObjectsByIdAsync(listEpisodes.ToList()); - - List episodesDTOConvert = new(); - foreach (var episode in resultEpisodes) - { - episodesDTOConvert.Add(EpisodeDTO.EpisodeToEpisodeDTO(episode)); - } - - return episodesDTOConvert; - } - - //update PercentualState - public async Task UpdateStateDownloadAsync(EpisodeDTO episode) - { - var episodeResult = await _episodeRepository.UpdateStateDownloadAsync(Episode.EpisodeDTOToEpisode(episode)); - - if (episodeResult == null) - return null; - - return EpisodeDTO.EpisodeToEpisodeDTO(episodeResult); - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Services/ProgressChapterService.cs b/src/references/Cesxhin.AnimeManga.Application/Services/ProgressChapterService.cs deleted file mode 100644 index 889975f..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Services/ProgressChapterService.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Interfaces.Repositories; -using Cesxhin.AnimeManga.Application.Interfaces.Services; -using Cesxhin.AnimeManga.Domain.DTO; -using Cesxhin.AnimeManga.Domain.Models; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Services -{ - public class ProgressChapterService : IProgressChapterService - { - public readonly IProgressChapterRepository _progressChapterRepository; - public ProgressChapterService(IProgressChapterRepository progressChapterRepository) - { - _progressChapterRepository = progressChapterRepository; - } - - public async Task GetProgressByName(string name, string username, string nameCfg) - { - var result = await _progressChapterRepository.CheckProgress(name, username, nameCfg); - return ProgressChapterDTO.ProgressChapterToProgressChapterDTO(result); - } - - public async Task UpdateProgress(ProgressChapterDTO progress) - { - ProgressChapter result; - - try - { - await _progressChapterRepository.CheckProgress(progress.Name, progress.Username, progress.NameCfg); - result = await _progressChapterRepository.UpdateProgress(ProgressChapter.ProgressChapterDTOToProgressChapter(progress)); - } - catch (ApiNotFoundException) - { - result = await _progressChapterRepository.CreateProgress(ProgressChapter.ProgressChapterDTOToProgressChapter(progress)); - } - - return ProgressChapterDTO.ProgressChapterToProgressChapterDTO(result); - - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Application/Services/ProgressEpisodeService.cs b/src/references/Cesxhin.AnimeManga.Application/Services/ProgressEpisodeService.cs deleted file mode 100644 index af3f7bc..0000000 --- a/src/references/Cesxhin.AnimeManga.Application/Services/ProgressEpisodeService.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Interfaces.Repositories; -using Cesxhin.AnimeManga.Application.Interfaces.Services; -using Cesxhin.AnimeManga.Domain.DTO; -using Cesxhin.AnimeManga.Domain.Models; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Services -{ - public class ProgressEpisodeService : IProgressEpisodeService - { - public readonly IProgressEpisodeRepository _progressEpisodeRepository; - public ProgressEpisodeService(IProgressEpisodeRepository progressEpisodeRepository) - { - _progressEpisodeRepository = progressEpisodeRepository; - } - - public async Task GetProgressByName(string name, string username, string nameCfg) - { - var result = await _progressEpisodeRepository.CheckProgress(name, username, nameCfg); - return ProgressEpisodeDTO.ProgressEpisodeToProgressEpisodeDTO(result); - } - - public async Task UpdateProgress(ProgressEpisodeDTO progress) - { - ProgressEpisode result; - - try - { - await _progressEpisodeRepository.CheckProgress(progress.Name, progress.Username, progress.NameCfg); - result = await _progressEpisodeRepository.UpdateProgress(ProgressEpisode.ProgressEpisodeDTOToProgressEpisode(progress)); - } - catch (ApiNotFoundException) - { - result = await _progressEpisodeRepository.CreateProgress(ProgressEpisode.ProgressEpisodeDTOToProgressEpisode(progress)); - } - - return ProgressEpisodeDTO.ProgressEpisodeToProgressEpisodeDTO(result); - - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Domain/Models/WatchList.cs b/src/references/Cesxhin.AnimeManga.Domain/Models/WatchList.cs index c6f43ba..06aa854 100644 --- a/src/references/Cesxhin.AnimeManga.Domain/Models/WatchList.cs +++ b/src/references/Cesxhin.AnimeManga.Domain/Models/WatchList.cs @@ -10,9 +10,11 @@ public class WatchList [Map("name")] public string Name { get; set; } + [Identity] [Map("username")] public string Username { get; set; } + [Identity] [Map("namecfg")] public string NameCfg { get; set; } diff --git a/src/references/Cesxhin.AnimeManga.Application/Cesxhin.AnimeManga.Application.csproj b/src/references/Cesxhin.AnimeManga.Modules/Cesxhin.AnimeManga.Modules.csproj similarity index 81% rename from src/references/Cesxhin.AnimeManga.Application/Cesxhin.AnimeManga.Application.csproj rename to src/references/Cesxhin.AnimeManga.Modules/Cesxhin.AnimeManga.Modules.csproj index 45ce5e5..c8a8d0a 100644 --- a/src/references/Cesxhin.AnimeManga.Application/Cesxhin.AnimeManga.Application.csproj +++ b/src/references/Cesxhin.AnimeManga.Modules/Cesxhin.AnimeManga.Modules.csproj @@ -4,11 +4,6 @@ net5.0 - - - - - diff --git a/src/references/Cesxhin.AnimeManga.Application/CronJob/HealthJob.cs b/src/references/Cesxhin.AnimeManga.Modules/CronJob/HealthJob.cs similarity index 82% rename from src/references/Cesxhin.AnimeManga.Application/CronJob/HealthJob.cs rename to src/references/Cesxhin.AnimeManga.Modules/CronJob/HealthJob.cs index f53e0af..6c9944b 100644 --- a/src/references/Cesxhin.AnimeManga.Application/CronJob/HealthJob.cs +++ b/src/references/Cesxhin.AnimeManga.Modules/CronJob/HealthJob.cs @@ -1,13 +1,13 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Generic; -using Cesxhin.AnimeManga.Application.NlogManager; +using Cesxhin.AnimeManga.Modules.Exceptions; +using Cesxhin.AnimeManga.Modules.Generic; +using Cesxhin.AnimeManga.Modules.NlogManager; using Cesxhin.AnimeManga.Domain.DTO; using NLog; using Quartz; using System; using System.Threading.Tasks; -namespace Cesxhin.AnimeManga.Application.CronJob +namespace Cesxhin.AnimeManga.Modules.CronJob { public class HealthJob : IJob { diff --git a/src/references/Cesxhin.AnimeManga.Application/CronJob/SpaceDiskJob.cs b/src/references/Cesxhin.AnimeManga.Modules/CronJob/SpaceDiskJob.cs similarity index 87% rename from src/references/Cesxhin.AnimeManga.Application/CronJob/SpaceDiskJob.cs rename to src/references/Cesxhin.AnimeManga.Modules/CronJob/SpaceDiskJob.cs index 79365f9..b14fe8a 100644 --- a/src/references/Cesxhin.AnimeManga.Application/CronJob/SpaceDiskJob.cs +++ b/src/references/Cesxhin.AnimeManga.Modules/CronJob/SpaceDiskJob.cs @@ -1,6 +1,6 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Generic; -using Cesxhin.AnimeManga.Application.NlogManager; +using Cesxhin.AnimeManga.Modules.Exceptions; +using Cesxhin.AnimeManga.Modules.Generic; +using Cesxhin.AnimeManga.Modules.NlogManager; using Cesxhin.AnimeManga.Domain.DTO; using NLog; using Quartz; @@ -8,7 +8,7 @@ using System.IO; using System.Threading.Tasks; -namespace Cesxhin.AnimeManga.Application.CronJob +namespace Cesxhin.AnimeManga.Modules.CronJob { public class SpaceDiskJob : IJob { diff --git a/src/references/Cesxhin.AnimeManga.Application/Exceptions/ApiConflictException.cs b/src/references/Cesxhin.AnimeManga.Modules/Exceptions/ApiConflictException.cs similarity index 85% rename from src/references/Cesxhin.AnimeManga.Application/Exceptions/ApiConflictException.cs rename to src/references/Cesxhin.AnimeManga.Modules/Exceptions/ApiConflictException.cs index 81dffd3..1d9017d 100644 --- a/src/references/Cesxhin.AnimeManga.Application/Exceptions/ApiConflictException.cs +++ b/src/references/Cesxhin.AnimeManga.Modules/Exceptions/ApiConflictException.cs @@ -1,6 +1,6 @@ using System; -namespace Cesxhin.AnimeManga.Application.Exceptions +namespace Cesxhin.AnimeManga.Modules.Exceptions { public class ApiConflictException : Exception { diff --git a/src/references/Cesxhin.AnimeManga.Application/Exceptions/ApiGenericException.cs b/src/references/Cesxhin.AnimeManga.Modules/Exceptions/ApiGenericException.cs similarity index 85% rename from src/references/Cesxhin.AnimeManga.Application/Exceptions/ApiGenericException.cs rename to src/references/Cesxhin.AnimeManga.Modules/Exceptions/ApiGenericException.cs index a8e7dbe..b261e18 100644 --- a/src/references/Cesxhin.AnimeManga.Application/Exceptions/ApiGenericException.cs +++ b/src/references/Cesxhin.AnimeManga.Modules/Exceptions/ApiGenericException.cs @@ -1,6 +1,6 @@ using System; -namespace Cesxhin.AnimeManga.Application.Exceptions +namespace Cesxhin.AnimeManga.Modules.Exceptions { public class ApiGenericException : Exception { diff --git a/src/references/Cesxhin.AnimeManga.Application/Exceptions/ApiNotAuthorizeException.cs b/src/references/Cesxhin.AnimeManga.Modules/Exceptions/ApiNotAuthorizeException.cs similarity index 85% rename from src/references/Cesxhin.AnimeManga.Application/Exceptions/ApiNotAuthorizeException.cs rename to src/references/Cesxhin.AnimeManga.Modules/Exceptions/ApiNotAuthorizeException.cs index 2163714..202bc77 100644 --- a/src/references/Cesxhin.AnimeManga.Application/Exceptions/ApiNotAuthorizeException.cs +++ b/src/references/Cesxhin.AnimeManga.Modules/Exceptions/ApiNotAuthorizeException.cs @@ -1,6 +1,6 @@ using System; -namespace Cesxhin.AnimeManga.Application.Exceptions +namespace Cesxhin.AnimeManga.Modules.Exceptions { public class ApiNotAuthorizeException : Exception { diff --git a/src/references/Cesxhin.AnimeManga.Application/Exceptions/ApiNotFoundException.cs b/src/references/Cesxhin.AnimeManga.Modules/Exceptions/ApiNotFoundException.cs similarity index 85% rename from src/references/Cesxhin.AnimeManga.Application/Exceptions/ApiNotFoundException.cs rename to src/references/Cesxhin.AnimeManga.Modules/Exceptions/ApiNotFoundException.cs index 6a51301..18f976a 100644 --- a/src/references/Cesxhin.AnimeManga.Application/Exceptions/ApiNotFoundException.cs +++ b/src/references/Cesxhin.AnimeManga.Modules/Exceptions/ApiNotFoundException.cs @@ -1,6 +1,6 @@ using System; -namespace Cesxhin.AnimeManga.Application.Exceptions +namespace Cesxhin.AnimeManga.Modules.Exceptions { public class ApiNotFoundException : Exception { diff --git a/src/references/Cesxhin.AnimeManga.Application/Generic/Api.cs b/src/references/Cesxhin.AnimeManga.Modules/Generic/Api.cs similarity index 98% rename from src/references/Cesxhin.AnimeManga.Application/Generic/Api.cs rename to src/references/Cesxhin.AnimeManga.Modules/Generic/Api.cs index 01d6ac6..e757913 100644 --- a/src/references/Cesxhin.AnimeManga.Application/Generic/Api.cs +++ b/src/references/Cesxhin.AnimeManga.Modules/Generic/Api.cs @@ -1,4 +1,4 @@ -using Cesxhin.AnimeManga.Application.Exceptions; +using Cesxhin.AnimeManga.Modules.Exceptions; using Microsoft.AspNetCore.WebUtilities; using Newtonsoft.Json.Linq; using System; @@ -8,7 +8,7 @@ using System.Text.Json; using System.Threading.Tasks; -namespace Cesxhin.AnimeManga.Application.Generic +namespace Cesxhin.AnimeManga.Modules.Generic { public class Api where T : class { diff --git a/src/references/Cesxhin.AnimeManga.Application/Generic/ConvertGeneric.cs b/src/references/Cesxhin.AnimeManga.Modules/Generic/ConvertGeneric.cs similarity index 88% rename from src/references/Cesxhin.AnimeManga.Application/Generic/ConvertGeneric.cs rename to src/references/Cesxhin.AnimeManga.Modules/Generic/ConvertGeneric.cs index 8f00b5b..da15cd2 100644 --- a/src/references/Cesxhin.AnimeManga.Application/Generic/ConvertGeneric.cs +++ b/src/references/Cesxhin.AnimeManga.Modules/Generic/ConvertGeneric.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Cesxhin.AnimeManga.Application.Generic +namespace Cesxhin.AnimeManga.Modules.Generic { public static class ConvertGeneric where T : class { diff --git a/src/references/Cesxhin.AnimeManga.Application/Generic/Hash.cs b/src/references/Cesxhin.AnimeManga.Modules/Generic/Hash.cs similarity index 94% rename from src/references/Cesxhin.AnimeManga.Application/Generic/Hash.cs rename to src/references/Cesxhin.AnimeManga.Modules/Generic/Hash.cs index 3f21536..8e9d8fa 100644 --- a/src/references/Cesxhin.AnimeManga.Application/Generic/Hash.cs +++ b/src/references/Cesxhin.AnimeManga.Modules/Generic/Hash.cs @@ -2,7 +2,7 @@ using System.Security.Cryptography; using System.Text; -namespace Cesxhin.AnimeManga.Application.Generic +namespace Cesxhin.AnimeManga.Modules.Generic { public static class Hash { diff --git a/src/references/Cesxhin.AnimeManga.Application/HtmlAgilityPack/RipperBookGeneric.cs b/src/references/Cesxhin.AnimeManga.Modules/HtmlAgilityPack/RipperBookGeneric.cs similarity index 98% rename from src/references/Cesxhin.AnimeManga.Application/HtmlAgilityPack/RipperBookGeneric.cs rename to src/references/Cesxhin.AnimeManga.Modules/HtmlAgilityPack/RipperBookGeneric.cs index 66328fc..5662a8f 100644 --- a/src/references/Cesxhin.AnimeManga.Application/HtmlAgilityPack/RipperBookGeneric.cs +++ b/src/references/Cesxhin.AnimeManga.Modules/HtmlAgilityPack/RipperBookGeneric.cs @@ -1,5 +1,5 @@ -using Cesxhin.AnimeManga.Application.NlogManager; -using Cesxhin.AnimeManga.Application.Parallel; +using Cesxhin.AnimeManga.Modules.NlogManager; +using Cesxhin.AnimeManga.Modules.Parallel; using Cesxhin.AnimeManga.Domain.DTO; using Cesxhin.AnimeManga.Domain.Models; using HtmlAgilityPack; @@ -9,7 +9,7 @@ using System.Collections.Generic; using System.Net; -namespace Cesxhin.AnimeManga.Application.HtmlAgilityPack +namespace Cesxhin.AnimeManga.Modules.HtmlAgilityPack { public static class RipperBookGeneric { diff --git a/src/references/Cesxhin.AnimeManga.Application/HtmlAgilityPack/RipperSchema.cs b/src/references/Cesxhin.AnimeManga.Modules/HtmlAgilityPack/RipperSchema.cs similarity index 99% rename from src/references/Cesxhin.AnimeManga.Application/HtmlAgilityPack/RipperSchema.cs rename to src/references/Cesxhin.AnimeManga.Modules/HtmlAgilityPack/RipperSchema.cs index 781e324..0a7a419 100644 --- a/src/references/Cesxhin.AnimeManga.Application/HtmlAgilityPack/RipperSchema.cs +++ b/src/references/Cesxhin.AnimeManga.Modules/HtmlAgilityPack/RipperSchema.cs @@ -1,4 +1,4 @@ -using Cesxhin.AnimeManga.Application.NlogManager; +using Cesxhin.AnimeManga.Modules.NlogManager; using Cesxhin.AnimeManga.Domain.DTO; using Cesxhin.AnimeManga.Domain.Models; using HtmlAgilityPack; @@ -11,7 +11,7 @@ using System.Net; using System.Text.RegularExpressions; -namespace Cesxhin.AnimeManga.Application.HtmlAgilityPack +namespace Cesxhin.AnimeManga.Modules.HtmlAgilityPack { public static class RipperSchema { diff --git a/src/references/Cesxhin.AnimeManga.Application/HtmlAgilityPack/RipperVideoGeneric.cs b/src/references/Cesxhin.AnimeManga.Modules/HtmlAgilityPack/RipperVideoGeneric.cs similarity index 97% rename from src/references/Cesxhin.AnimeManga.Application/HtmlAgilityPack/RipperVideoGeneric.cs rename to src/references/Cesxhin.AnimeManga.Modules/HtmlAgilityPack/RipperVideoGeneric.cs index 46dd6ca..e97ae6c 100644 --- a/src/references/Cesxhin.AnimeManga.Application/HtmlAgilityPack/RipperVideoGeneric.cs +++ b/src/references/Cesxhin.AnimeManga.Modules/HtmlAgilityPack/RipperVideoGeneric.cs @@ -1,5 +1,5 @@ -using Cesxhin.AnimeManga.Application.NlogManager; -using Cesxhin.AnimeManga.Application.Parallel; +using Cesxhin.AnimeManga.Modules.NlogManager; +using Cesxhin.AnimeManga.Modules.Parallel; using Cesxhin.AnimeManga.Domain.DTO; using Cesxhin.AnimeManga.Domain.Models; using HtmlAgilityPack; @@ -8,7 +8,7 @@ using System; using System.Collections.Generic; -namespace Cesxhin.AnimeManga.Application.HtmlAgilityPack +namespace Cesxhin.AnimeManga.Modules.HtmlAgilityPack { public static class RipperVideoGeneric { diff --git a/src/references/Cesxhin.AnimeManga.Application/NlogManager/NLogConsole.cs b/src/references/Cesxhin.AnimeManga.Modules/NlogManager/NLogConsole.cs similarity index 98% rename from src/references/Cesxhin.AnimeManga.Application/NlogManager/NLogConsole.cs rename to src/references/Cesxhin.AnimeManga.Modules/NlogManager/NLogConsole.cs index d03c5d1..c847734 100644 --- a/src/references/Cesxhin.AnimeManga.Application/NlogManager/NLogConsole.cs +++ b/src/references/Cesxhin.AnimeManga.Modules/NlogManager/NLogConsole.cs @@ -2,7 +2,7 @@ using NLog; using System; -namespace Cesxhin.AnimeManga.Application.NlogManager +namespace Cesxhin.AnimeManga.Modules.NlogManager { public class NLogConsole { diff --git a/src/references/Cesxhin.AnimeManga.Application/NlogManager/NLogManager.cs b/src/references/Cesxhin.AnimeManga.Modules/NlogManager/NLogManager.cs similarity index 95% rename from src/references/Cesxhin.AnimeManga.Application/NlogManager/NLogManager.cs rename to src/references/Cesxhin.AnimeManga.Modules/NlogManager/NLogManager.cs index dadd940..0661973 100644 --- a/src/references/Cesxhin.AnimeManga.Application/NlogManager/NLogManager.cs +++ b/src/references/Cesxhin.AnimeManga.Modules/NlogManager/NLogManager.cs @@ -2,7 +2,7 @@ using NLog.Config; using NLog.Targets; -namespace Cesxhin.AnimeManga.Application.Generic +namespace Cesxhin.AnimeManga.Modules.Generic { public class NLogManager { diff --git a/src/references/Cesxhin.AnimeManga.Application/Parallel/ParallelManager.cs b/src/references/Cesxhin.AnimeManga.Modules/Parallel/ParallelManager.cs similarity index 97% rename from src/references/Cesxhin.AnimeManga.Application/Parallel/ParallelManager.cs rename to src/references/Cesxhin.AnimeManga.Modules/Parallel/ParallelManager.cs index e79aadf..88f6ca4 100644 --- a/src/references/Cesxhin.AnimeManga.Application/Parallel/ParallelManager.cs +++ b/src/references/Cesxhin.AnimeManga.Modules/Parallel/ParallelManager.cs @@ -1,4 +1,4 @@ -using Cesxhin.AnimeManga.Application.NlogManager; +using Cesxhin.AnimeManga.Modules.NlogManager; using NLog; using System; using System.Collections.Generic; @@ -6,7 +6,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Cesxhin.AnimeManga.Application.Parallel +namespace Cesxhin.AnimeManga.Modules.Parallel { public class ParallelManager where T : class { diff --git a/src/references/Cesxhin.AnimeManga.Application/Proxy/ProxyManagement.cs b/src/references/Cesxhin.AnimeManga.Modules/Proxy/ProxyManagement.cs similarity index 98% rename from src/references/Cesxhin.AnimeManga.Application/Proxy/ProxyManagement.cs rename to src/references/Cesxhin.AnimeManga.Modules/Proxy/ProxyManagement.cs index f03acf1..4179513 100644 --- a/src/references/Cesxhin.AnimeManga.Application/Proxy/ProxyManagement.cs +++ b/src/references/Cesxhin.AnimeManga.Modules/Proxy/ProxyManagement.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; -namespace Cesxhin.AnimeManga.Application.Proxy +namespace Cesxhin.AnimeManga.Modules.Proxy { public static class ProxyManagement { diff --git a/src/references/Cesxhin.AnimeManga.Application/Schema/SchemaControl.cs b/src/references/Cesxhin.AnimeManga.Modules/Schema/SchemaControl.cs similarity index 99% rename from src/references/Cesxhin.AnimeManga.Application/Schema/SchemaControl.cs rename to src/references/Cesxhin.AnimeManga.Modules/Schema/SchemaControl.cs index 9359688..6ef6011 100644 --- a/src/references/Cesxhin.AnimeManga.Application/Schema/SchemaControl.cs +++ b/src/references/Cesxhin.AnimeManga.Modules/Schema/SchemaControl.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; -namespace Cesxhin.AnimeManga.Application.Schema +namespace Cesxhin.AnimeManga.Modules.Schema { public static class SchemaControl { diff --git a/src/references/Cesxhin.AnimeManga.Persistence/Cesxhin.AnimeManga.Persistence.csproj b/src/references/Cesxhin.AnimeManga.Persistence/Cesxhin.AnimeManga.Persistence.csproj deleted file mode 100644 index d7c5bd5..0000000 --- a/src/references/Cesxhin.AnimeManga.Persistence/Cesxhin.AnimeManga.Persistence.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - net5.0 - - - - - - - - - - - - - - - diff --git a/src/references/Cesxhin.AnimeManga.Persistence/Repositories/AccountRepository.cs b/src/references/Cesxhin.AnimeManga.Persistence/Repositories/AccountRepository.cs deleted file mode 100644 index 666754f..0000000 --- a/src/references/Cesxhin.AnimeManga.Persistence/Repositories/AccountRepository.cs +++ /dev/null @@ -1,155 +0,0 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Interfaces.Repositories; -using Cesxhin.AnimeManga.Application.NlogManager; -using Cesxhin.AnimeManga.Domain.Models; -using NLog; -using Npgsql; -using RepoDb; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Persistence.Repositories -{ - public class AccountRepository : IAccountRepository - { - //log - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - //env - readonly string _connectionString = Environment.GetEnvironmentVariable("DATABASE_CONNECTION"); - - public async Task CreateAccount(Auth auth) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - object rs = null; - try - { - rs = await connection.InsertAsync(auth); - } - catch (Exception ex) - { - _logger.Error($"Failed CreateAccount, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && !string.IsNullOrEmpty(rs.ToString())) - return auth; - else - throw new ApiNotFoundException("Not found CreateAccount"); - } - } - - public async Task DeleteWhiteList(WatchList whiteList) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - int rs = 0; - try - { - rs = await connection.DeleteAsync(whiteList); - } - catch (Exception ex) - { - _logger.Error($"Failed DeleteWhiteList, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs > 0) - return whiteList; - else - throw new ApiNotFoundException("Not found DeleteWhiteList"); - } - } - - public async Task FindAccountByUsername(string username) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - IEnumerable rs; - try - { - rs = await connection.QueryAsync(e => e.Username == username); - } - catch (Exception ex) - { - _logger.Error($"Failed findAccountByUsername, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && rs.Any()) - return rs.First(); - else - throw new ApiNotFoundException("Not found findAccountByUsername"); - } - } - - public async Task> GetListWatchListByUsername(string username) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - IEnumerable rs; - try - { - rs = await connection.QueryAsync(e => e.Username == username); - } - catch (Exception ex) - { - _logger.Error($"Failed GetListWatchListByUsername, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && rs.Any()) - return rs; - else - throw new ApiNotFoundException("Not found GetListWatchListByUsername"); - } - } - - public async Task InsertWhiteList(WatchList whiteList) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - object rs = null; - try - { - rs = await connection.InsertAsync(whiteList); - } - catch (Exception ex) - { - _logger.Error($"Failed InsertWhiteList, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && !string.IsNullOrEmpty(rs.ToString())) - return whiteList; - else - throw new ApiNotFoundException("Not found InsertWhiteList"); - } - } - - public async Task WhiteListCheckByName(string name) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - IEnumerable rs; - try - { - rs = await connection.QueryAsync(e => e.Name == name); - } - catch (Exception ex) - { - _logger.Error($"Failed InsertWhiteList, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && rs.Any()) - return true; - else - throw new ApiNotFoundException("Not found InsertWhiteList"); - } - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Persistence/Repositories/ChapterRegisterRepository.cs b/src/references/Cesxhin.AnimeManga.Persistence/Repositories/ChapterRegisterRepository.cs deleted file mode 100644 index e72c2a3..0000000 --- a/src/references/Cesxhin.AnimeManga.Persistence/Repositories/ChapterRegisterRepository.cs +++ /dev/null @@ -1,136 +0,0 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Interfaces.Repositories; -using Cesxhin.AnimeManga.Application.NlogManager; -using Cesxhin.AnimeManga.Domain.Models; -using NLog; -using Npgsql; -using RepoDb; -using RepoDb.Enumerations; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Persistence.Repositories -{ - public class ChapterRegisterRepository : IChapterRegisterRepository - { - //log - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - //env - readonly string _connectionString = Environment.GetEnvironmentVariable("DATABASE_CONNECTION"); - - public async Task GetObjectRegisterByObjectId(string id) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - IEnumerable rs; - try - { - rs = await connection.QueryAsync(e => e.ChapterId == id); - } - catch (Exception ex) - { - _logger.Error($"Failed GetChapterRegisterByChapterId, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && rs.Any()) - return rs.First(); - else - throw new ApiNotFoundException("Not found GetObjectsRegisterByObjectId"); - } - } - - public async Task> InsertObjectsRegisterAsync(List chapterRegister) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - int rs = 0; - try - { - rs = await connection.InsertAllAsync(chapterRegister); - - } - catch (Exception ex) - { - _logger.Error($"Failed InsertChapterRegisterAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs > 0) - return chapterRegister; - else - throw new ApiNotFoundException("Not found InsertObjectRegisterAsync"); - } - } - - public async Task InsertObjectRegisterAsync(ChapterRegister chapterRegister) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - object rs = null; - try - { - rs = await connection.InsertAsync(chapterRegister); - } - catch (Exception ex) - { - _logger.Error($"Failed InsertChapterRegisterAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && !string.IsNullOrEmpty(rs.ToString())) - return chapterRegister; - else - throw new ApiNotFoundException("Not found InsertObjectRegisterAsync"); - } - } - - public async Task UpdateObjectRegisterAsync(ChapterRegister chapterRegister) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - int rs = 0; - try - { - rs = await connection.UpdateAsync(chapterRegister, e => e.ChapterId == chapterRegister.ChapterId); - } - catch (Exception ex) - { - _logger.Error($"Failed UpdateEpisodeRegisterAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs > 0) - return chapterRegister; - else - throw new ApiNotFoundException("Not found UpdateObjectRegisterAsync"); - } - } - - public async Task> GetObjectsRegistersByListObjectId(List listChapters) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - IEnumerable rs; - - try - { - rs = await connection.QueryAsync(new QueryField("chapterid", Operation.In, listChapters.Select(e => e.ID))); - } - catch (Exception ex) - { - _logger.Error($"Failed GetObjectsRegistersByListObjectId, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && rs.Any()) - return rs; - else - throw new ApiNotFoundException("Not found GetObjectsRegistersByListObjectId"); - } - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Persistence/Repositories/ChapterRepository.cs b/src/references/Cesxhin.AnimeManga.Persistence/Repositories/ChapterRepository.cs deleted file mode 100644 index 7c9cf5e..0000000 --- a/src/references/Cesxhin.AnimeManga.Persistence/Repositories/ChapterRepository.cs +++ /dev/null @@ -1,219 +0,0 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Generic; -using Cesxhin.AnimeManga.Application.Interfaces.Repositories; -using Cesxhin.AnimeManga.Application.NlogManager; -using Cesxhin.AnimeManga.Domain.Models; -using NLog; -using Npgsql; -using RepoDb; -using RepoDb.Enumerations; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Persistence.Repositories -{ - public class ChapterRepository : IChapterRepository - { - //log - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - //env - readonly string _connectionString = Environment.GetEnvironmentVariable("DATABASE_CONNECTION"); - - public async Task DeleteByNameAsync(string id) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - int rs = 0; - try - { - rs = await connection.DeleteAsync(e => e.NameManga == id); - } - catch (Exception ex) - { - _logger.Error($"Failed GetChapterByIDAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs > 0) - return rs; - else - throw new ApiNotFoundException("Not found DeleteByNameAsync"); - } - } - - public async Task GetObjectByIDAsync(string id) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - IEnumerable rs; - - try - { - rs = await connection.QueryAsync(e => e.ID == id); - } - catch (Exception ex) - { - _logger.Error($"Failed GetChapterByIDAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && rs.Any()) - return rs.First(); - else - throw new ApiNotFoundException("Not found GetObjectsByIDAsync"); - } - } - - public async Task> GetObjectsByNameAsync(string nameManga) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - IEnumerable rs; - - try - { - rs = await connection.QueryAsync(e => e.NameManga == nameManga, orderBy: OrderField.Parse(new - { - currentchapter = Order.Ascending - })); - } - catch (Exception ex) - { - _logger.Error($"Failed GetChaptersByNameAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && rs.Any()) - return ConvertGeneric.ConvertIEnurableToListCollection(rs); - else - throw new ApiNotFoundException("Not found GetObjectsByNameAsync"); - } - } - - public async Task InsertObjectAsync(Chapter chapter) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - object rs = null; - - try - { - rs = await connection.InsertAsync(chapter); - } - catch (Exception ex) - { - _logger.Error($"Failed InsertObjectAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && !string.IsNullOrEmpty(rs.ToString())) - return chapter; - else - throw new ApiNotFoundException("Not found InsertObjectAsync"); - } - } - - public async Task> InsertObjectsAsync(List chapters) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - int rs = 0; - - try - { - rs = await connection.InsertAllAsync(chapters); - } - catch (Exception ex) - { - _logger.Error($"Failed InsertChapterAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs > 0) - return chapters; - else - throw new ApiNotFoundException("Not found InsertObjectsAsync"); - } - } - - public async Task ResetStatusDownloadObjectByIdAsync(Chapter chapter) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - int rs = 0; - - chapter.PercentualDownload = 0; - chapter.StateDownload = null; - - try - { - rs = await connection.UpdateAsync(chapter, e => e.StateDownload != "completed" && e.ID == chapter.ID); - } - catch (Exception ex) - { - _logger.Error($"Failed ResetStatusDownloadChaptersByIdAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs > 0) - return chapter; - else - throw new ApiNotFoundException("Not found ResetStatusDownloadObjectByIdAsync"); - } - } - - public async Task> ResetStatusDownloadObjectsByIdAsync(List chapters) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - int rs = 0; - try - { - var chaptersUpdate = chapters.Where(e => e.StateDownload != "completed").ToList(); - chaptersUpdate.ForEach(e => - { - e.PercentualDownload = 0; - e.StateDownload = null; - }); - - rs = await connection.UpdateAllAsync(chaptersUpdate); - } - catch (Exception ex) - { - _logger.Error($"Failed ResetStatusDownloadChaptersByIdAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs > 0) - return chapters; - else - throw new ApiNotFoundException("Not found ResetStatusDownloadObjectsByIdAsync"); - } - } - - public async Task UpdateStateDownloadAsync(Chapter chapter) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - int rs = 0; - try - { - rs = await connection.UpdateAsync(chapter); - } - catch (Exception ex) - { - _logger.Error($"Failed UpdateStateDownloadAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs > 0) - return chapter; - else - throw new ApiNotFoundException("Not found UpdateStateDownloadAsync"); - } - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Persistence/Repositories/DescriptionRepository.cs b/src/references/Cesxhin.AnimeManga.Persistence/Repositories/DescriptionRepository.cs deleted file mode 100644 index e1590d7..0000000 --- a/src/references/Cesxhin.AnimeManga.Persistence/Repositories/DescriptionRepository.cs +++ /dev/null @@ -1,187 +0,0 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Interfaces.Repositories; -using Cesxhin.AnimeManga.Application.NlogManager; -using MongoDB.Bson; -using MongoDB.Driver; -using Newtonsoft.Json.Linq; -using NLog; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text.RegularExpressions; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Persistence.Repositories -{ - public class DescriptionRepository : IDescriptionRepository - { - //log - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - //env - readonly string _connectionString = Environment.GetEnvironmentVariable("DATABASE_CONNECTION_MONGO"); - readonly string _nameDatabase = Environment.GetEnvironmentVariable("NAME_DATABASE_MONGO"); - readonly JObject _schema = JObject.Parse(Environment.GetEnvironmentVariable("SCHEMA")); - - private static string RemoveObjectId(string result) - { - var regex = new Regex(Regex.Escape("ObjectId(")); - var partOne = regex.Replace(result, "", 1); - - - regex = new Regex(Regex.Escape(")")); - return regex.Replace(partOne, "", 1); - - } - - private string GetNameTable(string nameCfg) - { - if (_schema.ContainsKey(nameCfg)) - { - return _schema.GetValue(nameCfg).ToObject().GetValue("name").ToString(); - } - - return null; - } - - public async Task DeleteNameAsync(string nameCfg, string id) - { - var client = new MongoClient(_connectionString); - - int rs = 0; - try - { - var database = client.GetDatabase(_nameDatabase); - var collection = database.GetCollection("description_" + GetNameTable(nameCfg)); - var deleteFilter = Builders.Filter.Eq("name_id", id); - var result = await collection.DeleteOneAsync(deleteFilter); - - rs = (int)result.DeletedCount; - } - catch (Exception ex) - { - client.Cluster.Dispose(); - _logger.Error($"Failed DeleteNameAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs > 0) - return rs; - else - throw new ApiNotFoundException("Not found DeleteNameAsync"); - } - - public Task> GetMostNameByNameAsync(string nameCfg, string name) - { - throw new NotImplementedException(); - } - - public async Task> GetNameAllAsync(string nameCfg) - { - var client = new MongoClient(_connectionString); - - List list; - try - { - var database = client.GetDatabase(_nameDatabase); - var collection = database.GetCollection("description_" + GetNameTable(nameCfg)); - list = collection.Find(Builders.Filter.Empty).ToList(); - } - catch (Exception ex) - { - client.Cluster.Dispose(); - _logger.Error($"Failed DeleteNameAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (list != null && list.Any()) - { - var listObject = new List(); - - foreach (var item in list) - { - listObject.Add(JObject.Parse(RemoveObjectId(item.ToString()))); - } - - return listObject; - } - else - throw new ApiNotFoundException("Not found GetNameAllAsync"); - } - - public async Task GetNameByNameAsync(string nameCfg, string name) - { - var client = new MongoClient(_connectionString); - - BsonDocument result; - try - { - var database = client.GetDatabase(_nameDatabase); - var collection = database.GetCollection("description_" + GetNameTable(nameCfg)); - var findFilter = Builders.Filter.Eq("name_id", name); - result = collection.Find(findFilter).FirstOrDefault(); - } - catch (Exception ex) - { - client.Cluster.Dispose(); - _logger.Error($"Failed DeleteNameAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (result != null && result.Any()) - return JObject.Parse(RemoveObjectId(result.ToString())); - else - throw new ApiNotFoundException("Not found GetNameByNameAsync"); - } - - public async Task InsertNameAsync(string nameCfg, JObject description) - { - var client = new MongoClient(_connectionString); - try - { - var database = client.GetDatabase(_nameDatabase); - var collection = database.GetCollection("description_" + GetNameTable(nameCfg)); - await collection.InsertOneAsync(BsonDocument.Parse(description.ToString())); - - return description; - } - catch (Exception ex) - { - client.Cluster.Dispose(); - _logger.Error($"Failed DeleteNameAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - } - - public async Task UpdateNameAsync(string nameCfg, JObject description) - { - var client = new MongoClient(_connectionString); - try - { - var database = client.GetDatabase(_nameDatabase); - var collection = database.GetCollection("description_" + GetNameTable(nameCfg)); - FilterDefinition findFilter = Builders.Filter.Eq("name_id", (string)description["name_id"]); - List> update = new(); - - update.Add(Builders.Update.Set("name_id", (string)description["name_id"])); - - foreach (var field in description) - { - if (field.Key == "_id") - continue; - update.Add(Builders.Update.Set(field.Key, (string)description[field.Key])); - } - - await collection.UpdateOneAsync(findFilter, Builders.Update.Combine(update)); - - return description; - } - catch (Exception ex) - { - client.Cluster.Dispose(); - _logger.Error($"Failed DeleteNameAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Persistence/Repositories/EpisodeRegisterRepository.cs b/src/references/Cesxhin.AnimeManga.Persistence/Repositories/EpisodeRegisterRepository.cs deleted file mode 100644 index 58207e4..0000000 --- a/src/references/Cesxhin.AnimeManga.Persistence/Repositories/EpisodeRegisterRepository.cs +++ /dev/null @@ -1,141 +0,0 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Interfaces.Repositories; -using Cesxhin.AnimeManga.Application.NlogManager; -using Cesxhin.AnimeManga.Domain.Models; -using NLog; -using Npgsql; -using RepoDb; -using RepoDb.Enumerations; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Persistence.Repositories -{ - public class EpisodeRegisterRepository : IEpisodeRegisterRepository - { - //log - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - //env - readonly string _connectionString = Environment.GetEnvironmentVariable("DATABASE_CONNECTION"); - - //get all episodesRegisters - public async Task GetObjectRegisterByObjectId(string id) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - IEnumerable rs; - try - { - rs = await connection.QueryAsync(e => e.EpisodeId == id); - } - catch (Exception ex) - { - _logger.Error($"Failed GetEpisodeRegisterByEpisodeId, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && rs.Any()) - return rs.First(); - else - throw new ApiNotFoundException("Not found GetObjectsRegisterByObjectId"); - } - } - - //insert - public async Task> InsertObjectsRegisterAsync(List episodeRegister) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - int rs = 0; - - try - { - rs = await connection.InsertAllAsync(episodeRegister); - } - catch (Exception ex) - { - _logger.Error($"Failed InsertEpisodeRegisterAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs > 0) - return episodeRegister; - else - throw new ApiNotFoundException("Not found InsertObjectRegisterAsync"); - } - } - - public async Task InsertObjectRegisterAsync(EpisodeRegister episodeRegister) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - object rs = null; - - try - { - rs = await connection.InsertAsync(episodeRegister); - } - catch (Exception ex) - { - _logger.Error($"Failed InsertEpisodeRegisterAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && !string.IsNullOrEmpty(rs.ToString())) - return episodeRegister; - else - throw new ApiNotFoundException("Not found InsertObjectRegisterAsync"); - } - } - - //update - public async Task UpdateObjectRegisterAsync(EpisodeRegister episodeRegister) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - int rs = 0; - - try - { - rs = await connection.UpdateAsync(episodeRegister, e => e.EpisodeId == episodeRegister.EpisodeId); - } - catch (Exception ex) - { - _logger.Error($"Failed UpdateEpisodeRegisterAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs > 0) - return episodeRegister; - else - throw new ApiNotFoundException("Not found UpdateObjectRegisterAsync"); - } - } - - public async Task> GetObjectsRegistersByListObjectId(List listEpisodes) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - IEnumerable rs; - - try - { - rs = await connection.QueryAsync(new QueryField("episodeid", Operation.In, listEpisodes.Select(e => e.ID))); - } - catch (Exception ex) - { - _logger.Error($"Failed GetObjectsRegistersByListObjectId, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && rs.Any()) - return rs; - else - throw new ApiNotFoundException("Not found GetObjectsRegistersByListObjectId"); - } - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Persistence/Repositories/EpisodeRepository.cs b/src/references/Cesxhin.AnimeManga.Persistence/Repositories/EpisodeRepository.cs deleted file mode 100644 index c952070..0000000 --- a/src/references/Cesxhin.AnimeManga.Persistence/Repositories/EpisodeRepository.cs +++ /dev/null @@ -1,228 +0,0 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Interfaces.Repositories; -using Cesxhin.AnimeManga.Application.NlogManager; -using Cesxhin.AnimeManga.Domain.Models; -using NLog; -using Npgsql; -using RepoDb; -using RepoDb.Enumerations; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Persistence.Repositories -{ - public class EpisodeRepository : IEpisodeRepository - { - //log - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - //env - readonly string _connectionString = Environment.GetEnvironmentVariable("DATABASE_CONNECTION"); - - public async Task DeleteByNameAsync(string id) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - int rs = 0; - - try - { - rs = await connection.DeleteAsync(e => e.VideoId == id); - } - catch (Exception ex) - { - _logger.Error($"Failed DeleteByNameAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs > 0) - return rs; - else - throw new ApiNotFoundException("Not found DeleteByNameAsync"); - } - } - - //get episode by id - public async Task GetObjectByIDAsync(string id) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - IEnumerable rs; - - try - { - rs = await connection.QueryAsync(e => e.ID == id); - } - catch (Exception ex) - { - _logger.Error($"Failed GetObjectByIDAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && rs.Any()) - return rs.First(); - else - throw new ApiNotFoundException("Not found GetObjectByIDAsync"); - } - } - - //get episodes by name - public async Task> GetObjectsByNameAsync(string name) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - IEnumerable rs; - - try - { - rs = await connection.QueryAsync(e => e.VideoId == name, orderBy: OrderField.Parse(new - { - numberepisodecurrent = Order.Ascending - })); - } - catch (Exception ex) - { - _logger.Error($"Failed GetObjectsByNameAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && rs.Any()) - return rs; - else - throw new ApiNotFoundException("Not found GetObjectsByNameAsync"); - } - } - - //insert episode - public async Task InsertObjectAsync(Episode episode) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - object rs = null; - - try - { - rs = await connection.InsertAsync(episode); - } - catch (Exception ex) - { - _logger.Error($"Failed InsertObjectAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && !string.IsNullOrEmpty(rs.ToString())) - return episode; - else - throw new ApiNotFoundException("Not found InsertObjectAsync"); - } - } - - public async Task> InsertObjectsAsync(List episodes) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - int rs = 0; - - try - { - rs = await connection.InsertAllAsync(episodes); - } - catch (Exception ex) - { - _logger.Error($"Failed InsertObjectsAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs > 0) - return episodes; - else - throw new ApiNotFoundException("Not found InsertObjectsAsync"); - } - } - - //reset StatusDownlod to null - public async Task ResetStatusDownloadObjectByIdAsync(Episode episode) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - int rs = 0; - - episode.PercentualDownload = 0; - episode.StateDownload = null; - - try - { - - rs = await connection.UpdateAsync(episode, e => e.StateDownload != "completed" && e.ID == episode.ID); - - } - catch (Exception ex) - { - _logger.Error($"Failed ResetStatusDownloadObjectByIdAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs > 0) - return episode; - else - throw new ApiNotFoundException("Not found ResetStatusDownloadObjectByIdAsync"); - } - } - - public async Task> ResetStatusDownloadObjectsByIdAsync(List episodes) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - int rs = 0; - - try - { - var episodesUpdate = episodes.Where(e => e.StateDownload != "completed").ToList(); - episodesUpdate.ForEach((e) => - { - e.PercentualDownload = 0; - e.StateDownload = null; - }); - - rs = await connection.UpdateAllAsync(episodesUpdate); - } - catch (Exception ex) - { - _logger.Error($"Failed ResetStatusDownloadObjectsByIdAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs > 0) - return episodes; - else - throw new ApiNotFoundException("Not found ResetStatusDownloadObjectsByIdAsync"); - } - } - - //update percentualDownload - public async Task UpdateStateDownloadAsync(Episode episode) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - int rs = 0; - - try - { - rs = await connection.UpdateAsync(episode); - } - catch (Exception ex) - { - _logger.Error($"Failed UpdateStateDownloadAsync, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs > 0) - return episode; - else - throw new ApiNotFoundException("Not found UpdateStateDownloadAsync"); - } - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Persistence/Repositories/ProgressChapterRepository.cs b/src/references/Cesxhin.AnimeManga.Persistence/Repositories/ProgressChapterRepository.cs deleted file mode 100644 index a35b8be..0000000 --- a/src/references/Cesxhin.AnimeManga.Persistence/Repositories/ProgressChapterRepository.cs +++ /dev/null @@ -1,91 +0,0 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Interfaces.Repositories; -using Cesxhin.AnimeManga.Application.NlogManager; -using Cesxhin.AnimeManga.Domain.Models; -using NLog; -using Npgsql; -using RepoDb; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Persistence.Repositories -{ - public class ProgressChapterRepository : IProgressChapterRepository - { - //log - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - //env - readonly string _connectionString = Environment.GetEnvironmentVariable("DATABASE_CONNECTION"); - - public async Task CheckProgress(string name, string username, string nameCfg) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - IEnumerable rs; - try - { - rs = await connection.QueryAsync(e => e.Name == name && e.Username == username && e.NameCfg == nameCfg); - } - catch (Exception ex) - { - _logger.Error($"Failed CheckProgress, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && rs.Any()) - return rs.First(); - else - throw new ApiNotFoundException("Not found CheckProgress"); - } - } - - public async Task CreateProgress(ProgressChapter progress) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - object rs = null; - - try - { - rs = await connection.InsertAsync(progress); - } - catch (Exception ex) - { - _logger.Error($"Failed CreateProgress, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && !string.IsNullOrEmpty(rs.ToString())) - return progress; - else - throw new ApiNotFoundException("Not found CreateProgress"); - } - } - - public async Task UpdateProgress(ProgressChapter progress) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - int rs = 0; - - try - { - rs = await connection.UpdateAsync(progress, e => e.Name == progress.Name && e.Username == progress.Username && e.NameCfg == progress.NameCfg); - } - catch (Exception ex) - { - _logger.Error($"Failed UpdateProgress, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs > 0) - return progress; - else - throw new ApiNotFoundException("Not found UpdateProgress"); - } - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Persistence/Repositories/ProgressEpisodeRepository.cs b/src/references/Cesxhin.AnimeManga.Persistence/Repositories/ProgressEpisodeRepository.cs deleted file mode 100644 index 5d6da8a..0000000 --- a/src/references/Cesxhin.AnimeManga.Persistence/Repositories/ProgressEpisodeRepository.cs +++ /dev/null @@ -1,91 +0,0 @@ -using Cesxhin.AnimeManga.Application.Exceptions; -using Cesxhin.AnimeManga.Application.Interfaces.Repositories; -using Cesxhin.AnimeManga.Application.NlogManager; -using Cesxhin.AnimeManga.Domain.Models; -using NLog; -using Npgsql; -using RepoDb; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Persistence.Repositories -{ - public class ProgressEpisodeRepository : IProgressEpisodeRepository - { - //log - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - //env - readonly string _connectionString = Environment.GetEnvironmentVariable("DATABASE_CONNECTION"); - - public async Task CheckProgress(string name, string username, string nameCfg) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - IEnumerable rs; - try - { - rs = await connection.QueryAsync(e => e.Name == name && e.Username == username && e.NameCfg == nameCfg); - } - catch (Exception ex) - { - _logger.Error($"Failed CheckProgress, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && rs.Any()) - return rs.First(); - else - throw new ApiNotFoundException("Not found CheckProgress"); - } - } - - public async Task CreateProgress(ProgressEpisode progress) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - object rs = null; - - try - { - rs = await connection.InsertAsync(progress); - } - catch (Exception ex) - { - _logger.Error($"Failed CreateProgress, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs != null && !string.IsNullOrEmpty(rs.ToString())) - return progress; - else - throw new ApiNotFoundException("Not found CreateProgress"); - } - } - - public async Task UpdateProgress(ProgressEpisode progress) - { - using (var connection = new NpgsqlConnection(_connectionString)) - { - int rs = 0; - - try - { - rs = await connection.UpdateAsync(progress, e => e.Name == progress.Name && e.Username == progress.Username && e.NameCfg == progress.NameCfg); - } - catch (Exception ex) - { - _logger.Error($"Failed UpdateProgress, details error: {ex.Message}"); - throw new ApiGenericException(ex.Message); - } - - if (rs > 0) - return progress; - else - throw new ApiNotFoundException("Not found UpdateProgress"); - } - } - } -} From 442fb0d8c574ed1edd5d7872bb4b14d8b2d7ffc2 Mon Sep 17 00:00:00 2001 From: Anime-Manga <> Date: Mon, 29 May 2023 19:07:19 +0000 Subject: [PATCH 02/15] Update from https://github.com/Anime-Manga/references/commit/e966a160bc7337f43ab670c9704b7c24a448b148 --- .../Cesxhin.AnimeManga.Modules/Cesxhin.AnimeManga.Modules.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/references/Cesxhin.AnimeManga.Modules/Cesxhin.AnimeManga.Modules.csproj b/src/references/Cesxhin.AnimeManga.Modules/Cesxhin.AnimeManga.Modules.csproj index c8a8d0a..f8acc93 100644 --- a/src/references/Cesxhin.AnimeManga.Modules/Cesxhin.AnimeManga.Modules.csproj +++ b/src/references/Cesxhin.AnimeManga.Modules/Cesxhin.AnimeManga.Modules.csproj @@ -21,5 +21,4 @@ - From a63643382ed1733ff306f30b62aed4e754869a97 Mon Sep 17 00:00:00 2001 From: Anime-Manga <> Date: Sat, 17 Jun 2023 14:56:49 +0000 Subject: [PATCH 03/15] Update from https://github.com/Anime-Manga/references/commit/5a6c7b30b3c8fc2f299db36f6f68dfea4951090d --- src/references/Cesxhin.AnimeManga.Domain/Models/Auth.cs | 2 +- src/references/Cesxhin.AnimeManga.Domain/Models/Chapter.cs | 2 +- .../Cesxhin.AnimeManga.Domain/Models/ProgressChapter.cs | 2 +- .../Cesxhin.AnimeManga.Domain/Models/WatchList.cs | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/references/Cesxhin.AnimeManga.Domain/Models/Auth.cs b/src/references/Cesxhin.AnimeManga.Domain/Models/Auth.cs index 03db548..140cba4 100644 --- a/src/references/Cesxhin.AnimeManga.Domain/Models/Auth.cs +++ b/src/references/Cesxhin.AnimeManga.Domain/Models/Auth.cs @@ -6,7 +6,7 @@ namespace Cesxhin.AnimeManga.Domain.Models [Map("account")] public class Auth { - [Identity] + [Primary] [Map("username")] public string Username { get; set; } diff --git a/src/references/Cesxhin.AnimeManga.Domain/Models/Chapter.cs b/src/references/Cesxhin.AnimeManga.Domain/Models/Chapter.cs index fa315cb..f6e19b9 100644 --- a/src/references/Cesxhin.AnimeManga.Domain/Models/Chapter.cs +++ b/src/references/Cesxhin.AnimeManga.Domain/Models/Chapter.cs @@ -6,7 +6,7 @@ namespace Cesxhin.AnimeManga.Domain.Models [Map("chapter")] public class Chapter { - [Identity] + [Primary] [Map("id")] public string ID { get; set; } diff --git a/src/references/Cesxhin.AnimeManga.Domain/Models/ProgressChapter.cs b/src/references/Cesxhin.AnimeManga.Domain/Models/ProgressChapter.cs index 03ef398..9bc8892 100644 --- a/src/references/Cesxhin.AnimeManga.Domain/Models/ProgressChapter.cs +++ b/src/references/Cesxhin.AnimeManga.Domain/Models/ProgressChapter.cs @@ -6,7 +6,7 @@ namespace Cesxhin.AnimeManga.Domain.Models [Map("progresschapter")] public class ProgressChapter { - [Identity] + [Primary] [Map("id")] public string ID { get; set; } [Map("username")] diff --git a/src/references/Cesxhin.AnimeManga.Domain/Models/WatchList.cs b/src/references/Cesxhin.AnimeManga.Domain/Models/WatchList.cs index 06aa854..f89e4c4 100644 --- a/src/references/Cesxhin.AnimeManga.Domain/Models/WatchList.cs +++ b/src/references/Cesxhin.AnimeManga.Domain/Models/WatchList.cs @@ -6,15 +6,15 @@ namespace Cesxhin.AnimeManga.Domain.Models [Map("whitelist")] public class WatchList { - [Identity] + [Primary] [Map("name")] public string Name { get; set; } - [Identity] + [Primary] [Map("username")] public string Username { get; set; } - [Identity] + [Primary] [Map("namecfg")] public string NameCfg { get; set; } From e0fd88f3c2801326fcc936b405b1041826e1c471 Mon Sep 17 00:00:00 2001 From: Anime-Manga <> Date: Sun, 1 Oct 2023 15:31:23 +0000 Subject: [PATCH 04/15] Update from https://github.com/Anime-Manga/references/commit/66bc0ca88e755478614941a6fb820f5bf899d503 --- .../Proxy/ProxyManagement.cs | 68 +++++-------------- 1 file changed, 18 insertions(+), 50 deletions(-) diff --git a/src/references/Cesxhin.AnimeManga.Modules/Proxy/ProxyManagement.cs b/src/references/Cesxhin.AnimeManga.Modules/Proxy/ProxyManagement.cs index 4179513..cb13ead 100644 --- a/src/references/Cesxhin.AnimeManga.Modules/Proxy/ProxyManagement.cs +++ b/src/references/Cesxhin.AnimeManga.Modules/Proxy/ProxyManagement.cs @@ -5,63 +5,35 @@ namespace Cesxhin.AnimeManga.Modules.Proxy { - public static class ProxyManagement + public class ProxyManagement { - private static List GetList(string name) - { - var env = Environment.GetEnvironmentVariable(name); - List listEnv = new(); - - if (!string.IsNullOrEmpty(env)) - listEnv.AddRange(env.Split(',')); - - return listEnv; - } - - private static JObject GetBlackList() - { - var blackList = Environment.GetEnvironmentVariable("BLACK_LIST_PROXY"); - var jsonBlackList = new JObject(); - - if (blackList != null) - jsonBlackList = JObject.Parse(blackList); + private string blackList = ""; + private List listProxy = new(); - return jsonBlackList; - } - public static void InitProxy() + public void InitProxy() { var enableProxy = Environment.GetEnvironmentVariable("PROXY_ENABLE") ?? "false"; if (enableProxy == "true") { - var listProxy = System.IO.File.ReadAllText("proxy.txt"); - - Environment.SetEnvironmentVariable("LIST_PROXY", listProxy); + listProxy = System.IO.File.ReadAllText("proxy.txt").Split(",").ToList(); } } - public static List GetAllIP() + public List GetAllIP() { - return GetList("LIST_PROXY"); + return listProxy; } - public static string GetIp(string id) + public string GetIp() { - var enableProxy = Environment.GetEnvironmentVariable("PROXY_ENABLE") ?? "false"; - - if(enableProxy == "true") + if(EnableProxy()) { - var listProxy = GetList("LIST_PROXY"); - var blackProxyJson = GetBlackList(); + var listBlackProxy = blackList.Split(",").ToList(); - if (blackProxyJson.ContainsKey(id)) + foreach (var blackProxy in listBlackProxy) { - var listBlackProxy = ((string)blackProxyJson[id]).Split(",").ToList(); - - foreach (var blackProxy in listBlackProxy) - { - listProxy = listProxy.Where(e => e != blackProxy).ToList(); - } + listProxy = listProxy.Where(e => e != blackProxy).ToList(); } if (listProxy.Count > 0) @@ -73,25 +45,21 @@ public static string GetIp(string id) return null; } - public static bool EnableProxy() + public bool EnableProxy() { var enableProxy = Environment.GetEnvironmentVariable("PROXY_ENABLE") ?? "false"; return enableProxy == "true"; } - public static void BlackListAdd(string ip, string id) + public void BlackListAdd(string ip) { - var jsonBlackList = GetBlackList(); - if (jsonBlackList.ContainsKey(id)) + var list = blackList.Split(",").ToList(); + + if(list.Find(e => e == ip) == null) { - var list = ((string)jsonBlackList[id]).Split(",").ToList(); list.Add(ip); - jsonBlackList[id] = string.Join(",", list); + blackList = string.Join(",", list); } - else - jsonBlackList[id] = ip; - - Environment.SetEnvironmentVariable("BLACK_LIST_PROXY", jsonBlackList.ToString()); } } } From d37b0a5c9aaee1db3b8025b089e5b69b833919aa Mon Sep 17 00:00:00 2001 From: Anime-Manga <> Date: Tue, 3 Oct 2023 18:52:24 +0000 Subject: [PATCH 05/15] Update from https://github.com/Anime-Manga/references/commit/46108f10cc0fa3d1b184ff6a9da4759a3d4f2d8c --- src/references/Cesxhin.AnimeManga.Domain/DTO/ProxyDTO.cs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/references/Cesxhin.AnimeManga.Domain/DTO/ProxyDTO.cs diff --git a/src/references/Cesxhin.AnimeManga.Domain/DTO/ProxyDTO.cs b/src/references/Cesxhin.AnimeManga.Domain/DTO/ProxyDTO.cs new file mode 100644 index 0000000..e15bfc5 --- /dev/null +++ b/src/references/Cesxhin.AnimeManga.Domain/DTO/ProxyDTO.cs @@ -0,0 +1,8 @@ +namespace Cesxhin.AnimeManga.Domain.DTO +{ + public class ProxyDTO + { + public string Action { get; set; } = "restart"; + public string Endpoint { get; set; } + } +} From eda317e8b576e9b86665cf709cdb88c510e79b96 Mon Sep 17 00:00:00 2001 From: Anime-Manga <> Date: Sun, 8 Oct 2023 18:48:57 +0000 Subject: [PATCH 06/15] Update from https://github.com/Anime-Manga/references/commit/f462d931f0dd71ec512f7709e8ce28b6593de7af --- .../Cesxhin.AnimeManga.Modules/Parallel/ParallelManager.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/references/Cesxhin.AnimeManga.Modules/Parallel/ParallelManager.cs b/src/references/Cesxhin.AnimeManga.Modules/Parallel/ParallelManager.cs index 88f6ca4..80eacca 100644 --- a/src/references/Cesxhin.AnimeManga.Modules/Parallel/ParallelManager.cs +++ b/src/references/Cesxhin.AnimeManga.Modules/Parallel/ParallelManager.cs @@ -39,7 +39,7 @@ private void Process(CancellationToken ct) ct.ThrowIfCancellationRequested(); //add task - if (capacity < NUMBER_PARALLEL_MAX && queue.Count > 0) + while(capacity < NUMBER_PARALLEL_MAX && queue.Count > 0) { var task = queue.First(); @@ -79,6 +79,7 @@ private void Process(CancellationToken ct) tasks.Remove(task); } + Thread.Sleep(1000); } while (capacity >= NUMBER_PARALLEL_MAX); } } From 632050275395ee5fc3690c5ff169aa186ab1e6c4 Mon Sep 17 00:00:00 2001 From: Anime-Manga <> Date: Sat, 14 Oct 2023 15:39:37 +0000 Subject: [PATCH 07/15] Update from https://github.com/Anime-Manga/references/commit/bbeb5230a8087e95f64dec84b48427cfde3ad3df --- .../Cesxhin.AnimeManga.Domain/DTO/AuthDTO.cs | 4 +- .../DTO/GenericQueueDTO.cs | 34 +++++++++++++++++ .../Cesxhin.AnimeManga.Domain/Models/Auth.cs | 6 ++- .../Models/ChapterQueue.cs | 37 +++++++++++++++++++ .../Models/EpisodeQueue.cs | 36 ++++++++++++++++++ 5 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 src/references/Cesxhin.AnimeManga.Domain/DTO/GenericQueueDTO.cs create mode 100644 src/references/Cesxhin.AnimeManga.Domain/Models/ChapterQueue.cs create mode 100644 src/references/Cesxhin.AnimeManga.Domain/Models/EpisodeQueue.cs diff --git a/src/references/Cesxhin.AnimeManga.Domain/DTO/AuthDTO.cs b/src/references/Cesxhin.AnimeManga.Domain/DTO/AuthDTO.cs index 21bbb72..ecfe7ea 100644 --- a/src/references/Cesxhin.AnimeManga.Domain/DTO/AuthDTO.cs +++ b/src/references/Cesxhin.AnimeManga.Domain/DTO/AuthDTO.cs @@ -5,13 +5,15 @@ namespace Cesxhin.AnimeManga.Domain.DTO public class AuthDTO { public string Username { get; set; } + public int Role { get; set; } //convert Auth to AuthDTO public static AuthDTO AuthToAuthDTO(Auth auth) { return new AuthDTO { - Username = auth.Username + Username = auth.Username, + Role = auth.Role }; } } diff --git a/src/references/Cesxhin.AnimeManga.Domain/DTO/GenericQueueDTO.cs b/src/references/Cesxhin.AnimeManga.Domain/DTO/GenericQueueDTO.cs new file mode 100644 index 0000000..01e2e42 --- /dev/null +++ b/src/references/Cesxhin.AnimeManga.Domain/DTO/GenericQueueDTO.cs @@ -0,0 +1,34 @@ +using Cesxhin.AnimeManga.Domain.Models; +using System; + +namespace Cesxhin.AnimeManga.Domain.DTO +{ + public class GenericQueueDTO + { + public string Url { get; set; } + public string NameCfg { get; set; } + public long TimeRequest { get; set; } = ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeMilliseconds(); + + //convert ChapterQueue to GenericQueueDTO + public static GenericQueueDTO ChapterQueueToGenericQueueDTO(ChapterQueue queue) + { + return new GenericQueueDTO + { + Url = queue.Url, + NameCfg = queue.NameCfg, + TimeRequest = queue.TimeRequest + }; + } + + //convert EpisodeQueue to GenericQueueDTO + public static GenericQueueDTO EpisodeQueueToGenericQueueDTO(EpisodeQueue queue) + { + return new GenericQueueDTO + { + Url = queue.Url, + NameCfg = queue.NameCfg, + TimeRequest = queue.TimeRequest + }; + } + } +} diff --git a/src/references/Cesxhin.AnimeManga.Domain/Models/Auth.cs b/src/references/Cesxhin.AnimeManga.Domain/Models/Auth.cs index 140cba4..9bb9518 100644 --- a/src/references/Cesxhin.AnimeManga.Domain/Models/Auth.cs +++ b/src/references/Cesxhin.AnimeManga.Domain/Models/Auth.cs @@ -13,12 +13,16 @@ public class Auth [Map("password")] public string Password { get; set; } + [Map("role")] + public int Role { get; set; } + //convert AuthDTO to Auth public static Auth AuthDTOToAuth(AuthDTO auth) { return new Auth { - Username = auth.Username + Username = auth.Username, + Role = auth.Role, }; } } diff --git a/src/references/Cesxhin.AnimeManga.Domain/Models/ChapterQueue.cs b/src/references/Cesxhin.AnimeManga.Domain/Models/ChapterQueue.cs new file mode 100644 index 0000000..10d58c7 --- /dev/null +++ b/src/references/Cesxhin.AnimeManga.Domain/Models/ChapterQueue.cs @@ -0,0 +1,37 @@ +using Cesxhin.AnimeManga.Domain.DTO; +using RepoDb.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cesxhin.AnimeManga.Domain.Models +{ + [Map("chapterqueue")] + public class ChapterQueue + { + [Primary] + [Map("url")] + public string Url { get; set; } + + [Primary] + [Map("namecfg")] + public string NameCfg { get; set; } + + [Map("timerequest")] + public long TimeRequest { get; set; } + + + //convert GenericQueueDTO to ChapterQueue + public static ChapterQueue GenericQueueDTOToChapterQueue(GenericQueueDTO queue) + { + return new ChapterQueue + { + Url = queue.Url, + NameCfg = queue.NameCfg, + TimeRequest = queue.TimeRequest + }; + } + } +} diff --git a/src/references/Cesxhin.AnimeManga.Domain/Models/EpisodeQueue.cs b/src/references/Cesxhin.AnimeManga.Domain/Models/EpisodeQueue.cs new file mode 100644 index 0000000..7538657 --- /dev/null +++ b/src/references/Cesxhin.AnimeManga.Domain/Models/EpisodeQueue.cs @@ -0,0 +1,36 @@ +using Cesxhin.AnimeManga.Domain.DTO; +using RepoDb.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cesxhin.AnimeManga.Domain.Models +{ + [Map("episodequeue")] + public class EpisodeQueue + { + [Primary] + [Map("url")] + public string Url { get; set; } + + [Primary] + [Map("namecfg")] + public string NameCfg { get; set; } + + [Map("timerequest")] + public long TimeRequest { get; set; } + + //convert GenericQueueDTO to EpisodeQueue + public static EpisodeQueue GenericQueueDTOToEpisodeQueue(GenericQueueDTO queue) + { + return new EpisodeQueue + { + Url = queue.Url, + NameCfg = queue.NameCfg, + TimeRequest = queue.TimeRequest + }; + } + } +} From 472dfe1168341fb14b0b582ef8e429d4f72bebdd Mon Sep 17 00:00:00 2001 From: Anime-Manga <> Date: Sun, 15 Oct 2023 16:24:21 +0000 Subject: [PATCH 08/15] Update from https://github.com/Anime-Manga/references/commit/a9efe31cb500595b9acee113237ab59248cd3231 --- .../DTO/GenericBlackListDTO.cs | 33 +++++++++++++++++++ .../DTO/GenericQueueDTO.cs | 3 ++ .../Models/ChapterBlacklist.cs | 31 +++++++++++++++++ .../Models/ChapterQueue.cs | 5 +++ .../Models/EpisodeBlacklist.cs | 31 +++++++++++++++++ .../Models/EpisodeQueue.cs | 5 +++ 6 files changed, 108 insertions(+) create mode 100644 src/references/Cesxhin.AnimeManga.Domain/DTO/GenericBlackListDTO.cs create mode 100644 src/references/Cesxhin.AnimeManga.Domain/Models/ChapterBlacklist.cs create mode 100644 src/references/Cesxhin.AnimeManga.Domain/Models/EpisodeBlacklist.cs diff --git a/src/references/Cesxhin.AnimeManga.Domain/DTO/GenericBlackListDTO.cs b/src/references/Cesxhin.AnimeManga.Domain/DTO/GenericBlackListDTO.cs new file mode 100644 index 0000000..207000e --- /dev/null +++ b/src/references/Cesxhin.AnimeManga.Domain/DTO/GenericBlackListDTO.cs @@ -0,0 +1,33 @@ +using Cesxhin.AnimeManga.Domain.Models; + +namespace Cesxhin.AnimeManga.Domain.DTO +{ + public class GenericBlackListDTO + { + public string Name { get; set; } + public string Url { get; set; } + public string NameCfg { get; set; } + + //convert EpisodeBlackList to GenericBlackListDTO + public static GenericBlackListDTO EpisodeBlackListToGenericBlackListDTO(EpisodeBlacklist auth) + { + return new GenericBlackListDTO + { + Name = auth.Name, + Url = auth.Url, + NameCfg = auth.NameCfg, + }; + } + + //convert ChapterBlackList to GenericBlackListDTO + public static GenericBlackListDTO ChapterBlackListToGenericBlackListDTO(ChapterBlacklist auth) + { + return new GenericBlackListDTO + { + Name = auth.Name, + Url = auth.Url, + NameCfg = auth.NameCfg, + }; + } + } +} diff --git a/src/references/Cesxhin.AnimeManga.Domain/DTO/GenericQueueDTO.cs b/src/references/Cesxhin.AnimeManga.Domain/DTO/GenericQueueDTO.cs index 01e2e42..c166b8e 100644 --- a/src/references/Cesxhin.AnimeManga.Domain/DTO/GenericQueueDTO.cs +++ b/src/references/Cesxhin.AnimeManga.Domain/DTO/GenericQueueDTO.cs @@ -5,6 +5,7 @@ namespace Cesxhin.AnimeManga.Domain.DTO { public class GenericQueueDTO { + public string Name { get; set; } public string Url { get; set; } public string NameCfg { get; set; } public long TimeRequest { get; set; } = ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeMilliseconds(); @@ -14,6 +15,7 @@ public static GenericQueueDTO ChapterQueueToGenericQueueDTO(ChapterQueue queue) { return new GenericQueueDTO { + Name = queue.Name, Url = queue.Url, NameCfg = queue.NameCfg, TimeRequest = queue.TimeRequest @@ -25,6 +27,7 @@ public static GenericQueueDTO EpisodeQueueToGenericQueueDTO(EpisodeQueue queue) { return new GenericQueueDTO { + Name = queue.Name, Url = queue.Url, NameCfg = queue.NameCfg, TimeRequest = queue.TimeRequest diff --git a/src/references/Cesxhin.AnimeManga.Domain/Models/ChapterBlacklist.cs b/src/references/Cesxhin.AnimeManga.Domain/Models/ChapterBlacklist.cs new file mode 100644 index 0000000..7fc4f8b --- /dev/null +++ b/src/references/Cesxhin.AnimeManga.Domain/Models/ChapterBlacklist.cs @@ -0,0 +1,31 @@ +using Cesxhin.AnimeManga.Domain.DTO; +using RepoDb.Attributes; + +namespace Cesxhin.AnimeManga.Domain.Models +{ + [Map("chapterblacklist")] + public class ChapterBlacklist + { + [Primary] + [Map("namemanga")] + public string Name { get; set; } + + [Map("url")] + public string Url { get; set; } + + [Primary] + [Map("namecfg")] + public string NameCfg { get; set; } + + //convert GenericBlackListDTO to ChapterBlacklist + public static ChapterBlacklist GenericQueueDTOToChapterBlacklist(GenericBlackListDTO blackList) + { + return new ChapterBlacklist + { + Url = blackList.Url, + NameCfg = blackList.NameCfg, + Name = blackList.Name + }; + } + } +} diff --git a/src/references/Cesxhin.AnimeManga.Domain/Models/ChapterQueue.cs b/src/references/Cesxhin.AnimeManga.Domain/Models/ChapterQueue.cs index 10d58c7..031a34b 100644 --- a/src/references/Cesxhin.AnimeManga.Domain/Models/ChapterQueue.cs +++ b/src/references/Cesxhin.AnimeManga.Domain/Models/ChapterQueue.cs @@ -11,6 +11,10 @@ namespace Cesxhin.AnimeManga.Domain.Models [Map("chapterqueue")] public class ChapterQueue { + [Primary] + [Map("namemanga")] + public string Name { get; set; } + [Primary] [Map("url")] public string Url { get; set; } @@ -28,6 +32,7 @@ public static ChapterQueue GenericQueueDTOToChapterQueue(GenericQueueDTO queue) { return new ChapterQueue { + Name = queue.Name, Url = queue.Url, NameCfg = queue.NameCfg, TimeRequest = queue.TimeRequest diff --git a/src/references/Cesxhin.AnimeManga.Domain/Models/EpisodeBlacklist.cs b/src/references/Cesxhin.AnimeManga.Domain/Models/EpisodeBlacklist.cs new file mode 100644 index 0000000..2ac5c25 --- /dev/null +++ b/src/references/Cesxhin.AnimeManga.Domain/Models/EpisodeBlacklist.cs @@ -0,0 +1,31 @@ +using Cesxhin.AnimeManga.Domain.DTO; +using RepoDb.Attributes; + +namespace Cesxhin.AnimeManga.Domain.Models +{ + [Map("episodeblacklist")] + public class EpisodeBlacklist + { + [Primary] + [Map("videoid")] + public string Name { get; set; } + + [Map("url")] + public string Url { get; set; } + + [Primary] + [Map("namecfg")] + public string NameCfg { get; set; } + + //convert GenericBlackListDTO to EpisodeBlacklist + public static EpisodeBlacklist GenericQueueDTOToEpisodeBlacklist(GenericBlackListDTO blackList) + { + return new EpisodeBlacklist + { + Url = blackList.Url, + NameCfg = blackList.NameCfg, + Name = blackList.Name + }; + } + } +} diff --git a/src/references/Cesxhin.AnimeManga.Domain/Models/EpisodeQueue.cs b/src/references/Cesxhin.AnimeManga.Domain/Models/EpisodeQueue.cs index 7538657..9a25425 100644 --- a/src/references/Cesxhin.AnimeManga.Domain/Models/EpisodeQueue.cs +++ b/src/references/Cesxhin.AnimeManga.Domain/Models/EpisodeQueue.cs @@ -11,6 +11,10 @@ namespace Cesxhin.AnimeManga.Domain.Models [Map("episodequeue")] public class EpisodeQueue { + [Primary] + [Map("videoid")] + public string Name { get; set; } + [Primary] [Map("url")] public string Url { get; set; } @@ -27,6 +31,7 @@ public static EpisodeQueue GenericQueueDTOToEpisodeQueue(GenericQueueDTO queue) { return new EpisodeQueue { + Name = queue.Name, Url = queue.Url, NameCfg = queue.NameCfg, TimeRequest = queue.TimeRequest From 0d6ab0e2275acfe14008773598c0558596d81a27 Mon Sep 17 00:00:00 2001 From: Cesxhin Date: Sun, 15 Oct 2023 21:04:15 +0200 Subject: [PATCH 09/15] Support with Telegram and improve queue for discord and removed service check health --- .github/workflows/docker-image.yml | 4 +- README.md | 22 ++++-- changelog | 4 + .../Cesxhin.AnimeManga.Application.csproj | 1 + .../Consumers/NotifyBookConsumer.cs | 33 ++++++++ .../Consumers/NotifyConsumer.cs | 54 ------------- .../Consumers/NotifyRequestBookConsumer.cs | 33 ++++++++ .../NotifyRequestTelegramConsumer.cs | 34 ++++++++ .../Consumers/NotifyRequestVideoConsumer.cs | 33 ++++++++ .../Consumers/NotifyTelegramConsumer.cs | 34 ++++++++ .../Consumers/NotifyVideoConsumer.cs | 33 ++++++++ .../Notify/Notify.cs | 9 +++ .../Notify/NotifyDiscord.cs | 50 ++++++++++++ .../Notify/NotifyTelegramChannel.cs | 44 +++++++++++ .../Cesxhin.AnimeManga.NotifyService.csproj | 2 - .../Program.cs | 79 +++++++++++++++---- 16 files changed, 387 insertions(+), 82 deletions(-) create mode 100644 src/Cesxhin.AnimeManga.Application/Consumers/NotifyBookConsumer.cs delete mode 100644 src/Cesxhin.AnimeManga.Application/Consumers/NotifyConsumer.cs create mode 100644 src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestBookConsumer.cs create mode 100644 src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestTelegramConsumer.cs create mode 100644 src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestVideoConsumer.cs create mode 100644 src/Cesxhin.AnimeManga.Application/Consumers/NotifyTelegramConsumer.cs create mode 100644 src/Cesxhin.AnimeManga.Application/Consumers/NotifyVideoConsumer.cs create mode 100644 src/Cesxhin.AnimeManga.Application/Notify/Notify.cs create mode 100644 src/Cesxhin.AnimeManga.Application/Notify/NotifyDiscord.cs create mode 100644 src/Cesxhin.AnimeManga.Application/Notify/NotifyTelegramChannel.cs diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 5a3a431..8a88be4 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -19,7 +19,7 @@ jobs: id: meta uses: docker/metadata-action@v4.1.1 with: - images: ${{ secrets.DOCKER_USER }}/animemanga-notifyservice:1.1.0 + images: ${{ secrets.DOCKER_USER }}/animemanga-notifyservice:2.0.0 - name: Build the Docker image Notify Service uses: docker/build-push-action@v3 @@ -27,4 +27,4 @@ jobs: context: . file: Dockerfile push: true - tags: ${{ secrets.DOCKER_USER }}/animemanga-notifyservice:1.1.0, ${{ secrets.DOCKER_USER }}/animemanga-notifyservice:latest \ No newline at end of file + tags: ${{ secrets.DOCKER_USER }}/animemanga-notifyservice:2.0.0, ${{ secrets.DOCKER_USER }}/animemanga-notifyservice:latest \ No newline at end of file diff --git a/README.md b/README.md index 8038199..01cdf9d 100644 --- a/README.md +++ b/README.md @@ -14,16 +14,22 @@ example: USERNAME_RABBIT: "guest" #guest [default] PASSWORD_RABBIT: "guest" #guest [default] ADDRESS_RABBIT: "localhost" #localhost [default] - - #--- API --- - ADDRESS_API: "localhost" #localhost [default] - PORT_API: "33333" #5000 [default] - PROTOCOL_API: "http" or "https" #http [default] - #---Webhook--- - WEBHOOK_DISCORD: "url" [require] + #--- Webhook --- + WEBHOOK_DISCORD_BOOK: "url" [require] + WEBHOOK_DISCORD_BOOK_REQUEST: "url" [require] + WEBHOOK_DISCORD_VIDEO: "url" [require] + WEBHOOK_DISCORD_VIDEO_REQUEST: "url" [require] + + #--- Bot Telegram --- + TOKEN_BOT: "token" [require] + CHAT_ID: "@channelusername" [require] + CHAT_ID_REQUEST: "@channelusername" [require] - #---logger--- + #--- logger --- LOG_LEVEL: "Debug|Info|Error" #Info [default] WEBHOOK_DISCORD_DEBUG: "url" [not require] + + #--- General --- + SELECT_SERVICE: "Discord|Telegram|Any" ``` \ No newline at end of file diff --git a/changelog b/changelog index bbbb456..e51d2d9 100644 --- a/changelog +++ b/changelog @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Released] +## [2.0.0] - 28-05-2023 +### Added +- Support also Telegram + ## [1.1.0] - 28-05-2023 ### Changed - Update lib diff --git a/src/Cesxhin.AnimeManga.Application/Cesxhin.AnimeManga.Application.csproj b/src/Cesxhin.AnimeManga.Application/Cesxhin.AnimeManga.Application.csproj index f57acfd..0a35033 100644 --- a/src/Cesxhin.AnimeManga.Application/Cesxhin.AnimeManga.Application.csproj +++ b/src/Cesxhin.AnimeManga.Application/Cesxhin.AnimeManga.Application.csproj @@ -16,6 +16,7 @@ + diff --git a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyBookConsumer.cs b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyBookConsumer.cs new file mode 100644 index 0000000..e9a4a26 --- /dev/null +++ b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyBookConsumer.cs @@ -0,0 +1,33 @@ +using Cesxhin.AnimeManga.Application.Notify; +using Cesxhin.AnimeManga.Modules.NlogManager; +using Cesxhin.AnimeManga.Domain.DTO; +using Discord.Webhook; +using MassTransit; +using NLog; +using System; +using System.Threading.Tasks; + +namespace Cesxhin.AnimeManga.Application.Consumers +{ + public class NotifyBookConsumer : IConsumer + { + //nlog + private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); + + //webhook discord + private readonly string _webhookDiscord = Environment.GetEnvironmentVariable("WEBHOOK_DISCORD_BOOK"); + + public Task Consume(ConsumeContext context) + { + DiscordWebhookClient discord = new(_webhookDiscord); + var managementNotify = new NotifyDiscord(); + + var notify = context.Message; + _logger.Info($"Recive this message: {notify.Message}"); + + managementNotify.SendNotify(discord, notify, null); + + return Task.CompletedTask; + } + } +} diff --git a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyConsumer.cs b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyConsumer.cs deleted file mode 100644 index cecfad9..0000000 --- a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyConsumer.cs +++ /dev/null @@ -1,54 +0,0 @@ -using Cesxhin.AnimeManga.Modules.Exceptions; -using Cesxhin.AnimeManga.Modules.NlogManager; -using Cesxhin.AnimeManga.Domain.DTO; -using Discord.Webhook; -using MassTransit; -using NLog; -using System; -using System.IO; -using System.Net; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Application.Consumers -{ - public class NotifyConsumer : IConsumer - { - //nlog - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - //webhook discord - private readonly string _webhookDiscord = Environment.GetEnvironmentVariable("WEBHOOK_DISCORD"); - - public Task Consume(ConsumeContext context) - { - DiscordWebhookClient discord = new(_webhookDiscord); - - var notify = context.Message; - _logger.Info($"Recive this message: {notify.Message}"); - - try - { - if (notify.Image != null) - { - byte[] bufferImage; - using (WebClient client = new WebClient()) - { - bufferImage = client.DownloadData(new Uri(notify.Image)); - } - - Stream image = new MemoryStream(bufferImage); - discord.SendFileAsync(image, "Cover.png", notify.Message).GetAwaiter().GetResult(); - } - else - discord.SendMessageAsync(notify.Message).GetAwaiter().GetResult(); - _logger.Info("Ok send done!"); - } - catch (ApiGenericException ex) - { - _logger.Fatal($"error send webhook to discord, details error: {ex.Message}"); - } - - return Task.CompletedTask; - } - } -} diff --git a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestBookConsumer.cs b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestBookConsumer.cs new file mode 100644 index 0000000..5b68b6e --- /dev/null +++ b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestBookConsumer.cs @@ -0,0 +1,33 @@ +using Cesxhin.AnimeManga.Application.Notify; +using Cesxhin.AnimeManga.Modules.NlogManager; +using Cesxhin.AnimeManga.Domain.DTO; +using Discord.Webhook; +using MassTransit; +using NLog; +using System; +using System.Threading.Tasks; + +namespace Cesxhin.AnimeManga.Application.Consumers +{ + public class NotifyRequestBookConsumer : IConsumer + { + //nlog + private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); + + //webhook discord + private readonly string _webhookDiscord = Environment.GetEnvironmentVariable("WEBHOOK_DISCORD_BOOK_REQUEST"); + + public Task Consume(ConsumeContext context) + { + DiscordWebhookClient discord = new(_webhookDiscord); + var managementNotify = new NotifyDiscord(); + + var notify = context.Message; + _logger.Info($"Recive this message: {notify.Message}"); + + managementNotify.SendNotify(discord, notify, null); + + return Task.CompletedTask; + } + } +} diff --git a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestTelegramConsumer.cs b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestTelegramConsumer.cs new file mode 100644 index 0000000..3a0423b --- /dev/null +++ b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestTelegramConsumer.cs @@ -0,0 +1,34 @@ +using Cesxhin.AnimeManga.Application.Notify; +using Cesxhin.AnimeManga.Modules.NlogManager; +using Cesxhin.AnimeManga.Domain.DTO; +using MassTransit; +using NLog; +using System; +using System.Threading.Tasks; +using Telegram.Bot; + +namespace Cesxhin.AnimeManga.Application.Consumers +{ + public class NotifyRequestTelegramConsumer : IConsumer + { + //nlog + private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); + + //settings for bot telegram + private readonly string tokenBot = Environment.GetEnvironmentVariable("TOKEN_BOT"); + private readonly string chat_id = Environment.GetEnvironmentVariable("CHAT_ID_REQUEST"); + + public Task Consume(ConsumeContext context) + { + var botTelegram = new TelegramBotClient(tokenBot); + var managementNotify = new NotifyTelegramChannel(); + + var notify = context.Message; + _logger.Info($"Recive this message: {context.MessageId}"); + + managementNotify.SendNotify(botTelegram, notify, chat_id); + + return Task.CompletedTask; + } + } +} diff --git a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestVideoConsumer.cs b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestVideoConsumer.cs new file mode 100644 index 0000000..54e1592 --- /dev/null +++ b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestVideoConsumer.cs @@ -0,0 +1,33 @@ +using Cesxhin.AnimeManga.Application.Notify; +using Cesxhin.AnimeManga.Modules.NlogManager; +using Cesxhin.AnimeManga.Domain.DTO; +using Discord.Webhook; +using MassTransit; +using NLog; +using System; +using System.Threading.Tasks; + +namespace Cesxhin.AnimeManga.Application.Consumers +{ + public class NotifyRequestVideoConsumer : IConsumer + { + //nlog + private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); + + //webhook discord + private readonly string _webhookDiscord = Environment.GetEnvironmentVariable("WEBHOOK_DISCORD_VIDEO_REQUEST"); + + public Task Consume(ConsumeContext context) + { + DiscordWebhookClient discord = new(_webhookDiscord); + var managementNotify = new NotifyDiscord(); + + var notify = context.Message; + _logger.Info($"Recive this message: {notify.Message}"); + + managementNotify.SendNotify(discord, notify, null); + + return Task.CompletedTask; + } + } +} diff --git a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyTelegramConsumer.cs b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyTelegramConsumer.cs new file mode 100644 index 0000000..c8f2914 --- /dev/null +++ b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyTelegramConsumer.cs @@ -0,0 +1,34 @@ +using Cesxhin.AnimeManga.Application.Notify; +using Cesxhin.AnimeManga.Modules.NlogManager; +using Cesxhin.AnimeManga.Domain.DTO; +using MassTransit; +using NLog; +using System; +using System.Threading.Tasks; +using Telegram.Bot; + +namespace Cesxhin.AnimeManga.Application.Consumers +{ + public class NotifyTelegramConsumer : IConsumer + { + //nlog + private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); + + //settings for bot telegram + private readonly string tokenBot = Environment.GetEnvironmentVariable("TOKEN_BOT"); + private readonly string chat_id = Environment.GetEnvironmentVariable("CHAT_ID"); + + public Task Consume(ConsumeContext context) + { + var botTelegram = new TelegramBotClient(tokenBot); + var managementNotify = new NotifyTelegramChannel(); + + var notify = context.Message; + _logger.Info($"Recive this message: {context.MessageId}"); + + managementNotify.SendNotify(botTelegram, notify, chat_id); + + return Task.CompletedTask; + } + } +} diff --git a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyVideoConsumer.cs b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyVideoConsumer.cs new file mode 100644 index 0000000..e564be2 --- /dev/null +++ b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyVideoConsumer.cs @@ -0,0 +1,33 @@ +using Cesxhin.AnimeManga.Application.Notify; +using Cesxhin.AnimeManga.Modules.NlogManager; +using Cesxhin.AnimeManga.Domain.DTO; +using Discord.Webhook; +using MassTransit; +using NLog; +using System; +using System.Threading.Tasks; + +namespace Cesxhin.AnimeManga.Application.Consumers +{ + public class NotifyVideoConsumer : IConsumer + { + //nlog + private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); + + //webhook discord + private readonly string _webhookDiscord = Environment.GetEnvironmentVariable("WEBHOOK_DISCORD_VIDEO"); + + public Task Consume(ConsumeContext context) + { + DiscordWebhookClient discord = new(_webhookDiscord); + var managementNotify = new NotifyDiscord(); + + var notify = context.Message; + _logger.Info($"Recive this message: {notify.Message}"); + + managementNotify.SendNotify(discord, notify, null); + + return Task.CompletedTask; + } + } +} diff --git a/src/Cesxhin.AnimeManga.Application/Notify/Notify.cs b/src/Cesxhin.AnimeManga.Application/Notify/Notify.cs new file mode 100644 index 0000000..2f7e6c8 --- /dev/null +++ b/src/Cesxhin.AnimeManga.Application/Notify/Notify.cs @@ -0,0 +1,9 @@ +using Discord.Webhook; + +namespace Cesxhin.AnimeManga.Application.Notify +{ + public abstract class Notify + { + public abstract void SendNotify(S whereSend, T notify, string token); + } +} diff --git a/src/Cesxhin.AnimeManga.Application/Notify/NotifyDiscord.cs b/src/Cesxhin.AnimeManga.Application/Notify/NotifyDiscord.cs new file mode 100644 index 0000000..7a5d347 --- /dev/null +++ b/src/Cesxhin.AnimeManga.Application/Notify/NotifyDiscord.cs @@ -0,0 +1,50 @@ +using Cesxhin.AnimeManga.Domain.DTO; +using Cesxhin.AnimeManga.Modules.NlogManager; +using Discord.Webhook; +using NLog; +using System; +using System.IO; +using System.Net; + +namespace Cesxhin.AnimeManga.Application.Notify +{ + public class NotifyDiscord : Notify + { + //nlog + private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); + + public override void SendNotify(DiscordWebhookClient discord, NotifyDTO notify, string token) + { + if (notify.Image != null) + { + byte[] bufferImage; + using (WebClient client = new WebClient()) + { + bufferImage = client.DownloadData(new Uri(notify.Image)); + } + + Stream image = new MemoryStream(bufferImage); + try + { + discord.SendFileAsync(image, "Cover.png", notify.Message).GetAwaiter().GetResult(); + } + catch (Exception err) + { + _logger.Error($"Problem webhook discord cannot send photo and text message, details: {err.Message}"); + } + } + else + { + try + { + discord.SendMessageAsync(notify.Message).GetAwaiter().GetResult(); + } + catch (Exception err) + { + _logger.Error($"Problem webhook discord cannot send text message, details: {err.Message}"); + } + } + _logger.Info("Ok send done!"); + } + } +} diff --git a/src/Cesxhin.AnimeManga.Application/Notify/NotifyTelegramChannel.cs b/src/Cesxhin.AnimeManga.Application/Notify/NotifyTelegramChannel.cs new file mode 100644 index 0000000..a7606d4 --- /dev/null +++ b/src/Cesxhin.AnimeManga.Application/Notify/NotifyTelegramChannel.cs @@ -0,0 +1,44 @@ +using Cesxhin.AnimeManga.Domain.DTO; +using Cesxhin.AnimeManga.Modules.NlogManager; +using NLog; +using System; +using Telegram.Bot; +using Telegram.Bot.Types; + +namespace Cesxhin.AnimeManga.Application.Notify +{ + public class NotifyTelegramChannel : Notify + { + //nlog + private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); + + public override void SendNotify(TelegramBotClient bot, NotifyDTO notify, string chat_id) + { + if (notify.Image != null) + { + Uri urlImage = new(notify.Image); + try + { + bot.SendPhotoAsync(chat_id, InputFile.FromUri(urlImage), null, notify.Message).GetAwaiter(); + } + catch (Exception err) + { + _logger.Error($"Problem bot telegram cannot send photo and text message, details: {err.Message}"); + } + } + else + { + try + { + bot.SendTextMessageAsync(chat_id, notify.Message); + } + catch (Exception err) + { + _logger.Error($"Problem bot telegram cannot send text message, details: {err.Message}"); + } + } + + _logger.Info("Ok send done!"); + } + } +} diff --git a/src/Cesxhin.AnimeManga.NotifyService/Cesxhin.AnimeManga.NotifyService.csproj b/src/Cesxhin.AnimeManga.NotifyService/Cesxhin.AnimeManga.NotifyService.csproj index ab56eaa..2d02472 100644 --- a/src/Cesxhin.AnimeManga.NotifyService/Cesxhin.AnimeManga.NotifyService.csproj +++ b/src/Cesxhin.AnimeManga.NotifyService/Cesxhin.AnimeManga.NotifyService.csproj @@ -9,8 +9,6 @@ - - diff --git a/src/Cesxhin.AnimeManga.NotifyService/Program.cs b/src/Cesxhin.AnimeManga.NotifyService/Program.cs index d55f00a..a55b504 100644 --- a/src/Cesxhin.AnimeManga.NotifyService/Program.cs +++ b/src/Cesxhin.AnimeManga.NotifyService/Program.cs @@ -5,7 +5,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using NLog; -using Quartz; using System; namespace Cesxhin.AnimeManga.NotifyService @@ -21,6 +20,36 @@ public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureServices((hostContext, services) => { + var selectService = (Environment.GetEnvironmentVariable("SELECT_SERVICE") ?? "any").ToLower(); + + //check envs + if (selectService == "discord" || selectService == "any") + { + if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBHOOK_DISCORD_BOOK"))) + throw new Exception("Missing env WEBHOOK_DISCORD_BOOK"); + + if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBHOOK_DISCORD_BOOK_REQUEST"))) + throw new Exception("Missing env WEBHOOK_DISCORD_BOOK_REQUEST"); + + if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBHOOK_DISCORD_VIDEO"))) + throw new Exception("Missing env WEBHOOK_DISCORD_VIDEO"); + + if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBHOOK_DISCORD_VIDEO_REQUEST"))) + throw new Exception("Missing env WEBHOOK_DISCORD_VIDEO_REQUEST"); + } + + if (selectService == "telegram" || selectService == "any") + { + if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TOKEN_BOT"))) + throw new Exception("Missing env TOKEN_BOT"); + + if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CHAT_ID"))) + throw new Exception("Missing env CHAT_ID"); + + if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CHAT_ID_REQUEST"))) + throw new Exception("Missing env CHAT_ID_REQUEST"); + } + //rabbit services.AddMassTransit( x => @@ -35,29 +64,47 @@ public static IHostBuilder CreateHostBuilder(string[] args) => credentials.Username(Environment.GetEnvironmentVariable("USERNAME_RABBIT") ?? "guest"); credentials.Password(Environment.GetEnvironmentVariable("PASSWORD_RABBIT") ?? "guest"); }); - cfg.ReceiveEndpoint("notify-anime", e => { - e.Consumer(); - }); + + if (selectService == "discord" || selectService == "any") + { + cfg.ReceiveEndpoint("notify-video", e => { + e.Consumer(); + }); + cfg.ReceiveEndpoint("notify-book", e => { + e.Consumer(); + }); + cfg.ReceiveEndpoint("notify-request-video", e => { + e.Consumer(); + }); + cfg.ReceiveEndpoint("notify-request-book", e => { + e.Consumer(); + }); + } + + if(selectService == "telegram" || selectService == "any") + { + cfg.ReceiveEndpoint("notify-video", e => { + e.Consumer(); + }); + cfg.ReceiveEndpoint("notify-book", e => { + e.Consumer(); + }); + cfg.ReceiveEndpoint("notify-request-video", e => { + e.Consumer(); + }); + cfg.ReceiveEndpoint("notify-request-book", e => { + e.Consumer(); + }); + } }); }); //setup nlog - var level = Environment.GetEnvironmentVariable("LOG_LEVEL").ToLower() ?? "info"; + var level = (Environment.GetEnvironmentVariable("LOG_LEVEL") ?? "info").ToLower(); LogLevel logLevel = NLogManager.GetLevel(level); NLogManager.Configure(logLevel); - //cronjob for check health - services.AddQuartz(q => - { - q.UseMicrosoftDependencyInjectionJobFactory(); - q.ScheduleJob(trigger => trigger - .StartNow() - .WithDailyTimeIntervalSchedule(x => x.WithIntervalInSeconds(60)), job => job.WithIdentity("notify")); - //q.AddJob(job => job.WithIdentity("update")); - }); - services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true); - services.AddHostedService(); }); } From 229909ded3f5ec41aed64f13379c883d37361de0 Mon Sep 17 00:00:00 2001 From: Cesxhin Date: Sun, 15 Oct 2023 21:29:07 +0200 Subject: [PATCH 10/15] Fix separate models --- .../Consumers/NotifyBookConsumer.cs | 6 ++-- ...sumer.cs => NotifyBookTelegramConsumer.cs} | 6 ++-- .../Consumers/NotifyRequestBookConsumer.cs | 6 ++-- ...s => NotifyRequestBookTelegramConsumer.cs} | 6 ++-- .../Consumers/NotifyRequestVideoConsumer.cs | 6 ++-- .../NotifyRequestVideoTelegramConsumer.cs | 34 +++++++++++++++++++ .../Consumers/NotifyVideoConsumer.cs | 6 ++-- .../Consumers/NotifyVideoTelegramConsumer.cs | 34 +++++++++++++++++++ .../Notify/NotifyDiscord.cs | 4 +-- .../Notify/NotifyTelegramChannel.cs | 4 +-- .../Program.cs | 8 ++--- 11 files changed, 94 insertions(+), 26 deletions(-) rename src/Cesxhin.AnimeManga.Application/Consumers/{NotifyTelegramConsumer.cs => NotifyBookTelegramConsumer.cs} (78%) rename src/Cesxhin.AnimeManga.Application/Consumers/{NotifyRequestTelegramConsumer.cs => NotifyRequestBookTelegramConsumer.cs} (76%) create mode 100644 src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestVideoTelegramConsumer.cs create mode 100644 src/Cesxhin.AnimeManga.Application/Consumers/NotifyVideoTelegramConsumer.cs diff --git a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyBookConsumer.cs b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyBookConsumer.cs index e9a4a26..f5a0ee4 100644 --- a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyBookConsumer.cs +++ b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyBookConsumer.cs @@ -9,7 +9,7 @@ namespace Cesxhin.AnimeManga.Application.Consumers { - public class NotifyBookConsumer : IConsumer + public class NotifyBookConsumer : IConsumer { //nlog private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); @@ -17,7 +17,7 @@ public class NotifyBookConsumer : IConsumer //webhook discord private readonly string _webhookDiscord = Environment.GetEnvironmentVariable("WEBHOOK_DISCORD_BOOK"); - public Task Consume(ConsumeContext context) + public Task Consume(ConsumeContext context) { DiscordWebhookClient discord = new(_webhookDiscord); var managementNotify = new NotifyDiscord(); @@ -25,7 +25,7 @@ public Task Consume(ConsumeContext context) var notify = context.Message; _logger.Info($"Recive this message: {notify.Message}"); - managementNotify.SendNotify(discord, notify, null); + managementNotify.SendNotify(discord, GenericNotify.NotifyMangaDTOToGenericNotify(notify), null); return Task.CompletedTask; } diff --git a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyTelegramConsumer.cs b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyBookTelegramConsumer.cs similarity index 78% rename from src/Cesxhin.AnimeManga.Application/Consumers/NotifyTelegramConsumer.cs rename to src/Cesxhin.AnimeManga.Application/Consumers/NotifyBookTelegramConsumer.cs index c8f2914..69b182e 100644 --- a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyTelegramConsumer.cs +++ b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyBookTelegramConsumer.cs @@ -9,7 +9,7 @@ namespace Cesxhin.AnimeManga.Application.Consumers { - public class NotifyTelegramConsumer : IConsumer + public class NotifyBookTelegramConsumer : IConsumer { //nlog private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); @@ -18,7 +18,7 @@ public class NotifyTelegramConsumer : IConsumer private readonly string tokenBot = Environment.GetEnvironmentVariable("TOKEN_BOT"); private readonly string chat_id = Environment.GetEnvironmentVariable("CHAT_ID"); - public Task Consume(ConsumeContext context) + public Task Consume(ConsumeContext context) { var botTelegram = new TelegramBotClient(tokenBot); var managementNotify = new NotifyTelegramChannel(); @@ -26,7 +26,7 @@ public Task Consume(ConsumeContext context) var notify = context.Message; _logger.Info($"Recive this message: {context.MessageId}"); - managementNotify.SendNotify(botTelegram, notify, chat_id); + managementNotify.SendNotify(botTelegram, GenericNotify.NotifyMangaDTOToGenericNotify(notify), chat_id); return Task.CompletedTask; } diff --git a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestBookConsumer.cs b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestBookConsumer.cs index 5b68b6e..8536de8 100644 --- a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestBookConsumer.cs +++ b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestBookConsumer.cs @@ -9,7 +9,7 @@ namespace Cesxhin.AnimeManga.Application.Consumers { - public class NotifyRequestBookConsumer : IConsumer + public class NotifyRequestBookConsumer : IConsumer { //nlog private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); @@ -17,7 +17,7 @@ public class NotifyRequestBookConsumer : IConsumer //webhook discord private readonly string _webhookDiscord = Environment.GetEnvironmentVariable("WEBHOOK_DISCORD_BOOK_REQUEST"); - public Task Consume(ConsumeContext context) + public Task Consume(ConsumeContext context) { DiscordWebhookClient discord = new(_webhookDiscord); var managementNotify = new NotifyDiscord(); @@ -25,7 +25,7 @@ public Task Consume(ConsumeContext context) var notify = context.Message; _logger.Info($"Recive this message: {notify.Message}"); - managementNotify.SendNotify(discord, notify, null); + managementNotify.SendNotify(discord, GenericNotify.NotifyRequestMangaDTOToGenericNotify(notify), null); return Task.CompletedTask; } diff --git a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestTelegramConsumer.cs b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestBookTelegramConsumer.cs similarity index 76% rename from src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestTelegramConsumer.cs rename to src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestBookTelegramConsumer.cs index 3a0423b..787eef4 100644 --- a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestTelegramConsumer.cs +++ b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestBookTelegramConsumer.cs @@ -9,7 +9,7 @@ namespace Cesxhin.AnimeManga.Application.Consumers { - public class NotifyRequestTelegramConsumer : IConsumer + public class NotifyRequestBookTelegramConsumer : IConsumer { //nlog private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); @@ -18,7 +18,7 @@ public class NotifyRequestTelegramConsumer : IConsumer private readonly string tokenBot = Environment.GetEnvironmentVariable("TOKEN_BOT"); private readonly string chat_id = Environment.GetEnvironmentVariable("CHAT_ID_REQUEST"); - public Task Consume(ConsumeContext context) + public Task Consume(ConsumeContext context) { var botTelegram = new TelegramBotClient(tokenBot); var managementNotify = new NotifyTelegramChannel(); @@ -26,7 +26,7 @@ public Task Consume(ConsumeContext context) var notify = context.Message; _logger.Info($"Recive this message: {context.MessageId}"); - managementNotify.SendNotify(botTelegram, notify, chat_id); + managementNotify.SendNotify(botTelegram, GenericNotify.NotifyRequestMangaDTOToGenericNotify(notify), chat_id); return Task.CompletedTask; } diff --git a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestVideoConsumer.cs b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestVideoConsumer.cs index 54e1592..ddf06a4 100644 --- a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestVideoConsumer.cs +++ b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestVideoConsumer.cs @@ -9,7 +9,7 @@ namespace Cesxhin.AnimeManga.Application.Consumers { - public class NotifyRequestVideoConsumer : IConsumer + public class NotifyRequestVideoConsumer : IConsumer { //nlog private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); @@ -17,7 +17,7 @@ public class NotifyRequestVideoConsumer : IConsumer //webhook discord private readonly string _webhookDiscord = Environment.GetEnvironmentVariable("WEBHOOK_DISCORD_VIDEO_REQUEST"); - public Task Consume(ConsumeContext context) + public Task Consume(ConsumeContext context) { DiscordWebhookClient discord = new(_webhookDiscord); var managementNotify = new NotifyDiscord(); @@ -25,7 +25,7 @@ public Task Consume(ConsumeContext context) var notify = context.Message; _logger.Info($"Recive this message: {notify.Message}"); - managementNotify.SendNotify(discord, notify, null); + managementNotify.SendNotify(discord, GenericNotify.NotifyRequestAnimeDTOToGenericNotify(notify), null); return Task.CompletedTask; } diff --git a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestVideoTelegramConsumer.cs b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestVideoTelegramConsumer.cs new file mode 100644 index 0000000..8973c27 --- /dev/null +++ b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyRequestVideoTelegramConsumer.cs @@ -0,0 +1,34 @@ +using Cesxhin.AnimeManga.Application.Notify; +using Cesxhin.AnimeManga.Modules.NlogManager; +using Cesxhin.AnimeManga.Domain.DTO; +using MassTransit; +using NLog; +using System; +using System.Threading.Tasks; +using Telegram.Bot; + +namespace Cesxhin.AnimeManga.Application.Consumers +{ + public class NotifyRequestVideoTelegramConsumer : IConsumer + { + //nlog + private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); + + //settings for bot telegram + private readonly string tokenBot = Environment.GetEnvironmentVariable("TOKEN_BOT"); + private readonly string chat_id = Environment.GetEnvironmentVariable("CHAT_ID_REQUEST"); + + public Task Consume(ConsumeContext context) + { + var botTelegram = new TelegramBotClient(tokenBot); + var managementNotify = new NotifyTelegramChannel(); + + var notify = context.Message; + _logger.Info($"Recive this message: {context.MessageId}"); + + managementNotify.SendNotify(botTelegram, GenericNotify.NotifyRequestAnimeDTOToGenericNotify(notify), chat_id); + + return Task.CompletedTask; + } + } +} diff --git a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyVideoConsumer.cs b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyVideoConsumer.cs index e564be2..2fde8d4 100644 --- a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyVideoConsumer.cs +++ b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyVideoConsumer.cs @@ -9,7 +9,7 @@ namespace Cesxhin.AnimeManga.Application.Consumers { - public class NotifyVideoConsumer : IConsumer + public class NotifyVideoConsumer : IConsumer { //nlog private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); @@ -17,7 +17,7 @@ public class NotifyVideoConsumer : IConsumer //webhook discord private readonly string _webhookDiscord = Environment.GetEnvironmentVariable("WEBHOOK_DISCORD_VIDEO"); - public Task Consume(ConsumeContext context) + public Task Consume(ConsumeContext context) { DiscordWebhookClient discord = new(_webhookDiscord); var managementNotify = new NotifyDiscord(); @@ -25,7 +25,7 @@ public Task Consume(ConsumeContext context) var notify = context.Message; _logger.Info($"Recive this message: {notify.Message}"); - managementNotify.SendNotify(discord, notify, null); + managementNotify.SendNotify(discord, GenericNotify.NotifyAnimeDTOToGenericNotify(notify), null); return Task.CompletedTask; } diff --git a/src/Cesxhin.AnimeManga.Application/Consumers/NotifyVideoTelegramConsumer.cs b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyVideoTelegramConsumer.cs new file mode 100644 index 0000000..186c974 --- /dev/null +++ b/src/Cesxhin.AnimeManga.Application/Consumers/NotifyVideoTelegramConsumer.cs @@ -0,0 +1,34 @@ +using Cesxhin.AnimeManga.Application.Notify; +using Cesxhin.AnimeManga.Modules.NlogManager; +using Cesxhin.AnimeManga.Domain.DTO; +using MassTransit; +using NLog; +using System; +using System.Threading.Tasks; +using Telegram.Bot; + +namespace Cesxhin.AnimeManga.Application.Consumers +{ + public class NotifyVideoTelegramConsumer : IConsumer + { + //nlog + private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); + + //settings for bot telegram + private readonly string tokenBot = Environment.GetEnvironmentVariable("TOKEN_BOT"); + private readonly string chat_id = Environment.GetEnvironmentVariable("CHAT_ID"); + + public Task Consume(ConsumeContext context) + { + var botTelegram = new TelegramBotClient(tokenBot); + var managementNotify = new NotifyTelegramChannel(); + + var notify = context.Message; + _logger.Info($"Recive this message: {context.MessageId}"); + + managementNotify.SendNotify(botTelegram, GenericNotify.NotifyAnimeDTOToGenericNotify(notify), chat_id); + + return Task.CompletedTask; + } + } +} diff --git a/src/Cesxhin.AnimeManga.Application/Notify/NotifyDiscord.cs b/src/Cesxhin.AnimeManga.Application/Notify/NotifyDiscord.cs index 7a5d347..2d586b4 100644 --- a/src/Cesxhin.AnimeManga.Application/Notify/NotifyDiscord.cs +++ b/src/Cesxhin.AnimeManga.Application/Notify/NotifyDiscord.cs @@ -8,12 +8,12 @@ namespace Cesxhin.AnimeManga.Application.Notify { - public class NotifyDiscord : Notify + public class NotifyDiscord : Notify { //nlog private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - public override void SendNotify(DiscordWebhookClient discord, NotifyDTO notify, string token) + public override void SendNotify(DiscordWebhookClient discord, GenericNotify notify, string token) { if (notify.Image != null) { diff --git a/src/Cesxhin.AnimeManga.Application/Notify/NotifyTelegramChannel.cs b/src/Cesxhin.AnimeManga.Application/Notify/NotifyTelegramChannel.cs index a7606d4..2600702 100644 --- a/src/Cesxhin.AnimeManga.Application/Notify/NotifyTelegramChannel.cs +++ b/src/Cesxhin.AnimeManga.Application/Notify/NotifyTelegramChannel.cs @@ -7,12 +7,12 @@ namespace Cesxhin.AnimeManga.Application.Notify { - public class NotifyTelegramChannel : Notify + public class NotifyTelegramChannel : Notify { //nlog private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - public override void SendNotify(TelegramBotClient bot, NotifyDTO notify, string chat_id) + public override void SendNotify(TelegramBotClient bot, GenericNotify notify, string chat_id) { if (notify.Image != null) { diff --git a/src/Cesxhin.AnimeManga.NotifyService/Program.cs b/src/Cesxhin.AnimeManga.NotifyService/Program.cs index a55b504..e364c05 100644 --- a/src/Cesxhin.AnimeManga.NotifyService/Program.cs +++ b/src/Cesxhin.AnimeManga.NotifyService/Program.cs @@ -84,16 +84,16 @@ public static IHostBuilder CreateHostBuilder(string[] args) => if(selectService == "telegram" || selectService == "any") { cfg.ReceiveEndpoint("notify-video", e => { - e.Consumer(); + e.Consumer(); }); cfg.ReceiveEndpoint("notify-book", e => { - e.Consumer(); + e.Consumer(); }); cfg.ReceiveEndpoint("notify-request-video", e => { - e.Consumer(); + e.Consumer(); }); cfg.ReceiveEndpoint("notify-request-book", e => { - e.Consumer(); + e.Consumer(); }); } From 9ab4abb494688378b974e8a4190cb704afa1227f Mon Sep 17 00:00:00 2001 From: Anime-Manga <> Date: Sun, 15 Oct 2023 19:29:34 +0000 Subject: [PATCH 11/15] Update from https://github.com/Anime-Manga/references/commit/05d7755c047a3fa9ae300264570ffe9b3faf77bf --- .../DTO/{NotifyDTO.cs => NotifyAnimeDTO.cs} | 2 +- .../DTO/NotifyMangaDTO.cs | 8 ++++ .../DTO/NotifyRequestAnimeDTO.cs | 8 ++++ .../DTO/NotifyRequestMangaDTO.cs | 8 ++++ .../Models/GenericNotify.cs | 48 +++++++++++++++++++ 5 files changed, 73 insertions(+), 1 deletion(-) rename src/references/Cesxhin.AnimeManga.Domain/DTO/{NotifyDTO.cs => NotifyAnimeDTO.cs} (81%) create mode 100644 src/references/Cesxhin.AnimeManga.Domain/DTO/NotifyMangaDTO.cs create mode 100644 src/references/Cesxhin.AnimeManga.Domain/DTO/NotifyRequestAnimeDTO.cs create mode 100644 src/references/Cesxhin.AnimeManga.Domain/DTO/NotifyRequestMangaDTO.cs create mode 100644 src/references/Cesxhin.AnimeManga.Domain/Models/GenericNotify.cs diff --git a/src/references/Cesxhin.AnimeManga.Domain/DTO/NotifyDTO.cs b/src/references/Cesxhin.AnimeManga.Domain/DTO/NotifyAnimeDTO.cs similarity index 81% rename from src/references/Cesxhin.AnimeManga.Domain/DTO/NotifyDTO.cs rename to src/references/Cesxhin.AnimeManga.Domain/DTO/NotifyAnimeDTO.cs index 3b5bed1..00a4e49 100644 --- a/src/references/Cesxhin.AnimeManga.Domain/DTO/NotifyDTO.cs +++ b/src/references/Cesxhin.AnimeManga.Domain/DTO/NotifyAnimeDTO.cs @@ -1,6 +1,6 @@ namespace Cesxhin.AnimeManga.Domain.DTO { - public class NotifyDTO + public class NotifyAnimeDTO { public string Message { get; set; } public string Image { get; set; } diff --git a/src/references/Cesxhin.AnimeManga.Domain/DTO/NotifyMangaDTO.cs b/src/references/Cesxhin.AnimeManga.Domain/DTO/NotifyMangaDTO.cs new file mode 100644 index 0000000..d874b40 --- /dev/null +++ b/src/references/Cesxhin.AnimeManga.Domain/DTO/NotifyMangaDTO.cs @@ -0,0 +1,8 @@ +namespace Cesxhin.AnimeManga.Domain.DTO +{ + public class NotifyMangaDTO + { + public string Message { get; set; } + public string Image { get; set; } + } +} diff --git a/src/references/Cesxhin.AnimeManga.Domain/DTO/NotifyRequestAnimeDTO.cs b/src/references/Cesxhin.AnimeManga.Domain/DTO/NotifyRequestAnimeDTO.cs new file mode 100644 index 0000000..79129df --- /dev/null +++ b/src/references/Cesxhin.AnimeManga.Domain/DTO/NotifyRequestAnimeDTO.cs @@ -0,0 +1,8 @@ +namespace Cesxhin.AnimeManga.Domain.DTO +{ + public class NotifyRequestAnimeDTO + { + public string Message { get; set; } + public string Image { get; set; } + } +} diff --git a/src/references/Cesxhin.AnimeManga.Domain/DTO/NotifyRequestMangaDTO.cs b/src/references/Cesxhin.AnimeManga.Domain/DTO/NotifyRequestMangaDTO.cs new file mode 100644 index 0000000..5645da1 --- /dev/null +++ b/src/references/Cesxhin.AnimeManga.Domain/DTO/NotifyRequestMangaDTO.cs @@ -0,0 +1,8 @@ +namespace Cesxhin.AnimeManga.Domain.DTO +{ + public class NotifyRequestMangaDTO + { + public string Message { get; set; } + public string Image { get; set; } + } +} diff --git a/src/references/Cesxhin.AnimeManga.Domain/Models/GenericNotify.cs b/src/references/Cesxhin.AnimeManga.Domain/Models/GenericNotify.cs new file mode 100644 index 0000000..db90fb7 --- /dev/null +++ b/src/references/Cesxhin.AnimeManga.Domain/Models/GenericNotify.cs @@ -0,0 +1,48 @@ +namespace Cesxhin.AnimeManga.Domain.DTO +{ + public class GenericNotify + { + public string Message { get; set; } + public string Image { get; set; } + + //convert NotifyAnimeDTO to GenericNotify + public static GenericNotify NotifyAnimeDTOToGenericNotify(NotifyAnimeDTO notify) + { + return new GenericNotify + { + Message = notify.Message, + Image = notify.Image + }; + } + + //convert NotifyMangaDTO to GenericNotify + public static GenericNotify NotifyMangaDTOToGenericNotify(NotifyMangaDTO notify) + { + return new GenericNotify + { + Message = notify.Message, + Image = notify.Image + }; + } + + //convert NotifyRequestAnimeDTO to GenericNotify + public static GenericNotify NotifyRequestAnimeDTOToGenericNotify(NotifyRequestAnimeDTO notify) + { + return new GenericNotify + { + Message = notify.Message, + Image = notify.Image + }; + } + + //convert NotifyRequestMangaDTO to GenericNotify + public static GenericNotify NotifyRequestMangaDTOToGenericNotify(NotifyRequestMangaDTO notify) + { + return new GenericNotify + { + Message = notify.Message, + Image = notify.Image + }; + } + } +} From a2d392246a999227860c569f748c0ead21685e63 Mon Sep 17 00:00:00 2001 From: Cesxhin Date: Sun, 15 Oct 2023 22:07:56 +0200 Subject: [PATCH 12/15] Problem same name of queue --- src/Cesxhin.AnimeManga.NotifyService/Program.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Cesxhin.AnimeManga.NotifyService/Program.cs b/src/Cesxhin.AnimeManga.NotifyService/Program.cs index e364c05..b5470d9 100644 --- a/src/Cesxhin.AnimeManga.NotifyService/Program.cs +++ b/src/Cesxhin.AnimeManga.NotifyService/Program.cs @@ -67,32 +67,32 @@ public static IHostBuilder CreateHostBuilder(string[] args) => if (selectService == "discord" || selectService == "any") { - cfg.ReceiveEndpoint("notify-video", e => { + cfg.ReceiveEndpoint("notify-video-discord", e => { e.Consumer(); }); - cfg.ReceiveEndpoint("notify-book", e => { + cfg.ReceiveEndpoint("notify-book-discord", e => { e.Consumer(); }); - cfg.ReceiveEndpoint("notify-request-video", e => { + cfg.ReceiveEndpoint("notify-request-video-discord", e => { e.Consumer(); }); - cfg.ReceiveEndpoint("notify-request-book", e => { + cfg.ReceiveEndpoint("notify-request-book-discord", e => { e.Consumer(); }); } if(selectService == "telegram" || selectService == "any") { - cfg.ReceiveEndpoint("notify-video", e => { + cfg.ReceiveEndpoint("notify-video-telegram", e => { e.Consumer(); }); - cfg.ReceiveEndpoint("notify-book", e => { + cfg.ReceiveEndpoint("notify-book-telegram", e => { e.Consumer(); }); - cfg.ReceiveEndpoint("notify-request-video", e => { + cfg.ReceiveEndpoint("notify-request-video-telegram", e => { e.Consumer(); }); - cfg.ReceiveEndpoint("notify-request-book", e => { + cfg.ReceiveEndpoint("notify-request-book-telegram", e => { e.Consumer(); }); } From 33aebcbd4f2fe71a48df891bed6a3058eb18f654 Mon Sep 17 00:00:00 2001 From: Anime-Manga <> Date: Mon, 16 Oct 2023 18:34:33 +0000 Subject: [PATCH 13/15] Update from https://github.com/Anime-Manga/references/commit/b513571acdaf72fde14590b7a74639f3519a65ac --- .../DTO/DiskSpaceDTO.cs | 10 ---- .../DTO/HealthDTO.cs | 9 ---- .../CronJob/HealthJob.cs | 39 --------------- .../CronJob/SpaceDiskJob.cs | 48 ------------------- 4 files changed, 106 deletions(-) delete mode 100644 src/references/Cesxhin.AnimeManga.Domain/DTO/DiskSpaceDTO.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Domain/DTO/HealthDTO.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Modules/CronJob/HealthJob.cs delete mode 100644 src/references/Cesxhin.AnimeManga.Modules/CronJob/SpaceDiskJob.cs diff --git a/src/references/Cesxhin.AnimeManga.Domain/DTO/DiskSpaceDTO.cs b/src/references/Cesxhin.AnimeManga.Domain/DTO/DiskSpaceDTO.cs deleted file mode 100644 index a5753a4..0000000 --- a/src/references/Cesxhin.AnimeManga.Domain/DTO/DiskSpaceDTO.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Cesxhin.AnimeManga.Domain.DTO -{ - public class DiskSpaceDTO - { - public long DiskSizeTotal { get; set; } - public long DiskSizeFree { get; set; } - public int Interval { get; set; } - public long LastCheck { get; set; } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Domain/DTO/HealthDTO.cs b/src/references/Cesxhin.AnimeManga.Domain/DTO/HealthDTO.cs deleted file mode 100644 index 4b82932..0000000 --- a/src/references/Cesxhin.AnimeManga.Domain/DTO/HealthDTO.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cesxhin.AnimeManga.Domain.DTO -{ - public class HealthDTO - { - public string NameService { get; set; } - public long LastCheck { get; set; } - public int Interval { get; set; } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Modules/CronJob/HealthJob.cs b/src/references/Cesxhin.AnimeManga.Modules/CronJob/HealthJob.cs deleted file mode 100644 index 6c9944b..0000000 --- a/src/references/Cesxhin.AnimeManga.Modules/CronJob/HealthJob.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Cesxhin.AnimeManga.Modules.Exceptions; -using Cesxhin.AnimeManga.Modules.Generic; -using Cesxhin.AnimeManga.Modules.NlogManager; -using Cesxhin.AnimeManga.Domain.DTO; -using NLog; -using Quartz; -using System; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Modules.CronJob -{ - public class HealthJob : IJob - { - //log - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - public Task Execute(IJobExecutionContext context) - { - Api api = new(); - - try - { - api.PutOne("/health", new HealthDTO - { - NameService = context.JobDetail.Key.Name.ToLower(), - LastCheck = new DateTimeOffset(DateTime.Now).ToUnixTimeMilliseconds(), - Interval = 60000 - }).GetAwaiter().GetResult(); - - } - catch (ApiGenericException ex) - { - _logger.Fatal($"Error api, error details: {ex.Message}"); - } - - return Task.CompletedTask; - } - } -} diff --git a/src/references/Cesxhin.AnimeManga.Modules/CronJob/SpaceDiskJob.cs b/src/references/Cesxhin.AnimeManga.Modules/CronJob/SpaceDiskJob.cs deleted file mode 100644 index b14fe8a..0000000 --- a/src/references/Cesxhin.AnimeManga.Modules/CronJob/SpaceDiskJob.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Cesxhin.AnimeManga.Modules.Exceptions; -using Cesxhin.AnimeManga.Modules.Generic; -using Cesxhin.AnimeManga.Modules.NlogManager; -using Cesxhin.AnimeManga.Domain.DTO; -using NLog; -using Quartz; -using System; -using System.IO; -using System.Threading.Tasks; - -namespace Cesxhin.AnimeManga.Modules.CronJob -{ - public class SpaceDiskJob : IJob - { - private readonly string _folder = Environment.GetEnvironmentVariable("BASE_PATH") ?? "/"; - - //log - private readonly NLogConsole _logger = new(LogManager.GetCurrentClassLogger()); - - - public Task Execute(IJobExecutionContext context) - { - Api checkDiskFreeSpaceApi = new(); - - //check disk space free (byte to gigabyte) - var freeGigabytes = new DriveInfo(_folder).AvailableFreeSpace / 1000000000; - var totalGigabytes = new DriveInfo(_folder).TotalSize / 1000000000; - - try - { - checkDiskFreeSpaceApi.PutOne("/disk", new DiskSpaceDTO - { - DiskSizeFree = freeGigabytes, - DiskSizeTotal = totalGigabytes, - Interval = 60000 - }).GetAwaiter().GetResult(); - - _logger.Info("Ok send done status space disk"); - } - catch (ApiGenericException ex) - { - _logger.Fatal($"Error send api DiskSpace, details error: {ex.Message}"); - } - - return Task.CompletedTask; - } - } -} From efb1ef30dfb8c06269be1bd3082ff4ac037e6ff9 Mon Sep 17 00:00:00 2001 From: Cesxhin Date: Mon, 16 Oct 2023 20:38:37 +0200 Subject: [PATCH 14/15] Fix --- src/Cesxhin.AnimeManga.NotifyService/Program.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Cesxhin.AnimeManga.NotifyService/Program.cs b/src/Cesxhin.AnimeManga.NotifyService/Program.cs index b5470d9..191235e 100644 --- a/src/Cesxhin.AnimeManga.NotifyService/Program.cs +++ b/src/Cesxhin.AnimeManga.NotifyService/Program.cs @@ -1,5 +1,4 @@ using Cesxhin.AnimeManga.Application.Consumers; -using Cesxhin.AnimeManga.Modules.CronJob; using Cesxhin.AnimeManga.Modules.Generic; using MassTransit; using Microsoft.Extensions.DependencyInjection; From 4e18802fe56d398628ea3242c01b787578ef878a Mon Sep 17 00:00:00 2001 From: Cesxhin Date: Mon, 16 Oct 2023 20:54:54 +0200 Subject: [PATCH 15/15] Update for release --- changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog b/changelog index e51d2d9..36a7b6c 100644 --- a/changelog +++ b/changelog @@ -5,7 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Released] -## [2.0.0] - 28-05-2023 +## [2.0.0] - 16-10-2023 ### Added - Support also Telegram