move rule parsing to Snapshot class

This commit is contained in:
Collin M. Barrett 2018-01-29 15:24:02 -06:00
parent 3a443e7e43
commit c1772a8680

View file

@ -70,10 +70,9 @@ private void AddOrUpdateRules(IEnumerable<Snapshot> snapshots)
private void AddOrUpdateRules(Snapshot snapshot)
{
// add new Rules
var snapshotRulesRaw =
snapshot.Content.Split(new[] {"\r\n", "\r", "\n"}, StringSplitOptions.RemoveEmptyEntries);
var preExistingSnapshotRules = filterListsDbContext.Rules.Where(x => snapshotRulesRaw.Contains(x.Raw));
var newSnapshotRulesRaw = snapshotRulesRaw.Except(preExistingSnapshotRules.Select(x => x.Raw));
snapshot.ParseRawRules();
var preExistingSnapshotRules = filterListsDbContext.Rules.Where(x => snapshot.RawRules.Contains(x.Raw));
var newSnapshotRulesRaw = snapshot.RawRules.Except(preExistingSnapshotRules.Select(x => x.Raw));
var newSnapshotRules =
newSnapshotRulesRaw.Select(newSnapshotRuleRaw => new Rule {Raw = newSnapshotRuleRaw});
filterListsDbContext.Rules.AddRange(newSnapshotRules);
@ -109,8 +108,14 @@ private class FilterListDto
private class Snapshot
{
public string Content { get; set; }
public string Content { private get; set; }
public int FilterListId { get; set; }
public string[] RawRules { get; private set; }
public void ParseRawRules()
{
RawRules = Content.Split(new[] {"\r\n", "\r", "\n"}, StringSplitOptions.RemoveEmptyEntries);
}
}
}
}