Exemplo n.º 1
0
        public void TestVSTSBug936228()
        {
            var evaluator = FileNameEvalutor.CreateFileNameEvaluator(new string [] { "Makefile|Makefile.am|Makefile.in" });

            Assert.IsTrue(evaluator.SupportsFile("Makefile.am"));
            Assert.IsTrue(evaluator.SupportsFile("/Makefile"));
            Assert.IsTrue(evaluator.SupportsFile("/a/b/Makefile.in"));
            Assert.IsFalse(evaluator.SupportsFile("NoMakefile.am"));
        }
Exemplo n.º 2
0
        public void SimplePattern(string[] patterns, string[] matches, string[] nonMatches)
        {
            var fileNameEvalutor = FileNameEvalutor.CreateFileNameEvaluator(patterns, ',');

            foreach (var p in matches)
            {
                Assert.IsTrue(fileNameEvalutor.SupportsFile(p), "File name '" + p + "' did not match");
            }
            foreach (var p in nonMatches)
            {
                Assert.IsFalse(fileNameEvalutor.SupportsFile(p), "File name '" + p + "' should not match");
            }
        }
Exemplo n.º 3
0
        public bool CanHandle(FilePath filePath, string mimeType)
        {
            if (fileExtensions == null)
            {
                fileExtensions = ParseList(FileExtension);
                mimeTypes      = ParseList(MimeType);
                var filePatterns = ParseList(FilePattern);
                if (filePatterns.Length > 0)
                {
                    patternEvaluator = FileNameEvalutor.CreateFileNameEvaluator(filePatterns, ',');
                }
            }

            if (fileExtensions.Contains("*") || mimeTypes.Contains("*") || FilePattern == "*")
            {
                return(true);
            }

            if (fileExtensions.Length > 0)
            {
                string ext = System.IO.Path.GetExtension(filePath);
                foreach (var allowedExtension in fileExtensions)
                {
                    if (string.Equals(ext, allowedExtension, StringComparison.OrdinalIgnoreCase))
                    {
                        return(true);
                    }
                }
            }

            if (mimeTypes.Length > 0)
            {
                IEnumerable <string> mimeTypeChain;
                if (!string.IsNullOrEmpty(mimeType))
                {
                    mimeTypeChain = IdeServices.DesktopService.GetMimeTypeInheritanceChain(mimeType);
                }
                else
                {
                    mimeTypeChain = IdeServices.DesktopService.GetMimeTypeInheritanceChainForFile(filePath);
                }
                foreach (var mt in mimeTypeChain)
                {
                    foreach (var allowedMime in mimeTypes)
                    {
                        if (mt == allowedMime)
                        {
                            return(true);
                        }
                    }
                }
            }

            if (patternEvaluator != null)
            {
                string name = filePath.FileName;
                if (patternEvaluator.SupportsFile(name))
                {
                    return(true);
                }
            }

            return(false);
        }