using KssSmaPlaLib.Commons; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace KssSmaPlaLib.InBox { public class SheetFilterUxer : IFilterUxer { private readonly HashSet includedSheets; private readonly HashSet excludedSheets; public SheetFilterUxer(IEnumerable included, IEnumerable excluded) { includedSheets = new HashSet(included ?? Enumerable.Empty()); excludedSheets = new HashSet(excluded ?? Enumerable.Empty()); } public IEnumerable ApplyFilter(IEnumerable sheetNames) { if (includedSheets.Any()) { // Included優先 → lineNamesの中でincludedに含まれるものだけ返す //return sheetNames.Where(name => includedSheets.Contains(name)); // ワイルドカード(*)ありとする! List listA = new List(); foreach (var name in sheetNames) { foreach (var iName in includedSheets) { if (StringUxer.WildcardMatch(name, iName)) { listA.Add(name); break; } } } return listA; } // Excluded適用 → lineNamesの中でexcludedに含まれないものだけ返す //return sheetNames.Where(name => !excludedSheets.Contains(name)); // ワイルドカード(*)ありとする! List listB = new List(); foreach (var name in sheetNames) { var isMatch = false; foreach (var eName in excludedSheets) { if (StringUxer.WildcardMatch(name, eName)) { isMatch = true; break; } } if (!isMatch) listB.Add(name); } return listB; } public bool CanPass(string sheetName) { return HasAnyPass(new[] { sheetName }); } public bool HasAnyPass(IEnumerable sheetNames) { return ApplyFilter(sheetNames).Any(); } } }