Esempio n. 1
0
        private void createZipFile(AssemblyPackageInput input, string childFolderName, ZipFileService zipService)
        {
            var contentDirectory = FileSystem.Combine(input.RootFolder, childFolderName);

            if (!Directory.Exists(contentDirectory))
            {
                return;
            }


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



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

            Console.WriteLine("Creating zip file " + contentFile);

            if (File.Exists(contentFile))
            {
                File.Delete(contentFile);
            }


            zipService.CreateZipFile(contentFile, file =>
            {
                file.AddFiles(new ZipFolderRequest()
                {
                    RootDirectory = contentDirectory,
                    ZipDirectory  = string.Empty
                });
            });

            if (input.ProjFileFlag.IsNotEmpty())
            {
                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))
                {
                    Console.WriteLine("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);
                }
                else
                {
                    Console.WriteLine("The file {0} is already embedded in project {1}".ToFormat(zipFileName, projectFileName));
                }
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
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();
        }