Ejemplo n.º 1
0
        public void EnumerateDirectoriesPassesCorrectArguments()
        {
            IDirectoryInformation info = Substitute.For <IDirectoryInformation>();

            info.EnumerateDirectories("foo", SearchOption.AllDirectories, 0);
            info.Received(1).EnumerateChildren(ChildType.Directory, "foo", SearchOption.AllDirectories, 0);
        }
Ejemplo n.º 2
0
        protected virtual void CleanOrphanedTempFolders()
        {
            // Clean up orphaned temp folders
            IDirectoryInformation rootInfo = _fileServiceProvider.GetPathInfo(_rootTempFolder) as IDirectoryInformation;

            if (rootInfo != null)
            {
                try
                {
                    var flagFiles =
                        from directory in rootInfo.EnumerateDirectories()
                        from file in directory.EnumerateFiles(XTaskFlagFileName)
                        select new { Directory = directory.Path, File = file.Path };

                    foreach (var flagFile in flagFiles.ToArray())
                    {
                        try
                        {
                            // If we can't delete the flag file (open handle) we'll throw and move on
                            _fileServiceProvider.DeleteFile(flagFile.File);
                            _fileServiceProvider.DeleteDirectory(flagFile.Directory, deleteChildren: true);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                catch (Exception)
                {
                    // Ignoring orphan cleanup errors as the DotNet file service chokes on long paths
                }
            }
        }
Ejemplo n.º 3
0
        protected override ExitCode ExecuteFileTask()
        {
            var fileService = this.GetService <IFileService>();

            Table output = Table.Create(
                new ColumnFormat(1),
                new ColumnFormat(1),
                new ColumnFormat(1, ContentVisibility.Default, Justification.Right),
                new ColumnFormat(4));

            output.HasHeader = false;

            int   directoryCount = 0;
            int   fileCount      = 0;
            ulong totalSize      = 0;

            IDirectoryInformation directory = fileService.GetDirectoryInfo(GetFullTargetPath());

            foreach (var subdir in directory.EnumerateDirectories().OrderBy(i => i.Name))
            {
                directoryCount++;
                this.AddToTable(output, subdir);
            }

            foreach (var file in directory.EnumerateFiles().OrderBy(i => i.Name))
            {
                fileCount++;
                totalSize += file.Length;
                this.AddToTable(output, file);
            }

            this.Loggers[LoggerType.Status].WriteLine($" Directory of {directory.Path}");
            this.Loggers[LoggerType.Status].WriteLine();
            this.Loggers[LoggerType.Result].Write(output);
            this.Loggers[LoggerType.Status].WriteLine();
            this.Loggers[LoggerType.Status].WriteLine($" {directoryCount} Dir(s) {fileCount} File(s) {totalSize:N0} bytes");
            return(ExitCode.Success);
        }