public void TestIsMatch() { NodeMatcher matcher = new NodeMatcher("NODE", null, null); Assert.True(matcher.IsMatch(new ConfigNode("NODE"))); Assert.False(matcher.IsMatch(new ConfigNode("PART"))); }
public void TestIsMatch__Name() { NodeMatcher matcher = new NodeMatcher("NODE", "blah", null); Assert.True(matcher.IsMatch(new TestConfigNode("NODE") { { "name", "blah" }, })); Assert.False(matcher.IsMatch(new ConfigNode("NODE"))); Assert.False(matcher.IsMatch(new TestConfigNode("NODE") { { "name", "bleh" }, })); Assert.False(matcher.IsMatch(new ConfigNode("PART"))); Assert.False(matcher.IsMatch(new TestConfigNode("PART") { { "name", "blah" }, })); Assert.False(matcher.IsMatch(new TestConfigNode("PART") { { "name", "bleh" }, })); }
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)); } PatchContext context = new PatchContext(UrlConfig, databaseConfigs, logger, progress); for (LinkedListNode <IProtoUrlConfig> listNode = databaseConfigs.First; listNode != null; listNode = listNode.Next) { IProtoUrlConfig protoConfig = listNode.Value; try { if (!NodeMatcher.IsMatch(protoConfig.Node)) { continue; } if (loop) { logger.Info($"Looping on {UrlConfig.SafeUrl()} to {protoConfig.FullUrl}"); } do { progress.ApplyingUpdate(protoConfig, UrlConfig); listNode.Value = protoConfig = new ProtoUrlConfig(protoConfig.UrlFile, MMPatchLoader.ModifyNode(new NodeStack(protoConfig.Node), UrlConfig.config, context)); } while (loop && NodeMatcher.IsMatch(protoConfig.Node)); if (loop) { protoConfig.Node.RemoveNodes("MM_PATCH_LOOP"); } } catch (Exception ex) { progress.Exception(UrlConfig, $"Exception while applying update {UrlConfig.SafeUrl()} to {protoConfig.FullUrl}", ex); } } }
public void Apply(UrlDir.UrlFile file, IPatchProgress progress, IBasicLogger logger) { if (file == null) { throw new ArgumentNullException(nameof(file)); } if (progress == null) { throw new ArgumentNullException(nameof(progress)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } PatchContext context = new PatchContext(UrlConfig, file.root, logger, progress); for (int i = 0; i < file.configs.Count; i++) { UrlDir.UrlConfig urlConfig = file.configs[i]; try { if (!NodeMatcher.IsMatch(urlConfig.config)) { continue; } if (loop) { logger.Info($"Looping on {UrlConfig.SafeUrl()} to {urlConfig.SafeUrl()}"); } do { progress.ApplyingUpdate(urlConfig, UrlConfig); file.configs[i] = urlConfig = new UrlDir.UrlConfig(file, MMPatchLoader.ModifyNode(new NodeStack(urlConfig.config), UrlConfig.config, context)); } while (loop && NodeMatcher.IsMatch(urlConfig.config)); if (loop) { file.configs[i].config.RemoveNodes("MM_PATCH_LOOP"); } } catch (Exception ex) { progress.Exception(UrlConfig, $"Exception while applying update {UrlConfig.SafeUrl()} to {urlConfig.SafeUrl()}", ex); } } }
public void Apply(UrlDir.UrlFile file, IPatchProgress progress, IBasicLogger logger) { if (file == null) { throw new ArgumentNullException(nameof(file)); } if (progress == null) { throw new ArgumentNullException(nameof(progress)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } PatchContext context = new PatchContext(UrlConfig, file.root, logger, progress); // Avoid checking the new configs we are creating int count = file.configs.Count; for (int i = 0; i < count; i++) { UrlDir.UrlConfig url = file.configs[i]; try { if (!NodeMatcher.IsMatch(url.config)) { continue; } ConfigNode clone = MMPatchLoader.ModifyNode(new NodeStack(url.config), UrlConfig.config, context); if (url.config.HasValue("name") && url.config.GetValue("name") == clone.GetValue("name")) { progress.Error(UrlConfig, $"Error - when applying copy {UrlConfig.SafeUrl()} to {url.SafeUrl()} - the copy needs to have a different name than the parent (use @name = xxx)"); } else { progress.ApplyingCopy(url, UrlConfig); file.AddConfig(clone); } } catch (Exception ex) { progress.Exception(UrlConfig, $"Exception while applying copy {UrlConfig.SafeUrl()} to {url.SafeUrl()}", ex); } } }
public void TestIsMatch__Constraints() { NodeMatcher matcher = new NodeMatcher("NODE", "blah", "@FOO[bar*],#something[else]"); Assert.True(matcher.IsMatch(new TestConfigNode("NODE") { { "name", "blah" }, { "something", "else" }, new TestConfigNode("FOO") { { "name", "barbar" }, }, })); Assert.False(matcher.IsMatch(new TestConfigNode("NODE") { { "name", "blah" }, })); Assert.False(matcher.IsMatch(new TestConfigNode("NODE") { { "name", "blah" }, { "something", "else" }, })); Assert.False(matcher.IsMatch(new TestConfigNode("NODE") { { "name", "blah" }, new TestConfigNode("FOO") { { "name", "barbar" }, }, })); Assert.False(matcher.IsMatch(new TestConfigNode("NODE") { { "name", "bleh" }, { "something", "else" }, new TestConfigNode("FOO") { { "name", "barbar" }, }, })); Assert.False(matcher.IsMatch(new TestConfigNode("NADE") { { "name", "blah" }, { "something", "else" }, new TestConfigNode("FOO") { { "name", "barbar" }, }, })); }
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)); } PatchContext context = new PatchContext(UrlConfig, databaseConfigs, logger, progress); for (LinkedListNode <IProtoUrlConfig> listNode = databaseConfigs.First; listNode != null; listNode = listNode.Next) { IProtoUrlConfig protoConfig = listNode.Value; try { if (!NodeMatcher.IsMatch(protoConfig.Node)) { continue; } ConfigNode clone = MMPatchLoader.ModifyNode(new NodeStack(protoConfig.Node), UrlConfig.config, context); if (protoConfig.Node.GetValue("name") is string name && name == clone.GetValue("name")) { progress.Error(UrlConfig, $"Error - when applying copy {UrlConfig.SafeUrl()} to {protoConfig.FullUrl} - the copy needs to have a different name than the parent (use @name = xxx)"); } else { progress.ApplyingCopy(protoConfig, UrlConfig); listNode = databaseConfigs.AddAfter(listNode, new ProtoUrlConfig(protoConfig.UrlFile, clone)); } }
public void Apply(UrlDir.UrlFile file, IPatchProgress progress, IBasicLogger logger) { if (file == null) { throw new ArgumentNullException(nameof(file)); } if (progress == null) { throw new ArgumentNullException(nameof(progress)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } int i = 0; while (i < file.configs.Count) { UrlDir.UrlConfig url = file.configs[i]; try { if (NodeMatcher.IsMatch(url.config)) { progress.ApplyingDelete(url, UrlConfig); file.configs.RemoveAt(i); } else { i++; } } catch (Exception ex) { progress.Exception(UrlConfig, $"Exception while applying delete {UrlConfig.SafeUrl()} to {url.SafeUrl()}", ex); } } }
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); } } }