コード例 #1
0
ファイル: Factory.cs プロジェクト: mnelson104/2sxc
        public static IApp App(int zoneId, int appId, PortalSettings ownerPortalSettings, bool versioningEnabled = false, bool showDrafts = false)
        {
            var appStuff = new App(new DnnTenant(ownerPortalSettings), zoneId, appId,
                                   ConfigurationProvider.Build(showDrafts, versioningEnabled, new ValueCollectionProvider()), true, null);

            return(appStuff);
        }
コード例 #2
0
ファイル: Factory.cs プロジェクト: mnelson104/2sxc
        public static IApp App(int appId, PortalSettings ownerPortalSettings, bool versioningEnabled = false, bool showDrafts = false)
        {
            // 2018-09-22 new
            var appStuff = new App(new DnnTenant(ownerPortalSettings), Eav.Apps.App.AutoLookupZone, appId,
                                   ConfigurationProvider.Build(showDrafts, versioningEnabled, new ValueCollectionProvider()), true, null);

            return(appStuff);
        }
コード例 #3
0
        [AllowAnonymous]   // will check security internally, so assume no requirements
        public Dictionary <string, object> CreateOrUpdate([FromUri] string contentType, [FromBody] Dictionary <string, object> newContentItem, [FromUri] int?id = null, [FromUri] string appPath = null)
        {
            Log.Add($"create or update type:{contentType}, id:{id}, path:{appPath}");
            // if app-path specified, use that app, otherwise use from context
            var appIdentity = AppFinder.GetAppIdFromPathOrContext(appPath, SxcInstance);

            // Check that this ID is actually of this content-type,
            // this throws an error if it's not the correct type
            var itm = id == null
                ? null
                : new EntityApi(appIdentity.AppId, Log).GetOrThrow(contentType, id.Value);

            var ok = itm == null
                ? new MultiPermissionsTypes(SxcInstance, appIdentity.AppId, contentType, Log)
                     .EnsureAll(Grants.Create.AsSet(), out var exp)
                : new MultiPermissionsItems(SxcInstance, appIdentity.AppId, itm, Log)
                     .EnsureAll(Grants.Update.AsSet(), out exp);

            if (!ok)
            {
                throw exp;
            }

            //2018-09-15 2dm moved/disabled
            //var context = GetContext(SxcInstance, Log);
            //PerformSecurityCheck(appIdentity, contentType, perm, appPath == null ? context.Dnn.Module : null, itm);

            // Convert to case-insensitive dictionary just to be safe!
            newContentItem = new Dictionary <string, object>(newContentItem, StringComparer.OrdinalIgnoreCase);

            // Now create the cleaned up import-dictionary so we can create a new entity
            var cleanedNewItem = new AppContentEntityBuilder(Log)
                                 .CreateEntityDictionary(contentType, newContentItem, appIdentity.AppId);

            var userName = new DnnUser().IdentityToken;

            // try to create
            var publish = Factory.Resolve <IEnvironmentFactory>().PagePublisher(Log);
            // 2018-09-22 new
            // todo: something looks wrong here, I think create/update would fail if it doesn't have a moduleid
            var currentApp = new App(new DnnTenant(PortalSettings), appIdentity.ZoneId, appIdentity.AppId,
                                     ConfigurationProvider.Build(false, publish.IsEnabled(ActiveModule.ModuleID),
                                                                 SxcInstance.Data.ConfigurationProvider), true, Log);

            // 2018-09-22 old
            //currentApp.InitData(false,
            //    publish.IsEnabled(ActiveModule.ModuleID),
            //    SxcInstance.Data.ConfigurationProvider);
            if (id == null)
            {
                currentApp.Data.Create(contentType, cleanedNewItem, userName);
                // Todo: try to return the newly created object
                return(null);
            }

            currentApp.Data.Update(id.Value, cleanedNewItem, userName);
            return(InitEavAndSerializer(appIdentity.AppId).Prepare(currentApp.Data.List.One(id.Value)));
        }
コード例 #4
0
ファイル: BlockFromModule.cs プロジェクト: micahsdad1402/2sxc
        /// <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}");
        }
コード例 #5
0
        private void _constructor(IContentBlock parent, Eav.Interfaces.IEntity cbDefinition)
        {
            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
            SxcInstance = new SxcInstance(this, Parent.SxcInstance.EnvInstance, Parent.SxcInstance.Parameters, Log);

            if (AppId == 0)
            {
                return;
            }

            // 2018-09-22 old
            // try to load the app - if possible
            //App = new App(Tenant, ZoneId, AppId);

            //Configuration = ConfigurationProvider.GetConfigProviderForModule(ParentId, App, SxcInstance);

            // maybe ensure that App.Data is ready
            //var userMayEdit = SxcInstance.UserMayEdit;
            //var publishingEnabled = SxcInstance.Environment.PagePublishing.IsEnabled(Parent.SxcInstance.EnvInstance.Id);
            //App.InitData(userMayEdit, publishingEnabled, Configuration);

            // 2018-09-22 new
            App = new App(Tenant, ZoneId, AppId, ConfigurationProvider.Build(SxcInstance, false), true, Log);

            ContentGroup = App.ContentGroupManager.GetContentGroupOrGeneratePreview(_contentGroupGuid, _previewTemplateGuid);

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

            // use the content-group template, which already covers stored data + module-level stored settings
            SxcInstance.SetTemplateOrOverrideFromUrl(ContentGroup.Template);
        }
コード例 #6
0
        private bool PostSaveUpdateIdsInParent(
            int appId,
            Dictionary <Guid, int> postSaveIds,
            IEnumerable <IGrouping <string, BundleWithHeader <IEntity> > > pairsOrSingleItems)
        {
            var wrapLog = Log.Call <bool>($"{appId}");
            var app     = Factory.Resolve <Apps.App>().Init(new AppIdentity(Eav.Apps.App.AutoLookupZone, appId),
                                                            ConfigurationProvider.Build(Block, true), false, Log);

            foreach (var bundle in pairsOrSingleItems)
            {
                Log.Add("processing:" + bundle.Key);
                var entity = app.Data.List.One(bundle.First().Header.ListParent());
                var targetIsContentBlock = entity.Type.Name == BlocksRuntime.BlockTypeName;

                var primaryItem = targetIsContentBlock ? FindContentItem(bundle) : bundle.First();
                var primaryId   = GetIdFromGuidOrError(postSaveIds, primaryItem.Entity.EntityGuid);

                var ids = targetIsContentBlock
                    ? new[] { primaryId, FindPresentationItem(postSaveIds, bundle) }
                    : new[] { primaryId as int? };

                var index = primaryItem.Header.ListIndex();

                // add or update slots
                //var itemIsReallyNew = primaryItem.EntityId == 0; // only really add if it's really new
                var willAdd = primaryItem.Header.ListAdd();// && itemIsReallyNew;

                // 2019-07-01 2dm needed to add this, because new-save already gives it an ID
                //if (primaryItem.Header.ReallyAddBecauseAlreadyVerified != null)
                //    willAdd = primaryItem.Header.ReallyAddBecauseAlreadyVerified.Value;

                Log.Add($"will add: {willAdd}; " + // add-pre-verified:{primaryItem.Header.ReallyAddBecauseAlreadyVerified}; " +
                        $"Group.Add:{primaryItem.Header.Add}; EntityId:{primaryItem.Entity.EntityId}");

                var cms       = new CmsManager(app, Log);
                var fieldPair = targetIsContentBlock
                    ? ViewParts.PickPair(primaryItem.Header.Group.Part)
                    : new[] { primaryItem.Header.Field };

                if (willAdd) // this cannot be auto-detected, it must be specified
                {
                    cms.Entities.FieldListAdd(entity, fieldPair, index, ids, cms.EnablePublishing);
                }
                else
                {
                    cms.Entities.FieldListReplaceIfModified(entity, fieldPair, index, ids, cms.EnablePublishing);
                }
            }

            // update-module-title
            BlockEditorBase.GetEditor(Block).UpdateTitle();
            return(wrapLog("ok", true));
        }
コード例 #7
0
ファイル: BlockBase.cs プロジェクト: kieran23101/2sxc
        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));
        }
コード例 #8
0
ファイル: SxcAppForWebApi.cs プロジェクト: micahsdad1402/2sxc
        //private IApp App { get; }

        //internal static IApp AppBasedOnUserPermissions(int zoneId, int appId, UserInfo user, ILog log)
        //    => GetBasedOnUserPermissions(zoneId, appId, user, log).App;


        internal static IApp AppBasedOnUserPermissions(int zoneId, int appId, UserInfo user, ILog log)
        {
            var wrapLog = log.Call <IApp>($"superuser: {user.IsSuperUser}");
            var app     = user.IsSuperUser
                ? new Apps.App(new DnnTenant(PortalSettings.Current), zoneId, appId,
                               ConfigurationProvider.Build(true, true, new LookUpEngine(log)), true, log)
                                                                 // GetApp(zoneId, appId, log) // only super-user may switch to another zone for export
                : Dnn.Factory.App(appId, false, parentLog: log); // GetApp(appId, false, log);

            return(wrapLog(null, app));
        }
コード例 #9
0
ファイル: AppInits.cs プロジェクト: kieran23101/2sxc
        public static IApp Init(this App app, int appId, ILog log, IBlock optionalBlock = null, bool showDrafts = false)
        {
            var appIdentity = new AppIdentity(SystemRuntime.ZoneIdOfApp(appId), appId);

            if (optionalBlock == null)
            {
                return(app.Init(appIdentity, log, showDrafts));
            }
            var buildConfig = ConfigurationProvider.Build(optionalBlock, true);

            return(app.Init(appIdentity, buildConfig, false, log));
        }
コード例 #10
0
        [AllowAnonymous]   // will check security internally, so assume no requirements
        public Dictionary <string, IEnumerable <Dictionary <string, object> > > PublicQuery([FromUri] string appPath, [FromUri] string name, [FromUri] string stream = null)
        {
            var wrapLog     = Log.Call($"path:{appPath}, name:{name}");
            var appIdentity = AppFinder.GetCurrentAppIdFromPath(appPath);
            var queryApp    = new Apps.App(new DnnTenant(PortalSettings), appIdentity.ZoneId, appIdentity.AppId,
                                           ConfigurationProvider.Build(false, false), false, Log);

            // now just run the default query check and serializer
            var result = BuildQueryAndRun(queryApp, name, stream, false, null, Log, BlockBuilder);

            wrapLog(null);
            return(result);
        }
コード例 #11
0
ファイル: BlockFromEntity.cs プロジェクト: micahsdad1402/2sxc
        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");
        }
コード例 #12
0
ファイル: ImpExpHelpers.cs プロジェクト: kieran23101/2sxc
        /// <summary>
        /// Get an app - but only allow zone change if super-user
        /// </summary>
        /// <returns></returns>
        internal static IApp GetAppAndCheckZoneSwitchPermissions(int zoneId, int appId, IUser user, int contextZoneId, ILog log)
        {
            var wrapLog = log.Call <IApp>($"superuser: {user.IsSuperUser}");

            if (!user.IsSuperUser && zoneId != contextZoneId)
            {
                wrapLog("error", null);
                throw Eav.WebApi.Errors.HttpException.PermissionDenied("Tried to access app from another zone. Requires SuperUser permissions.");
            }

            var app = Factory.Resolve <Apps.App>().Init(new AppIdentity(zoneId, appId),
                                                        ConfigurationProvider.Build(true, true, new LookUpEngine(log)), true, log);

            return(wrapLog(null, app));
        }
コード例 #13
0
        [AllowAnonymous]   // will check security internally, so assume no requirements
        public Dictionary <string, IEnumerable <Dictionary <string, object> > > PublicQuery([FromUri] string appPath, [FromUri] string name, [FromUri] string stream = null)
        {
            Log.Add($"public query path:{appPath}, name:{name}");
            // 2018-09-22 new
            var appIdentity = AppFinder.GetCurrentAppIdFromPath(appPath);
            var queryApp    = new App(new DnnTenant(PortalSettings), appIdentity.ZoneId, appIdentity.AppId,
                                      ConfigurationProvider.Build(false, false), false, Log);

            // 2018-09-22 old
            // ensure the queries can be executed (needs configuration provider, usually given in SxcInstance, but we don't hav that here)
            //var config = DataSources.ConfigurationProvider.GetConfigProviderForModule(0, queryApp, null);
            //queryApp.InitData(false, false, config);

            // now just run the default query check and serializer
            return(BuildQueryAndRun(queryApp, name, stream, false, null, Log, SxcInstance));
        }
コード例 #14
0
ファイル: Factory.cs プロジェクト: kieran23101/2sxc
        public static IApp App(
            int zoneId,
            int appId,
            ITenant tenant,
            bool publishingEnabled,
            bool showDrafts,
            ILog parentLog)
        {
            var log = new Log("Mvc.Factry", parentLog);

            log.Add($"Create App(z:{zoneId}, a:{appId}, tenantObj:{tenant != null}, publishingEnabled: {publishingEnabled}, showDrafts: {showDrafts}, parentLog: {parentLog != null})");
            var appStuff = Eav.Factory.Resolve <App>().Init(new AppIdentity(zoneId, appId),
                                                            ConfigurationProvider.Build(showDrafts, publishingEnabled, new LookUpEngine(parentLog)),
                                                            true, parentLog);

            return(appStuff);
        }
コード例 #15
0
        protected MultiPermissionsApp(IBlockBuilder blockBuilder, int zoneId, int appId, ILog parentLog)
            : base("Api.Perms", parentLog)
        {
            var wrapLog = Log.Call($"..., appId: {appId}, ...");

            BlockBuilder = blockBuilder;
            var tenant        = new DnnTenant(PortalSettings.Current);
            var environment   = Factory.Resolve <IEnvironmentFactory>().Environment(Log);
            var contextZoneId = environment.ZoneMapper.GetZoneId(tenant.Id);

            App = new App(tenant, zoneId, appId,
                          ConfigurationProvider.Build(blockBuilder, true),
                          false, Log);
            SamePortal             = contextZoneId == zoneId;
            PortalForSecurityCheck = SamePortal ? PortalSettings.Current : null;
            wrapLog($"ready for z/a:{zoneId}/{appId} t/z:{tenant.Id}/{contextZoneId} same:{SamePortal}");
        }
コード例 #16
0
        private static IApp App(
            int zoneId,
            int appId,
            ITenant tenant,
            bool publishingEnabled,
            bool showDrafts,
            ILog parentLog)
        {
            var log = new Log("Dnn.Factry", parentLog);

            log.Add($"Create App(z:{zoneId}, a:{appId}, tenantObj:{tenant != null}, publishingEnabled: {publishingEnabled}, showDrafts: {showDrafts}, parentLog: {parentLog != null})");
            var appStuff = new App(tenant, zoneId, appId,
                                   ConfigurationProvider.Build(showDrafts, publishingEnabled, new LookUpEngine(parentLog)),
                                   true, parentLog);

            return(appStuff);
        }
コード例 #17
0
ファイル: AppQuery.cs プロジェクト: kieran23101/2sxc
        PublicQuery(IInstanceContext context, string appPath, string name, string stream, IBlock block)
        {
            var wrapLog = Log.Call($"path:{appPath}, name:{name}");

            if (string.IsNullOrEmpty(name))
            {
                throw HttpException.MissingParam(nameof(name));
            }
            var appIdentity = AppFinder.GetAppIdFromPath(appPath);
            var queryApp    = Factory.Resolve <Apps.App>().Init(appIdentity,
                                                                ConfigurationProvider.Build(false, false), false, Log);

            // now just run the default query check and serializer
            var result = BuildQueryAndRun(queryApp, name, stream, false, context, Log, block?.EditAllowed ?? false);

            wrapLog(null);
            return(result);
        }
コード例 #18
0
        public List <AppDto> Apps(ITenant tenant, IBlock block, int zoneId)
        {
            var cms = new CmsZones(zoneId, Log);
            var configurationBuilder = ConfigurationProvider.Build(block, true);
            var list = cms.AppsRt.GetApps(tenant, configurationBuilder);

            return(list.Select(a => new AppDto
            {
                Id = a.AppId,
                IsApp = a.AppGuid != Eav.Constants.DefaultAppName,
                Guid = a.AppGuid,
                Name = a.Name,
                Folder = a.Folder,
                AppRoot = a.Path,
                IsHidden = a.Hidden,
                ConfigurationId = a.Configuration?.Id,
                Items = a.Data.List.Count(),
                Thumbnail = a.Thumbnail,
                Version = a.VersionSafe()
            }).ToList());
        }
コード例 #19
0
        public dynamic Apps(int zoneId)
        {
            var cms    = new CmsZones(zoneId, Env, Log);
            var tenant = new DnnTenant(new PortalSettings(ActiveModule.OwnerPortalID));
            var configurationBuilder = ConfigurationProvider.Build(BlockBuilder, true);
            var list = cms.AppsRt.GetApps(tenant, configurationBuilder);

            return(list.Select(a => new
            {
                Id = a.AppId,
                IsApp = a.AppGuid != Eav.Constants.DefaultAppName,
                Guid = a.AppGuid,
                a.Name,
                a.Folder,
                AppRoot = a.Path,
                IsHidden = a.Hidden,
                ConfigurationId = a.Configuration?.Id,
                Items = a.Data.List.Count(),
                a.Thumbnail,
                Version = a.VersionSafe()
            }).ToList());
        }
コード例 #20
0
        private void UpdateList <T>(
            int appId,
            Dictionary <Guid, int> postSaveIds,
            IEnumerable <IGrouping <string, BundleWithHeader <T> > > groupItems)
        {
            var myLog = new Log("2Ap.GrpPrc", Log, "start");
            // 2018-09-22 new
            var app = new App(new DnnTenant(PortalSettings.Current), Eav.Apps.App.AutoLookupZone, appId,
                              ConfigurationProvider.Build(SxcInstance, true), false, Log);

            // 2018-09-22 old
            //var userMayEdit = SxcInstance.UserMayEdit;
            //app.InitData(userMayEdit, SxcInstance.Environment.PagePublishing.IsEnabled(SxcInstance.EnvInstance.Id), SxcInstance.Data.ConfigurationProvider);

            foreach (var entitySets in groupItems)
            {
                myLog.Add("processing:" + entitySets.Key);
                var contItem =
                    entitySets.FirstOrDefault(e => e.Header.Group.Part.ToLower() == AppConstants.ContentLower) ??
                    entitySets.FirstOrDefault(e => e.Header.Group.Part.ToLower() == AppConstants.ListContentLower);
                if (contItem == null)
                {
                    throw new Exception("unexpected group-entity assigment, cannot figure it out");
                }

                var presItem =
                    entitySets.FirstOrDefault(e => e.Header.Group.Part.ToLower() == AppConstants.PresentationLower) ??
                    entitySets.FirstOrDefault(e => e.Header.Group.Part.ToLower() == AppConstants.ListPresentationLower);

                // Get group to assign to and parameters
                var contentGroup = app.ContentGroupManager.GetContentGroup(contItem.Header.Group.Guid);
                var partName     = contItem.Header.Group.Part;

                // var part = contentGroup[partName];
                var index = contItem.Header.Group.Index;

                // Get saved entity (to get its ID)
                if (!postSaveIds.ContainsKey(contItem.EntityGuid))
                {
                    throw new Exception("Saved entity not found - not able to update ContentGroup");
                }

                var postSaveId = postSaveIds[contItem.EntityGuid];

                int?presentationId = null;

                if (presItem != null)
                {
                    if (postSaveIds.ContainsKey(presItem.EntityGuid))
                    {
                        presentationId = postSaveIds[presItem.EntityGuid];
                    }

                    presentationId = presItem.Header.Group.SlotIsEmpty ? null : presentationId;
                    // use null if it shouldn't have one
                }
                // add or update slots
                var reallyAddGroup = contItem.EntityId == 0;     // only really add if it's really new
                if (contItem.Header.Group.Add && reallyAddGroup) // this cannot be auto-detected, it must be specified
                {
                    contentGroup.AddContentAndPresentationEntity(partName, index, postSaveId, presentationId);
                }
                else // if (part.Count <= index || part[index] == null)
                {
                    contentGroup.UpdateEntityIfChanged(partName, index, postSaveId, true, presentationId);
                }
            }

            // update-module-title
            SxcInstance.ContentBlock.Manager.UpdateTitle();
        }
コード例 #21
0
        /// <summary>
        /// Create a module-content block
        /// </summary>
        /// <param name="instanceInfo">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 ModuleContentBlock(IInstanceInfo instanceInfo, Log parentLog, ITenant tenant, IEnumerable <KeyValuePair <string, string> > overrideParams = null) : base(parentLog, "CB.Mod")
        {
            InstanceInfo   = instanceInfo ?? throw new Exception("Need valid Instance/ModuleInfo / ModuleConfiguration of runtime");
            ParentId       = instanceInfo.Id;
            ContentBlockId = ParentId;

            // url-params
            _urlParams = overrideParams ?? DnnWebForms.Helpers.SystemWeb.GetUrlParams();

            // 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.TennantId

            AppId = Factory.Resolve <IMapAppToInstance>().GetAppIdFromInstance(instanceInfo, 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
            SxcInstance = new SxcInstance(this, InstanceInfo, _urlParams, Log);

            if (AppId != 0)
            {
                Log.Add("real app, will load data");
                // 2018-09-22 old
                // try to load the app - if possible
                //App = new App(Tenant, ZoneId, AppId, parentLog: Log);

                //Configuration = ConfigurationProvider.GetConfigProviderForModule(InstanceInfo.Id, App, SxcInstance);

                //// maybe ensure that App.Data is ready
                //var userMayEdit = SxcInstance.UserMayEdit;
                //App.InitData(userMayEdit, SxcInstance.Environment.PagePublishing.IsEnabled(InstanceInfo.Id),
                //    Configuration);

                // 2018-09-22 new with auto-init-data
                App = new App(Tenant, ZoneId, AppId, ConfigurationProvider.Build(SxcInstance, false), true, Log);

                ContentGroup = App.ContentGroupManager.GetInstanceContentGroup(instanceInfo.Id, instanceInfo.PageId);

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

                SxcInstance.SetTemplateOrOverrideFromUrl(ContentGroup.Template);
            }
        }
コード例 #22
0
ファイル: AppInits.cs プロジェクト: kieran23101/2sxc
        public static IApp Init(this App app, IAppIdentity appIdentity, ILog log, bool showDrafts = false)
        {
            var buildConfig = ConfigurationProvider.Build(showDrafts, false, new LookUpEngine(log));

            return(app.Init(appIdentity, buildConfig, false, log));
        }