public void Imported(ImportLayoutContext context) { var elementTree = LoadElements(context.Layout).ToArray(); var elements = elementTree.Flatten().ToArray(); _elementManager.Imported(elements, context); context.Layout.LayoutData = _serializer.Serialize(elementTree); }
public void ImportCompleted(IEnumerable <Element> elements, ImportLayoutContext context) { foreach (var element in elements) { var importingContext = new ImportElementContext(element, context.Layout, element.ExportableData ?? new ElementDataDictionary(), context.Session); _elementEventHandler.ImportCompleted(importingContext); element.Descriptor.ImportCompleted(importingContext); } }
public void Importing(IEnumerable <Element> elements, ImportLayoutContext context) { InvokeDriver(elements, (driver, element) => { var importElementContext = new ImportElementContext { Layout = context.Layout, Element = element, ExportableData = element.ExportableData, Session = context.Session }; driver.Importing(importElementContext); }); }
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(); } }