forked from sarbian/ModuleManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeletePatch.cs
More file actions
51 lines (47 loc) · 2.09 KB
/
Copy pathDeletePatch.cs
File metadata and controls
51 lines (47 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using ModuleManager.Extensions;
using ModuleManager.Logging;
using ModuleManager.Patches.PassSpecifiers;
using ModuleManager.Progress;
namespace ModuleManager.Patches
{
public class DeletePatch : IPatch
{
public UrlDir.UrlConfig UrlConfig { get; }
public INodeMatcher NodeMatcher { get; }
public IPassSpecifier PassSpecifier { get; }
public bool CountsAsPatch => true;
public DeletePatch(UrlDir.UrlConfig urlConfig, INodeMatcher nodeMatcher, IPassSpecifier passSpecifier)
{
UrlConfig = urlConfig ?? throw new ArgumentNullException(nameof(urlConfig));
NodeMatcher = nodeMatcher ?? throw new ArgumentNullException(nameof(nodeMatcher));
PassSpecifier = passSpecifier ?? throw new ArgumentNullException(nameof(passSpecifier));
}
public void Apply(LinkedList<IProtoUrlConfig> databaseConfigs, IPatchProgress progress, IBasicLogger logger)
{
if (databaseConfigs == null) throw new ArgumentNullException(nameof(databaseConfigs));
if (progress == null) throw new ArgumentNullException(nameof(progress));
if (logger == null) throw new ArgumentNullException(nameof(logger));
LinkedListNode<IProtoUrlConfig> currentNode = databaseConfigs.First;
while (currentNode != null)
{
IProtoUrlConfig protoConfig = currentNode.Value;
try
{
LinkedListNode<IProtoUrlConfig> nextNode = currentNode.Next;
if (NodeMatcher.IsMatch(protoConfig.Node))
{
progress.ApplyingDelete(protoConfig, UrlConfig);
databaseConfigs.Remove(currentNode);
}
currentNode = nextNode;
}
catch (Exception ex)
{
progress.Exception(UrlConfig, $"Exception while applying delete {UrlConfig.SafeUrl()} to {protoConfig.FullUrl}", ex);
}
}
}
}
}