Exemple #1
0
        public async Task <IActionResult> UninstallSystemPackage()
        {
            try
            {
                // Get the plugin name
                string package;
                using (StreamReader reader = new(HttpContext.Request.Body))
                {
                    package = await reader.ReadToEndAsync();
                }

                // Uninstall it
                using CommandConnection connection = await BuildConnection();

                await connection.UninstallSystemPackage(package);

                return(NoContent());
            }
            catch (Exception e)
            {
                if (e is AggregateException ae)
                {
                    e = ae.InnerException;
                }
                if (e is IncompatibleVersionException)
                {
                    _logger.LogError($"[{nameof(UninstallPlugin)}] Incompatible DCS version");
                    return(StatusCode(502, "Incompatible DCS version"));
                }
                if (e is SocketException)
                {
                    _logger.LogError($"[{nameof(UninstallPlugin)}] DCS is not started");
                    return(StatusCode(503, "Failed to connect to Duet, please check your connection (DCS is not started)"));
                }
                _logger.LogWarning(e, $"[{nameof(UninstallPlugin)} Failed to uninstall system package");
                return(StatusCode(500, e.Message));
            }
        }