Exemple #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());
         }
     }
 }
Exemple #2
0
        public void TestFindsCartridges()
        {
            var cartridges = CartridgeHelper.FindAllInDirectory("testdata/cartridges");

            Assert.Equal(1, cartridges.Count);
            Assert.Equal("app_something", cartridges[0].Name);
        }
Exemple #3
0
        public async Task <int> RunCommand(string location)
        {
            if (string.IsNullOrEmpty(location))
            {
                location = Directory.GetCurrentDirectory();
            }

            var cartridges = CartridgeHelper.FindAllInDirectory(location);

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

            var watchers = new List <FileSystemWatcher>();

            foreach (var cartridge in cartridges)
            {
                _console.Write("Watching ");
                _console.Green(cartridge.Name, eol: "");
                _console.Write("...\n");
                var watcher = new FileSystemWatcher()
                {
                    Path         = cartridge.Path,
                    NotifyFilter = NotifyFilters.LastWrite
                                   | NotifyFilters.FileName
                                   | NotifyFilters.DirectoryName
                };
                watcher.Changed += OnChanged;
                watcher.Renamed += OnRenamed;
                watcher.IncludeSubdirectories = true;
                watchers.Add(watcher);

                // TODO https://stackoverflow.com/questions/15519089/avoid-error-too-many-changes-at-once-in-directory/35432077#35432077
            }

            foreach (var watcher in watchers)
            {
                watcher.EnableRaisingEvents = true;
            }

            try
            {
                while (Console.Read() != null)
                {
                    ;
                }
            }
            catch (TaskCanceledException e)
            {
                return(0);
            }

            return(0);
        }
Exemple #4
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);
        }