public void Importing(ImportLayoutContext context) { var elementTree = LoadElements(context.Layout).ToArray(); var elements = elementTree.Flatten().ToArray(); _elementManager.Importing(elements, context); context.Layout.LayoutData = _serializer.Serialize(elementTree); }
protected override void Importing(ElementWrapperPart part, ImportContentContext context) { HandleImportEvent(part, context, (describeContext, element) => { _elementManager.Importing(new[] { element }, new ImportLayoutContext { Session = new ImportContentContextWrapper(context) }); }); }
protected override void Importing(ElementWrapperPart part, ImportContentContext context) { var root = context.Data.Element(part.PartDefinition.Name); if (root == null) { return; } var exportedData = root.Value; var describeContext = CreateDescribeContext(part); var element = _serializer.Deserialize(exportedData, describeContext); _elementManager.Importing(new[] { element }, new ImportLayoutContext { Session = new ImportContentContextWrapper(context) }); part.ElementData = element.Data.Serialize(); }
public override void Execute(RecipeExecutionContext context) { var blueprintEntries = context.RecipeStep.Step.Elements().Select(xmlBlueprint => { var typeName = xmlBlueprint.Attribute("ElementTypeName").Value; Logger.Information("Importing custom element '{0}'.", typeName); try { var blueprint = GetOrCreateElement(typeName); blueprint.BaseElementTypeName = xmlBlueprint.Attribute("BaseElementTypeName").Value; blueprint.ElementDisplayName = xmlBlueprint.Attribute("ElementDisplayName").Value; blueprint.ElementDescription = xmlBlueprint.Attribute("ElementDescription").Value; blueprint.ElementCategory = xmlBlueprint.Attribute("ElementCategory").Value; blueprint.BaseElementState = xmlBlueprint.Element("BaseElementState").Value; var describeContext = DescribeElementsContext.Empty; var descriptor = _elementManager.GetElementDescriptorByTypeName(describeContext, blueprint.BaseElementTypeName); var baseElement = _elementManager.ActivateElement(descriptor); baseElement.Data = ElementDataHelper.Deserialize(blueprint.BaseElementState); baseElement.ExportableData = ElementDataHelper.Deserialize(xmlBlueprint.Attribute("BaseExportableData").Value); return(new { Blueprint = blueprint, BaseElement = baseElement }); } catch (Exception ex) { Logger.Error(ex, "Error while importing custom element '{0}'.", typeName); throw; } }).ToList(); var baseElements = blueprintEntries.Select(e => e.BaseElement).ToList(); var importContentSession = new ImportContentSession(_orchardServices.ContentManager); var importLayoutContext = new ImportLayoutContext { Session = new ImportContentSessionWrapper(importContentSession) }; _elementManager.Importing(baseElements, importLayoutContext); _elementManager.Imported(baseElements, importLayoutContext); _elementManager.ImportCompleted(baseElements, importLayoutContext); foreach (var blueprintEntry in blueprintEntries) { blueprintEntry.Blueprint.BaseElementState = blueprintEntry.BaseElement.Data.Serialize(); } }