public ActionResult Edit(HiveId?id) { if (id.IsNullValueOrEmpty()) { return(HttpNotFound()); } using (var uow = _hive.Create()) { var def = PackageBuilderHelper.GetPackageDefinitionById(uow, id.Value); if (def == null) { return(HttpNotFound()); } var pkg = PackageBuilderHelper.GetPackageFileById(uow, id.Value); var model = BackOfficeRequestContext.Application.FrameworkContext.TypeMappers .Map <PackageDefinition, PackageDefinitionEditorModel>(def); model.Id = id.Value; model.IsPublished = pkg != null; PopulateCollections(model); return(View(model)); } }
public ActionResult Download(HiveId?id) { if (id.IsNullValueOrEmpty()) { return(HttpNotFound()); } using (var uow = _hive.Create()) { var def = PackageBuilderHelper.GetPackageDefinitionById(uow, id.Value); if (def == null) { return(HttpNotFound()); } var pkg = PackageBuilderHelper.GetPackageFileById(uow, id.Value); if (pkg == null) { return(HttpNotFound()); } return(File(pkg.ContentBytes, "application/zip", def.Alias + "." + def.Version + ".nupkg")); } }
protected ActionResult ProcessSubmit(PackageDefinitionEditorModel model, bool publish) { Mandate.ParameterNotNull(model, "model"); //if there's model errors, return the view if (!ModelState.IsValid) { AddValidationErrorsNotification(); return(View("Edit", model)); } //persist the data using (var uow = _hive.Create()) { var entity = BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map <PackageDefinitionEditorModel, PackageDefinition>(model); var randomId = Guid.NewGuid().ToString(); if (!model.Id.IsNullValueOrEmpty()) { var oldFolder = uow.Repositories.Get <Rebel.Framework.Persistence.Model.IO.File>(model.Id); if (oldFolder != null) { uow.Repositories.Delete <Rebel.Framework.Persistence.Model.IO.File>(oldFolder.Id); randomId = oldFolder.Id.Value.ToString(); } } // Create folder var folder = new Rebel.Framework.Persistence.Model.IO.File( randomId, "") { IsContainer = true }; uow.Repositories.AddOrUpdate(folder); // Create definition file var file = new Rebel.Framework.Persistence.Model.IO.File( randomId + "/package.definition", Encoding.UTF8.GetBytes(entity.ToJsonString())); uow.Repositories.AddOrUpdate(file); model.Id = folder.Id; uow.Complete(); //add path for entity for SupportsPathGeneration (tree syncing) to work GeneratePathsForCurrentEntity(new EntityPathCollection(model.Id, new[] { new EntityPath(new[] { new HiveId(FixedSchemaTypes.SystemRoot, null, new HiveIdValue(new Guid("802282F2-134E-4165-82B5-6DB2AFDDD135"))), new HiveId(3), model.Id, }) })); if (publish) { // Generate the package file var result = PackageBuilderHelper.CreatePackage(randomId, entity); if (!result.Success) { ModelState.AddModelError("", "An error occured whilst trying to create the package file:\n" + result.ErrorMessage); return(View("Edit", model)); } } Notifications.Add(new NotificationMessage( "Package.Save.Message".Localize(this), "Package.Save.Title".Localize(this), NotificationType.Success)); return(RedirectToAction("Edit", new { id = model.Id })); } }
protected override RebelTreeResult GetTreeData(HiveId parentId, FormCollection queryStrings) { if (parentId == RootNodeId) { foreach (var node in PackageTreeNodes .Select(x => CreateTreeNode( x.Item1, queryStrings, x.Item2, !string.IsNullOrWhiteSpace(x.Item3) ? Url.GetEditorUrl(x.Item3, null, EditorControllerId, BackOfficeRequestContext.RegisteredComponents, BackOfficeRequestContext.Application.Settings) : Url.GetCurrentDashboardUrl(), x.Item3, false, "tree-repository"))) { if ((int)node.HiveId.Value.Value == 3) { node.AddEditorMenuItem <CreateItem>(this, "createUrl", "Create"); node.AddMenuItem <Reload>(); node.HasChildren = true; } NodeCollection.Add(node); } } else { if ((int)parentId.Value.Value == 3) { using (var uow = BackOfficeRequestContext.Application.Hive.OpenReader <IFileStore>(new Uri("storage://created-packages"))) { var root = uow.Repositories.Get <File>(new HiveId("/")); var defs = uow.Repositories.GetChildRelations(root, FixedRelationTypes.DefaultRelationType) .Select(x => PackageBuilderHelper.GetPackageDefinitionById(uow, x.DestinationId)) .Where(x => x != null) .ToList(); foreach (var def in defs) { var n = CreateTreeNode( def.Id, queryStrings, def.Name, Url.GetEditorUrl("Edit", def.Id, EditorControllerId, BackOfficeRequestContext.RegisteredComponents, BackOfficeRequestContext.Application.Settings), "Edit", false, "tree-package"); n.AddEditorMenuItem <Delete>(this, "deleteUrl", "Delete"); NodeCollection.Add(n); } } } else { throw new NotImplementedException("The Packaging tree does not support more than 1 level"); } } return(RebelTree()); }