コード例 #1
0
        public void before_all()
        {
            // setup
            _command      = new NewCommand();
            _fileSystem   = new FileSystem();
            _zipService   = new ZipFileService(_fileSystem);
            _commandInput = new NewCommandInput();

            tmpDir  = FileSystem.Combine("Templating", Guid.NewGuid().ToString());
            repoZip = FileSystem.Combine("Templating", "repo.zip");
            _zipService.ExtractTo(repoZip, tmpDir, ExplodeOptions.DeleteDestination);

            solutionFile = FileSystem.Combine("Templating", "sample", "myproject.txt");
            oldContents  = _fileSystem.ReadStringFromFile(solutionFile);
            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";

            _commandResult = _command.Execute(_commandInput);

            newSolutionContents = _fileSystem.ReadStringFromFile(solutionFile);
        }
コード例 #2
0
        public void read_a_package_manifest()
        {
            var manifest = new PackageManifest {
                Role = "application",
                Name = "something"
            };

            new FileSystem().WriteObjectToFile(PackageManifest.FILE, manifest);

            if (File.Exists("zip1.zip"))
            {
                File.Delete("zip1.zip");
            }

            using (var zip1 = new ZipFile("zip1.zip"))
            {
                zip1.AddFile(PackageManifest.FILE, "");
                zip1.Save();
            }

            var service   = new ZipFileService(new FileSystem());
            var manifest2 = service.GetPackageManifest("zip1.zip");

            manifest2.Name.ShouldEqual(manifest.Name);
            manifest2.Role.ShouldEqual(manifest.Role);
        }
コード例 #3
0
 public NewCommand()
 {
     FileSystem          = new FileSystem();
     ZipService          = new ZipFileService(FileSystem);
     KeywordReplacer     = new KeywordReplacer();
     ProcessFactory      = new ProcessFactory();
     PlanExecutor        = new TemplatePlanExecutor(FileSystem);
     SolutionFileService = new SolutionFileService(FileSystem);
     CsProjGatherer      = new CsProjGatherer(FileSystem);
     RakeRunner          = new RakeRunner(ProcessFactory, FileSystem);
 }
コード例 #4
0
        public override bool Execute(AssemblyPackageInput input)
        {
            input.RootFolder = AliasCommand.AliasFolder(input.RootFolder);

            var zipService = new ZipFileService(fileSystem);


            createZipFile(input, "WebContent", zipService);
            createZipFile(input, "Data", zipService);


            return true;
        }
コード例 #5
0
        public void SetUp()
        {
            var assembly = typeof(AssemblyPackageMarker).Assembly;
            var stream   = assembly.GetManifestResourceStream(typeof(AssemblyPackageMarker), "pak-data.zip");

            var service = new ZipFileService();

            service.ExtractTo("description of this", stream, "package-data");

            // These 3 files should be in the zip file embedded within the AssemblyPackage assembly
            File.Exists(Path.Combine("package-data", "1.txt")).ShouldBeTrue();
            File.Exists(Path.Combine("package-data", "2.txt")).ShouldBeTrue();;
            File.Exists(Path.Combine("package-data", "3.txt")).ShouldBeTrue();;
        }
コード例 #6
0
        public void create_test_zip_to_a_nonexistent_path()
        {
            var fileSystem = new FileSystem();

            fileSystem.DeleteDirectory("nonexist");

            fileSystem.FileExists("nonexist".AppendPath("silly.zip")).ShouldBeFalse();

            fileSystem.WriteStringToFile("bob.txt", "hi");
            var service = new ZipFileService(fileSystem);

            service.CreateZipFile("nonexist".AppendPath("silly.zip"), f =>
            {
                f.AddFile("bob.txt", "");
            });

            fileSystem.FileExists("nonexist".AppendPath("silly.zip")).ShouldBeTrue();
        }
コード例 #7
0
        public static IEnumerable <string> GetFilesInZip(string zipFileName)
        {
            var tempPath     = Path.GetTempPath();
            var zipDirectory = Path.Combine(tempPath, "zip-contents");

            if (Directory.Exists(zipDirectory))
            {
                Directory.Delete(zipDirectory, true);
            }

            Directory.CreateDirectory(zipDirectory);

            var zfs = new ZipFileService(new FileSystem());

            zfs.ExtractTo(zipFileName, zipDirectory, ExplodeOptions.DeleteDestination);

            return
                (Directory.GetFiles(zipDirectory, "*", SearchOption.AllDirectories).Select(
                     x => x.PathRelativeTo(zipDirectory)));
        }
コード例 #8
0
ファイル: ZipFileServiceTester.cs プロジェクト: Memmo/fubumvc
        public void read_version_out_of_a_zip_file()
        {
            var versionFile = Path.Combine(Path.GetTempPath(), BottleFiles.VersionFile);
            var guid = Guid.NewGuid();
            new FileSystem().WriteStringToFile(versionFile, guid.ToString());

            if (File.Exists("zip1.zip"))
            {
                File.Delete("zip1.zip");
            }

            using (var zip1 = new ZipFile("zip1.zip"))
            {
                zip1.AddFile(versionFile, "");
                zip1.Save();
            }

            var service = new ZipFileService();

            service.GetVersion("zip1.zip").ShouldEqual(guid);
        }
コード例 #9
0
        public void read_version_out_of_a_zip_file()
        {
            var versionFile = Path.Combine(Path.GetTempPath(), BottleFiles.VersionFile);
            var guid        = Guid.NewGuid();

            new FileSystem().WriteStringToFile(versionFile, guid.ToString());

            if (File.Exists("zip1.zip"))
            {
                File.Delete("zip1.zip");
            }

            using (var zip1 = new ZipFile("zip1.zip"))
            {
                zip1.AddFile(versionFile, "");
                zip1.Save();
            }

            var service = new ZipFileService();

            service.GetVersion("zip1.zip").ShouldEqual(guid);
        }
コード例 #10
0
        public override bool Execute(AssemblyPackageInput input)
        {
            input.RootFolder = new AliasService().GetFolderForAlias(input.RootFolder);

            determineMissingCsProjFile(input);

            if (input.PreviewFlag)
            {
                return(displayPreview(input));
            }

            if (input.InitFlag)
            {
                createNewManifest(input);
                return(true);
            }

            var zipService = new ZipFileService(fileSystem);

            var manifest = fileSystem.LoadPackageManifestFrom(input.RootFolder);

            if (manifest == null)
            {
                System.Console.WriteLine("No PackageManifest found, using defaults instead");
                manifest = new PackageManifest();
                manifest.SetRole(BottleRoles.Module);


                System.Console.WriteLine("WebContent:  " + manifest.ContentFileSet);
            }

            createZipFile(input, BottleFiles.WebContentFolder, zipService, manifest.ContentFileSet);
            createZipFile(input, BottleFiles.DataFolder, zipService, BottleFiles.DataFiles);
            createZipFile(input, BottleFiles.ConfigFolder, zipService, BottleFiles.ConfigFiles);


            return(true);
        }
コード例 #11
0
        private void createZipFile(AssemblyPackageInput input, string childFolderName, ZipFileService zipService)
        {
            var contentDirectory = FileSystem.Combine(input.RootFolder, childFolderName);
            if (!fileSystem.DirectoryExists(contentDirectory)) return;


            var zipFileName = "pak-{0}.zip".ToFormat(childFolderName);



            var contentFile = FileSystem.Combine(input.RootFolder, zipFileName);
            ConsoleWriter.Write("Creating zip file " + contentFile);

            fileSystem.DeleteFile(contentFile);


            zipService.CreateZipFile(contentFile, file =>
            {

                file.AddFiles(new ZipFolderRequest()
                              {
                                  FileSet = new FileSet(){DeepSearch = true, Include="*.*"}, 
                                  RootDirectory = contentDirectory,
                                  ZipDirectory = string.Empty
                              });
            });

            if (!input.ProjFileFlag.IsNotEmpty())
                return;

            var document = new XmlDocument();
            var projectFileName = FileSystem.Combine(input.RootFolder, input.ProjFileFlag);
            document.Load(projectFileName);

            //var search = "//ItemGroup/EmbeddedResource[@Include='{0}']".ToFormat(zipFileName);
            //if (document.DocumentElement.SelectSingleNode(search, new XmlNamespaceManager(document.NameTable)) == null)
            if (document.DocumentElement.OuterXml.Contains(zipFileName))
            {
                ConsoleWriter.Write("The file {0} is already embedded in project {1}".ToFormat(zipFileName, projectFileName));
                return;
            }

            ConsoleWriter.Write("Adding the ItemGroup / Embedded Resource for {0} to {1}".ToFormat(zipFileName,
                                                                                                   projectFileName));
            var node = document.CreateNode(XmlNodeType.Element, "ItemGroup", document.DocumentElement.NamespaceURI);
            var element = document.CreateNode(XmlNodeType.Element, "EmbeddedResource", document.DocumentElement.NamespaceURI);
            var attribute = document.CreateAttribute("Include");
            attribute.Value = zipFileName;
            element.Attributes.Append(attribute);
            node.AppendChild(element);
            document.DocumentElement.AppendChild(node);

            document.Save(projectFileName);

        }
コード例 #12
0
        private void createZipFile(AssemblyPackageInput input, string childFolderName, ZipFileService zipService, FileSet fileSearch)
        {
            var zipRequest = BuildZipRequest(input, fileSearch);

            if (zipRequest == null)
            {
                ConsoleWriter.Write("No content for " + childFolderName);

                return;
            }

            // Hackey, but it makes /data and data/*.* work
            if (fileSystem.DirectoryExists(input.RootFolder.AppendPath(childFolderName)) && zipRequest.FileSet.Include.StartsWith(childFolderName, StringComparison.InvariantCultureIgnoreCase))
            {
                zipRequest.FileSet       = FileSet.Deep("*.*");
                zipRequest.RootDirectory = zipRequest.RootDirectory.AppendPath(childFolderName);
            }

            var zipFileName = "pak-{0}.zip".ToFormat(childFolderName);

            // do not create a zip file if there's no files there.
            if (!fileSystem.FindFiles(input.RootFolder, zipRequest.FileSet).Any())
            {
                Console.WriteLine("No matching files for Bottle directory " + childFolderName);

                var projectFileName = input.FindCsProjFile();
                var csProjFile      = CsProjFile.LoadFrom(projectFileName);
                if (csProjFile.Find <EmbeddedResource>(zipFileName) != null)
                {
                    csProjFile.Remove <EmbeddedResource>(zipFileName);
                    csProjFile.Save();
                }

                var zipFilePath = input.RootFolder.AppendPath(zipFileName);
                if (fileSystem.FileExists(zipFilePath))
                {
                    Console.WriteLine("Removing obsolete file " + zipFilePath);
                    fileSystem.DeleteFile(zipFilePath);
                }


                return;
            }


            var contentFile = FileSystem.Combine(input.RootFolder, zipFileName);

            ConsoleWriter.Write("Creating zip file " + contentFile);
            fileSystem.DeleteFile(contentFile);


            zipService.CreateZipFile(contentFile, file => file.AddFiles(zipRequest));

            if (input.ProjFileFlag.IsEmpty())
            {
                return;
            }

            attachZipFileToProjectFile(input, zipFileName);
        }