示例#1
0
 public void TestCreatesZipFile()
 {
     using (var memory = new MemoryStream())
     {
         var cartridges = CartridgeHelper.FindAllInDirectory("testdata/cartridges");
         CartridgeHelper.CartridgesToZipFile(cartridges, "testing", memory);
         using (var outputFile = new StreamWriter("testfile.zip"))
         {
             memory.WriteTo(outputFile.BaseStream);
         }
     }
     using (var inputFile = new StreamReader("testfile.zip"))
     {
         var zipFile = new ZipArchive(inputFile.BaseStream, ZipArchiveMode.Read);
         var entry   = zipFile.GetEntry("testing/app_something/.project");
         Assert.NotNull(entry);
         entry = zipFile.GetEntry("foo");
         Assert.Null(entry);
         entry = zipFile.GetEntry("testing/app_something/cartridge/controllers/TestController.js");
         Assert.NotNull(entry);
         using (var entryStream = new StreamReader(entry.Open()))
         {
             var contents = entryStream.ReadToEnd();
             Assert.Equal("\"hello world\";", contents.TrimEnd());
         }
     }
 }
示例#2
0
        public async Task <int> RunCommand(string location, bool deleteAndReactivate = false)
        {
            if (string.IsNullOrEmpty(location))
            {
                location = Directory.GetCurrentDirectory();
            }

            var cartridges = CartridgeHelper.FindAllInDirectory(location);

            _logger.LogDebug("Found {NumCartridges} cartridges in {Location}", cartridges.Count, location);

            foreach (var cartridge in cartridges)
            {
                _console.Write("Collecting ");
                _console.Green(cartridge.Name, eol: "");
                _console.Write("...\n");
            }

            if (deleteAndReactivate)
            {
                _console.WriteLine($"Deleting code version {_env.CodeVersion}");
                if (!await _client.DELETE(WebDAVLocation.Cartridges, _env.CodeVersion))
                {
                    _console.Yellow("Code version was not deleted (may not exist)");
                }
            }

            await using (var ms = new MemoryStream())
            {
                _console.Write("Syncing code version ");
                _console.Yellow(_env.CodeVersion, eol: "");
                _console.Write(" on ");
                _console.Yellow(_env.Server);

                // Write a zip archive to the in memory stream
                CartridgeHelper.CartridgesToZipFile(cartridges, _env.CodeVersion, ms);

                var progressBar = _console.CreateProgressBar();

                if (!await _client.PUT(WebDAVLocation.Cartridges, $"{_env.CodeVersion}.zip", ms,
                                       progressBar.ProgressHandler))
                {
                    _logger.LogError("Could not upload code version");
                    return(1);
                }
            }

            _console.WriteLine("Extracting...");
            if (!await _client.UNZIP(WebDAVLocation.Cartridges, $"{_env.CodeVersion}.zip"))
            {
                _logger.LogError("Could not unzip code version");
                return(1);
            }

            //await _client.DELETE(WebDAVLocation.Cartridges, $"{_env.CodeVersion}.zip");
            _console.Green($"Successfully synced cartridges with {_env.Server}");

            if (deleteAndReactivate)
            {
                _console.Write("Activating code version...");
                if (!await _codeVersionsClient.ActivateCodeVersion(_env.CodeVersion))
                {
                    _logger.LogError("Could not activate code version");
                    return(1);
                }
            }

            return(0);
        }