public void SafeDelete()
 {
     var dir = new DirectoryInfo("abc");
     dir.SafeDelete(true);
     dir.Refresh();
     Assert.That(dir.SafeDelete(true), Is.False);
     Directory.CreateDirectory(dir.GetDirectory("test2").FullName);
     dir.Refresh();
     Assert.That(dir.SafeDelete(true), Is.True);
     dir.Refresh();
     Assert.That(dir.Exists, Is.False);
 }
 public void Clear()
 {
     var dir = new DirectoryInfo("abc");
     var subdir = dir.GetDirectory("test2");
     subdir.Create();
     using (var fs = new FileStream(subdir.GetFile("test3.txt").FullName, FileMode.Create)) {
         fs.WriteByte(1);
     }
     dir.Clear();
     Assert.That(dir.Exists, Is.True);
     Assert.That(dir.SafeClear(), Is.True);
     Assert.That(dir.SafeDelete(), Is.True);
     dir.Refresh();
     Assert.That(dir.Exists, Is.False);
     Assert.That(dir.SafeClear(), Is.False);
 }
        public static void CopyToDirectory(this DirectoryInfo source, DirectoryInfo destination, bool deleteDestination)
        {
            if (deleteDestination)
            {
                if (destination.Exists)
                    destination.SafeDelete();
            }

            if (!destination.Exists)
                destination.Create();

            LogCopyTask(source, destination);

            CopyFiles(source, destination);

            CopyDirectories(source, destination, deleteDestination);
        }
        public void clone_git_repo_and_append_to_existing_solution()
        {
            var tmpDir = FileSystem.Combine("Templating", Guid.NewGuid().ToString());
            var repoZip = FileSystem.Combine("Templating", "repo.zip");
            _zipService.ExtractTo(repoZip, tmpDir, ExplodeOptions.DeleteDestination);

            var solutionFile = FileSystem.Combine("Templating", "sample", "myproject.txt");
            var oldContents = _fileSystem.ReadStringFromFile(solutionFile);
            var solutionDir = _fileSystem.GetDirectory(solutionFile);

            _commandInput.GitFlag = "file:///{0}".ToFormat(_fileSystem.GetFullPath(tmpDir).Replace("\\", "/"));
            _commandInput.ProjectName = "MyProject";
            _commandInput.SolutionFlag = solutionFile;
            _commandInput.OutputFlag = solutionDir;
            _commandInput.RakeFlag = "init.rb";

            _command
                .Execute(_commandInput)
                .ShouldBeTrue();

            _fileSystem
                .DirectoryExists("Templating", "sample", "MyProject")
                .ShouldBeTrue();

            _fileSystem
                .DirectoryExists("Templating", "sample", "MyProject.Tests")
                .ShouldBeTrue();

            _fileSystem
                .FileExists("Templating", "sample", "MyProject", "MyProject.csproj")
                .ShouldBeTrue();

            _fileSystem
                .FileExists("Templating", "sample", "MyProject.Tests", "MyProject.Tests.csproj")
                .ShouldBeTrue();

            // .fubuignore
            _fileSystem
                .FileExists("Templating", "sample", MoveContent.FubuIgnoreFile)
                .ShouldBeFalse();

            _fileSystem
                .FileExists("Templating", "sample", "ignored.txt")
                .ShouldBeFalse();

            _fileSystem
                .FileExists("Templating", "sample", "MyProject.xml")
                .ShouldBeTrue();

            var solutionContents = _fileSystem.ReadStringFromFile(solutionFile);

            // cleanup first
            var info = new DirectoryInfo(tmpDir);
            info.SafeDelete();
            _fileSystem.DeleteDirectory("Templating", "sample", "MyProject");
            _fileSystem.DeleteDirectory("Templating", "sample", "MyProject.Tests");
            _fileSystem.WriteStringToFile(solutionFile, oldContents);

            var lines = ((SolutionFileService) _command.SolutionFileService).SplitSolution(solutionContents);
            var guid = _command.KeywordReplacer.Replace("GUID1");
            lines[2].ShouldEqual("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"MyProject\", \"MyProject\\MyProject.csproj\", \"{" + guid +  "}\"");
            lines[3].ShouldEqual("EndProject");
        }
Exemple #5
0
        public void Execute(TemplatePlanContext context)
        {
            var fileSet = new FileSet
                                   {
                                       DeepSearch = false,
                                       Include = "*.*",
                                       Exclude = "*.exe;*.dll;.git;*{0};".ToFormat(FubuIgnoreFile)
                                   };
            var fubuIgnore = FileSystem.Combine(context.TempDir, FubuIgnoreFile);
            if(_fileSystem.FileExists(fubuIgnore))
            {
                _fileSystem
                    .ReadStringFromFile(fubuIgnore)
                    .SplitOnNewLine()
                    .Each(ignore =>
                              {
                                  fileSet.Exclude += "{0};".ToFormat(ignore);
                              });
            }

            var excludedFiles = fileSet.ExcludedFilesFor(context.TempDir);
            _fileSystem
                .FindFiles(context.TempDir, fileSet)
                .Where(file => !excludedFiles.Contains(file))
                .Each(from =>
                          {
                              var destination = Path.Combine(context.TargetPath, _fileSystem.GetFileName(from));
                              if (_fileSystem.FileExists(destination)) _fileSystem.DeleteFile(destination);
                              _fileSystem.MoveFile(from, destination);
                          });

            _fileSystem
                .ChildDirectoriesFor(context.TempDir)
                .Each(directory =>
                          {
                              var destinationName = _fileSystem.GetFileName(directory);
                              if(destinationName == ".git")
                              {
                                  return;
                              }

                              var destination = Path.Combine(context.TargetPath, destinationName);
                              if (_fileSystem.DirectoryExists(destination))
                              {
                                  _fileSystem.DeleteDirectory(destination);
                              }
                              _fileSystem.MoveDirectory(directory, destination);
                          });

            var info = new DirectoryInfo(context.TempDir);
            info.SafeDelete();
        }