예제 #1
0
 private void DisplayPrompt()
 {
     _console.Write("[");
     _console.Blue($"{_env.Server}", eol: "");
     _console.Write(":");
     _console.Yellow($"{_location.Value}", eol: "");
     _console.Write("]");
     _console.Write($" {_workingDirectory.AbsolutePath}> ");
 }
예제 #2
0
        /// <summary>
        /// Parse and output logs (or only the last for initial call) to stdout
        /// offsetting within the file contents
        /// </summary>
        /// <param name="file"></param>
        /// <param name="onlyLast"></param>
        /// <param name="offset"></param>
        private void OutputLastLogs(WebDAVFile file, bool onlyLast = false, int offset = 0)
        {
            _console.Yellow($"------- {file.Filename}");
            var _logLines = Regex.Split(file.ContentsAsString(offset), @"^(?=\[\d{4}.+?\w{3}\])", RegexOptions.Multiline);
            var logLines  = _logLines.Where(l => !String.IsNullOrWhiteSpace(l)).Select(l => l.Trim());

            if (onlyLast)
            {
                logLines = logLines.TakeLast(1);
            }
            foreach (var logLine in logLines)
            {
                _console.WriteLine(logLine);
            }

            _console.Yellow($"--------------------");
            _console.WriteLine("");
        }
예제 #3
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);
        }