private IEnumerable <SituationEdge <T> > DevelopRuleInputEdges(string RuleName) { ProcessingQueue <string, SituationEdge <T> > queue; queue = new ProcessingQueue <string, SituationEdge <T> >(); queue.Add(RuleName); queue.Process((q, ruleName) => { foreach (IRule <T> rule in GetRootNodes(ruleName).Select(item => item.Rule)) { foreach (SituationEdge <T> edge in GetRuleInputEdges(rule)) { q.AddResult(edge); if (!(edge.Predicate is INonTerminalPredicate <T> nonTerminal)) { continue; } q.Add(nonTerminal.Name); } } }); return(queue.Results); }
private async Task LoadBranches(DirectoryInfo sourceDirectory, string outputDirectoryName, bool testRun) { DirectoryInfo branchDirectory = new (Path.Combine(sourceDirectory.FullName, "NC Branches")); if (!branchDirectory.Exists) { _logger.LogError("Unable to locate NC Branches directory at path {path}", branchDirectory); throw new ApplicationException($"Unable to locate NC Branches directory at path { branchDirectory }"); } var fileTasks = branchDirectory.GetDirectories("*", SearchOption.TopDirectoryOnly) .Select(d => d.GetFiles()) .SelectMany(fi => fi.Select(f => Task.Run(() => ConstructOutputFile(f, outputDirectoryName, StatementType.NcBranch, testRun)))); var topLevelFileTasks = branchDirectory.GetFiles() .Select(f => Task.Run(() => ConstructOutputFile(f, outputDirectoryName, StatementType.NcBranch, testRun))); var files = await Task.WhenAll(fileTasks.Concat(topLevelFileTasks)); await _processingQueue.Add(files); }
public void ShouldAddAndContains() { ProcessingQueue <string, string> queue; queue = new ProcessingQueue <string, string>( ); for (int t = 0; t < 10; t++) { Assert.IsFalse(queue.Contains(t.ToString())); queue.Add(t.ToString()); Assert.IsTrue(queue.Contains(t.ToString())); } }
public void ShouldProcess() { ProcessingQueue <string, string> queue; string[] results; queue = new ProcessingQueue <string, string>(); for (int t = 0; t < 10; t++) { queue.Add(t.ToString()); } queue.Process((q, item) => { q.Add(item); q.AddResult(item); }); results = queue.Results.ToArray(); Assert.AreEqual(10, results.Length); for (int t = 0; t < 10; t++) { Assert.AreEqual(t.ToString(), results[t]); } }
public void Add(ITerminalRangeInput <T> Range) { ProcessingQueue <ITerminalRangeInput <T>, bool> queue; ITerminalRangeInput <T> existingRange; queue = new ProcessingQueue <ITerminalRangeInput <T>, bool>(); queue.Add(Range); queue.Process((q, range) => { for (int t = 0; t < items.Count; t++) { existingRange = items[t]; if ((range.LastValue.CompareTo(existingRange.FirstValue) < 0) || (range.FirstValue.CompareTo(existingRange.LastValue) > 0)) { continue; } // englobed if ((range.FirstValue.CompareTo(existingRange.FirstValue) >= 0) && (range.LastValue.CompareTo(existingRange.LastValue) <= 0)) { items.RemoveAt(t); if (range.FirstValue.CompareTo(existingRange.FirstValue) > 0) { items.Insert(t, provider.CreateTerminalRangeInput(existingRange.FirstValue, provider.GetPreviousValue(range.FirstValue))); t++; } items.Insert(t, range); t++; if (range.LastValue.CompareTo(existingRange.LastValue) < 0) { items.Insert(t, provider.CreateTerminalRangeInput(provider.GetNextValue(range.LastValue), existingRange.LastValue)); t++; } return; } // englobing if ((range.FirstValue.CompareTo(existingRange.FirstValue) <= 0) && (range.LastValue.CompareTo(existingRange.LastValue) >= 0)) { if (range.FirstValue.CompareTo(existingRange.FirstValue) < 0) { items.Insert(t, provider.CreateTerminalRangeInput(range.FirstValue, provider.GetPreviousValue(existingRange.FirstValue))); } t++; if (range.LastValue.CompareTo(existingRange.LastValue) > 0) { q.Add(provider.CreateTerminalRangeInput(provider.GetNextValue(existingRange.LastValue), range.LastValue)); } return; } // left if (range.FirstValue.CompareTo(existingRange.FirstValue) < 0) { items.RemoveAt(t); items.Insert(t, provider.CreateTerminalRangeInput(range.FirstValue, provider.GetPreviousValue(existingRange.FirstValue))); t++; items.Insert(t, provider.CreateTerminalRangeInput(existingRange.FirstValue, range.LastValue)); t++; items.Insert(t, provider.CreateTerminalRangeInput(provider.GetNextValue(range.LastValue), existingRange.LastValue)); t++; return; } // right if (range.FirstValue.CompareTo(existingRange.FirstValue) > 0) { items.RemoveAt(t); items.Insert(t, provider.CreateTerminalRangeInput(existingRange.FirstValue, provider.GetPreviousValue(range.FirstValue))); t++; items.Insert(t, provider.CreateTerminalRangeInput(range.FirstValue, existingRange.LastValue)); t++; q.Add(provider.CreateTerminalRangeInput(provider.GetNextValue(existingRange.LastValue), range.LastValue)); t++; return; } } items.Add(range); }); }