From 86d785522a26264f02f39c3e45caa97bd0013473 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Tue, 5 Jun 2018 19:44:05 -0500 Subject: [PATCH] tidying up some syntax --- .../V1/Controllers/BaseController.cs | 8 ++- .../V1/Controllers/ForksController.cs | 13 ++--- .../V1/Controllers/LanguagesController.cs | 10 +--- .../V1/Controllers/LicensesController.cs | 10 +--- .../V1/Controllers/ListsController.cs | 23 +++------ .../Controllers/ListsLanguagesController.cs | 11 ++-- .../Controllers/ListsMaintainersController.cs | 11 ++-- .../V1/Controllers/MaintainersController.cs | 10 +--- .../V1/Controllers/MergesController.cs | 13 ++--- .../V1/Controllers/SoftwareController.cs | 10 +--- .../Controllers/SoftwareSyntaxesController.cs | 14 ++--- .../V1/Controllers/SyntaxesController.cs | 10 +--- src/FilterLists.Data/Entities/FilterList.cs | 2 + src/FilterLists.Data/Entities/Language.cs | 2 + src/FilterLists.Data/Entities/License.cs | 2 + src/FilterLists.Data/Entities/Maintainer.cs | 2 + src/FilterLists.Data/Entities/Software.cs | 2 + src/FilterLists.Data/Entities/Syntax.cs | 2 + src/FilterLists.Data/FilterLists.Data.csproj | 1 + .../Extensions/SeedFilterListsDbContext.cs | 15 ++---- .../Extensions/ConfigureServicesCollection.cs | 9 ++-- .../FilterList/FilterListService.cs | 24 ++++----- .../FilterList/FilterListServiceExtensions.cs | 8 +-- .../FilterList/ListDetailsDto.cs | 37 +------------- .../FilterList/ListLanguagesDto.cs | 11 ++++ .../FilterList/ListLicenseDto.cs | 11 ++++ .../FilterList/ListMaintainerDto.cs | 16 ++++++ .../FilterList/ListSummaryDto.cs | 8 +-- .../FilterList/ListSyntaxDto.cs | 13 +++++ .../MaintainerAdditionalListsDto.cs | 11 ++++ .../FilterList/MappingProfiles.cs | 12 ++--- .../FilterList/SyntaxSupportedSoftwareDto.cs | 11 ++++ .../FilterLists.Services.csproj | 1 + .../Seed/Models/FilterListSeedDto.cs | 2 + .../Junctions/FilterListLanguageSeedDto.cs | 5 +- .../Junctions/FilterListMaintainerSeedDto.cs | 5 +- .../Seed/Models/Junctions/ForkSeedDto.cs | 5 +- .../Seed/Models/Junctions/MergeSeedDto.cs | 5 +- .../Models/Junctions/SoftwareSyntaxSeedDto.cs | 5 +- .../Seed/Models/LanguageSeedDto.cs | 5 +- .../Seed/Models/LicenseSeedDto.cs | 5 +- .../Seed/Models/MaintainerSeedDto.cs | 5 +- .../Seed/Models/SoftwareSeedDto.cs | 5 +- .../Seed/Models/SyntaxSeedDto.cs | 5 +- src/FilterLists.Services/Seed/SeedService.cs | 37 +++++++------- .../Snapshot/FilterListViewUrlDto.cs | 5 +- .../Snapshot/RawRuleLinterExtensions.cs | 28 +++------- .../Snapshot/SnapshotBatchDe.cs | 35 ++++++------- .../Snapshot/SnapshotDe.cs | 51 +++++++++---------- .../Snapshot/SnapshotService.cs | 16 +++--- 50 files changed, 278 insertions(+), 289 deletions(-) create mode 100644 src/FilterLists.Services/FilterList/ListLanguagesDto.cs create mode 100644 src/FilterLists.Services/FilterList/ListLicenseDto.cs create mode 100644 src/FilterLists.Services/FilterList/ListMaintainerDto.cs create mode 100644 src/FilterLists.Services/FilterList/ListSyntaxDto.cs create mode 100644 src/FilterLists.Services/FilterList/MaintainerAdditionalListsDto.cs create mode 100644 src/FilterLists.Services/FilterList/SyntaxSupportedSoftwareDto.cs diff --git a/src/FilterLists.Api/V1/Controllers/BaseController.cs b/src/FilterLists.Api/V1/Controllers/BaseController.cs index f46f0e31d..9c65281d5 100644 --- a/src/FilterLists.Api/V1/Controllers/BaseController.cs +++ b/src/FilterLists.Api/V1/Controllers/BaseController.cs @@ -1,12 +1,16 @@ -using Microsoft.AspNetCore.Mvc; +using FilterLists.Services.Seed; +using Microsoft.AspNetCore.Mvc; namespace FilterLists.Api.V1.Controllers { [ApiVersion("1.0")] public class BaseController : Controller { - protected BaseController() + protected readonly SeedService SeedService; + + protected BaseController(SeedService seedService) { + SeedService = seedService; } } } \ No newline at end of file diff --git a/src/FilterLists.Api/V1/Controllers/ForksController.cs b/src/FilterLists.Api/V1/Controllers/ForksController.cs index 72e2f838a..edd908156 100644 --- a/src/FilterLists.Api/V1/Controllers/ForksController.cs +++ b/src/FilterLists.Api/V1/Controllers/ForksController.cs @@ -8,19 +8,12 @@ namespace FilterLists.Api.V1.Controllers { public class ForksController : BaseController { - private readonly SeedService seedService; - - public ForksController(SeedService seedService) + public ForksController(SeedService seedService) : base(seedService) { - this.seedService = seedService; } [HttpGet] - public async Task Seed() - { - return Json(await seedService.GetAllAsync( - typeof(Fork).GetProperty("UpstreamFilterListId"), - typeof(Fork).GetProperty("ForkFilterListId"))); - } + public async Task Seed() => Json(await SeedService.GetAllAsync( + typeof(Fork).GetProperty("UpstreamFilterListId"), typeof(Fork).GetProperty("ForkFilterListId"))); } } \ No newline at end of file diff --git a/src/FilterLists.Api/V1/Controllers/LanguagesController.cs b/src/FilterLists.Api/V1/Controllers/LanguagesController.cs index 0dae5aa5b..5ea6cf163 100644 --- a/src/FilterLists.Api/V1/Controllers/LanguagesController.cs +++ b/src/FilterLists.Api/V1/Controllers/LanguagesController.cs @@ -8,17 +8,11 @@ namespace FilterLists.Api.V1.Controllers { public class LanguagesController : BaseController { - private readonly SeedService seedService; - - public LanguagesController(SeedService seedService) + public LanguagesController(SeedService seedService) : base(seedService) { - this.seedService = seedService; } [HttpGet] - public async Task Seed() - { - return Json(await seedService.GetAllAsync()); - } + public async Task Seed() => Json(await SeedService.GetAllAsync()); } } \ No newline at end of file diff --git a/src/FilterLists.Api/V1/Controllers/LicensesController.cs b/src/FilterLists.Api/V1/Controllers/LicensesController.cs index 32fb3a6fd..743466ba2 100644 --- a/src/FilterLists.Api/V1/Controllers/LicensesController.cs +++ b/src/FilterLists.Api/V1/Controllers/LicensesController.cs @@ -8,17 +8,11 @@ namespace FilterLists.Api.V1.Controllers { public class LicensesController : BaseController { - private readonly SeedService seedService; - - public LicensesController(SeedService seedService) + public LicensesController(SeedService seedService) : base(seedService) { - this.seedService = seedService; } [HttpGet] - public async Task Seed() - { - return Json(await seedService.GetAllAsync()); - } + public async Task Seed() => Json(await SeedService.GetAllAsync()); } } \ No newline at end of file diff --git a/src/FilterLists.Api/V1/Controllers/ListsController.cs b/src/FilterLists.Api/V1/Controllers/ListsController.cs index d835e70a4..f9477e0ae 100644 --- a/src/FilterLists.Api/V1/Controllers/ListsController.cs +++ b/src/FilterLists.Api/V1/Controllers/ListsController.cs @@ -9,31 +9,20 @@ namespace FilterLists.Api.V1.Controllers { public class ListsController : BaseController { - private readonly FilterListService filterListService; - private readonly SeedService seedService; + private readonly FilterListService _filterListService; - public ListsController(SeedService seedService, FilterListService filterListService) + public ListsController(SeedService seedService, FilterListService filterListService) : base(seedService) { - this.seedService = seedService; - this.filterListService = filterListService; + _filterListService = filterListService; } [HttpGet] - public async Task Index() - { - return Json(await filterListService.GetAllSummariesAsync()); - } + public async Task Index() => Json(await _filterListService.GetAllSummariesAsync()); [HttpGet] - public async Task GetById(int id) - { - return Json(await filterListService.GetDetailsAsync(id)); - } + public async Task GetById(int id) => Json(await _filterListService.GetDetailsAsync(id)); [HttpGet] - public async Task Seed() - { - return Json(await seedService.GetAllAsync()); - } + public async Task Seed() => Json(await SeedService.GetAllAsync()); } } \ No newline at end of file diff --git a/src/FilterLists.Api/V1/Controllers/ListsLanguagesController.cs b/src/FilterLists.Api/V1/Controllers/ListsLanguagesController.cs index f0e231747..79c7bdb61 100644 --- a/src/FilterLists.Api/V1/Controllers/ListsLanguagesController.cs +++ b/src/FilterLists.Api/V1/Controllers/ListsLanguagesController.cs @@ -8,19 +8,14 @@ namespace FilterLists.Api.V1.Controllers { public class ListsLanguagesController : BaseController { - private readonly SeedService seedService; - - public ListsLanguagesController(SeedService seedService) + public ListsLanguagesController(SeedService seedService) : base(seedService) { - this.seedService = seedService; } [HttpGet] - public async Task Seed() - { - return Json(await seedService.GetAllAsync( + public async Task Seed() => + Json(await SeedService.GetAllAsync( typeof(FilterListLanguage).GetProperty("FilterListId"), typeof(FilterListLanguage).GetProperty("LanguageId"))); - } } } \ No newline at end of file diff --git a/src/FilterLists.Api/V1/Controllers/ListsMaintainersController.cs b/src/FilterLists.Api/V1/Controllers/ListsMaintainersController.cs index 26c7d3224..3e9e168da 100644 --- a/src/FilterLists.Api/V1/Controllers/ListsMaintainersController.cs +++ b/src/FilterLists.Api/V1/Controllers/ListsMaintainersController.cs @@ -8,19 +8,14 @@ namespace FilterLists.Api.V1.Controllers { public class ListsMaintainersController : BaseController { - private readonly SeedService seedService; - - public ListsMaintainersController(SeedService seedService) + public ListsMaintainersController(SeedService seedService) : base(seedService) { - this.seedService = seedService; } [HttpGet] - public async Task Seed() - { - return Json(await seedService.GetAllAsync( + public async Task Seed() => Json( + await SeedService.GetAllAsync( typeof(FilterListMaintainer).GetProperty("MaintainerId"), typeof(FilterListMaintainer).GetProperty("FilterListId"))); - } } } \ No newline at end of file diff --git a/src/FilterLists.Api/V1/Controllers/MaintainersController.cs b/src/FilterLists.Api/V1/Controllers/MaintainersController.cs index 362a1d00e..fcca204ef 100644 --- a/src/FilterLists.Api/V1/Controllers/MaintainersController.cs +++ b/src/FilterLists.Api/V1/Controllers/MaintainersController.cs @@ -8,17 +8,11 @@ namespace FilterLists.Api.V1.Controllers { public class MaintainersController : BaseController { - private readonly SeedService seedService; - - public MaintainersController(SeedService seedService) + public MaintainersController(SeedService seedService) : base(seedService) { - this.seedService = seedService; } [HttpGet] - public async Task Seed() - { - return Json(await seedService.GetAllAsync()); - } + public async Task Seed() => Json(await SeedService.GetAllAsync()); } } \ No newline at end of file diff --git a/src/FilterLists.Api/V1/Controllers/MergesController.cs b/src/FilterLists.Api/V1/Controllers/MergesController.cs index 6a754bb8c..af82b85f2 100644 --- a/src/FilterLists.Api/V1/Controllers/MergesController.cs +++ b/src/FilterLists.Api/V1/Controllers/MergesController.cs @@ -8,19 +8,12 @@ namespace FilterLists.Api.V1.Controllers { public class MergesController : BaseController { - private readonly SeedService seedService; - - public MergesController(SeedService seedService) + public MergesController(SeedService seedService) : base(seedService) { - this.seedService = seedService; } [HttpGet] - public async Task Seed() - { - return Json(await seedService.GetAllAsync( - typeof(Merge).GetProperty("MergeFilterListId"), - typeof(Merge).GetProperty("UpstreamFilterListId"))); - } + public async Task Seed() => Json(await SeedService.GetAllAsync( + typeof(Merge).GetProperty("MergeFilterListId"), typeof(Merge).GetProperty("UpstreamFilterListId"))); } } \ No newline at end of file diff --git a/src/FilterLists.Api/V1/Controllers/SoftwareController.cs b/src/FilterLists.Api/V1/Controllers/SoftwareController.cs index 8eaebf1a7..28462a216 100644 --- a/src/FilterLists.Api/V1/Controllers/SoftwareController.cs +++ b/src/FilterLists.Api/V1/Controllers/SoftwareController.cs @@ -8,17 +8,11 @@ namespace FilterLists.Api.V1.Controllers { public class SoftwareController : BaseController { - private readonly SeedService seedService; - - public SoftwareController(SeedService seedService) + public SoftwareController(SeedService seedService) : base(seedService) { - this.seedService = seedService; } [HttpGet] - public async Task Seed() - { - return Json(await seedService.GetAllAsync()); - } + public async Task Seed() => Json(await SeedService.GetAllAsync()); } } \ No newline at end of file diff --git a/src/FilterLists.Api/V1/Controllers/SoftwareSyntaxesController.cs b/src/FilterLists.Api/V1/Controllers/SoftwareSyntaxesController.cs index ca2992869..b042b1e13 100644 --- a/src/FilterLists.Api/V1/Controllers/SoftwareSyntaxesController.cs +++ b/src/FilterLists.Api/V1/Controllers/SoftwareSyntaxesController.cs @@ -8,19 +8,13 @@ namespace FilterLists.Api.V1.Controllers { public class SoftwareSyntaxesController : BaseController { - private readonly SeedService seedService; - - public SoftwareSyntaxesController(SeedService seedService) + public SoftwareSyntaxesController(SeedService seedService) : base(seedService) { - this.seedService = seedService; } [HttpGet] - public async Task Seed() - { - return Json(await seedService.GetAllAsync( - typeof(SoftwareSyntax).GetProperty("SyntaxId"), - typeof(SoftwareSyntax).GetProperty("SoftwareId"))); - } + public async Task Seed() => + Json(await SeedService.GetAllAsync( + typeof(SoftwareSyntax).GetProperty("SyntaxId"), typeof(SoftwareSyntax).GetProperty("SoftwareId"))); } } \ No newline at end of file diff --git a/src/FilterLists.Api/V1/Controllers/SyntaxesController.cs b/src/FilterLists.Api/V1/Controllers/SyntaxesController.cs index 8f64e00bd..68d6fc4b9 100644 --- a/src/FilterLists.Api/V1/Controllers/SyntaxesController.cs +++ b/src/FilterLists.Api/V1/Controllers/SyntaxesController.cs @@ -8,17 +8,11 @@ namespace FilterLists.Api.V1.Controllers { public class SyntaxesController : BaseController { - private readonly SeedService seedService; - - public SyntaxesController(SeedService seedService) + public SyntaxesController(SeedService seedService) : base(seedService) { - this.seedService = seedService; } [HttpGet] - public async Task Seed() - { - return Json(await seedService.GetAllAsync()); - } + public async Task Seed() => Json(await SeedService.GetAllAsync()); } } \ No newline at end of file diff --git a/src/FilterLists.Data/Entities/FilterList.cs b/src/FilterLists.Data/Entities/FilterList.cs index 31e3b6d40..270322721 100644 --- a/src/FilterLists.Data/Entities/FilterList.cs +++ b/src/FilterLists.Data/Entities/FilterList.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; using FilterLists.Data.Entities.Junctions; +using JetBrains.Annotations; namespace FilterLists.Data.Entities { + [UsedImplicitly] public class FilterList : BaseEntity { public string ChatUrl { get; set; } diff --git a/src/FilterLists.Data/Entities/Language.cs b/src/FilterLists.Data/Entities/Language.cs index 178aca1ae..3eccc4970 100644 --- a/src/FilterLists.Data/Entities/Language.cs +++ b/src/FilterLists.Data/Entities/Language.cs @@ -1,8 +1,10 @@ using System.Collections.Generic; using FilterLists.Data.Entities.Junctions; +using JetBrains.Annotations; namespace FilterLists.Data.Entities { + [UsedImplicitly] public class Language : BaseEntity { public ICollection FilterListLanguages { get; set; } diff --git a/src/FilterLists.Data/Entities/License.cs b/src/FilterLists.Data/Entities/License.cs index fecc22fce..6defde9db 100644 --- a/src/FilterLists.Data/Entities/License.cs +++ b/src/FilterLists.Data/Entities/License.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; +using JetBrains.Annotations; namespace FilterLists.Data.Entities { + [UsedImplicitly] public class License : BaseEntity { public string DescriptionUrl { get; set; } diff --git a/src/FilterLists.Data/Entities/Maintainer.cs b/src/FilterLists.Data/Entities/Maintainer.cs index 64b6f46e9..2dd3bc563 100644 --- a/src/FilterLists.Data/Entities/Maintainer.cs +++ b/src/FilterLists.Data/Entities/Maintainer.cs @@ -1,8 +1,10 @@ using System.Collections.Generic; using FilterLists.Data.Entities.Junctions; +using JetBrains.Annotations; namespace FilterLists.Data.Entities { + [UsedImplicitly] public class Maintainer : BaseEntity { public string EmailAddress { get; set; } diff --git a/src/FilterLists.Data/Entities/Software.cs b/src/FilterLists.Data/Entities/Software.cs index d3d918697..0cac0b92f 100644 --- a/src/FilterLists.Data/Entities/Software.cs +++ b/src/FilterLists.Data/Entities/Software.cs @@ -1,8 +1,10 @@ using System.Collections.Generic; using FilterLists.Data.Entities.Junctions; +using JetBrains.Annotations; namespace FilterLists.Data.Entities { + [UsedImplicitly] public class Software : BaseEntity { public string DownloadUrl { get; set; } diff --git a/src/FilterLists.Data/Entities/Syntax.cs b/src/FilterLists.Data/Entities/Syntax.cs index 7a25dabe3..d677c1609 100644 --- a/src/FilterLists.Data/Entities/Syntax.cs +++ b/src/FilterLists.Data/Entities/Syntax.cs @@ -1,8 +1,10 @@ using System.Collections.Generic; using FilterLists.Data.Entities.Junctions; +using JetBrains.Annotations; namespace FilterLists.Data.Entities { + [UsedImplicitly] public class Syntax : BaseEntity { public string DefinitionUrl { get; set; } diff --git a/src/FilterLists.Data/FilterLists.Data.csproj b/src/FilterLists.Data/FilterLists.Data.csproj index 4e1d27620..c752d2787 100644 --- a/src/FilterLists.Data/FilterLists.Data.csproj +++ b/src/FilterLists.Data/FilterLists.Data.csproj @@ -6,6 +6,7 @@ + diff --git a/src/FilterLists.Data/Seed/Extensions/SeedFilterListsDbContext.cs b/src/FilterLists.Data/Seed/Extensions/SeedFilterListsDbContext.cs index bd7094a77..570fc16a4 100644 --- a/src/FilterLists.Data/Seed/Extensions/SeedFilterListsDbContext.cs +++ b/src/FilterLists.Data/Seed/Extensions/SeedFilterListsDbContext.cs @@ -46,13 +46,7 @@ private static List GetPropertiesLessValueGeneratedTimestamps(IEntity { //TODO: get seed properties dynamically from JSON return entityType.GetProperties() - .Where(x => - !new List - { - "CreatedDateUtc", - "ModifiedDateUtc" - } - .Contains(x.Name)) + .Where(x => !new List {"CreatedDateUtc", "ModifiedDateUtc"}.Contains(x.Name)) .ToList(); } @@ -60,8 +54,7 @@ private static string CreateValues(IReadOnlyCollection p { return GetSeedRows(dataPath) .Select(row => CreateRowValues(properties, row)) - .Aggregate("", - (current, rowValues) => current == "" ? rowValues : current + ", " + rowValues); + .Aggregate("", (current, rowValues) => current == "" ? rowValues : current + ", " + rowValues); } private static List GetSeedRows(string dataPath) @@ -81,7 +74,7 @@ private static List GetSeedRows(string dataPath) private static string CreateRowValues(IEnumerable properties, TEntityType row) { return (from property in properties - let value = row.GetType().GetProperty(property.Name).GetValue(row) + let value = row.GetType().GetProperty(property.Name)?.GetValue(row) select FormatDataForMySql(property, value)).Aggregate("", (rowValues, value) => rowValues == "" ? "(" + value : rowValues + ", " + value) + ")"; } @@ -94,7 +87,7 @@ private static object FormatDataForMySql(IProperty property, object value) if (property.ClrType == typeof(bool)) return Convert.ToInt32(value); if (property.ClrType == typeof(DateTime?)) - return "'" + ((DateTime)value).ToString("yyyy-MM-dd HH:mm:ss") + "'"; + return "'" + ((DateTime) value).ToString("yyyy-MM-dd HH:mm:ss") + "'"; return value; } diff --git a/src/FilterLists.Services/DependencyInjection/Extensions/ConfigureServicesCollection.cs b/src/FilterLists.Services/DependencyInjection/Extensions/ConfigureServicesCollection.cs index 289630b9f..45bd3a690 100644 --- a/src/FilterLists.Services/DependencyInjection/Extensions/ConfigureServicesCollection.cs +++ b/src/FilterLists.Services/DependencyInjection/Extensions/ConfigureServicesCollection.cs @@ -1,5 +1,8 @@ using AutoMapper; using FilterLists.Data; +using FilterLists.Services.FilterList; +using FilterLists.Services.Seed; +using FilterLists.Services.Snapshot; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -17,9 +20,9 @@ public static void AddFilterListsServices(this IServiceCollection services, ICon options.UseMySql(configuration.GetConnectionString("FilterListsConnection"), b => b.MigrationsAssembly("FilterLists.Api")) .EnableSensitiveDataLogging()); - services.TryAddScoped(); - services.TryAddScoped(); - services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); services.AddAutoMapper(); } } diff --git a/src/FilterLists.Services/FilterList/FilterListService.cs b/src/FilterLists.Services/FilterList/FilterListService.cs index 87c9f7e58..6cddccfa5 100644 --- a/src/FilterLists.Services/FilterList/FilterListService.cs +++ b/src/FilterLists.Services/FilterList/FilterListService.cs @@ -3,35 +3,35 @@ using System.Threading.Tasks; using AutoMapper.QueryableExtensions; using FilterLists.Data; +using JetBrains.Annotations; using Microsoft.EntityFrameworkCore; namespace FilterLists.Services.FilterList { + [UsedImplicitly] public class FilterListService { - private readonly FilterListsDbContext filterListsDbContext; + private readonly FilterListsDbContext _filterListsDbContext; public FilterListService(FilterListsDbContext filterListsDbContext) { - this.filterListsDbContext = filterListsDbContext; + _filterListsDbContext = filterListsDbContext; } public async Task> GetAllSummariesAsync() { - return await filterListsDbContext.FilterLists - .AsNoTracking() - .OrderBy(x => x.Name) - .ProjectTo() - .ToListAsync(); + return await _filterListsDbContext.FilterLists.AsNoTracking() + .OrderBy(x => x.Name) + .ProjectTo() + .ToListAsync(); } public async Task GetDetailsAsync(int id) { - return await filterListsDbContext.FilterLists - .AsNoTracking() - .ProjectTo() - .FirstAsync(x => x.Id == id) - .FilterParentListFromMaintainerAdditionalLists(); + return await _filterListsDbContext.FilterLists.AsNoTracking() + .ProjectTo() + .FirstAsync(x => x.Id == id) + .FilterParentListFromMaintainerAdditionalLists(); } } } \ No newline at end of file diff --git a/src/FilterLists.Services/FilterList/FilterListServiceExtensions.cs b/src/FilterLists.Services/FilterList/FilterListServiceExtensions.cs index 46547a384..ec304a758 100644 --- a/src/FilterLists.Services/FilterList/FilterListServiceExtensions.cs +++ b/src/FilterLists.Services/FilterList/FilterListServiceExtensions.cs @@ -9,10 +9,10 @@ public static async Task FilterParentListFromMaintainerAdditiona this Task listDetailsDtos) { foreach (var maintainer in listDetailsDtos.Result.Maintainers) - maintainer.AdditionalLists = maintainer.AdditionalLists - .Where(additionalList => - additionalList.Id != listDetailsDtos.Result.Id) - .ToList(); + maintainer.AdditionalLists = maintainer + .AdditionalLists.Where(additionalList => + additionalList.Id != listDetailsDtos.Result.Id) + .ToList(); return await listDetailsDtos; } } diff --git a/src/FilterLists.Services/FilterList/ListDetailsDto.cs b/src/FilterLists.Services/FilterList/ListDetailsDto.cs index c78038d11..5c8d67ff2 100644 --- a/src/FilterLists.Services/FilterList/ListDetailsDto.cs +++ b/src/FilterLists.Services/FilterList/ListDetailsDto.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using JetBrains.Annotations; namespace FilterLists.Services.FilterList { + [UsedImplicitly] public class ListDetailsDto { public int Id { get; set; } @@ -25,39 +27,4 @@ public class ListDetailsDto public ListSyntaxDto Syntax { get; set; } public string ViewUrl { get; set; } } - - public class ListMaintainerDto - { - public int Id { get; set; } - public string EmailAddress { get; set; } - public string HomeUrl { get; set; } - public string Name { get; set; } - public string TwitterHandle { get; set; } - public IEnumerable AdditionalLists { get; set; } - } - - public class MaintainerAdditionalListsDto - { - public int Id { get; set; } - public string Name { get; set; } - } - - public class ListLicenseDto - { - public string DescriptionUrl { get; set; } - public string Name { get; set; } - } - - public class ListSyntaxDto - { - public string DefinitionUrl { get; set; } - public string Name { get; set; } - public IEnumerable SupportedSoftware { get; set; } - } - - public class SyntaxSupportedSoftwareDto - { - public string HomeUrl { get; set; } - public string Name { get; set; } - } } \ No newline at end of file diff --git a/src/FilterLists.Services/FilterList/ListLanguagesDto.cs b/src/FilterLists.Services/FilterList/ListLanguagesDto.cs new file mode 100644 index 000000000..2be827218 --- /dev/null +++ b/src/FilterLists.Services/FilterList/ListLanguagesDto.cs @@ -0,0 +1,11 @@ +using JetBrains.Annotations; + +namespace FilterLists.Services.FilterList +{ + [UsedImplicitly] + public class ListLanguagesDto + { + public string Name { get; set; } + public string Iso6391 { get; set; } + } +} \ No newline at end of file diff --git a/src/FilterLists.Services/FilterList/ListLicenseDto.cs b/src/FilterLists.Services/FilterList/ListLicenseDto.cs new file mode 100644 index 000000000..9fb1a3072 --- /dev/null +++ b/src/FilterLists.Services/FilterList/ListLicenseDto.cs @@ -0,0 +1,11 @@ +using JetBrains.Annotations; + +namespace FilterLists.Services.FilterList +{ + [UsedImplicitly] + public class ListLicenseDto + { + public string DescriptionUrl { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/src/FilterLists.Services/FilterList/ListMaintainerDto.cs b/src/FilterLists.Services/FilterList/ListMaintainerDto.cs new file mode 100644 index 000000000..b62988940 --- /dev/null +++ b/src/FilterLists.Services/FilterList/ListMaintainerDto.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; +using JetBrains.Annotations; + +namespace FilterLists.Services.FilterList +{ + [UsedImplicitly] + public class ListMaintainerDto + { + public int Id { get; set; } + public string EmailAddress { get; set; } + public string HomeUrl { get; set; } + public string Name { get; set; } + public string TwitterHandle { get; set; } + public IEnumerable AdditionalLists { get; set; } + } +} \ No newline at end of file diff --git a/src/FilterLists.Services/FilterList/ListSummaryDto.cs b/src/FilterLists.Services/FilterList/ListSummaryDto.cs index 5c900a3e6..bc804011d 100644 --- a/src/FilterLists.Services/FilterList/ListSummaryDto.cs +++ b/src/FilterLists.Services/FilterList/ListSummaryDto.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; +using JetBrains.Annotations; namespace FilterLists.Services.FilterList { + [UsedImplicitly] public class ListSummaryDto { public int Id { get; set; } @@ -9,10 +11,4 @@ public class ListSummaryDto public string Name { get; set; } public string ViewUrl { get; set; } } - - public class ListLanguagesDto - { - public string Name { get; set; } - public string Iso6391 { get; set; } - } } \ No newline at end of file diff --git a/src/FilterLists.Services/FilterList/ListSyntaxDto.cs b/src/FilterLists.Services/FilterList/ListSyntaxDto.cs new file mode 100644 index 000000000..6bd6067c5 --- /dev/null +++ b/src/FilterLists.Services/FilterList/ListSyntaxDto.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using JetBrains.Annotations; + +namespace FilterLists.Services.FilterList +{ + [UsedImplicitly] + public class ListSyntaxDto + { + public string DefinitionUrl { get; set; } + public string Name { get; set; } + public IEnumerable SupportedSoftware { get; set; } + } +} \ No newline at end of file diff --git a/src/FilterLists.Services/FilterList/MaintainerAdditionalListsDto.cs b/src/FilterLists.Services/FilterList/MaintainerAdditionalListsDto.cs new file mode 100644 index 000000000..162a02f2d --- /dev/null +++ b/src/FilterLists.Services/FilterList/MaintainerAdditionalListsDto.cs @@ -0,0 +1,11 @@ +using JetBrains.Annotations; + +namespace FilterLists.Services.FilterList +{ + [UsedImplicitly] + public class MaintainerAdditionalListsDto + { + public int Id { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/src/FilterLists.Services/FilterList/MappingProfiles.cs b/src/FilterLists.Services/FilterList/MappingProfiles.cs index df6c16e73..73c5d8afd 100644 --- a/src/FilterLists.Services/FilterList/MappingProfiles.cs +++ b/src/FilterLists.Services/FilterList/MappingProfiles.cs @@ -10,26 +10,20 @@ public MappingProfiles() { CreateMap() .ForMember(dto => dto.Languages, - conf => conf.MapFrom(list => - list.FilterListLanguages.Select(listLangs => listLangs.Language))); - + conf => conf.MapFrom(list => list.FilterListLanguages.Select(listLangs => listLangs.Language))); CreateMap() .ForMember(dto => dto.Languages, - conf => conf.MapFrom(list => - list.FilterListLanguages.Select(listLangs => listLangs.Language.Name))) + conf => conf.MapFrom(list => list.FilterListLanguages.Select(listLangs => listLangs.Language.Name))) .ForMember(dto => dto.Maintainers, conf => conf.MapFrom(list => list.FilterListMaintainers.Select(listMaints => listMaints.Maintainer))); - CreateMap() .ForMember(dto => dto.AdditionalLists, conf => conf.MapFrom(maint => maint.FilterListMaintainers.Select(listMaints => listMaints.FilterList))); - CreateMap() .ForMember(dto => dto.SupportedSoftware, - conf => conf.MapFrom(syntax => - syntax.SoftwareSyntaxes.Select(softSyn => softSyn.Software))); + conf => conf.MapFrom(syntax => syntax.SoftwareSyntaxes.Select(softSyn => softSyn.Software))); } } } \ No newline at end of file diff --git a/src/FilterLists.Services/FilterList/SyntaxSupportedSoftwareDto.cs b/src/FilterLists.Services/FilterList/SyntaxSupportedSoftwareDto.cs new file mode 100644 index 000000000..7dc00340d --- /dev/null +++ b/src/FilterLists.Services/FilterList/SyntaxSupportedSoftwareDto.cs @@ -0,0 +1,11 @@ +using JetBrains.Annotations; + +namespace FilterLists.Services.FilterList +{ + [UsedImplicitly] + public class SyntaxSupportedSoftwareDto + { + public string HomeUrl { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/src/FilterLists.Services/FilterLists.Services.csproj b/src/FilterLists.Services/FilterLists.Services.csproj index 5eb520833..ea4bb2292 100644 --- a/src/FilterLists.Services/FilterLists.Services.csproj +++ b/src/FilterLists.Services/FilterLists.Services.csproj @@ -8,6 +8,7 @@ + diff --git a/src/FilterLists.Services/Seed/Models/FilterListSeedDto.cs b/src/FilterLists.Services/Seed/Models/FilterListSeedDto.cs index 91f834338..d71a00243 100644 --- a/src/FilterLists.Services/Seed/Models/FilterListSeedDto.cs +++ b/src/FilterLists.Services/Seed/Models/FilterListSeedDto.cs @@ -1,7 +1,9 @@ using System; +using JetBrains.Annotations; namespace FilterLists.Services.Seed.Models { + [UsedImplicitly] public class FilterListSeedDto { public int Id { get; set; } diff --git a/src/FilterLists.Services/Seed/Models/Junctions/FilterListLanguageSeedDto.cs b/src/FilterLists.Services/Seed/Models/Junctions/FilterListLanguageSeedDto.cs index dde76dd3b..84c42039e 100644 --- a/src/FilterLists.Services/Seed/Models/Junctions/FilterListLanguageSeedDto.cs +++ b/src/FilterLists.Services/Seed/Models/Junctions/FilterListLanguageSeedDto.cs @@ -1,5 +1,8 @@ -namespace FilterLists.Services.Seed.Models.Junctions +using JetBrains.Annotations; + +namespace FilterLists.Services.Seed.Models.Junctions { + [UsedImplicitly] public class FilterListLanguageSeedDto { public int FilterListId { get; set; } diff --git a/src/FilterLists.Services/Seed/Models/Junctions/FilterListMaintainerSeedDto.cs b/src/FilterLists.Services/Seed/Models/Junctions/FilterListMaintainerSeedDto.cs index 77a6eb9f1..3dcb8ca39 100644 --- a/src/FilterLists.Services/Seed/Models/Junctions/FilterListMaintainerSeedDto.cs +++ b/src/FilterLists.Services/Seed/Models/Junctions/FilterListMaintainerSeedDto.cs @@ -1,5 +1,8 @@ -namespace FilterLists.Services.Seed.Models.Junctions +using JetBrains.Annotations; + +namespace FilterLists.Services.Seed.Models.Junctions { + [UsedImplicitly] public class FilterListMaintainerSeedDto { public int FilterListId { get; set; } diff --git a/src/FilterLists.Services/Seed/Models/Junctions/ForkSeedDto.cs b/src/FilterLists.Services/Seed/Models/Junctions/ForkSeedDto.cs index 7a8eacec6..4d723ff99 100644 --- a/src/FilterLists.Services/Seed/Models/Junctions/ForkSeedDto.cs +++ b/src/FilterLists.Services/Seed/Models/Junctions/ForkSeedDto.cs @@ -1,5 +1,8 @@ -namespace FilterLists.Services.Seed.Models.Junctions +using JetBrains.Annotations; + +namespace FilterLists.Services.Seed.Models.Junctions { + [UsedImplicitly] public class ForkSeedDto { public int ForkFilterListId { get; set; } diff --git a/src/FilterLists.Services/Seed/Models/Junctions/MergeSeedDto.cs b/src/FilterLists.Services/Seed/Models/Junctions/MergeSeedDto.cs index 1d09b68e2..f502db398 100644 --- a/src/FilterLists.Services/Seed/Models/Junctions/MergeSeedDto.cs +++ b/src/FilterLists.Services/Seed/Models/Junctions/MergeSeedDto.cs @@ -1,5 +1,8 @@ -namespace FilterLists.Services.Seed.Models.Junctions +using JetBrains.Annotations; + +namespace FilterLists.Services.Seed.Models.Junctions { + [UsedImplicitly] public class MergeSeedDto { public int MergeFilterListId { get; set; } diff --git a/src/FilterLists.Services/Seed/Models/Junctions/SoftwareSyntaxSeedDto.cs b/src/FilterLists.Services/Seed/Models/Junctions/SoftwareSyntaxSeedDto.cs index 9a70fbd0c..585b5cde5 100644 --- a/src/FilterLists.Services/Seed/Models/Junctions/SoftwareSyntaxSeedDto.cs +++ b/src/FilterLists.Services/Seed/Models/Junctions/SoftwareSyntaxSeedDto.cs @@ -1,5 +1,8 @@ -namespace FilterLists.Services.Seed.Models.Junctions +using JetBrains.Annotations; + +namespace FilterLists.Services.Seed.Models.Junctions { + [UsedImplicitly] public class SoftwareSyntaxSeedDto { public int SoftwareId { get; set; } diff --git a/src/FilterLists.Services/Seed/Models/LanguageSeedDto.cs b/src/FilterLists.Services/Seed/Models/LanguageSeedDto.cs index 707cfc9e5..52b3f9d4b 100644 --- a/src/FilterLists.Services/Seed/Models/LanguageSeedDto.cs +++ b/src/FilterLists.Services/Seed/Models/LanguageSeedDto.cs @@ -1,5 +1,8 @@ -namespace FilterLists.Services.Seed.Models +using JetBrains.Annotations; + +namespace FilterLists.Services.Seed.Models { + [UsedImplicitly] public class LanguageSeedDto { public int Id { get; set; } diff --git a/src/FilterLists.Services/Seed/Models/LicenseSeedDto.cs b/src/FilterLists.Services/Seed/Models/LicenseSeedDto.cs index c433e9391..9d4fb5135 100644 --- a/src/FilterLists.Services/Seed/Models/LicenseSeedDto.cs +++ b/src/FilterLists.Services/Seed/Models/LicenseSeedDto.cs @@ -1,5 +1,8 @@ -namespace FilterLists.Services.Seed.Models +using JetBrains.Annotations; + +namespace FilterLists.Services.Seed.Models { + [UsedImplicitly] public class LicenseSeedDto { public int Id { get; set; } diff --git a/src/FilterLists.Services/Seed/Models/MaintainerSeedDto.cs b/src/FilterLists.Services/Seed/Models/MaintainerSeedDto.cs index cf663727a..ff864887c 100644 --- a/src/FilterLists.Services/Seed/Models/MaintainerSeedDto.cs +++ b/src/FilterLists.Services/Seed/Models/MaintainerSeedDto.cs @@ -1,5 +1,8 @@ -namespace FilterLists.Services.Seed.Models +using JetBrains.Annotations; + +namespace FilterLists.Services.Seed.Models { + [UsedImplicitly] public class MaintainerSeedDto { public int Id { get; set; } diff --git a/src/FilterLists.Services/Seed/Models/SoftwareSeedDto.cs b/src/FilterLists.Services/Seed/Models/SoftwareSeedDto.cs index c28f4eca7..6c3a03554 100644 --- a/src/FilterLists.Services/Seed/Models/SoftwareSeedDto.cs +++ b/src/FilterLists.Services/Seed/Models/SoftwareSeedDto.cs @@ -1,5 +1,8 @@ -namespace FilterLists.Services.Seed.Models +using JetBrains.Annotations; + +namespace FilterLists.Services.Seed.Models { + [UsedImplicitly] public class SoftwareSeedDto { public int Id { get; set; } diff --git a/src/FilterLists.Services/Seed/Models/SyntaxSeedDto.cs b/src/FilterLists.Services/Seed/Models/SyntaxSeedDto.cs index 4a677216a..db9b2d113 100644 --- a/src/FilterLists.Services/Seed/Models/SyntaxSeedDto.cs +++ b/src/FilterLists.Services/Seed/Models/SyntaxSeedDto.cs @@ -1,5 +1,8 @@ -namespace FilterLists.Services.Seed.Models +using JetBrains.Annotations; + +namespace FilterLists.Services.Seed.Models { + [UsedImplicitly] public class SyntaxSeedDto { public int Id { get; set; } diff --git a/src/FilterLists.Services/Seed/SeedService.cs b/src/FilterLists.Services/Seed/SeedService.cs index 3feaece51..c64423c5b 100644 --- a/src/FilterLists.Services/Seed/SeedService.cs +++ b/src/FilterLists.Services/Seed/SeedService.cs @@ -4,46 +4,43 @@ using System.Threading.Tasks; using AutoMapper.QueryableExtensions; using FilterLists.Data; +using JetBrains.Annotations; using Microsoft.EntityFrameworkCore; namespace FilterLists.Services.Seed { + [UsedImplicitly] public class SeedService { - private readonly FilterListsDbContext filterListsDbContext; + private readonly FilterListsDbContext _filterListsDbContext; public SeedService(FilterListsDbContext filterListsDbContext) { - this.filterListsDbContext = filterListsDbContext; + _filterListsDbContext = filterListsDbContext; } - public async Task> GetAllAsync() where TEntity : class - { - return await filterListsDbContext.Set() - .AsNoTracking() - .ProjectTo() - .ToArrayAsync(); - } + public async Task> GetAllAsync() where TEntity : class => + await _filterListsDbContext.Set().AsNoTracking().ProjectTo().ToArrayAsync(); public async Task> GetAllAsync(PropertyInfo primarySort) where TEntity : class { - return await filterListsDbContext.Set() - .OrderBy(x => primarySort.GetValue(x, null)) - .AsNoTracking() - .ProjectTo() - .ToArrayAsync(); + return await _filterListsDbContext.Set() + .OrderBy(x => primarySort.GetValue(x, null)) + .AsNoTracking() + .ProjectTo() + .ToArrayAsync(); } public async Task> GetAllAsync(PropertyInfo primarySort, PropertyInfo secondarySort) where TEntity : class { - return await filterListsDbContext.Set() - .OrderBy(x => primarySort.GetValue(x, null)) - .ThenBy(x => secondarySort.GetValue(x, null)) - .AsNoTracking() - .ProjectTo() - .ToArrayAsync(); + return await _filterListsDbContext.Set() + .OrderBy(x => primarySort.GetValue(x, null)) + .ThenBy(x => secondarySort.GetValue(x, null)) + .AsNoTracking() + .ProjectTo() + .ToArrayAsync(); } } } \ No newline at end of file diff --git a/src/FilterLists.Services/Snapshot/FilterListViewUrlDto.cs b/src/FilterLists.Services/Snapshot/FilterListViewUrlDto.cs index 2647dc1c7..52c5e9da2 100644 --- a/src/FilterLists.Services/Snapshot/FilterListViewUrlDto.cs +++ b/src/FilterLists.Services/Snapshot/FilterListViewUrlDto.cs @@ -1,5 +1,8 @@ -namespace FilterLists.Services.Snapshot +using JetBrains.Annotations; + +namespace FilterLists.Services.Snapshot { + [UsedImplicitly] public class FilterListViewUrlDto { public int Id { get; set; } diff --git a/src/FilterLists.Services/Snapshot/RawRuleLinterExtensions.cs b/src/FilterLists.Services/Snapshot/RawRuleLinterExtensions.cs index 314901487..cfe0c95e9 100644 --- a/src/FilterLists.Services/Snapshot/RawRuleLinterExtensions.cs +++ b/src/FilterLists.Services/Snapshot/RawRuleLinterExtensions.cs @@ -19,29 +19,17 @@ private static string TrimLeadingAndTrailingWhitespace(this string rule) return rule.Trim(charsToTrim); } - private static string DropIfEmpty(this string rule) - { - return rule == "" ? null : rule; - } + private static string DropIfEmpty(this string rule) => rule == "" ? null : rule; - private static string DropIfComment(this string rule) - { - return rule.StartsWith(@"!") && !rule.StartsWith(@"!#") || rule.StartsWith(@"!##") ? null : rule; - } + private static string DropIfComment(this string rule) => + rule.StartsWith(@"!") && !rule.StartsWith(@"!#") || rule.StartsWith(@"!##") ? null : rule; - private static string DropIfTooLong(this string rule) - { - return rule.Length > 8192 ? null : rule; - } + private static string DropIfTooLong(this string rule) => rule.Length > 8192 ? null : rule; - private static string DropIfContainsBackslashSingleQuote(this string rule) - { - return rule.Contains(@"\'") ? null : rule; - } + private static string DropIfContainsBackslashSingleQuote(this string rule) => + rule.Contains(@"\'") ? null : rule; - private static string TrimSingleBackslashFromEnd(this string rule) - { - return rule.EndsWith(@"\") && !rule.EndsWith(@"\\") ? rule.Remove(rule.Length - 1) : rule; - } + private static string TrimSingleBackslashFromEnd(this string rule) => + rule.EndsWith(@"\") && !rule.EndsWith(@"\\") ? rule.Remove(rule.Length - 1) : rule; } } \ No newline at end of file diff --git a/src/FilterLists.Services/Snapshot/SnapshotBatchDe.cs b/src/FilterLists.Services/Snapshot/SnapshotBatchDe.cs index e0ac2eb82..2985e70ec 100644 --- a/src/FilterLists.Services/Snapshot/SnapshotBatchDe.cs +++ b/src/FilterLists.Services/Snapshot/SnapshotBatchDe.cs @@ -10,42 +10,43 @@ namespace FilterLists.Services.Snapshot { public class SnapshotBatchDe { - private readonly FilterListsDbContext dbContext; - private readonly IEnumerable rawRules; - private readonly Data.Entities.Snapshot snapshot; - private IQueryable rules; + private readonly FilterListsDbContext _dbContext; + private readonly IEnumerable _rawRules; + private readonly Data.Entities.Snapshot _snapshot; + private IQueryable _rules; - public SnapshotBatchDe(FilterListsDbContext dbContext, Data.Entities.Snapshot snapshot, IEnumerable rawRules) + public SnapshotBatchDe(FilterListsDbContext dbContext, Data.Entities.Snapshot snapshot, + IEnumerable rawRules) { - this.dbContext = dbContext; - this.snapshot = snapshot; - this.rawRules = rawRules; + _dbContext = dbContext; + _snapshot = snapshot; + _rawRules = rawRules; } public async Task SaveSnapshotBatchAsync() { AddRules(); AddSnapshotRules(); - await dbContext.SaveChangesAsync(); + await _dbContext.SaveChangesAsync(); } private void AddRules() { - var existingRules = dbContext.Rules.Where(rule => rawRules.Contains(rule.Raw)); - var newRawRules = rawRules.Except(existingRules.Select(r => r.Raw)); + var existingRules = _dbContext.Rules.Where(rule => _rawRules.Contains(rule.Raw)); + var newRawRules = _rawRules.Except(existingRules.Select(r => r.Raw)); var newRules = newRawRules.Select(newRawRule => new Rule {Raw = newRawRule}).ToList(); - dbContext.Rules.AddRange(newRules); - rules = existingRules.Concat(newRules); + _dbContext.Rules.AddRange(newRules); + _rules = existingRules.Concat(newRules); } private void AddSnapshotRules() { var snapshotRules = new List(); - foreach (var rule in rules) + foreach (var rule in _rules) snapshotRules.Add(new SnapshotRule {Rule = rule}); - if (snapshot.AddedSnapshotRules == null) - snapshot.AddedSnapshotRules = new List(); - snapshot.AddedSnapshotRules.AddRange(snapshotRules); + if (_snapshot.AddedSnapshotRules == null) + _snapshot.AddedSnapshotRules = new List(); + _snapshot.AddedSnapshotRules.AddRange(snapshotRules); } } } \ No newline at end of file diff --git a/src/FilterLists.Services/Snapshot/SnapshotDe.cs b/src/FilterLists.Services/Snapshot/SnapshotDe.cs index 6ac5fba87..fac26e3e4 100644 --- a/src/FilterLists.Services/Snapshot/SnapshotDe.cs +++ b/src/FilterLists.Services/Snapshot/SnapshotDe.cs @@ -5,7 +5,6 @@ using System.Net.Http; using System.Threading.Tasks; using FilterLists.Data; -using FilterLists.Data.Entities; using FilterLists.Data.Entities.Junctions; using FilterLists.Services.Extensions; @@ -13,19 +12,18 @@ namespace FilterLists.Services.Snapshot { public class SnapshotDe { - private const int BatchSize = 1000; - private const string UserAgentString = @"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"; - private readonly FilterListsDbContext dbContext; - private readonly FilterListViewUrlDto list; - private Data.Entities.Snapshot snapshot; + private const int BatchSize = 1000; + private readonly FilterListsDbContext _dbContext; + private readonly FilterListViewUrlDto _list; + private Data.Entities.Snapshot _snapshot; public SnapshotDe(FilterListsDbContext dbContext, FilterListViewUrlDto list) { - this.dbContext = dbContext; - this.list = list; + _dbContext = dbContext; + _list = list; } public async Task SaveSnapshotAsync() @@ -44,14 +42,14 @@ private async Task CaptureSnapshot() { await AddSnapshot(); var content = await TryGetContent(); - await dbContext.SaveChangesAsync(); + await _dbContext.SaveChangesAsync(); return content; } private async Task AddSnapshot() { - snapshot = new Data.Entities.Snapshot {FilterListId = list.Id}; - await dbContext.Snapshots.AddAsync(snapshot); + _snapshot = new Data.Entities.Snapshot {FilterListId = _list.Id}; + await _dbContext.Snapshots.AddAsync(_snapshot); } private async Task TryGetContent() @@ -62,13 +60,13 @@ private async Task TryGetContent() } catch (WebException we) { - snapshot.HttpStatusCode = ((int)((HttpWebResponse)we.Response).StatusCode).ToString(); + _snapshot.HttpStatusCode = ((int) ((HttpWebResponse) we.Response).StatusCode).ToString(); return null; } catch (Exception) { //TODO: log exception (#148) - snapshot.HttpStatusCode = null; + _snapshot.HttpStatusCode = null; return null; } } @@ -78,9 +76,9 @@ private async Task GetContent() using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgentString); - using (var httpResponseMessage = await httpClient.GetAsync(list.ViewUrl)) + using (var httpResponseMessage = await httpClient.GetAsync(_list.ViewUrl)) { - snapshot.HttpStatusCode = ((int)httpResponseMessage.StatusCode).ToString(); + _snapshot.HttpStatusCode = ((int) httpResponseMessage.StatusCode).ToString(); if (httpResponseMessage.IsSuccessStatusCode) return await httpResponseMessage.Content.ReadAsStringAsync(); } @@ -107,7 +105,7 @@ private static IEnumerable GetRawRules(string content) private IEnumerable GetSnapshotBatches(IEnumerable rawRules) { return rawRules.Batch(BatchSize) - .Select(rawRuleBatch => new SnapshotBatchDe(dbContext, snapshot, rawRuleBatch)); + .Select(rawRuleBatch => new SnapshotBatchDe(_dbContext, _snapshot, rawRuleBatch)); } private static async Task SaveSnapshotBatches(IEnumerable snapshotBatches) @@ -121,37 +119,36 @@ private async Task DedupSnapshotRules() var existingSnapshotRules = GetExistingSnapshotRules(); UpdateRemovedSnapshotRules(existingSnapshotRules); RemoveDuplicateSnapshotRules(existingSnapshotRules); - await dbContext.SaveChangesAsync(); + await _dbContext.SaveChangesAsync(); } private IQueryable GetExistingSnapshotRules() { - return dbContext.SnapshotRules.Where(sr => - sr.AddedBySnapshot.FilterListId == list.Id && - sr.AddedBySnapshot != snapshot && + return _dbContext.SnapshotRules.Where(sr => + sr.AddedBySnapshot.FilterListId == _list.Id && sr.AddedBySnapshot != _snapshot && sr.RemovedBySnapshot == null); } private void UpdateRemovedSnapshotRules(IQueryable existingSnapshotRules) { - var newSnapshotRules = dbContext.SnapshotRules.Where(sr => sr.AddedBySnapshot == snapshot); + var newSnapshotRules = _dbContext.SnapshotRules.Where(sr => sr.AddedBySnapshot == _snapshot); var removedSnapshotRules = existingSnapshotRules.Where(sr => !newSnapshotRules.Any(nsr => nsr.Rule == sr.Rule)); - removedSnapshotRules.ToList().ForEach(sr => sr.RemovedBySnapshot = snapshot); + removedSnapshotRules.ToList().ForEach(sr => sr.RemovedBySnapshot = _snapshot); } private void RemoveDuplicateSnapshotRules(IQueryable existingSnapshotRules) { - var duplicateSnapshotRules = dbContext.SnapshotRules.Where(sr => - sr.AddedBySnapshot == snapshot && + var duplicateSnapshotRules = _dbContext.SnapshotRules.Where(sr => + sr.AddedBySnapshot == _snapshot && existingSnapshotRules.Any(esr => esr.Rule == sr.Rule)); - dbContext.SnapshotRules.RemoveRange(duplicateSnapshotRules); + _dbContext.SnapshotRules.RemoveRange(duplicateSnapshotRules); } private async Task SetCompleted() { - snapshot.IsCompleted = true; - await dbContext.SaveChangesAsync(); + _snapshot.IsCompleted = true; + await _dbContext.SaveChangesAsync(); } } } \ No newline at end of file diff --git a/src/FilterLists.Services/Snapshot/SnapshotService.cs b/src/FilterLists.Services/Snapshot/SnapshotService.cs index 13d645ad1..df3a473a5 100644 --- a/src/FilterLists.Services/Snapshot/SnapshotService.cs +++ b/src/FilterLists.Services/Snapshot/SnapshotService.cs @@ -4,16 +4,17 @@ using System.Threading.Tasks; using AutoMapper.QueryableExtensions; using FilterLists.Data; +using JetBrains.Annotations; using Microsoft.EntityFrameworkCore; namespace FilterLists.Services.Snapshot { + [UsedImplicitly] public class SnapshotService { - private readonly FilterListsDbContext dbContext; - //TODO: update algorithm to support non-standard list sizes and formats (#200, #201) - private readonly List ignoreLists = new List {48, 149, 173, 185, 186, 187, 188, 189, 352}; + private readonly List _ignoreLists = new List {48, 149, 173, 185, 186, 187, 188, 189, 352}; + private readonly FilterListsDbContext dbContext; public SnapshotService(FilterListsDbContext dbContext) { @@ -41,15 +42,12 @@ private async Task> GetListsToCapture(int batc .FilterLists .Where(list => (!list.Snapshots.Any() || - list.Snapshots - .Select(ss => ss.CreatedDateUtc) + list.Snapshots.Select(ss => ss.CreatedDateUtc) .OrderByDescending(sscd => sscd) - .FirstOrDefault() < DateTime.UtcNow.AddDays(-1)) && - !ignoreLists.Contains(list.Id)) + .FirstOrDefault() < DateTime.UtcNow.AddDays(-1)) && !_ignoreLists.Contains(list.Id)) .OrderBy(list => list.Snapshots.Any()) .ThenBy(list => - list.Snapshots - .Select(ss => ss.CreatedDateUtc) + list.Snapshots.Select(ss => ss.CreatedDateUtc) .OrderByDescending(sscd => sscd) .FirstOrDefault()) .Take(batchSize)