public void DirectoryEnumeratorConstructorTest1()
        {
            DirectoryInfo       di     = new DirectoryInfo("C:\\test");
            DirectoryEnumerator target = new DirectoryEnumerator(di);

            Assert.IsNotNull(target);
        }
示例#2
0
        public DnxProjectSystem(OmnisharpWorkspace workspace,
                                IOmnisharpEnvironment env,
                                IOptions <OmniSharpOptions> optionsAccessor,
                                ILoggerFactory loggerFactory,
                                IMetadataFileReferenceCache metadataFileReferenceCache,
                                IApplicationLifetime lifetime,
                                IFileSystemWatcher watcher,
                                IEventEmitter emitter,
                                DnxContext context)
        {
            _workspace = workspace;
            _env       = env;
            _logger    = loggerFactory.CreateLogger <DnxProjectSystem>();
            _metadataFileReferenceCache = metadataFileReferenceCache;
            _options  = optionsAccessor.Options;
            _dnxPaths = new DnxPaths(env, _options, loggerFactory);
            _designTimeHostManager = new DesignTimeHostManager(loggerFactory, _dnxPaths);
            _packagesRestoreTool   = new PackagesRestoreTool(_options, loggerFactory, emitter, context, _dnxPaths);
            _context             = context;
            _watcher             = watcher;
            _emitter             = emitter;
            _directoryEnumerator = new DirectoryEnumerator(loggerFactory);

            lifetime.ApplicationStopping.Register(OnShutdown);
        }
        public void SetUp()
        {
            directoryEnumerator = new DirectoryEnumerator();
            temporaryDirectory  = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + "\\");
            Directory.CreateDirectory(temporaryDirectory);

            f1 = Path.GetRandomFileName() + ".js";
            f2 = Path.GetRandomFileName() + ".js";
            f3 = Path.GetRandomFileName() + ".css";
            f4 = Path.GetRandomFileName() + ".css";
            f5 = Path.GetRandomFileName() + "-vsdoc.js";


            File.CreateText(temporaryDirectory + f1).Dispose();
            File.CreateText(temporaryDirectory + f2).Dispose();
            File.CreateText(temporaryDirectory + f3).Dispose();
            File.CreateText(temporaryDirectory + f4).Dispose();
            File.CreateText(temporaryDirectory + f5).Dispose();

            var sw = new StreamWriter(temporaryDirectory + "ordering.txt", false, System.Text.Encoding.UTF8);

            sw.WriteLine(f1);
            sw.WriteLine(f2);
            sw.WriteLine(f3);
            sw.WriteLine(f4);
            sw.WriteLine(f5);
            sw.WriteLine("ordering.txt");
            sw.Dispose();
        }
        public void ResetTest()
        {
            DirectoryInfo       di     = null;                        // TODO: Initialize to an appropriate value
            DirectoryEnumerator target = new DirectoryEnumerator(di); // TODO: Initialize to an appropriate value

            target.Reset();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
        public void DirectoryEnumeratorConstructorTest()
        {
            DirectoryInfo       di     = new DirectoryInfo("C:\\test");
            Node                node   = new Node(null, di);
            DirectoryEnumerator target = new DirectoryEnumerator(node);

            Assert.IsNotNull(target);
        }
        public void CurrentTest()
        {
            DirectoryInfo       di     = null;                        // TODO: Initialize to an appropriate value
            DirectoryEnumerator target = new DirectoryEnumerator(di); // TODO: Initialize to an appropriate value
            Node actual;

            actual = target.Current;
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
示例#7
0
        internal static NativeMethods.WIN32_FIND_DATA GetExtendedNonRootDirectoryInfo(string path, out Exception exception)
        {
            exception = null;
            NativeMethods.WIN32_FIND_DATA win32_FIND_DATA = default(NativeMethods.WIN32_FIND_DATA);
            DirectoryInfo di = null;

            exception = MountPointUtil.HandleIOExceptions(delegate
            {
                di = new DirectoryInfo(path);
            });
            if (exception != null)
            {
                return(win32_FIND_DATA);
            }
            if (!di.Exists)
            {
                exception = new DirectoryNotFoundException();
                return(win32_FIND_DATA);
            }
            if (di.Parent == null)
            {
                DiagCore.RetailAssert(false, "An invalid root path was passed in: {0}", new object[]
                {
                    path
                });
                exception = new IOException(string.Format("An invalid root path was passed in: {0}", path));
                return(win32_FIND_DATA);
            }
            NativeMethods.WIN32_FIND_DATA result;
            using (DirectoryEnumerator dirEnum = new DirectoryEnumerator(di.Parent, false, false))
            {
                bool foundNext = false;
                NativeMethods.WIN32_FIND_DATA tempFindData = default(NativeMethods.WIN32_FIND_DATA);
                string dirName;
                exception = MountPointUtil.HandleIOExceptions(delegate
                {
                    foundNext = dirEnum.GetNextDirectoryExtendedInfo(di.Name, out dirName, out tempFindData);
                });
                if (exception != null)
                {
                    result = win32_FIND_DATA;
                }
                else if (!foundNext)
                {
                    exception = new DirectoryNotFoundException();
                    result    = win32_FIND_DATA;
                }
                else
                {
                    exception = null;
                    result    = tempFindData;
                }
            }
            return(result);
        }
        public void TestMethod1()
        {
            DirectoryInfo       info = new DirectoryInfo("C:\\Test");
            DirectoryNode       node = new DirectoryNode(info);
            DirectoryEnumerator iter = new DirectoryEnumerator(node);

            while (iter.MoveNext() != null)
            {
                Console.WriteLine(iter.Current.Current.FullName);
            }
        }
        public void MoveNextTest()
        {
            DirectoryInfo       di     = null;                        // TODO: Initialize to an appropriate value
            DirectoryEnumerator target = new DirectoryEnumerator(di); // TODO: Initialize to an appropriate value
            bool expected = false;                                    // TODO: Initialize to an appropriate value
            bool actual;

            actual = target.MoveNext();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
示例#10
0
    public static IEnumerable <DirectoryInfo> GetDirectories(DirectoryInfo directoryInfo, bool recurse = true)
    {
        var directoryEnumerator        = new DirectoryEnumerator();
        var eventEnumeratingEnumerable = new EventEnumerator <DirectoryInfo>();

        eventEnumeratingEnumerable.Action(() => { directoryEnumerator.Enumerate(directoryInfo, recurse); });
        directoryEnumerator.OnNewDirectory +=
            (sender, eventHandler) =>
        {
            eventEnumeratingEnumerable.Callback(((DirectoryEventArgs)eventHandler).DirectoryInfo);
        };
        return(eventEnumeratingEnumerable);
    }
示例#11
0
        internal static bool IsDirectoryMountPoint(string path, out Exception exception)
        {
            exception = null;
            DirectoryInfo di = null;

            exception = MountPointUtil.HandleIOExceptions(delegate
            {
                di = new DirectoryInfo(path);
            });
            if (exception != null)
            {
                return(false);
            }
            if (!di.Exists)
            {
                return(false);
            }
            if (!BitMasker.IsOn((int)di.Attributes, 1024))
            {
                return(false);
            }
            if (di.Parent == null)
            {
                return(false);
            }
            using (DirectoryEnumerator dirEnum = new DirectoryEnumerator(di.Parent, false, false))
            {
                NativeMethods.WIN32_FIND_DATA findData = default(NativeMethods.WIN32_FIND_DATA);
                bool   foundNext = false;
                string dirName;
                exception = MountPointUtil.HandleIOExceptions(delegate
                {
                    foundNext = dirEnum.GetNextDirectoryExtendedInfo(di.Name, out dirName, out findData);
                });
                if (exception != null)
                {
                    return(false);
                }
                if (!foundNext)
                {
                    return(false);
                }
                if (findData.Reserved0 == 2684354563U)
                {
                    return(true);
                }
            }
            return(false);
        }
            public void ShouldOnlyContainFilesMatchingPattern()
            {
                // Arrange
                var dir = CreateDirectory();
                var sut = new DirectoryEnumerator();

                // Act
                var actual = sut.Files(dir, "*.ext", true);

                // Assert
                var expected = new[] { "d.ext" }.Select(x => Path.Combine(dir, x)).ToList();

                Assert.Equal(expected, actual);

                RemoveDirectory(dir);
            }
            public void ShouldContainAllFilesOfRoot()
            {
                // Arrange
                var dir = CreateDirectory();
                var sut = new DirectoryEnumerator();

                // Act
                var actual = sut.Files(dir, "*.*", false);

                // Assert
                var expected = new[] { "a.txt", "d.ext" }.Select(x => Path.Combine(dir, x)).ToList();

                Assert.Equal(expected, actual);

                RemoveDirectory(dir);
            }
            public void ShouldContainAllFilesOfNestedFolders()
            {
                // Arrange
                var dir = CreateDirectory();
                var sut = new DirectoryEnumerator();

                // Act
                var actual = sut.Files(dir, "*.*", true).OrderBy(x => x).ToList();

                // Assert
                var expected = new[] { "a.txt", Path.Combine("sub", "b.txt"), Path.Combine("sub2", "c.txt"), "d.ext" }
                .Select(x => Path.Combine(dir, x)).OrderBy(x => x).ToList();

                Assert.Equal(expected, actual);

                RemoveDirectory(dir);
            }
示例#15
0
        internal static bool IsDirectoryNonExistentOrEmpty(string directory, out Exception exception)
        {
            DirectoryInfo di = null;

            exception = MountPointUtil.HandleIOExceptions(delegate
            {
                di = new DirectoryInfo(directory);
            });
            if (exception != null)
            {
                MountPointUtil.Tracer.TraceError <string, Exception>(0L, "IsDirectoryNonExistentOrEmpty(): Failed to construct DirectoryInfo for directory '{0}'. Exception: {1}", directory, exception);
                return(false);
            }
            if (!di.Exists)
            {
                MountPointUtil.Tracer.TraceDebug <string>(0L, "IsDirectoryNonExistentOrEmpty(): Directory '{0}' is not present. Returning true.", directory);
                return(true);
            }
            bool result;

            using (DirectoryEnumerator dirEnum = new DirectoryEnumerator(di, false, false))
            {
                int count = 0;
                exception = MountPointUtil.HandleIOExceptions(delegate
                {
                    count = dirEnum.EnumerateFilesAndDirectoriesExcludingHiddenAndSystem("*").Count <string>();
                });
                if (exception != null)
                {
                    MountPointUtil.Tracer.TraceError <string, Exception>(0L, "IsDirectoryNonExistentOrEmpty(): Failed to enumerate files/directories for directory '{0}'. Exception: {1}", directory, exception);
                    result = false;
                }
                else if (count > 0)
                {
                    MountPointUtil.Tracer.TraceDebug <string, int>(0L, "IsDirectoryNonExistentOrEmpty(): Directory '{0}' has {1} files and/or directories. Returning false.", directory, count);
                    result = false;
                }
                else
                {
                    MountPointUtil.Tracer.TraceDebug <string, int>(0L, "IsDirectoryNonExistentOrEmpty(): Directory '{0}' has 0 files and/or directories. Returning true.", directory, count);
                    result = true;
                }
            }
            return(result);
        }
示例#16
0
        internal static bool DoesContainAnyFiles(string directory, bool recurse, out Exception exception)
        {
            bool foundFiles = false;

            exception = MountPointUtil.HandleIOExceptions(delegate
            {
                DirectoryInfo path = new DirectoryInfo(directory);
                using (DirectoryEnumerator directoryEnumerator = new DirectoryEnumerator(path, recurse, false))
                {
                    IEnumerable <string> source = directoryEnumerator.EnumerateFiles("*", DirectoryEnumerator.ExcludeHiddenAndSystemFilter);
                    if (source.Any <string>())
                    {
                        foundFiles = true;
                    }
                }
            });
            return(foundFiles);
        }
            public void ShouldNotContainFilesOfNestedFolderWhenRecursiveIsFalse()
            {
                // Arrange
                var dir = CreateDirectory();
                var sut = new DirectoryEnumerator();

                // Act
                var actual = sut.Files(dir, "*.*", false).ToList();

                // Assert
                var notExpected = new[] { Path.Combine("sub", "b.txt"), Path.Combine("sub2", "c.txt") }.Select(x => Path.Combine(dir, x)).ToList();

                foreach (var x in notExpected)
                {
                    Assert.DoesNotContain(x, actual);
                }

                RemoveDirectory(dir);
            }
        public void EnumerationSkipsVsDocFiles()
        {
            var temporaryDirectory = CreateNewTemporaryDirectory();

            try
            {
                CreateJsFileWithRandomName(temporaryDirectory);
                CreateJsFileWithRandomNameAndSuffix(temporaryDirectory, "-vsdoc");

                var directoryEnumerator = new DirectoryEnumerator();
                var result = directoryEnumerator.GetFiles(temporaryDirectory).ToList();

                Assert.AreEqual(1, result.Count);
            }
            finally
            {
                System.IO.Directory.Delete(temporaryDirectory, true);
            }
        }
示例#19
0
 public static Exception CleanupTemporaryFiles(string logFilePrefix, string destinationLogPath, out Exception exception)
 {
     exception = LastLogReplacer.HandleExceptions(delegate
     {
         string filter  = LastLogReplacer.BuildLogFileSearchPattern(logFilePrefix, ".ReplacementNew");
         string filter2 = LastLogReplacer.BuildLogFileSearchPattern(logFilePrefix, ".ReplacementOld");
         using (DirectoryEnumerator directoryEnumerator = new DirectoryEnumerator(new DirectoryInfo(destinationLogPath), false, false))
         {
             foreach (string path in directoryEnumerator.EnumerateFiles(filter, null))
             {
                 File.Delete(path);
             }
             foreach (string path2 in directoryEnumerator.EnumerateFiles(filter2, null))
             {
                 File.Delete(path2);
             }
         }
     });
     return(exception);
 }
        public void CanEnumerateDirectory()
        {
            var temporaryDirectory = CreateNewTemporaryDirectory();

            try
            {
                for (int i = 0; i < 3; i++)
                {
                    CreateJsFileWithRandomName(temporaryDirectory);
                }

                var directoryEnumerator = new DirectoryEnumerator();
                var result = directoryEnumerator.GetFiles(temporaryDirectory).ToList();

                Assert.AreEqual(3, result.Count);
            }
            finally
            {
                System.IO.Directory.Delete(temporaryDirectory, true);
            }
        }
        public DnxProjectSystem(OmnisharpWorkspace workspace,
                                IOmnisharpEnvironment env,
                                ILoggerFactory loggerFactory,
                                IMetadataFileReferenceCache metadataFileReferenceCache,
                                IApplicationLifetime lifetime,
                                IFileSystemWatcher watcher,
                                IEventEmitter emitter,
                                DnxContext context)
        {
            _workspace     = workspace;
            _env           = env;
            _loggerFactory = loggerFactory;
            _logger        = loggerFactory.CreateLogger <DnxProjectSystem>();
            _metadataFileReferenceCache = metadataFileReferenceCache;
            _context             = context;
            _watcher             = watcher;
            _emitter             = emitter;
            _directoryEnumerator = new DirectoryEnumerator(loggerFactory);

            lifetime?.ApplicationStopping.Register(OnShutdown);
        }
示例#22
0
        public static bool AreTemporaryFilesPresent(string logFilePrefix, string destinationLogPath, out Exception exception)
        {
            bool fTempFilesPresent = false;

            exception = LastLogReplacer.HandleExceptions(delegate
            {
                string filter  = LastLogReplacer.BuildLogFileSearchPattern(logFilePrefix, ".ReplacementNew");
                string filter2 = LastLogReplacer.BuildLogFileSearchPattern(logFilePrefix, ".ReplacementOld");
                DirectoryInfo directoryInfo = new DirectoryInfo(destinationLogPath);
                if (!directoryInfo.Exists)
                {
                    fTempFilesPresent = false;
                    return;
                }
                using (DirectoryEnumerator directoryEnumerator = new DirectoryEnumerator(directoryInfo, false, false))
                {
                    fTempFilesPresent = (directoryEnumerator.EnumerateFiles(filter, null).Count <string>() > 0 || directoryEnumerator.EnumerateFiles(filter2, null).Count <string>() > 0);
                }
            });
            return(exception == null && fTempFilesPresent);
        }
示例#23
0
    private static void Examples()
    {
        // Recursive file enumeration
        var files1 = DirectoryEnumerator.GetFiles(new DirectoryInfo("C:\\")).ToList();
        // File enumeration
        var files2 = DirectoryEnumerator.GetFiles(new DirectoryInfo("C:\\"), false).ToList();
        // Recursive directory enumeration
        var directory1 = DirectoryEnumerator.GetDirectories(new DirectoryInfo("C:\\")).ToList();
        // Directory enumeration
        var directory2 = DirectoryEnumerator.GetDirectories(new DirectoryInfo("C:\\"), false).ToList();


        // Event enumeration
        var directoryEnumerator = new DirectoryEnumerator();

        directoryEnumerator.OnNewFile += (sender, file) => {
            // dosomething
        };

        directoryEnumerator.OnNewDirectory += (sender, file) => {
            // dosomething
        };
        directoryEnumerator.Enumerate(new DirectoryInfo("C:\\"), false);
    }
        public void CanOrderFilesInDirectory()
        {
            var temporaryDirectory = CreateNewTemporaryDirectory();

            try
            {
                for (int i = 0; i < 4; i++)
                {
                    string fileName = String.Format("{0}File{1}.js", temporaryDirectory, (1 + i));
                    File.CreateText(fileName).Dispose();
                }
                using (var ordering = File.CreateText(temporaryDirectory + "ordering.txt"))
                {
                    ordering.WriteLine("File3.js");
                    ordering.WriteLine("File4.js");
                    ordering.WriteLine("File1.js");
                    ordering.WriteLine("File2.js");
                }

                var directoryEnumerator = new DirectoryEnumerator();
                var result = directoryEnumerator.GetFiles(temporaryDirectory).ToList();

                var expectedList = new List <string>
                {
                    temporaryDirectory + "File3.js",
                    temporaryDirectory + "File4.js",
                    temporaryDirectory + "File1.js",
                    temporaryDirectory + "File2.js"
                };
                CollectionAssert.AreEqual(expectedList, result, StringComparer.OrdinalIgnoreCase);
            }
            finally
            {
                System.IO.Directory.Delete(temporaryDirectory, true);
            }
        }
示例#25
0
        public static void RollbackLastLogIfNecessary(IReplayConfiguration config)
        {
            Exception ex = LastLogReplacer.HandleExceptions(delegate
            {
                int num        = 0;
                int num2       = 0;
                string text    = null;
                string text2   = null;
                string text3   = EseHelper.MakeLogFilePath(config, 0L, config.DestinationLogPath);
                string filter  = LastLogReplacer.BuildLogFileSearchPattern(config.LogFilePrefix, ".ReplacementNew");
                string filter2 = LastLogReplacer.BuildLogFileSearchPattern(config.LogFilePrefix, ".ReplacementOld");
                using (DirectoryEnumerator directoryEnumerator = new DirectoryEnumerator(new DirectoryInfo(config.DestinationLogPath), false, false))
                {
                    foreach (string text4 in directoryEnumerator.EnumerateFiles(filter, null))
                    {
                        num++;
                        text = text4;
                    }
                    if (num > 1)
                    {
                        throw new LastLogReplacementTooManyTempFilesException(config.DisplayName, filter, num, config.DestinationLogPath);
                    }
                    foreach (string text5 in directoryEnumerator.EnumerateFiles(filter2, null))
                    {
                        num2++;
                        text2 = text5;
                    }
                    if (num2 > 1)
                    {
                        throw new LastLogReplacementTooManyTempFilesException(config.DisplayName, filter2, num2, config.DestinationLogPath);
                    }
                }
                if (num == 0 && num2 == 0)
                {
                    LastLogReplacer.Tracer.TraceDebug <string>(0L, "RollbackLastLogIfNecessary(): '{0}': Case 1: Nothing to do.", config.DisplayName);
                    return;
                }
                if (num == 1 && num2 == 0)
                {
                    LastLogReplacer.Tracer.TraceDebug <string, string>(0L, "RollbackLastLogIfNecessary(): '{0}': Case 2: Considering to delete temp new file: {1}", config.DisplayName, text);
                    LastLogReplacer.DeleteTempNewFile(config, text, text3);
                    return;
                }
                if (num == 1 && num2 == 1)
                {
                    LastLogReplacer.Tracer.TraceDebug(0L, "RollbackLastLogIfNecessary(): '{0}': Case 3: Rolling back temp file '{1}' to '{2}' and considering to delete temp new file: {3}", new object[]
                    {
                        config.DisplayName,
                        text2,
                        text3,
                        text
                    });
                    File.Move(text2, text3);
                    LastLogReplacer.DeleteTempNewFile(config, text, text3);
                    return;
                }
                if (num == 0 && num2 == 1)
                {
                    LastLogReplacer.Tracer.TraceDebug <string, string>(0L, "RollbackLastLogIfNecessary(): '{0}': Case 4: Considering moving out temp old file '{1}' to IgnoredLogs directory.", config.DisplayName, text2);
                    LastLogReplacer.DeleteTempOldFile(config, text2);
                    return;
                }
                LastLogReplacer.Tracer.TraceError <string, int, int>(0L, "RollbackLastLogIfNecessary(): '{0}': Unexpected temporary files found. tempOldFileCount={1}, tempNewFileCount={2}, e00Exists=false", config.DisplayName, num2, num);
                throw new LastLogReplacementUnexpectedTempFilesException(config.DisplayName, config.DestinationLogPath);
            });

            if (ex != null)
            {
                throw new LastLogReplacementRollbackFailedException(config.DisplayName, ex.Message, ex);
            }
        }
示例#26
0
        internal static DateTime GetLastWriteTimeUtcInDirectory(string directory, bool recurse, out string lastWriteTimePath, out Exception exception)
        {
            DateTime dateTime = DateTime.MaxValue;

            lastWriteTimePath = string.Empty;
            DirectoryInfo di = null;

            exception = MountPointUtil.HandleIOExceptions(delegate
            {
                di = new DirectoryInfo(directory);
            });
            if (exception != null)
            {
                MountPointUtil.Tracer.TraceError <string, Exception>(0L, "GetLastWriteTimeUtcOfFilesInDirectory(): Failed to construct DirectoryInfo for directory '{0}'. Exception: {1}", directory, exception);
                return(dateTime);
            }
            if (!di.Exists)
            {
                MountPointUtil.Tracer.TraceError <string>(0L, "GetLastWriteTimeUtcOfFilesInDirectory(): Directory '{0}' is not present.", directory);
                return(dateTime);
            }
            string   maxTimePath = string.Empty;
            DateTime maxTime     = DateTime.MinValue;

            using (DirectoryEnumerator dirEnum = new DirectoryEnumerator(di, recurse, false))
            {
                Exception tempEx = null;
                DateTime  currentTime;
                exception = MountPointUtil.HandleIOExceptions(delegate
                {
                    IEnumerable <string> enumerable = dirEnum.EnumerateFilesAndDirectoriesExcludingHiddenAndSystem("*");
                    foreach (string text in enumerable)
                    {
                        NativeMethods.WIN32_FILE_ATTRIBUTE_DATA fileAttributesEx = FileOperations.GetFileAttributesEx(text, out tempEx);
                        if (tempEx != null)
                        {
                            MountPointUtil.Tracer.TraceError <string, Exception>(0L, "GetLastWriteTimeUtcOfFilesInDirectory(): GetFileAttributesEx() FAILED for '{0}'. Exception: {1}", text, tempEx);
                            break;
                        }
                        currentTime = DateTimeHelper.FromFileTimeUtc(fileAttributesEx.LastWriteTime);
                        if (currentTime > maxTime)
                        {
                            maxTime     = currentTime;
                            maxTimePath = text;
                        }
                    }
                });
                if (exception == null)
                {
                    exception = tempEx;
                }
            }
            if (exception != null)
            {
                MountPointUtil.Tracer.TraceError <string, Exception>(0L, "GetLastWriteTimeUtcOfFilesInDirectory(): FAILED for directory '{0}'. Exception: {1}", directory, exception);
                return(dateTime);
            }
            if (maxTime > DateTime.MinValue)
            {
                dateTime          = maxTime;
                lastWriteTimePath = maxTimePath;
            }
            MountPointUtil.Tracer.TraceDebug <string, DateTime, string>(0L, "GetLastWriteTimeUtcOfFilesInDirectory() for directory '{0}' returning '{1}' for file '{2}'", directory, dateTime, lastWriteTimePath);
            return(dateTime);
        }