Beispiel #1
0
        public string GetDataList(RenderInfo info, OpenContentSettings settings, bool clientSide)
        {
            string templateKey = "";

            info.ResetData();

            IDataSource ds        = DataSourceManager.GetDataSource(Settings.Manifest.DataSource);
            var         dsContext = OpenContentUtils.CreateDataContext(_module);

            IEnumerable <IDataItem> resultList = new List <IDataItem>();

            if (clientSide || !info.Files.DataInTemplate)
            {
                if (ds.Any(dsContext))
                {
                    info.SetData(resultList, settings.Data);
                    info.DataExist = true;
                }

                if (info.Template.Views != null)
                {
                    var indexConfig = OpenContentUtils.GetIndexConfig(info.Template);
                    templateKey = GetTemplateKey(indexConfig);
                }
            }
            else
            {
                //server side
                bool useLucene = info.Template.Manifest.Index;
                if (useLucene)
                {
                    PortalSettings portalSettings = PortalSettings.Current;
                    var            indexConfig    = OpenContentUtils.GetIndexConfig(info.Template);
                    if (info.Template.Views != null)
                    {
                        templateKey = GetTemplateKey(indexConfig);
                    }
                    bool         isEditable   = _module.ViewModule.CheckIfEditable(portalSettings);//portalSettings.UserMode != PortalSettings.Mode.Edit;
                    QueryBuilder queryBuilder = new QueryBuilder(indexConfig);
                    queryBuilder.Build(settings.Query, !isEditable, portalSettings.UserId, DnnLanguageUtils.GetCurrentCultureCode(), portalSettings.UserInfo.Social.Roles, QueryString);

                    resultList = ds.GetAll(dsContext, queryBuilder.Select).Items;
                    if (LogContext.IsLogActive)
                    {
                        //LogContext.Log(_module.ModuleID, "RequestContext", "EditMode", !addWorkFlow);
                        LogContext.Log(_module.ViewModule.ModuleID, "RequestContext", "IsEditable", isEditable);
                        LogContext.Log(_module.ViewModule.ModuleID, "RequestContext", "UserRoles", portalSettings.UserInfo.Social.Roles.Select(r => r.RoleName));
                        LogContext.Log(_module.ViewModule.ModuleID, "RequestContext", "CurrentUserId", portalSettings.UserId);
                        var logKey = "Query";
                        LogContext.Log(_module.ViewModule.ModuleID, logKey, "select", queryBuilder.Select);
                        //LogContext.Log(_module.ModuleID, logKey, "result", resultList);
                    }
                    //Log.Logger.DebugFormat("Query returned [{0}] results.", total);
                    if (!resultList.Any())
                    {
                        /*
                         * if (ds.Any(dsContext) && settings.Query.IsEmpty())
                         * {
                         *   //there seems to be data in de database, but we did not find it in Lucene, so probably the data isn't indexed anymore/yet
                         *   //Components.Lucene.LuceneController.Instance.ReIndexModuleData(_module.ViewModule.ModuleID, settings);
                         * }
                         */
                        //Log.Logger.DebugFormat("Query did not return any results. API request: [{0}], Lucene Filter: [{1}], Lucene Query:[{2}]", settings.Query, queryDef.Filter == null ? "" : queryDef.Filter.ToString(), queryDef.Query == null ? "" : queryDef.Query.ToString());
                        if (ds.Any(dsContext))
                        {
                            info.SetData(resultList, settings.Data);
                            info.DataExist = true;
                        }
                    }
                }
                else
                {
                    resultList = ds.GetAll(dsContext, null).Items;
                    //if (LogContext.IsLogActive)
                    //{
                    //    var logKey = "Get all data of module";
                    //    LogContext.Log(_module.ModuleID, logKey, "result", resultList);
                    //}
                }
                if (resultList.Any())
                {
                    info.SetData(resultList, settings.Data);
                }
            }
            return(templateKey);
        }
Beispiel #2
0
        private string GetDataList(RenderInfo info, OpenContentModuleConfig ocModuleConfig)
        {
            var    clientSide  = info.Template.ClientSideData;
            string templateKey = "";

            info.ResetData();

            IDataSource ds        = DataSourceManager.GetDataSource(_settings.Manifest.DataSource);
            var         dsContext = OpenContentUtils.CreateDataContext(ocModuleConfig);

            IEnumerable <IDataItem> resultList = new List <IDataItem>();

            if (clientSide || !info.Files.DataInTemplate)
            {
                if (ds.Any(dsContext))
                {
                    info.SetData(resultList, ocModuleConfig.Settings.Data);
                    info.DataExist = true;
                }

                if (info.Template.Views != null)
                {
                    var indexConfig = OpenContentUtils.GetIndexConfig(info.Template);
                    templateKey = GetTemplateKey(indexConfig);
                }
            }
            else
            {
                //server side
                bool useLucene = info.Template.Manifest.Index;
                if (useLucene)
                {
                    var indexConfig = OpenContentUtils.GetIndexConfig(info.Template);
                    if (info.Template.Views != null)
                    {
                        templateKey = GetTemplateKey(indexConfig);
                    }
                    bool         isEditable   = _module.ViewModule.CheckIfEditable(ocModuleConfig);
                    QueryBuilder queryBuilder = new QueryBuilder(indexConfig);
                    queryBuilder.Build(ocModuleConfig.Settings.Query, !isEditable, ocModuleConfig.UserId, DnnLanguageUtils.GetCurrentCultureCode(), ocModuleConfig.UserRoles.FromDnnRoles(), QueryString);

                    resultList = ds.GetAll(dsContext, queryBuilder.Select).Items;
                    if (LogContext.IsLogActive)
                    {
                        //LogContext.Log(_module.ModuleID, "RequestContext", "EditMode", !addWorkFlow);
                        LogContext.Log(_module.ViewModule.ModuleId, "RequestContext", "IsEditable", isEditable);
                        LogContext.Log(_module.ViewModule.ModuleId, "RequestContext", "UserRoles", ocModuleConfig.UserRoles.Select(r => r.RoleName));
                        LogContext.Log(_module.ViewModule.ModuleId, "RequestContext", "CurrentUserId", ocModuleConfig.UserId);
                        var logKey = "Query";
                        LogContext.Log(_module.ViewModule.ModuleId, logKey, "select", queryBuilder.Select);
                        //LogContext.Log(_module.ModuleID, logKey, "result", resultList);
                    }
                    //App.Services.Logger.Debug($"Query returned [{0}] results.", total);
                    if (!resultList.Any())
                    {
                        //App.Services.Logger.Debug($"Query did not return any results. API request: [{0}], Lucene Filter: [{1}], Lucene Query:[{2}]", settings.Query, queryDef.Filter == null ? "" : queryDef.Filter.ToString(), queryDef.Query == null ? "" : queryDef.Query.ToString());
                        if (ds.Any(dsContext))
                        {
                            info.SetData(resultList, ocModuleConfig.Settings.Data);
                            info.DataExist = true;
                        }
                    }
                }
                else
                {
                    resultList = ds.GetAll(dsContext, null).Items;
                    //if (LogContext.IsLogActive)
                    //{
                    //    var logKey = "Get all data of module";
                    //    LogContext.Log(_module.ModuleID, logKey, "result", resultList);
                    //}
                }
                if (resultList.Any())
                {
                    info.SetData(resultList, ocModuleConfig.Settings.Data);
                }
            }
            return(templateKey);
        }