Example #1
0
        /// <summary>
        /// Uninstall package
        /// </summary>
        /// <param name="pkgId"></param>
        /// <returns></returns>
        public static JsonResponse UninstallPackage(string pkgId)
        {
            try
            {
                var packageManager = new NuGet.PackageManager(
                    _repository,
                    new DefaultPackagePathResolver(_feedUrl),
                    new PhysicalFileSystem(HttpContext.Current.Server.MapPath(Utils.ApplicationRelativeWebRoot + "App_Data/packages"))
                    );

                var package = _repository.FindPackage(pkgId);

                if (package == null)
                {
                    return new JsonResponse {
                               Success = false, Message = "Package " + pkgId + " not found"
                    }
                }
                ;

                packageManager.UninstallPackage(package, true);

                FileSystem.RemovePackageFiles(package.Id, package.Version.ToString());

                // reset cache
                Blog.CurrentInstance.Cache.Remove("Installed-Themes");
            }
            catch (Exception ex)
            {
                Utils.Log("PackageManager.UninstallPackage", ex);
                return(new JsonResponse {
                    Success = false, Message = "Error uninstalling package, see logs for details"
                });
            }

            return(new JsonResponse {
                Success = true, Message = "Package successfully uninstalled"
            });
        }