public JsonResult RunPackageActions(string id) { bool onlyCheck; if (!bool.TryParse(ValueProvider.GetValue("onlyCheck").AttemptedValue, out onlyCheck)) { throw new InvalidCastException("The required onlyCheck parameter is not found or was not recognized as boolean"); } if (!onlyCheck) { var nugetPackage = _requestContext.PackageContext.LocalPackageManager.SourceRepository.FindPackage(id); //Run the configuration taks //get the package with the name and ensure it exists if (nugetPackage != null) { var packageFolderName = _requestContext.PackageContext.LocalPathResolver.GetPackageDirectory(nugetPackage); //Run the post pacakge install tasks var taskExeContext = _packageInstallUtility.GetTaskExecutionContext(nugetPackage, packageFolderName, PackageInstallationState.Installing, this); _packageInstallUtility.RunPostPackageInstallActions(PackageInstallationState.Installing, taskExeContext, packageFolderName); } return(Json(new { status = "complete", message = "Installation completed!", percentage = 100 })); } return(Json(new { percentage = 40 })); }
public ActionResult ManagePackage() { var toInstallVal = ValueProvider.GetValue("install") == null ? new object[] { } : ValueProvider.GetValue("install").AttemptedValue.Split('-'); var toInstall = toInstallVal.Length > 0 ? toInstallVal[0] : null; var toUninstallVal = ValueProvider.GetValue("uninstall") == null ? new object[] { } : ValueProvider.GetValue("uninstall").AttemptedValue.Split('-'); var toUninstall = toUninstallVal.Length > 0 ? toUninstallVal[0] : null; var toRemoveVal = ValueProvider.GetValue("remove") == null ? new object[] { } : ValueProvider.GetValue("remove").AttemptedValue.Split('-'); var toRemove = toRemoveVal.Length > 0 ? toRemoveVal[0] : null; if (toInstall != null) { //get the package from the source var package = BackOfficeRequestContext.PackageContext.LocalPackageManager.SourceRepository.FindPackage(toInstall.ToString()); var version = Version.Parse(toInstallVal[1].ToString()); BackOfficeRequestContext.PackageContext.LocalPackageManager.InstallPackage(package.Id, version, false); var logger = new PackageLogger(BackOfficeRequestContext, HttpContext, package); var installation = new PackageInstallation(BackOfficeRequestContext, HttpContext, package); //Copy files from package folder to destination and log results var fileResults = installation.CopyPackageFiles(); foreach (var info in fileResults) { logger.Log(info.IsCopiable, info.Message()); } //Import data and log results var dataResults = installation.ImportData(); foreach (var attributeType in dataResults.AttributeTypes) { logger.Log(attributeType.IsImportable, string.Format("AttributeType {0}", attributeType.ObjectId.Value.ToString())); } foreach (var schema in dataResults.Schemas) { logger.Log(schema.IsImportable, string.Format("Schema {0}", schema.ObjectId.Value.ToString())); } foreach (var schemaRelation in dataResults.SchemaRelations) { logger.Log(schemaRelation.IsImportable, string.Format("Schema Relation {0}", schemaRelation.ObjectId.Value.ToString())); } foreach (var entity in dataResults.Entities) { logger.Log(entity.IsImportable, string.Format("Entity {0}", entity.ObjectId.Value.ToString())); } foreach (var entityRelation in dataResults.EntityRelations) { logger.Log(entityRelation.IsImportable, string.Format("Entity Relation {0}", entityRelation.ObjectId.Value.ToString())); } foreach (var language in dataResults.Languages) { logger.Log(language.IsImportable, string.Format("Language {0}", language.ObjectId.Value.ToString())); } //Notifications.Add(new NotificationMessage(package.Title + " has been installed", "Package installed", NotificationType.Success)); SuccessfulOnRedirectAttribute.EnsureRouteData(this, "id", package.Id); logger.Persist(); return(RedirectToAction("RecycleApplication", new { id = package.Id, state = PackageInstallationState.Installing })); } if (toUninstall != null) { //get the package from the installed location var nugetPackage = BackOfficeRequestContext.PackageContext.LocalPackageManager.LocalRepository.FindPackage(toUninstall.ToString()); var packageFolderName = BackOfficeRequestContext.PackageContext.LocalPathResolver.GetPackageDirectory(nugetPackage); //execute some tasks var taskExeContext = _packageInstallUtility.GetTaskExecutionContext(nugetPackage, packageFolderName, PackageInstallationState.Uninstalling, this); _packageInstallUtility.RunPrePackageUninstallActions(taskExeContext, packageFolderName); BackOfficeRequestContext.PackageContext.LocalPackageManager.UninstallPackage(nugetPackage, false, false); //Notifications.Add(new NotificationMessage(nugetPackage.Title + " has been uninstalled", "Package uninstalled", NotificationType.Success)); SuccessfulOnRedirectAttribute.EnsureRouteData(this, "id", nugetPackage.Id); return(RedirectToAction("RecycleApplication", new { id = nugetPackage.Id, state = PackageInstallationState.Uninstalling })); } if (toRemove != null) { var package = BackOfficeRequestContext.PackageContext.LocalPackageManager.SourceRepository.FindPackage(toRemove.ToString()); var packageFile = BackOfficeRequestContext.PackageContext.LocalPathResolver.GetPackageFileName(package); //delete the package folder... this will check if the file exists by just the package name or also with the version if (BackOfficeRequestContext.PackageContext.LocalPackageManager.FileSystem.FileExists(packageFile)) { BackOfficeRequestContext.PackageContext.LocalPackageManager.FileSystem.DeleteFile( Path.Combine(BackOfficeRequestContext.PackageContext.LocalPackageManager.SourceRepository.Source, packageFile)); } else { var fileNameWithVersion = packageFile.Substring(0, packageFile.IndexOf(".nupkg")) + "." + package.Version + ".nupkg"; BackOfficeRequestContext.PackageContext.LocalPackageManager.FileSystem.DeleteFile( Path.Combine(BackOfficeRequestContext.PackageContext.LocalPackageManager.SourceRepository.Source, fileNameWithVersion)); } Notifications.Add(new NotificationMessage(package.Title + " has been removed from the local repository", "Package removed", NotificationType.Success)); SuccessfulOnRedirectAttribute.EnsureRouteData(this, "id", package.Id); return(RedirectToAction("LocalRepository")); } return(HttpNotFound()); }
public ActionResult ManagePackage() { var toInstallVal = ValueProvider.GetValue("install") == null ? new object[] { } : ValueProvider.GetValue("install").AttemptedValue.Split('-'); var toInstall = toInstallVal.Length > 0 ? toInstallVal[0] : null; var toUninstallVal = ValueProvider.GetValue("uninstall") == null ? new object[] { } : ValueProvider.GetValue("uninstall").AttemptedValue.Split('-'); var toUninstall = toUninstallVal.Length > 0 ? toUninstallVal[0] : null; var toRemoveVal = ValueProvider.GetValue("remove") == null ? new object[] { } : ValueProvider.GetValue("remove").AttemptedValue.Split('-'); var toRemove = toRemoveVal.Length > 0 ? toRemoveVal[0] : null; if (toInstall != null) { //get the package from the source var package = BackOfficeRequestContext.PackageContext.LocalPackageManager.SourceRepository.FindPackage(toInstall.ToString()); var version = Version.Parse(toInstallVal[1].ToString()); BackOfficeRequestContext.PackageContext.LocalPackageManager.InstallPackage(package.Id, version, false); Notifications.Add(new NotificationMessage(package.Title + " has been installed", "Package installed", NotificationType.Success)); SuccessfulOnRedirectAttribute.EnsureRouteData(this, "id", package.Id); return(RedirectToAction("RecycleApplication", new { id = package.Id, state = PackageInstallationState.Installing })); } if (toUninstall != null) { //get the package from the installed location var nugetPackage = BackOfficeRequestContext.PackageContext.LocalPackageManager.LocalRepository.FindPackage(toUninstall.ToString()); var packageFolderName = BackOfficeRequestContext.PackageContext.LocalPathResolver.GetPackageDirectory(nugetPackage); //execute some tasks var taskExeContext = _packageInstallUtility.GetTaskExecutionContext(nugetPackage, packageFolderName, PackageInstallationState.Uninstalling, this); _packageInstallUtility.RunPrePackageUninstallActions(taskExeContext, packageFolderName); BackOfficeRequestContext.PackageContext.LocalPackageManager.UninstallPackage(nugetPackage, false, false); Notifications.Add(new NotificationMessage(nugetPackage.Title + " has been uninstalled", "Package uninstalled", NotificationType.Success)); SuccessfulOnRedirectAttribute.EnsureRouteData(this, "id", nugetPackage.Id); return(RedirectToAction("RecycleApplication", new { id = nugetPackage.Id, state = PackageInstallationState.Uninstalling })); } if (toRemove != null) { var package = BackOfficeRequestContext.PackageContext.LocalPackageManager.SourceRepository.FindPackage(toRemove.ToString()); var packageFile = BackOfficeRequestContext.PackageContext.LocalPathResolver.GetPackageFileName(package); //delete the package folder... this will check if the file exists by just the package name or also with the version if (BackOfficeRequestContext.PackageContext.LocalPackageManager.FileSystem.FileExists(packageFile)) { BackOfficeRequestContext.PackageContext.LocalPackageManager.FileSystem.DeleteFile( Path.Combine(BackOfficeRequestContext.PackageContext.LocalPackageManager.SourceRepository.Source, packageFile)); } else { var fileNameWithVersion = packageFile.Substring(0, packageFile.IndexOf(".nupkg")) + "." + package.Version + ".nupkg"; BackOfficeRequestContext.PackageContext.LocalPackageManager.FileSystem.DeleteFile( Path.Combine(BackOfficeRequestContext.PackageContext.LocalPackageManager.SourceRepository.Source, fileNameWithVersion)); } Notifications.Add(new NotificationMessage(package.Title + " has been removed from the local repository", "Package removed", NotificationType.Success)); SuccessfulOnRedirectAttribute.EnsureRouteData(this, "id", package.Id); return(RedirectToAction("LocalRepository")); } return(HttpNotFound()); }