Exemplo n.º 1
0
        /// <summary>
        /// Performs the Transform.
        /// </summary>
        public override void Transform(Engine engine, Package package)
        {
            Logger.Debug("Transform");

            Initialize(engine, package);

            int expandLinkDepth;

            package.TryGetParameter("expandLinkDepth", out expandLinkDepth, Logger);

            string[] modelBuilderTypeNames = GetModelBuilderTypeNames();

            RenderedItem renderedItem = Engine.PublishingContext.RenderedItem;
            Page         page         = GetPage();

            try
            {
                DataModelBuilderSettings settings = new DataModelBuilderSettings
                {
                    ExpandLinkDepth     = expandLinkDepth,
                    GenerateXpmMetadata = IsXpmEnabled || IsPreview,
                    Locale = GetLocale()
                };

                DataModelBuilderPipeline modelBuilderPipeline = new DataModelBuilderPipeline(renderedItem, settings, modelBuilderTypeNames);
                PageModelData            pageModel            = modelBuilderPipeline.CreatePageModel(page);
                OutputJson = JsonSerialize(pageModel, IsPreview, DataModelBinder.SerializerSettings);
            }
            catch (Exception ex)
            {
                throw new DxaException($"An error occurred while rendering {page.FormatIdentifier()}", ex);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Performs the Transform.
        /// </summary>
        public override void Transform(Engine engine, Package package)
        {
            Logger.Debug("Transform");

            Initialize(engine, package);

            bool includeComponentTemplateData;

            if (!package.TryGetParameter("includeComponentTemplateData", out includeComponentTemplateData, Logger))
            {
                includeComponentTemplateData = true; // Default
            }

            int expandLinkDepth;

            package.TryGetParameter("expandLinkDepth", out expandLinkDepth, Logger);

            string[] modelBuilderTypeNames = GetModelBuilderTypeNames();

            RenderedItem      renderedItem = Engine.PublishingContext.RenderedItem;
            Component         component    = GetComponent();
            ComponentTemplate ct           = GetComponentTemplate();

            try
            {
                DataModelBuilderSettings settings = new DataModelBuilderSettings
                {
                    ExpandLinkDepth     = expandLinkDepth,
                    GenerateXpmMetadata = IsXpmEnabled || IsPreview
                };

                DataModelBuilderPipeline modelBuilderPipeline = new DataModelBuilderPipeline(renderedItem, settings, modelBuilderTypeNames);
                EntityModelData          entityModel          = modelBuilderPipeline.CreateEntityModel(component, includeComponentTemplateData ? ct : null);

                string entityModelJson = JsonSerialize(entityModel, IsPreview, DataModelBinder.SerializerSettings);
                Item   outputItem      = Package.CreateStringItem(ContentType.Text, entityModelJson);
                Package.PushItem(Package.OutputName, outputItem);
            }
            catch (Exception ex)
            {
                throw new DxaException($"An error occurred while rendering {component.FormatIdentifier()} with {ct.FormatIdentifier()}", ex);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Create data model pipeline with specified settings
 /// </summary>
 /// <param name="settings">Settings to use when creating data model pipeline</param>
 /// <returns>Data Model Pipeline</returns>
 protected DataModelBuilderPipeline CreatePipeline(DataModelBuilderSettings settings)
 => new DataModelBuilderPipeline(RenderedItem, settings, GetModelBuilderTypeNames());