예제 #1
0
        public AppExportInfoDto GetAppInfo(int appId, int zoneId)
        {
            Log.Add($"get app info for app:{appId} and zone:{zoneId}");
            var contextZoneId = _zoneMapper.GetZoneId(_tenantId);
            var currentApp    = ImpExpHelpers.GetAppAndCheckZoneSwitchPermissions(zoneId, appId, _user, contextZoneId, Log);

            var zipExport = Factory.Resolve <ZipExport>().Init(zoneId, appId, currentApp.Folder, currentApp.PhysicalPath, Log);
            var cultCount = _zoneMapper
                            .CulturesWithState(currentApp.Tenant.Id, currentApp.ZoneId)
                            .Count(c => c.Active);

            var cms = new CmsRuntime(currentApp, Log, true, false);

            return(new AppExportInfoDto
            {
                Name = currentApp.Name,
                Guid = currentApp.AppGuid,
                Version = currentApp.VersionSafe(),
                EntitiesCount = cms.Entities.All.Count(),
                LanguagesCount = cultCount,
                TemplatesCount = cms.Views.GetAll().Count(),
                HasRazorTemplates = cms.Views.GetRazor().Any(),
                HasTokenTemplates = cms.Views.GetToken().Any(),
                FilesCount = zipExport.FileManager.AllFiles.Count(),
                TransferableFilesCount = zipExport.FileManager.AllTransferableFiles.Count()
            });
        }
예제 #2
0
        private BlockConfiguration LoadBlockConfiguration()
        {
            var wrapLog = Log.Call <BlockConfiguration>();

            if (UseSxcInstanceContentGroup)
            {
                return(wrapLog("need content-group, will use from sxc-context", Block.Configuration));
            }

            // If we don't have a context, then look it up based on the InstanceId
            Log.Add("need content-group, will construct as cannot use context");
            if (!InstanceId.HasValue)
            {
                wrapLog("Error, no module-id", null);
                throw new Exception("Looking up BlockConfiguration failed because ModuleId is null.");
            }
            var publish     = Factory.Resolve <IPagePublishing>().Init(Log);
            var userMayEdit = HasInstanceContext && Block.EditAllowed;

            var cms       = new CmsRuntime(this, Log, HasInstanceContext && userMayEdit, publish.IsEnabled(InstanceId.Value));
            var container = Factory.Resolve <IContainer>().Init(InstanceId.Value, Log);
            var blockId   = container.BlockIdentifier;

            return(wrapLog("ok", cms.Blocks.GetOrGeneratePreviewConfig(blockId)));
        }
예제 #3
0
        private IView TryToGetTemplateBasedOnUrlParams(IContextOfBlock context, CmsRuntime cms)
        {
            var wrapLog = Log.Call <IView>("template override - check");

            if (context.Page.Parameters == null)
            {
                return(wrapLog("no params", null));
            }

            var urlParameterDict = context.Page.Parameters.ToDictionary(pair => pair.Key?.ToLowerInvariant() ?? "", pair =>
                                                                        $"{pair.Key}/{pair.Value}".ToLowerInvariant());

            var allTemplates = cms.Views.GetAll();

            foreach (var template in allTemplates.Where(t => !string.IsNullOrEmpty(t.UrlIdentifier)))
            {
                var desiredFullViewName = template.UrlIdentifier.ToLowerInvariant();
                if (desiredFullViewName.EndsWith("/.*"))   // match details/.* --> e.g. details/12
                {
                    var keyName = desiredFullViewName.Substring(0, desiredFullViewName.Length - 3);
                    if (urlParameterDict.ContainsKey(keyName))
                    {
                        return(wrapLog("template override - found:" + template.Name, template));
                    }
                }
                else if (urlParameterDict.ContainsValue(desiredFullViewName)) // match view/details
                {
                    return(wrapLog("template override - found:" + template.Name, template));
                }
            }

            return(wrapLog("template override - none", null));
        }
예제 #4
0
        public dynamic GetAppInfo(int appId, int zoneId)
        {
            Log.Add($"get app info for app:{appId} and zone:{zoneId}");
            var currentApp = SxcAppForWebApi.AppBasedOnUserPermissions(zoneId, appId, UserInfo, Log);

            var zipExport = new ZipExport(zoneId, appId, currentApp.Folder, currentApp.PhysicalPath, Log);
            var cultCount = Env.ZoneMapper
                            .CulturesWithState(currentApp.Tenant.Id, currentApp.ZoneId)
                            .Count(c => c.Active);

            var cms = new CmsRuntime(currentApp, Log, true, false);

            return(new
            {
                currentApp.Name,
                Guid = currentApp.AppGuid,
                Version = currentApp.VersionSafe(),
                EntitiesCount = cms.Entities.All.Count(),
                LanguagesCount = cultCount,
                TemplatesCount = cms.Views.GetAll().Count(),
                HasRazorTemplates = cms.Views.GetRazor().Any(),
                HasTokenTemplates = cms.Views.GetToken().Any(),
                FilesCount = zipExport.FileManager.AllFiles.Count(),
                TransferableFilesCount = zipExport.FileManager.AllTransferableFiles.Count()
            });
        }
예제 #5
0
        public IEnumerable <ViewDto> ViewUsage(IInstanceContext context, int appId, Guid guid,
                                               Func <List <IView>, List <BlockConfiguration>, IEnumerable <ViewDto> > finalBuilder)
        {
            var wrapLog = Log.Call <IEnumerable <ViewDto> >($"{appId}, {guid}");

            // extra security to only allow zone change if host user
            var permCheck = new MultiPermissionsApp().Init(context, GetApp(appId, null), Log);

            if (!permCheck.EnsureAll(GrantSets.ReadSomething, out var error))
            {
                throw HttpException.PermissionDenied(error);
            }

            var cms = new CmsRuntime(appId, Log, true);
            // treat view as a list - in case future code will want to analyze many views together
            var views = new List <IView> {
                cms.Views.Get(guid)
            };

            var blocks = cms.Blocks.AllWithView();

            Log.Add($"Found {blocks.Count} content blocks");

            var result = finalBuilder(views, blocks);

            return(wrapLog("ok", result));
        }
예제 #6
0
        public IEnumerable <ViewDetailsDto> GetAll(int appId)
        {
            Log.Add($"get all a#{appId}");
            var cms = new CmsRuntime(appId, Log, true);

            var attributeSetList = cms.ContentTypes.FromScope(Settings.AttributeSetScope).ToList();
            var templateList     = cms.Views.GetAll().ToList();

            Log.Add($"attrib list count:{attributeSetList.Count}, template count:{templateList.Count}");
            var templates = templateList.Select(c => new ViewDetailsDto
            {
                Id = c.Id, Name = c.Name, ContentType = MiniCTSpecs(attributeSetList, c.ContentType, c.ContentItem),
                PresentationType     = MiniCTSpecs(attributeSetList, c.PresentationType, c.PresentationItem),
                ListContentType      = MiniCTSpecs(attributeSetList, c.HeaderType, c.HeaderItem),
                ListPresentationType = MiniCTSpecs(attributeSetList, c.HeaderPresentationType, c.HeaderPresentationItem),
                TemplatePath         = c.Path,
                IsHidden             = c.IsHidden,
                ViewNameInUrl        = c.UrlIdentifier,
                Guid     = c.Guid,
                List     = c.UseForList,
                HasQuery = c.QueryRaw != null,
                Used     = c.Entity.Parents().Count
            });

            return(templates);
        }
예제 #7
0
        public string RemoteInstallDialogUrl(string dialog, bool isContentApp)
        {
            // note / warning: some duplicate code with SystemController.cs
            // ReSharper disable StringLiteralTypo

            if (dialog != "gettingstarted")
            {
                throw new Exception("unknown dialog name: " + dialog);
            }


            var moduleInfo = Request.FindModuleInfo();
            var modName    = moduleInfo.DesktopModule.ModuleName;

            // new: check if it should allow this
            // it should only be allowed, if the current situation is either
            // Content - and no views exist (even invisible ones)
            // App - and no apps exist - this is already checked on client side, so I won't include a check here
            if (isContentApp)
            {
                // we'll usually run into errors if nothing is installed yet, so on errors, we'll continue
                try
                {
                    var all = new CmsRuntime(BlockBuilder.App, Log, Edit.Enabled, false).Views.GetAll();
                    if (all.Any())
                    {
                        return(null);
                    }
                }
                catch
                {
                    // ignored
                }
            }

            // Add desired destination
            // Add DNN Version, 2SexyContent Version, module type, module id, Portal ID
            var gettingStartedSrc = "//gettingstarted.2sxc.org/router.aspx?"
                                    + "destination=autoconfigure" + (isContentApp ? Eav.Constants.ContentAppName.ToLower() : "app")
                                    + "&DnnVersion=" + Assembly.GetAssembly(typeof(Globals)).GetName().Version.ToString(4)
                                    + "&2SexyContentVersion=" + Settings.ModuleVersion
                                    + "&ModuleName=" + modName + "&ModuleId=" + moduleInfo.ModuleID
                                    + "&PortalID=" + moduleInfo.PortalID;
            // Add VDB / Zone ID (if set)
            var zoneId = Env.ZoneMapper.GetZoneId(moduleInfo.PortalID);

            gettingStartedSrc += "&ZoneID=" + zoneId;
            // ReSharper restore StringLiteralTypo

            // Add DNN Guid
            var hostSettings = HostController.Instance.GetSettingsDictionary();

            gettingStartedSrc += hostSettings.ContainsKey("GUID") ? "&DnnGUID=" + hostSettings["GUID"] : "";
            // Add Portal Default Language & current language
            gettingStartedSrc += "&DefaultLanguage=" + PortalSettings.DefaultLanguage
                                 + "&CurrentLanguage=" + PortalSettings.CultureCode;

            // Set src to iframe
            return(gettingStartedSrc);
        }
예제 #8
0
        public dynamic Usage(int appId, Guid guid)
        {
            var wrapLog = Log.Call <dynamic>($"{appId}, {guid}");

            // extra security to only allow zone change if host user
            var permCheck = new MultiPermissionsApp(BlockBuilder, appId, Log);

            if (!permCheck.EnsureAll(GrantSets.ReadSomething, out var exception))
            {
                throw exception;
            }

            var cms = new CmsRuntime(appId, Log, true);
            // treat view as a list - in case future code will want to analyze many views together
            var views = new List <IView> {
                cms.Views.Get(guid)
            };

            var blocks = cms.Blocks.AllWithView();

            Log.Add($"Found {blocks.Count} content blocks");

            // create array with all 2sxc modules in this portal
            var allMods = new Pages(Log).AllModulesWithContent(PortalSettings.PortalId);

            Log.Add($"Found {allMods.Count} modules");

            var result = views.Select(vwb => new ViewDto(vwb, blocks, allMods));

            return(wrapLog("ok", result));
        }
예제 #9
0
        public void SetAppId(IContainer instance, /*IAppEnvironment env,*/ int?appId, ILog parentLog)
        {
            Log.Add($"SetAppIdForInstance({instance.Id}, -, appid: {appId})");
            // Reset temporary template
            ClearPreview(instance.Id);

            // ToDo: Should throw exception if a real BlockConfiguration exists

            var module = (instance as Container <ModuleInfo>).UnwrappedContents;
            var zoneId = _environment.ZoneMapper.GetZoneId(module.OwnerPortalID);

            if (appId == Constants.AppIdEmpty || !appId.HasValue)
            {
                DnnTenantSettings.UpdateInstanceSettingForAllLanguages(instance.Id, Settings.AppNameString, null, Log);
            }
            else
            {
                var appName = State.Zones[zoneId].Apps[appId.Value];
                DnnTenantSettings.UpdateInstanceSettingForAllLanguages(instance.Id, Settings.AppNameString, appName, Log);
            }

            // Change to 1. available template if app has been set
            if (appId.HasValue)
            {
                var appIdentity  = new AppIdentity(zoneId, appId.Value);
                var cms          = new CmsRuntime(appIdentity, Log, true, _environment.PagePublishing.IsEnabled(instance.Id));
                var templateGuid = cms.Views.GetAll().FirstOrDefault(t => !t.IsHidden)?.Guid;
                if (templateGuid.HasValue)
                {
                    SetPreview(instance.Id, templateGuid.Value);
                }
            }
        }
예제 #10
0
 public BlockConfiguration(IEntity entity, CmsRuntime cmsRuntime, string languageCode, ILog parentLog) : base(entity, languageCode, parentLog, "Blk.Config")
 {
     Log.Add("Entity is " + (entity == null ? "" : "not") + " null");
     _cmsRuntime = cmsRuntime;
     ZoneId      = cmsRuntime.ZoneId;
     AppId       = cmsRuntime.AppId;
     ShowDrafts  = cmsRuntime.ShowDrafts;
 }
예제 #11
0
 public BlockConfiguration(IEntity contentGroupEntity, CmsRuntime cmsRuntime, ILog parentLog)
     : this(cmsRuntime, parentLog, "constructor from entity")
 {
     Entity = contentGroupEntity
              ?? throw new Exception("BlockConfiguration entity is null. " +
                                     "This usually happens when you are duplicating a site, and have not yet imported the other content/apps. " +
                                     "If that is your issue, check 2sxc.org/help?tag=export-import");
 }
예제 #12
0
 public AppViewPickerBackend Init(IInstanceContext context, IBlock block, ILog parentLog)
 {
     Log.LinkTo(parentLog);
     _context    = context;
     _block      = block;
     _cmsRuntime = _block.App == null ? null : new CmsRuntime(_block.App, Log, true, false);
     return(this);
 }
예제 #13
0
 public BlockConfiguration(CmsRuntime cmsRuntime, ILog parentLog, string logNote)
     : base("Blk.Config", new CodeRef(), parentLog, logNote)
 {
     _cmsRuntime       = cmsRuntime;
     ZoneId            = cmsRuntime.ZoneId;
     AppId             = cmsRuntime.AppId;
     ShowDrafts        = cmsRuntime.ShowDrafts;
     VersioningEnabled = cmsRuntime.EnablePublishing;
 }
예제 #14
0
        /// <summary>
        /// Create a module-content block
        /// </summary>
        /// <param name="container">the dnn module-info</param>
        /// <param name="parentLog">a parent-log; can be null but where possible you should wire one up</param>
        /// <param name="tenant"></param>
        /// <param name="overrideParams">optional override parameters</param>
        public BlockFromModule(IContainer container, ILog parentLog, ITenant tenant, IEnumerable <KeyValuePair <string, string> > overrideParams = null) : base(parentLog, "CB.Mod")
        {
            var wrapLog = Log.Call();

            Container      = container ?? throw new Exception("Need valid Instance/ModuleInfo / ModuleConfiguration of runtime");
            ParentId       = container.Id;
            ContentBlockId = ParentId;

            // Ensure we know what portal the stuff is coming from
            // PortalSettings is null, when in search mode
            Tenant = tenant;

            // important: don't use the SxcInstance.Environment, as it would try to init the Sxc-object before the app is known, causing various side-effects
            var tempEnv = Factory.Resolve <IEnvironmentFactory>().Environment(parentLog);

            ZoneId = tempEnv.ZoneMapper.GetZoneId(tenant.Id);                                           // use tenant as reference, as it can be different from instance.TenantId

            AppId = Factory.Resolve <IMapAppToInstance>().GetAppIdFromInstance(container, ZoneId) ?? 0; // fallback/undefined YET

            Log.Add($"parent#{ParentId}, content-block#{ContentBlockId}, z#{ZoneId}, a#{AppId}");

            if (AppId == Settings.DataIsMissingInDb)
            {
                _dataIsMissing = true;
                Log.Add("data is missing, will stop here");
                return;
            }

            // 2018-09-22 new with auto-init-data
            var urlParams = overrideParams ?? SystemWeb.GetUrlParams();

            BlockBuilder = new BlockBuilder(null, this, Container, urlParams, Log);

            if (AppId != 0)
            {
                Log.Add("real app, will load data");

                App = new App(Tenant, ZoneId, AppId, ConfigurationProvider.Build(BlockBuilder, false), true, Log);

                // 2019-11-11 2dm new, with CmsRuntime
                var cms = new CmsRuntime(App, Log, BlockBuilder.UserMayEdit,
                                         BlockBuilder.Environment.PagePublishing.IsEnabled(BlockBuilder.Container.Id));

                Configuration = cms.Blocks.GetInstanceContentGroup(container.Id, container.PageId);

                if (Configuration.DataIsMissing)
                {
                    _dataIsMissing = true;
                    App            = null;
                    return;
                }

                ((BlockBuilder)BlockBuilder).SetTemplateOrOverrideFromUrl(Configuration.View);
            }

            wrapLog($"ok a:{AppId}, container:{container.Id}, content-group:{Configuration?.Id}");
        }
        public string GetAutoInstallPackagesUiUrl(ITenant tenant, IContainer container, bool isContentApp, int appId)
        {
            var moduleInfo = (container as DnnContainer)?.UnwrappedContents;
            var portal     = (tenant as DnnTenant)?.UnwrappedContents;

            if (moduleInfo == null || portal == null)
            {
                throw new ArgumentException("missing portal/module");
            }

            // new: check if it should allow this
            // it should only be allowed, if the current situation is either
            // Content - and no views exist (even invisible ones)
            // App - and no apps exist - this is already checked on client side, so I won't include a check here
            if (isContentApp)
            {
                try
                {
                    // we'll usually run into errors if nothing is installed yet, so on errors, we'll continue
                    var contentViews = new CmsRuntime(appId, Log, /*Edit.Enabled,*/ false).Views.GetAll();
                    if (contentViews.Any())
                    {
                        return(null);
                    }
                }
                catch { /* ignore */ }
            }

            // ReSharper disable StringLiteralTypo
            // Add desired destination
            // Add DNN Version, 2SexyContent Version, module type, module id, Portal ID
            var gettingStartedSrc =
                "//gettingstarted.2sxc.org/router.aspx?"
                + "destination=autoconfigure" + (isContentApp ? Eav.Constants.ContentAppName.ToLower() : "app")
                + "&DnnVersion=" + Assembly.GetAssembly(typeof(Globals)).GetName().Version.ToString(4)
                + "&2SexyContentVersion=" + Settings.ModuleVersion
                + "&ModuleName=" + moduleInfo.DesktopModule.ModuleName
                + "&ModuleId=" + moduleInfo.ModuleID
                + "&PortalID=" + moduleInfo.PortalID;
            // Add VDB / Zone ID (if set)
            var zoneMapper = Eav.Factory.Resolve <IZoneMapper>().Init(Log);
            var zoneId     = zoneMapper.GetZoneId(moduleInfo.PortalID);

            gettingStartedSrc += "&ZoneID=" + zoneId;
            // ReSharper restore StringLiteralTypo

            // Add DNN Guid
            var hostSettings = HostController.Instance.GetSettingsDictionary();

            gettingStartedSrc += hostSettings.ContainsKey("GUID") ? "&DnnGUID=" + hostSettings["GUID"] : "";
            // Add Portal Default Language & current language
            gettingStartedSrc += "&DefaultLanguage=" + portal.DefaultLanguage
                                 + "&CurrentLanguage=" + portal.CultureCode;

            // Set src to iframe
            return(gettingStartedSrc);
        }
예제 #16
0
파일: AssetEditor.cs 프로젝트: valadas/2sxc
        private void InitShared(IApp app, bool isSuperUser, bool isAdmin, ILog parentLog)
        {
            Log.LinkTo(parentLog);
            _app             = app;
            _userIsSuperUser = isSuperUser;
            _userIsAdmin     = isAdmin;

            // todo: 2dm Views - see if we can get logger to flow
            _cmsRuntime = _cmsRuntimeLazy.Value.Init(app, true, Log);
        }
예제 #17
0
        protected T CompleteInit <T>(IBlockBuilder rootBuilder, IBlockIdentifier blockId, int blockNumberUnsureIfNeeded) where T : class
        {
            var wrapLog = Log.Call <T>();

            ParentId       = Context.Container.Id;
            ContentBlockId = blockNumberUnsureIfNeeded;

            Log.Add($"parent#{ParentId}, content-block#{ContentBlockId}, z#{ZoneId}, a#{AppId}");

            // 2020-09-04 2dm - new change, moved BlockBuilder up so it's never null - may solve various issues
            // but may introduce new ones
            BlockBuilder = new BlockBuilder(rootBuilder, this, Log);

            // If specifically no app found, end initialization here
            // Means we have no data, and no BlockBuilder
            if (AppId == AppConstants.AppIdNotFound || AppId == Eav.Constants.NullId)
            {
                DataIsMissing = true;
                return(wrapLog("stop: app & data are missing", this as T));
            }

            // If no app yet, stop now with BlockBuilder created
            if (AppId == Eav.Constants.AppIdEmpty)
            {
                var msg = $"stop a:{AppId}, container:{Context.Container.Id}, content-group:{Configuration?.Id}";
                return(wrapLog(msg, this as T));
            }


            Log.Add("Real app specified, will load App object with Data");

            // Get App for this block
            App = Eav.Factory.Resolve <App>().PreInit(Context.Tenant)
                  .Init(this, ConfigurationProvider.Build(this, false),
                        true, Log);

            // note: requires EditAllowed, which isn't ready till App is created
            var publishing = Eav.Factory.Resolve <IPagePublishing>().Init(Log);
            var cms        = new CmsRuntime(App, Log, EditAllowed, publishing.IsEnabled(Context.Container.Id));

            Configuration = cms.Blocks.GetOrGeneratePreviewConfig(blockId);

            // handle cases where the content group is missing - usually because of incomplete import
            if (Configuration.DataIsMissing)
            {
                DataIsMissing = true;
                App           = null;
                return(wrapLog($"DataIsMissing a:{AppId}, container:{Context.Container.Id}, content-group:{Configuration?.Id}", this as T));
            }

            // use the content-group template, which already covers stored data + module-level stored settings
            View = new BlockViewLoader(Log).PickView(this, Configuration.View, Context, cms);
            return(wrapLog($"ok a:{AppId}, container:{Context.Container.Id}, content-group:{Configuration?.Id}", this as T));
        }
예제 #18
0
        private BlockConfiguration GetContentGroup(Guid contentGroupGuid)
        {
            Log.Add($"get group:{contentGroupGuid}");
            var cms          = new CmsRuntime(BlockBuilder.App, Log, true, false);
            var contentGroup = cms.Blocks.GetBlockConfig(contentGroupGuid);

            if (contentGroup == null)
            {
                throw new Exception("BlockConfiguration with Guid " + contentGroupGuid + " does not exist.");
            }
            return(contentGroup);
        }
예제 #19
0
        public AssetEditor(IApp app, int templateId, bool isSuperUser, bool isAdmin, ILog parentLog)
            : base("Sxc.AstEdt", parentLog)
        {
            _app             = app;
            _userIsSuperUser = isSuperUser;
            _userIsAdmin     = isAdmin;

            // todo: 2dm Views - see if we can get logger to flow
            var template = new CmsRuntime(app, Log, true, false).Views.Get(templateId);

            EditInfo = TemplateAssetsInfo(template);
        }
예제 #20
0
        private void ResolveItemIdOfGroup(int appId, ItemIdentifier item)
        {
            if (item.Group == null)
            {
                return;
            }
            var cms = new CmsRuntime(appId, Log, true);

            var contentGroup = cms.Blocks.GetBlockConfig(item.Group.Guid);
            var part         = contentGroup[item.Group.Part];

            item.EntityId = part[item.ListIndex()].EntityId;
        }
예제 #21
0
        private void _constructor(IBlock parent, IEntity cbDefinition)
        {
            var wrapLog = Log.Call();

            Parent = parent;
            ParseContentBlockDefinition(cbDefinition);
            ParentId       = parent.ParentId;
            ContentBlockId = -cbDefinition.EntityId;

            // Ensure we know what portal the stuff is coming from
            Tenant = Parent.App.Tenant;

            ZoneId = Parent.ZoneId;

            AppId = AppHelpers.GetAppIdFromGuidName(ZoneId, _appName); // should be 0 if unknown, must test

            if (AppId == Settings.DataIsMissingInDb)
            {
                _dataIsMissing = true;
                return;
            }

            // 2018-09-22 new, must come before the AppId == 0 check
            BlockBuilder = new BlockBuilder(parent.BlockBuilder, this, Parent.BlockBuilder.Container, Parent.BlockBuilder.Parameters, Log);

            if (AppId == 0)
            {
                return;
            }

            App = new App(Tenant, ZoneId, AppId, ConfigurationProvider.Build(BlockBuilder, false), true, Log);

            // 2019-11-11 2dm new, with CmsRuntime
            var cms = new CmsRuntime(App, Log, parent.BlockBuilder.UserMayEdit,
                                     parent.BlockBuilder.Environment.PagePublishing.IsEnabled(parent.BlockBuilder.Container.Id));

            Configuration = cms.Blocks.GetContentGroupOrGeneratePreview(_contentGroupGuid, _previewTemplateGuid);

            // handle cases where the content group is missing - usually because of incomplete import
            if (Configuration.DataIsMissing)
            {
                _dataIsMissing = true;
                App            = null;
                return;
            }

            // use the content-group template, which already covers stored data + module-level stored settings
            ((BlockBuilder)BlockBuilder).SetTemplateOrOverrideFromUrl(Configuration.View);

            wrapLog("ok");
        }
예제 #22
0
        internal static ItemIdentifier ResolveItemIdOfGroup(int appId, ItemIdentifier item, ILog log)
        {
            if (item.Group == null)
            {
                return(item);
            }
            var cms = new CmsRuntime(appId, log, true);

            var contentGroup = cms.Blocks.GetBlockConfig(item.Group.Guid);
            var part         = contentGroup[item.Group.Part];

            item.EntityId = part[item.ListIndex()].EntityId;
            return(item);
        }
예제 #23
0
        public PolymorphismDto Polymorphism(int appId)
        {
            var callLog = Log.Call <dynamic>($"a#{appId}");
            var cms     = new CmsRuntime(appId, Log, true);
            var poly    = new Polymorphism.Polymorphism(cms.Data, Log);
            var result  = new PolymorphismDto
            {
                Id       = poly.Entity?.EntityId,
                Resolver = poly.Resolver,
                TypeName = PolymorphismConstants.Name
            };

            return(callLog(null, result));
        }
예제 #24
0
        internal void UpdateTitle()
        {
            Log.Add("update title");
            // check the blockConfiguration as to what should be the module title, then try to set it
            // technically it could have multiple different groups to save in,
            // ...but for now we'll just update the current modules title
            // note: it also correctly handles published/unpublished, but I'm not sure why :)

            var cms          = new CmsRuntime(Block.App, Log, true, false);
            var contentGroup = cms.Blocks.GetBlockConfig(BlockConfiguration.Guid);

            var titleItem = contentGroup.Header.FirstOrDefault() ?? contentGroup.Content.FirstOrDefault();

            UpdateTitle(titleItem);
        }
예제 #25
0
        public object DeletePipeline(int appId, int id)
        {
            Log.Add($"delete pipe:{id} on app:{appId}");
            // Stop if a Template uses this Pipeline
            //var app = GetApp.LightWithoutData(new DnnTenant(PortalSettings.Current), appId, Log);
            var cms = new CmsRuntime(appId, Log, true);
            var templatesUsingPipeline = cms.Views.GetAll()
                                         .Where(t => t.Query?.Id == id)
                                         .Select(t => t.Id)
                                         .ToArray();

            if (templatesUsingPipeline.Any())
            {
                throw new Exception(
                          $"Pipeline is used by Views and cant be deleted. Pipeline EntityId: {id}. TemplateIds: {string.Join(", ", templatesUsingPipeline)}");
            }

            return(_eavCont.DeletePipeline(appId, id));
        }
예제 #26
0
        public ExportPartsOverviewDto PreExportSummary(int appId, int zoneId, string scope)
        {
            Log.Add($"get content info for z#{zoneId}, a#{appId}, scope:{scope} super?:{_user.IsSuperUser}");
            var contextZoneId = _zoneMapper.GetZoneId(_tenantId);
            var currentApp    = ImpExpHelpers.GetAppAndCheckZoneSwitchPermissions(zoneId, appId, _user, contextZoneId, Log);

            var cms          = new CmsRuntime(currentApp, Log, true, false);
            var contentTypes = cms.ContentTypes.FromScope(scope);
            var entities     = cms.Entities.All;
            var templates    = cms.Views.GetAll();

            return(new ExportPartsOverviewDto
            {
                ContentTypes = contentTypes.Select(c => new ExportPartsContentTypesDto
                {
                    Id = c.ContentTypeId,
                    Name = c.Name,
                    StaticName = c.StaticName,
                    Templates = templates.Where(t => t.ContentType == c.StaticName)
                                .Select(t => new IdNameDto
                    {
                        Id = t.Id,
                        Name = t.Name
                    }),
                    Entities = entities
                               .Where(e => e.Type.ContentTypeId == c.ContentTypeId)
                               .Select(e => new ExportPartsEntitiesDto
                    {
                        Title = e.GetBestTitle(),
                        Id = e.EntityId
                    })
                }),
                TemplatesWithoutContentTypes = templates
                                               .Where(t => !string.IsNullOrEmpty(t.ContentType))
                                               .Select(t => new IdNameDto
                {
                    Id = t.Id,
                    Name = t.Name
                })
            });
        }
예제 #27
0
        public HttpResponseMessage RenderTemplate([FromUri] int templateId, [FromUri] string lang, bool cbIsEntity = false)
        {
            Log.Add($"render template:{templateId}, lang:{lang}, isEnt:{cbIsEntity}");
            try
            {
                // Try setting thread language to enable 2sxc to render the template in this language
                if (!string.IsNullOrEmpty(lang))
                {
                    try
                    {
                        var culture = global::System.Globalization.CultureInfo.GetCultureInfo(lang);
                        global::System.Threading.Thread.CurrentThread.CurrentCulture = culture;
                    }
                    // Fallback / ignore if the language specified has not been found
                    catch (global::System.Globalization.CultureNotFoundException) { }
                }

                var cbToRender = BlockBuilder.Block;

                // if a real templateId was specified, swap to that
                if (templateId > 0)
                {
                    var template = new CmsRuntime(cbToRender.App, Log, Edit.Enabled, false).Views.Get(templateId);
                    ((BlockBuilder)cbToRender.BlockBuilder).View = template;
                }

                var rendered = cbToRender.BlockBuilder.Render().ToString();

                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(rendered, Encoding.UTF8, "text/plain")
                });
            }
            catch (Exception e)
            {
                Exceptions.LogException(e);
                throw;
            }
        }
예제 #28
0
        public dynamic GetContentInfo(int appId, int zoneId, string scope)
        {
            Log.Add($"get content info for z#{zoneId}, a#{appId}, scope:{scope} super?:{UserInfo.IsSuperUser}");
            var currentApp = SxcAppForWebApi.AppBasedOnUserPermissions(zoneId, appId, UserInfo, Log);// AppWithRestrictedZoneChange(appId, zoneId);

            var cms          = new CmsRuntime(currentApp, Log, true, false);
            var contentTypes = cms.ContentTypes.FromScope(scope);
            var entities     = cms.Entities.All;
            var templates    = cms.Views.GetAll();

            return(new
            {
                ContentTypes = contentTypes.Select(c => new
                {
                    Id = c.ContentTypeId,
                    c.Name,
                    c.StaticName,
                    Templates = templates.Where(t => t.ContentType == c.StaticName).Select(t => new
                    {
                        t.Id,
                        t.Name
                    }),
                    Entities = entities
                               .Where(e => e.Type.ContentTypeId == c.ContentTypeId)
                               .Select(e => new
                    {
                        Title = e.GetBestTitle(),
                        Id = e.EntityId
                    })
                }),
                TemplatesWithoutContentTypes = templates.Where(t => !string.IsNullOrEmpty(t.ContentType)).Select(t => new
                {
                    t.Id,
                    t.Name
                })
            });
        }
예제 #29
0
        internal IView PickView(IBlock block, IView configView, IContextOfBlock context, CmsRuntime cms)
        {
            //View = configView;
            // skip on ContentApp (not a feature there) or if not relevant or not yet initialized
            if (block.IsContentApp || block.App == null)
            {
                return(configView);
            }

            // #2 Change Template if URL contains the part in the metadata "ViewNameInUrl"
            var viewFromUrlParam = TryToGetTemplateBasedOnUrlParams(context, cms);

            return(viewFromUrlParam ?? configView);
        }
예제 #30
0
 public IdentifierHelper(CmsRuntime cmsRuntime) : base("Bck.IdHlpr") => _cmsRuntime = cmsRuntime;