Ejemplo n.º 1
0
        public ActionResult StarterKitForm(string starterKitId)
        {
            Mandate.ParameterNotNull(starterKitId, "starterKitName");

            //var publicPackage = _requestContext.PackageContext.PublicPackageManager.SourceRepository.FindPackage(starterKitId);

            //var fileName = _requestContext.PackageContext.PublicPackageManager.PathResolver.GetPackageFileName(publicPackage);
            //var filePath = Path.Combine(_requestContext.PackageContext.LocalPackageManager.SourceRepository.Source, fileName);
            //if (!global::System.IO.File.Exists(filePath))
            //{
            //    using (var file = global::System.IO.File.Create(filePath))
            //    {
            //        publicPackage.GetStream().CopyTo(file);
            //        file.Close();
            //    }
            //}

            var localPackage = _requestContext.PackageContext.LocalPackageManager.SourceRepository.FindPackage(starterKitId);

            _requestContext.PackageContext.LocalPackageManager.InstallPackage(localPackage, false);

            var installation = new PackageInstallation(_requestContext, HttpContext, localPackage);

            installation.CopyPackageFiles();
            installation.ImportData();

            SuccessfulOnRedirectAttribute.EnsureRouteData(this, "id", localPackage.Id);

            return(RedirectToAction("PostStarterKitInstall", new { id = localPackage.Id }));
        }
Ejemplo n.º 2
0
        public ActionResult AddLocalPackage(HttpPostedFileBase file)
        {
            if (file == null)
            {
                ModelState.AddModelError("PackageFileValidation", "No file selected. Please select a package file to upload.");
                return(LocalRepository());
            }

            if (!Path.GetExtension(file.FileName).EndsWith("nupkg"))
            {
                ModelState.AddModelError("PackageFileValidation", "The file uploaded is not a valid package file, only Nuget packages are supported");
                return(LocalRepository());
            }

            IPackage package;

            try
            {
                package = new ZipPackage(file.InputStream);
            }
            catch (Exception ex)
            {
                LogHelper.Error <PackagingEditorController>("Package could not be unziped.", ex);

                ModelState.AddModelError("PackageFileValidation", "The Nuget package file uploaded could not be read");
                return(LocalRepository());
            }

            try
            {
                var fileName = Path.Combine(BackOfficeRequestContext.PackageContext.LocalPackageManager.SourceRepository.Source, file.FileName);
                file.SaveAs(fileName);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("PackageFileValidation", "The package file could not be saved. " + ex.Message);
                return(LocalRepository());
            }

            if (!string.IsNullOrWhiteSpace(Request.Form["autoinstall"]))
            {
                BackOfficeRequestContext.PackageContext.LocalPackageManager.InstallPackage(package, 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 }));
            }

            Notifications.Add(new NotificationMessage(package.Title + " added to local repository", "Package added", NotificationType.Success));
            SuccessfulOnRedirectAttribute.EnsureRouteData(this, "id", package.Id);
            return(RedirectToAction("LocalRepository"));
        }
Ejemplo n.º 3
0
        public ActionResult StarterKitForm(string starterKitId)
        {
            Mandate.ParameterNotNull(starterKitId, "starterKitName");

            var package = _requestContext.PackageContext.LocalPackageManager.SourceRepository.FindPackage(starterKitId);

            _requestContext.PackageContext.LocalPackageManager.InstallPackage(package, false);

            SuccessfulOnRedirectAttribute.EnsureRouteData(this, "id", package.Id);

            return(RedirectToAction("PostStarterKitInstall", new { id = package.Id }));
        }
        public ActionResult RunPackageActions(string id, PackageInstallationState state)
        {
            var nugetPackage = BackOfficeRequestContext.PackageContext.LocalPackageManager.SourceRepository.FindPackage(id);

            //Run the configuration tasks
            //get the package with the name and ensure it exists

            if (nugetPackage != null)
            {
                //get the package folder name, create the task execution context and then execute the package tasks using the utility class
                var packageFolderName = BackOfficeRequestContext.PackageContext.LocalPathResolver.GetPackageDirectory(nugetPackage);
                var taskExeContext    = _packageInstallUtility.GetTaskExecutionContext(nugetPackage, packageFolderName, state, this);
                _packageInstallUtility.RunPostPackageInstallActions(state, taskExeContext, packageFolderName);

                //re-issue authentication token incase any permissions have changed so that a re-login is not required.
                if (User.Identity is RebelBackOfficeIdentity)
                {
                    var userId   = ((RebelBackOfficeIdentity)User.Identity).Id;
                    var user     = BackOfficeRequestContext.Application.Security.Users.GetById(userId, true);
                    var userData = BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map <UserData>(user);
                    HttpContext.CreateRebelAuthTicket(userData);
                }

                switch (state)
                {
                case PackageInstallationState.Installing:

                    Notifications.Add(new NotificationMessage(nugetPackage.Title + " has been installed", "Package installed", NotificationType.Success));
                    SuccessfulOnRedirectAttribute.EnsureRouteData(this, "id", nugetPackage.Id);

                    return(RedirectToAction("Installed", new { id = nugetPackage.Id }));

                case PackageInstallationState.Uninstalling:

                    Notifications.Add(new NotificationMessage(nugetPackage.Title + " has been uninstalled", "Package uninstalled", NotificationType.Success));
                    SuccessfulOnRedirectAttribute.EnsureRouteData(this, "id", nugetPackage.Id);

                    return(RedirectToAction("Uninstalled"));
                }
            }

            //if the task did not redirect, then perform default redirects
            return(RedirectToAction("LocalRepository"));
        }
        public ActionResult AddLocalPackage(HttpPostedFileBase file)
        {
            if (file == null)
            {
                ModelState.AddModelError("PackageFileValidation", "No file selected. Please select a package file to upload.");
                return(LocalRepository());
            }

            if (!Path.GetExtension(file.FileName).EndsWith("nupkg"))
            {
                ModelState.AddModelError("PackageFileValidation", "The file uploaded is not a valid package file, only Nuget packages are supported");
                return(LocalRepository());
            }

            IPackage package;

            try
            {
                package = new ZipPackage(file.InputStream);
            }
            catch (Exception ex)
            {
                LogHelper.Error <PackagingEditorController>("Package could not be unziped.", ex);

                ModelState.AddModelError("PackageFileValidation", "The Nuget package file uploaded could not be read");
                return(LocalRepository());
            }

            try
            {
                var fileName = Path.Combine(BackOfficeRequestContext.PackageContext.LocalPackageManager.SourceRepository.Source, file.FileName);
                file.SaveAs(fileName);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("PackageFileValidation", "The package file could not be saved. " + ex.Message);
                return(LocalRepository());
            }

            if (!string.IsNullOrWhiteSpace(Request.Form["autoinstall"]))
            {
                BackOfficeRequestContext.PackageContext.LocalPackageManager.InstallPackage(package, 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);

                return(RedirectToAction("RecycleApplication", new { id = package.Id, state = PackageInstallationState.Installing }));
            }

            Notifications.Add(new NotificationMessage(package.Title + " added to local repository", "Package added", NotificationType.Success));
            SuccessfulOnRedirectAttribute.EnsureRouteData(this, "id", package.Id);

            return(RedirectToAction("LocalRepository"));
        }
        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());
        }
Ejemplo n.º 7
0
        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());
        }