static HashSet <string> GetSelectionsBySamples(List <PathPattern> fileSamples, List <PathPattern> dirSamples)
        {
            List <PathPattern> samples = new List <PathPattern>();

            samples.AddRange(fileSamples);
            samples.AddRange(dirSamples);

            HashSet <string> hash = new HashSet <string>();

            for (int i = 0; i < samples.Count; i++)
            {
                PathPattern sample = samples[i];

                if (!Directory.Exists(sample.dir))
                {
                    DebugUtil.LogWarning("The directory isn't  exist : " + sample.dir);
                    continue;
                }

                string[] entries;
                if (i < fileSamples.Count)
                {
                    entries = FilePathTools.SelectEntries(FilePathTools.GetFiles(sample.dir, sample.regex, sample.searchOption), FILTER_META_REGEX);
                }
                else
                {
                    entries = FilePathTools.GetDirectories(sample.dir, sample.regex, sample.searchOption);
                }

                hash.UnionWith(entries);
                DebugUtil.Log("\"" + EditorCommonUtils.NormalizeDirectory(sample.dir) + sample.regex + "\" match " + (i < fileSamples.Count ? "files" : "directories") + " : " + entries.Length);
            }

            return(hash);
        }
Exemplo n.º 2
0
        public void Match_EmptyPattern()
        {
            var pattern = new PathPattern("");

            Assert.IsTrue(pattern.Match(""));
            Assert.IsFalse(pattern.Match("a"));
        }
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.Append('"');
            sb.Append(MatchPattern.ToString());
            sb.Append('"');
            sb.Append(" -> ");
            sb.Append('"');
            sb.Append(SubstitutionPattern);
            sb.Append('"');
            if (PathPattern != null)
            {
                sb.Append(" on files ");
                sb.Append('"');
                sb.Append(PathPattern.ToString());
                sb.Append('"');
            }
            if (MaximumRepeatCount > 0)
            {
                if (MaximumRepeatCount >= int.MaxValue)
                {
                    sb.Append(" repeated forever");
                }
                else
                {
                    sb.Append(" repeated up to ");
                    sb.Append(MaximumRepeatCount);
                    sb.Append(" times");
                }
            }
            return(sb.ToString());
        }
Exemplo n.º 4
0
            protected bool MatchDeleted(string path)
            {
                // Check path
                if (PathPattern.Match(path))
                {
                    // Also check file/folder DOES NOT exists since we might be watching for a folder/file with same path.
                    if (!PathExist(path))
                    {
                        // Notify CREATED if we had doubts previously
                        if (_mightBeQuicklyDeletedAfterCreate)
                        {
                            RegisterMatchingPath(path);
                            NotifyCreated(path);
                            _mightBeQuicklyDeletedAfterCreate = false;
                        }

                        return(true);
                    }

                    // If file/folder DO exist, there is two possibility:
                    //   1. The path might be used by a different entry type (folder/file).
                    //   2. The entry might have been quickly CREATED after DELETE.
                    // We will wait next events since second case will trigger CREATED after that.
                    _mightBeQuicklyCreatedAfterDelete = true;
                }

                // Other case can be reset
                _mightBeQuicklyDeletedAfterCreate = false;
                return(false);
            }
Exemplo n.º 5
0
 public PathChangedEventArgs(PathPattern watchedPathPattern, string path, string newPath = null, string oldPath = null)
 {
     WatchedPathPattern = watchedPathPattern;
     Path    = path;
     NewPath = newPath;
     OldPath = oldPath;
 }
Exemplo n.º 6
0
        public void TestIsMatchWithContentPattern(bool isMatchResult)
        {
            var          contnetPatternMock = NewMock <IHttpRequestContentPattern>();
            const string method             = "post";
            const string path         = "/";
            var          contentBytes = new byte[0];
            const string contentType  = "application/json";

            contnetPatternMock.Setup(x => x.IsMatch(contentBytes, contentType)).Returns(isMatchResult);

            var httpRequestMock = new HttpRequestMock
            {
                Method  = MethodPattern.Standart(method),
                Path    = PathPattern.Smart(path),
                Content = contnetPatternMock.Object,
                Query   = QueryPattern.Any(),
                Headers = HeadersPattern.Any()
            };
            var httpRequestPattern = new HttpRequestPattern(httpRequestMock);
            var httpRequestInfo    = new HttpRequest
            {
                Method       = method,
                Path         = path,
                ContentBytes = contentBytes,
                ContentType  = contentType
            };

            httpRequestPattern.IsMatch(httpRequestInfo).ShouldBeEquivalentTo(isMatchResult);
        }
Exemplo n.º 7
0
        public IEnumerable <IQuerySuggestion> Compute(SuggestionState state)
        {
            var expected = state.Expected.Find(item =>
                                               item.RuleIndices[0] == QueryParser.RULE_source);

            // make sure we are in the select part of a query
            if (expected == null)
            {
                return(Enumerable.Empty <IQuerySuggestion>());
            }

            // make sure we are in a path pattern
            if (state.Caret.ParentToken == null ||
                state.Caret.ParentToken.Type != QueryLexer.STRING)
            {
                return(Enumerable.Empty <IQuerySuggestion>());
            }

            // make sure the caret is in the pattern (not after the last quote)
            if (state.Caret.ParentOffset >= state.Caret.ParentToken.Text.Length &&
                state.Caret.ParentToken.Text[state.Caret.ParentOffset - 1] == '\"')
            {
                return(Enumerable.Empty <IQuerySuggestion>());
            }

            var patternParts = Split(state.Caret.ParentPrefix);

            // if the directory name at the caret is a pattern, don't suggest anything
            if (PathPattern.ContainsSpecialCharacters(patternParts.LastPart))
            {
                return(Enumerable.Empty <IQuerySuggestion>());
            }

            if (patternParts.LastPart.Length == 0)
            {
                patternParts.LastPart = "*";
            }
            else
            {
                patternParts.LastPart = "*" + patternParts.LastPart + "*";
            }

            try
            {
                var pattern = Path.Combine(patternParts.Prefix, patternParts.LastPart);
                var finder  = _fileSystem.CreateFileFinder(pattern);
                var result  = finder
                              .GetDirectories()
                              .Select(PathUtils.GetLastPart)
                              .Distinct()
                              .Select(name => new DirectorySuggestion(state.Caret, name));
                return(result);
            }
            catch (ArgumentException) // the pattern contains invalid characters
            {
                // suggestions should not throw for invalid input
                return(Enumerable.Empty <IQuerySuggestion>());
            }
        }
        public override void SetUp()
        {
            base.SetUp();

            httpRequestMockBuilder = new HttpRequestMockBuilder();
            httpRequestMockBuilder.Method(MethodPattern.Standart("GET"));
            httpRequestMockBuilder.Path(PathPattern.Smart("/"));
        }
Exemplo n.º 9
0
        public bool IsMatch(HttpContext httpContext)
        {
            if (httpContext.Request.HttpMethod == HttpMethod && PathPattern.IsMatch(httpContext.Request.Path))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 10
0
        public IEnumerable <string> GetFolders(PathPattern pathPattern)
        {
            if (!Directory.Exists(pathPattern.FolderPath))
            {
                return(Enumerable.Empty <string>());
            }

            return(Directory.GetDirectories(pathPattern.FolderPath, pathPattern.NamePattern));
        }
Exemplo n.º 11
0
        protected void SetFileNamePattern(PathPattern pattern)
        {
            PathPattern = pattern;

            var file_system = PreferencesPage.Add(new Section("file-system", Catalog.GetString("File Organization"), 5));

            file_system.Add(new SchemaPreference <string> (pattern.FolderSchema, Catalog.GetString("Folder hie_rarchy")));
            file_system.Add(new SchemaPreference <string> (pattern.FileSchema, Catalog.GetString("File _name")));
        }
Exemplo n.º 12
0
        public void Match_DifferentOrderOfRecursiveGeneralPatternWithNonRecursivePattern()
        {
            var pattern = new PathPattern("*/**");

            Assert.IsFalse(pattern.Match(""));
            Assert.IsTrue(pattern.Match("a"));
            Assert.IsTrue(pattern.Match("abcd"));
            Assert.IsTrue(pattern.Match("ab/cd"));
            Assert.IsTrue(pattern.Match("ab/cd/efg"));
        }
Exemplo n.º 13
0
        public void Match_RecursiveGeneralPatternWithNonRecursivePattern()
        {
            var pattern = new PathPattern("**/*");

            Assert.IsFalse(pattern.Match(""));
            Assert.IsTrue(pattern.Match("a"));
            Assert.IsTrue(pattern.Match("abcd"));
            Assert.IsTrue(pattern.Match("ab/cd"));
            Assert.IsTrue(pattern.Match("ab/cd/efg"));
            Assert.IsFalse(pattern.Match("a//b"));
        }
Exemplo n.º 14
0
        public void Match_MultipleGeneralPatternsInSuccession()
        {
            var pattern = new PathPattern("a/**/**/b");

            Assert.IsFalse(pattern.Match("a"));
            Assert.IsFalse(pattern.Match("b"));
            Assert.IsTrue(pattern.Match("a/b"));
            Assert.IsFalse(pattern.Match("a//b"));
            Assert.IsFalse(pattern.Match("a///b"));
            Assert.IsFalse(pattern.Match(@"a\\b"));
        }
Exemplo n.º 15
0
        public void Match_StarPatternWontMatchEmptyString()
        {
            var pattern = new PathPattern("a/*/b");

            Assert.IsFalse(pattern.Match("a"));
            Assert.IsFalse(pattern.Match("a/"));
            Assert.IsFalse(pattern.Match("a/b"));
            Assert.IsFalse(pattern.Match("a//b"));
            Assert.IsFalse(pattern.Match("a\\\\b"));
            Assert.IsTrue(pattern.Match("a/c/b"));
        }
Exemplo n.º 16
0
        public void Match_CombinedPattern()
        {
            var pattern = new PathPattern("C:/a/**/b*/c");

            Assert.IsFalse(pattern.Match("C:/a"));
            Assert.IsFalse(pattern.Match("C:/a/c"));
            Assert.IsTrue(pattern.Match("C:/a/b/c"));
            Assert.IsTrue(pattern.Match("C:/a/bx/c"));
            Assert.IsTrue(pattern.Match("C:/a/bxy/c"));
            Assert.IsTrue(pattern.Match("C:/a/x/b/c"));
            Assert.IsFalse(pattern.Match("C:/a/x/b"));
        }
Exemplo n.º 17
0
        public void Match_StartsWithPattern()
        {
            var pattern = new PathPattern("a?b*c/**");

            Assert.IsFalse(pattern.Match(""));
            Assert.IsFalse(pattern.Match("a"));
            Assert.IsFalse(pattern.Match("ab"));
            Assert.IsFalse(pattern.Match("abc"));
            Assert.IsTrue(pattern.Match("axbc"));
            Assert.IsTrue(pattern.Match("axbc/yz"));
            Assert.IsFalse(pattern.Match("abc/yz/uv"));
        }
Exemplo n.º 18
0
        public void Match_GeneralPatternAtTheEnd()
        {
            var pattern = new PathPattern("a/**");

            Assert.IsTrue(pattern.Match("a"));
            Assert.IsTrue(pattern.Match("a/"));
            Assert.IsTrue(pattern.Match("a/b"));
            Assert.IsTrue(pattern.Match("a/b/c"));
            Assert.IsFalse(pattern.Match("b/a"));
            Assert.IsFalse(pattern.Match("b"));
            Assert.IsFalse(pattern.Match(""));
        }
Exemplo n.º 19
0
                    private IEnumerable <IFile> GetMatching(string rawPattern)
                    {
                        PathPattern pattern = new PathPattern(rawPattern);

                        foreach (KeyValuePair <PathPart, FakeFile> kv in this.fakeFiles)
                        {
                            if (pattern.Matches(kv.Key))
                            {
                                yield return(kv.Value);
                            }
                        }
                    }
Exemplo n.º 20
0
 internal HttpRequestMockBuilder()
 {
     httpRequestMock = new HttpRequestMock
     {
         Method  = MethodPattern.Any(),
         Path    = PathPattern.Any(),
         Query   = QueryPattern.Any(),
         Content = ContentPattern.Any(),
         Headers = HeadersPattern.Any()
     };
     httpResponseMockBuilder = new HttpResponseMockBuilder(200);
 }
Exemplo n.º 21
0
        public void Match_JustTheStarPattern()
        {
            var pattern = new PathPattern("*");

            Assert.IsFalse(pattern.Match(""));
            Assert.IsFalse(pattern.Match("/"));
            Assert.IsTrue(pattern.Match("a"));
            Assert.IsTrue(pattern.Match("a/"));
            Assert.IsFalse(pattern.Match("a/b"));
            Assert.IsFalse(pattern.Match("a/b/c"));
            Assert.IsFalse(pattern.Match("c/a/b"));
        }
Exemplo n.º 22
0
        public void Match_PathWithGeneralPattern()
        {
            var pattern = new PathPattern("C:/a/**/c");

            Assert.IsFalse(pattern.Match("C:/a"));
            Assert.IsTrue(pattern.Match("C:/a/c"));
            Assert.IsFalse(pattern.Match("C:/ac"));
            Assert.IsFalse(pattern.Match("C:/a/bc"));
            Assert.IsFalse(pattern.Match("C:/ab/c"));
            Assert.IsTrue(pattern.Match("C:/a/x/c"));
            Assert.IsTrue(pattern.Match("C:/a/x/y/c"));
            Assert.IsFalse(pattern.Match("C:/a/x/y"));
        }
Exemplo n.º 23
0
        public void Match_PathWithOneQuestionMarkPattern()
        {
            var pattern = new PathPattern("C:/a/b?/c");

            Assert.IsFalse(pattern.Match("C:/a"));
            Assert.IsFalse(pattern.Match("C:/a/c"));
            Assert.IsFalse(pattern.Match("C:/a/x/c"));
            Assert.IsFalse(pattern.Match("C:/a/b/c"));
            Assert.IsTrue(pattern.Match("C:/a/bx/c"));
            Assert.IsTrue(pattern.Match("C:\\a\\bx/c\\"));
            Assert.IsFalse(pattern.Match("C:/a/bxy/c"));
            Assert.IsFalse(pattern.Match("C:/a/bxyz/c"));
        }
Exemplo n.º 24
0
        public void Match_PathWithOneAsteriskPattern()
        {
            var pattern = new PathPattern("C:/a/b*/c");

            Assert.IsFalse(pattern.Match("C:/a"));
            Assert.IsFalse(pattern.Match("C:/a/c"));
            Assert.IsFalse(pattern.Match("C:/a/x/c"));
            Assert.IsTrue(pattern.Match("C:/a/b/c"));
            Assert.IsTrue(pattern.Match("C:/a\\b/c\\"));
            Assert.IsTrue(pattern.Match("C:/a/bx/c"));
            Assert.IsTrue(pattern.Match("C:/a/bxy/c"));
            Assert.IsTrue(pattern.Match("C:/a/bxyz/c"));
        }
Exemplo n.º 25
0
        public void Match_PathWithoutPattern()
        {
            var pattern = new PathPattern("C:/directory/a/b/c");

            Assert.IsFalse(pattern.Match("C:/"));
            Assert.IsFalse(pattern.Match("C:/directory"));
            Assert.IsFalse(pattern.Match("C:/directory/a"));
            Assert.IsFalse(pattern.Match("C:/directory/a/b"));
            Assert.IsTrue(pattern.Match("C:/directory/a/b/c"));
            Assert.IsTrue(pattern.Match("C:/directory/a/b/c/"));
            Assert.IsTrue(pattern.Match("C:\\directory\\a\\b\\c"));
            Assert.IsTrue(pattern.Match("C:\\directory\\a\\b\\c\\"));
        }
        public override string[] Handle(DirectoryEnumerateEntriesArguments arguments)
        {
            Guard.NotNull(arguments, nameof(arguments));

            DirectoryEntry directory = ResolveDirectory(arguments.Path);

            PathPattern pattern = PathPattern.Create(arguments.SearchPattern);

            IEnumerable <string> absoluteNames =
                EnumerateEntriesInDirectory(directory, pattern, arguments.Path, arguments.SearchOption, arguments.Filter);

            return(ToRelativeNames(absoluteNames, arguments.Path, arguments.IncomingPath).ToArray());
        }
Exemplo n.º 27
0
        public void Match_EndsWithPattern()
        {
            var pattern = new PathPattern("**/a?b*c");

            Assert.IsFalse(pattern.Match(""));
            Assert.IsFalse(pattern.Match("a"));
            Assert.IsFalse(pattern.Match("ab"));
            Assert.IsFalse(pattern.Match("abc"));
            Assert.IsTrue(pattern.Match("axbc"));
            Assert.IsTrue(pattern.Match("yz/axbc"));
            Assert.IsTrue(pattern.Match("yz/uv/axbc"));
            Assert.IsFalse(pattern.Match("axbc/uv"));
        }
Exemplo n.º 28
0
        public override object Invoke(object[] args)
        {
            var path = args[0].ToString();

            if (string.IsNullOrWhiteSpace(path))
            {
                return(null);
            }

            var pattern = new PathPattern(path);
            var parent  = pattern.GetParent();

            return(parent?.Text);
        }
Exemplo n.º 29
0
        public void Match_JustTheQuestionMarkPattern()
        {
            var pattern = new PathPattern("?");

            Assert.IsFalse(pattern.Match(""));
            Assert.IsFalse(pattern.Match("/"));
            Assert.IsTrue(pattern.Match("a"));
            Assert.IsTrue(pattern.Match("b"));
            Assert.IsTrue(pattern.Match("a/"));
            Assert.IsFalse(pattern.Match("ab"));
            Assert.IsFalse(pattern.Match("a/b"));
            Assert.IsFalse(pattern.Match("a/b/c"));
            Assert.IsFalse(pattern.Match("c/a/b"));
        }
Exemplo n.º 30
0
        public void Match_JustTheGeneralPattern()
        {
            var pattern = new PathPattern("**");

            Assert.IsTrue(pattern.Match(""));
            Assert.IsTrue(pattern.Match("/"));
            Assert.IsTrue(pattern.Match("a"));
            Assert.IsTrue(pattern.Match("a/b"));
            Assert.IsTrue(pattern.Match("a/b/c"));
            Assert.IsTrue(pattern.Match("c/a/b"));
            Assert.IsTrue(pattern.Match("//"));
            Assert.IsTrue(pattern.Match("/\\"));
            Assert.IsTrue(pattern.Match("/\\/"));
            Assert.IsFalse(pattern.Match("c//a/b"));
        }