private static DirectoryScanOptions ReadDirectoryScanOptions(ScanFilterOptions globalExcludes, SetRecord set) { if (set == null) { return(null); } if (!set.TryGetValue("path", out RecordBase pathRecord) || !set.TryGetValue("depth", out RecordBase depthRecord)) { return(null); } if (!(pathRecord is ScalerRecord pathScaler) || !(depthRecord is ScalerRecord depthScaler)) { return(null); } if (!pathScaler.TryReadAs(out string path) || !depthScaler.TryReadAs(out int depth)) { return(null); } if (depth <= 0) { depth = 1; } ScanFilterOptions includeOptions; ScanFilterOptions excludeOptions; if (set.TryGetValue("include", out RecordBase includeRecordBase) && includeRecordBase is SetRecord includeRecord) { includeOptions = ReadFilterOptions(includeRecord); } else { includeOptions = ScanFilterOptions.CreateIncludeDefault(); } if (set.TryGetValue("exclude", out RecordBase excludeRecordBase) && excludeRecordBase is SetRecord excludeRecord) { excludeOptions = ReadFilterOptions(excludeRecord); } else { excludeOptions = ScanFilterOptions.CreateExcludeDefault(); } bool ignoreGlobalExclude = false; if (set.TryGetValue("ignoreGlobalExclude", out RecordBase ignoreGlobalExcludeBase) && ignoreGlobalExcludeBase is ScalerRecord ignoreGlobalExcludeScaler && ignoreGlobalExcludeScaler.TryReadAs <bool>(out bool ignoreGlobalExcludeValue)) { ignoreGlobalExclude = ignoreGlobalExcludeValue; } if (!ignoreGlobalExclude) { excludeOptions.Combine(globalExcludes); } return(new DirectoryScanOptions(path, depth, includeOptions, excludeOptions)); }
public static IConfiguartion Read(SetRecord set) { if (set == null) { throw new ArgumentNullException(nameof(set)); } RecordBase record; SetRecord setIncludeItems = null; SetRecord setGlobalExcludes = null; ListRecord setScanDirectories = null; if (set.TryGetValue("scan", out record)) { setScanDirectories = record as ListRecord; } if (set.TryGetValue("include", out record)) { setIncludeItems = record as SetRecord; } if (set.TryGetValue("exclude", out record)) { setGlobalExcludes = record as SetRecord; } ItemIncludeOptions resultInclude = ReadItemIncludeOptions(setIncludeItems); ScanFilterOptions resultExclude = null; if (setGlobalExcludes == null) { resultExclude = ScanFilterOptions.CreateExcludeDefault(); } else { resultExclude = ReadFilterOptions(setGlobalExcludes); } List <DirectoryScanOptions> resultScanDirectories = new List <DirectoryScanOptions>(); if (setScanDirectories != null) { foreach (RecordBase scanOptions in setScanDirectories) { if (scanOptions is SetRecord setScanOptions) { resultScanDirectories.Add(ReadDirectoryScanOptions(resultExclude, setScanOptions)); } } } return(new Configuration(resultExclude, resultInclude, resultScanDirectories)); }