Beispiel #1
0
        protected IBlock GetBlock(bool allowNoContextFound = true)
        {
            var wrapLog = Log.Call <IBlock>(parameters: $"request:..., {nameof(allowNoContextFound)}: {allowNoContextFound}");

            var containerId    = GetTypedHeader(Sxc.WebApi.WebApiConstants.HeaderInstanceId, -1);
            var contentblockId = GetTypedHeader(Sxc.WebApi.WebApiConstants.HeaderContentBlockId, 0); // this can be negative, so use 0
            var pageId         = GetTypedHeader(Sxc.WebApi.WebApiConstants.HeaderPageId, -1);
            var instance       = TestIds.FindInstance(containerId);

            if (containerId == -1 || pageId == -1 || instance == null)
            {
                if (allowNoContextFound)
                {
                    return(wrapLog("not found", null));
                }
                throw new Exception("No context found, cannot continue");
            }

            var ctx = SxcMvc.CreateContext(HttpContext, instance.Zone, pageId, containerId, instance.App,
                                           instance.Block);
            IBlock block = new BlockFromModule().Init(ctx, Log);

            // only if it's negative, do we load the inner block
            if (contentblockId > 0)
            {
                return(wrapLog("found", block));
            }

            Log.Add($"Inner Content: {contentblockId}");
            block = new BlockFromEntity().Init(block, contentblockId, Log);

            return(wrapLog("found", block));
        }
        public string GenerateContentBlock(int parentId, string field, int sortOrder, string app = "", Guid?guid = null)
        {
            var entityId = Backend.NewBlock(parentId, field, sortOrder, app, guid);

            // now return a rendered instance
            var newContentBlock = new BlockFromEntity().Init(GetBlock(), entityId, Log);

            return(newContentBlock.BlockBuilder.Render());
        }
Beispiel #3
0
        internal static IHtmlString Render(IBlock parentBlock, IEntity entity, ILog parentLog)
        {
            var log = new Log("Htm.Render", parentBlock.Log, "simple");

            // if not the expected content-type, just output a hidden html placeholder
            if (entity.Type.Name != Settings.AttributeSetStaticNameContentBlockTypeName)
            {
                log.Add("empty, will return hidden html placeholder");
                return(new HtmlString(string.Format(EmptyMessage, entity.EntityId)));
            }

            // render it
            log.Add("found, will render");
            var cb = new BlockFromEntity().Init(parentBlock, entity, log);

            return(new HtmlString(cb.BlockBuilder.Render()));
        }
        public string GenerateContentBlock(int parentId, string field, int sortOrder, string app = "", Guid?guid = null)
        {
            Log.Add($"get CB parent:{parentId}, field:{field}, order:{sortOrder}, app:{app}, guid:{guid}");
            var contentTypeName = Settings.AttributeSetStaticNameContentBlockTypeName;
            var values          = new Dictionary <string, object>
            {
                { BlockFromEntity.CbPropertyTitle, "" },
                { BlockFromEntity.CbPropertyApp, app },
                { BlockFromEntity.CbPropertyShowChooser, true },
            };
            var newGuid  = guid ?? Guid.NewGuid();
            var entityId = CreateItemAndAddToList(parentId, field, sortOrder, contentTypeName, values, newGuid);

            // now return a rendered instance
            var newContentBlock = new BlockFromEntity(BlockBuilder.Block, entityId, Log);

            return(newContentBlock.BlockBuilder.Render().ToString());
        }
Beispiel #5
0
        internal static IBlock GetCmsBlock(HttpRequestMessage request, bool allowNoContextFound, ILog log)
        {
            var wrapLog = log.Call <IBlock>(parameters: $"request:..., {nameof(allowNoContextFound)}: {allowNoContextFound}");

            //const string headerId = "ContentBlockId";
            var moduleInfo = request.FindModuleInfo();

            if (allowNoContextFound & moduleInfo == null)
            {
                return(wrapLog("request ModuleInfo not found, allowed", null));
            }

            if (moduleInfo == null)
            {
                log.Add("context/module not found");
            }

            var container = new DnnContainer().Init(moduleInfo, log);

            var tenant = moduleInfo == null
                ? new DnnTenant(null)
                : new DnnTenant().Init(moduleInfo.OwnerPortalID);

            var    context = new DnnContext(tenant, container, new DnnUser(), GetOverrideParams(request));
            IBlock block   = new BlockFromModule().Init(context, log);

            // check if we need an inner block
            if (request.Headers.Contains(WebApiConstants.HeaderContentBlockId))
            {
                var blockHeaderId = request.Headers.GetValues(WebApiConstants.HeaderContentBlockId).FirstOrDefault();
                int.TryParse(blockHeaderId, out var blockId);
                if (blockId < 0)   // negative id, so it's an inner block
                {
                    log.Add($"Inner Content: {blockId}");
                    block = new BlockFromEntity().Init(block, blockId, log);
                }
            }

            return(wrapLog("ok", block));
        }
Beispiel #6
0
        internal static IBlockBuilder GetCmsBlock(HttpRequestMessage request, bool allowNoContextFound, ILog log)
        {
            var wrapLog = log.Call <IBlockBuilder>(parameters: $"request:..., {nameof(allowNoContextFound)}: {allowNoContextFound}");

            const string headerId   = "ContentBlockId";
            var          moduleInfo = request.FindModuleInfo();

            if (allowNoContextFound & moduleInfo == null)
            {
                return(wrapLog("request ModuleInfo not found, allowed", null));
            }

            if (moduleInfo == null)
            {
                log.Add("context/module not found");
            }

            var urlParams = PrepareUrlParamsForInternalUse(request);

            var tenant = moduleInfo == null
                ? new DnnTenant(null)
                : new DnnTenant(new PortalSettings(moduleInfo.OwnerPortalID));

            IBlock contentBlock = new BlockFromModule(new DnnContainer(moduleInfo), log, tenant, urlParams);

            // check if we need an inner block
            if (request.Headers.Contains(headerId))
            {
                var blockHeaderId = request.Headers.GetValues(headerId).FirstOrDefault();
                int.TryParse(blockHeaderId, out var blockId);
                if (blockId < 0)   // negative id, so it's an inner block
                {
                    log.Add($"Inner Content: {blockId}");
                    contentBlock = new BlockFromEntity(contentBlock, blockId, log);
                }
            }

            return(wrapLog("ok", contentBlock.BlockBuilder));
        }