コード例 #1
0
        /// <summary>
        /// Get a Root CMS Block if you know the TabId and the ModId
        /// </summary>
        /// <param name="tabId">The DNN tab id (page id)</param>
        /// <param name="modId">The DNN Module id</param>
        /// <returns>An initialized CMS Block, ready to use/render</returns>
        public static IBlockBuilder CmsBlock(int tabId, int modId)
        {
            var moduleInfo = new ModuleController().GetModule(modId, tabId, false);
            var instance   = new DnnContainer().Init(moduleInfo, null);

            return(CmsBlock(instance));
        }
コード例 #2
0
        //[ValidateAntiForgeryToken] - never activate this, because this is a GET and can't include the RVT
        public HttpResponseMessage InstallPackage(string packageUrl)
        {
            PreventServerTimeout300();

            Log.Add("install package:" + packageUrl);
            var container = new DnnContainer().Init(ActiveModule, Log);
            var block     = container.BlockIdentifier;

            var result = new ImportFromRemote().Init(new DnnUser(UserInfo), Log)
                         .InstallPackage(block.ZoneId, block.AppId, ActiveModule.DesktopModule.ModuleName == "2sxc-app", packageUrl, Exceptions.LogException);

            Log.Add("install completed with success:" + result.Item1);
            return(Request.CreateResponse(result.Item1 ? HttpStatusCode.OK : HttpStatusCode.InternalServerError, new { result.Item1, result.Item2 }));
        }
コード例 #3
0
ファイル: GetDnnBlock.cs プロジェクト: kieran23101/2sxc
        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));
        }
コード例 #4
0
        public void Publish(int instanceId, int version)
        {
            Log.Add($"Publish(m:{instanceId}, v:{version})");
            try
            {
                // publish all entites of this content block
                var dnnModule    = ModuleController.Instance.GetModule(instanceId, Null.NullInteger, true);
                var instanceInfo = new DnnContainer(dnnModule);
                // must find tenant through module, as the PortalSettings.Current is null in search mode
                var tenant = new DnnTenant(new PortalSettings(dnnModule.OwnerPortalID));
                var cb     = new BlockFromModule(instanceInfo, Log, tenant);

                Log.Add($"found dnn mod {instanceInfo.Id}, tenant {tenant.Id}, cb exists: {cb.ContentGroupExists}");
                if (cb.ContentGroupExists)
                {
                    Log.Add("cb exists");
                    var appManager = new AppManager(cb /*.AppId*/, Log);

                    // Add content entities
                    IEnumerable <IEntity> list = new List <IEntity>();
                    list = TryToAddStream(list, cb.Data, Constants.DefaultStreamName);
                    list = TryToAddStream(list, cb.Data, "ListContent");
                    list = TryToAddStream(list, cb.Data, "PartOfPage");

                    // ReSharper disable PossibleMultipleEnumeration
                    // Find related presentation entities
                    var attachedPresItems = list
                                            .Where(e => (e as EntityInBlock)?.Presentation != null)
                                            .Select(e => ((EntityInBlock)e).Presentation);
                    Log.Add($"adding presentation item⋮{attachedPresItems.Count()}");
                    list = list.Concat(attachedPresItems);
                    // ReSharper restore PossibleMultipleEnumeration

                    var ids = list.Where(e => !e.IsPublished).Select(e => e.EntityId).ToList();

                    // publish BlockConfiguration as well - if there already is one
                    if (cb.Configuration != null)
                    {
                        Log.Add($"add group id:{cb.Configuration.Id}");
                        ids.Add(cb.Configuration.Id);
                    }

                    Log.Add(() => $"will publish id⋮{ids.Count} ids:[{ string.Join(",", ids.Select(i => i.ToString()).ToArray()) }]");

                    if (ids.Any())
                    {
                        appManager.Entities.Publish(ids.ToArray());
                    }
                    else
                    {
                        Log.Add("no ids found, won\'t publish items");
                    }
                }

                // Set published version
                new PagePublishing.ModuleVersions(instanceId, Log).PublishLatestVersion();
                Log.Add("publish completed");
            }
            catch (Exception ex)
            {
                DnnLogging.LogToDnn("exception", "publishing", Log, force: true);
                DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
                throw;
            }
        }