コード例 #1
0
        public IEnumerable <InsqlDescriptor> GetDescriptors()
        {
            var optionsValue = this.options.Value;

            if (!optionsValue.Enabled)
            {
                return(new List <InsqlDescriptor>());
            }

            if (string.IsNullOrWhiteSpace(optionsValue.Matches))
            {
                throw new ArgumentNullException(nameof(optionsValue.Matches), $"{nameof(ExternalDescriptorOptions)} `Matches` is null!");
            }

            GlobMatcher globMatcher = new GlobMatcher(optionsValue.Matches, new GlobMatcherOptions
            {
                AllowWindowsPaths = true
            });

            var directory = optionsValue.Directory;

            if (string.IsNullOrWhiteSpace(directory))
            {
                directory = AppDomain.CurrentDomain.BaseDirectory;
            }

            if (!Path.IsPathRooted(directory))
            {
                directory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, directory);
            }

            var fileNames = Directory.EnumerateFiles(directory, "*", SearchOption.AllDirectories).Where(path => globMatcher.IsMatch(path)).ToList();

            return(fileNames.Select(path =>
            {
                if (!File.Exists(path))
                {
                    return null;
                }

                using (var stream = File.OpenRead(path))
                {
                    return InsqlDescriptorXmlParser.Instance.ParseDescriptor(stream, optionsValue.Namespace);
                }
            }).Where(item => item != null).ToList());
        }
コード例 #2
0
        public void Rejects(string glob, string path)
        {
            var matcher = new GlobMatcher(new GlobParser().Parse(glob), true);

            Assert.That(matcher.IsMatch(path.Split('/')), Is.False);
        }