Exemplo n.º 1
0
 protected override void Imported(ElementWrapperPart part, ImportContentContext context)
 {
     HandleSecondaryImportEvent(part, context, (describeContext, element) => {
         _elementManager.Imported(new[] { element }, new ImportLayoutContext {
             Session = new ImportContentContextWrapper(context)
         });
     });
 }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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();
            }
        }