diff --git a/FilterLists.sln.DotSettings b/FilterLists.sln.DotSettings index 2384b8683..30e48687e 100644 --- a/FilterLists.sln.DotSettings +++ b/FilterLists.sln.DotSettings @@ -2,6 +2,9 @@ xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> + + True + 6B3E6765-5B8B-4A23-AD12-7E2BC5F4D2E6/d:wwwroot/d:dist True True diff --git a/src/FilterLists.Data/Seed/Extensions/SeedFilterListsDbContext.cs b/src/FilterLists.Data/Seed/Extensions/SeedFilterListsDbContext.cs index 01ab21ea4..3789ff60a 100644 --- a/src/FilterLists.Data/Seed/Extensions/SeedFilterListsDbContext.cs +++ b/src/FilterLists.Data/Seed/Extensions/SeedFilterListsDbContext.cs @@ -12,8 +12,6 @@ namespace FilterLists.Data.Seed.Extensions { public static class SeedFilterListsDbContext { - //TODO: consider handling deleted entities on seed - //TODO: read entities from model and iterate over public static void SeedOrUpdate(this FilterListsDbContext dbContext, string dataPath) { dbContext.InsertOnDuplicateKeyUpdate(dataPath); @@ -29,7 +27,6 @@ public static void SeedOrUpdate(this FilterListsDbContext dbContext, string data dbContext.InsertOnDuplicateKeyUpdate(dataPath); } - //TODO: improve raw SQL against injection attacks private static void InsertOnDuplicateKeyUpdate(this DbContext dbContext, string dataPath) where TEntityType : class { @@ -47,16 +44,26 @@ private static void InsertOnDuplicateKeyUpdate(this DbContext dbCon private static List GetPropertiesLessValueGeneratedTimestamps(IEntityType entityType) { - //TODO: filter dynamically from JSON - return entityType.GetProperties().Where(x => - !new List {"CreatedDateUtc", "ModifiedDateUtc", "ScrapedDateUtc", "UpdatedDateUtc"} - .Contains(x.Name)).ToList(); + //TODO: get seed properties dynamically from JSON + return entityType.GetProperties() + .Where(x => + !new List + { + "CreatedDateUtc", + "ModifiedDateUtc", + "ScrapedDateUtc", + "UpdatedDateUtc" + } + .Contains(x.Name)) + .ToList(); } private static string CreateValues(IReadOnlyCollection properties, string dataPath) { - return GetSeedRows(dataPath).Select(row => CreateRowValues(properties, row)).Aggregate("", - (current, rowValues) => current == "" ? rowValues : current + ", " + rowValues); + return GetSeedRows(dataPath) + .Select(row => CreateRowValues(properties, row)) + .Aggregate("", + (current, rowValues) => current == "" ? rowValues : current + ", " + rowValues); } private static List GetSeedRows(string dataPath) @@ -81,7 +88,6 @@ select FormatDataForMySql(property, value)).Aggregate("", (rowValues, value) => rowValues == "" ? "(" + value : rowValues + ", " + value) + ")"; } - //TODO: use .NET, EF, or other library rather than maintaining this private static object FormatDataForMySql(IProperty property, object value) { if (value == null) return "NULL"; @@ -97,15 +103,14 @@ private static object FormatDataForMySql(IProperty property, object value) private static string CreateUpdates(IReadOnlyCollection properties) { var update = - (from property in properties - where !property.IsPrimaryKey() - select property.Name + " = VALUES(" + property.Name + ")").Aggregate("", - (updates, columnUpdates) => updates == "" ? columnUpdates : updates + ", " + columnUpdates); + (from property in properties + where !property.IsPrimaryKey() + select property.Name + " = VALUES(" + property.Name + ")").Aggregate("", + (updates, columnUpdates) => updates == "" ? columnUpdates : updates + ", " + columnUpdates); if (update == "") update = GetUpdateUnchangedColumnHack(properties); return update; } - //TODO: eliminate wasted IO updating unchanged column (https://stackoverflow.com/a/4596409/2343739) private static string GetUpdateUnchangedColumnHack(IEnumerable properties) { var firstId = properties.First(x => x.IsPrimaryKey()).Name;