コード例 #1
0
        public static ISxcInstance SxcInstanceForModule(ModuleInfo moduleInfo)
        {
            ModuleContentBlock mcb = new ModuleContentBlock(moduleInfo);

            return(mcb.SxcInstance);
            //var appId = AppHelpers.GetAppIdFromModule(moduleInfo).Value;
            //var zoneId = ZoneHelpers.GetZoneID(moduleInfo.PortalID).Value;
            //ISxcInstance sxcSxcInstance = new SxcInstance(zoneId, appId, moduleInfo);
            //return sxcSxcInstance;
        }
コード例 #2
0
        internal static SxcInstance GetSxcOfApiRequest(HttpRequestMessage request)
        {
            string cbidHeader = "ContentBlockId";
            var    moduleInfo = request.FindModuleInfo();

            // get url parameters and provide override values to ensure all configuration is
            // preserved in AJAX calls
            List <KeyValuePair <string, string> > urlParams = null;
            var requestParams = request.GetQueryNameValuePairs();
            var origParams    = requestParams.Where(p => p.Key == "originalparameters").ToList();

            if (origParams.Any())
            {
                var paramSet = origParams.First().Value;

                // Workaround for deserializing KeyValuePair -it requires lowercase properties(case sensitive), which seems to be a bug in some Newtonsoft.Json versions: http://stackoverflow.com/questions/11266695/json-net-case-insensitive-property-deserialization
                var items = Json.Deserialize <List <UpperCaseStringKeyValuePair> >(paramSet);
                urlParams = items.Select(a => new KeyValuePair <string, string>(a.Key, a.Value)).ToList();

                //urlParams = requestParams
                //    .Where(keyValuePair => keyValuePair.Key.IndexOf("orig", StringComparison.Ordinal) == 0)
                //    .Select(pair => new KeyValuePair<string, string>(pair.Key.Substring(4), pair.Value))
                //    .ToList();
            }
            // first, check the special overrides
            //var origparams = requestParams.Select(np => np.Key == "urlparameters").ToList();
            //if (origparams.Any())
            //{
            //    var paramSet = origparams.First();
            //}

            // then add remaining params


            IContentBlock contentBlock = new ModuleContentBlock(moduleInfo, urlParams);

            // check if we need an inner block
            if (request.Headers.Contains(cbidHeader))
            {
                var cbidh = request.Headers.GetValues(cbidHeader).FirstOrDefault();
                int cbid;
                Int32.TryParse(cbidh, out cbid);
                if (cbid < 0)   // negative id, so it's an inner block
                {
                    contentBlock = new EntityContentBlock(contentBlock, cbid);
                }
            }

            return(contentBlock.SxcInstance);
        }
コード例 #3
0
        internal static SxcInstance GetSxcOfApiRequest(HttpRequestMessage request)
        {
            string cbidHeader = "ContentBlockId";
            var    moduleInfo = request.FindModuleInfo();

            // get url parameters and provide override values to ensure all configuration is
            // preserved in AJAX calls
            List <KeyValuePair <string, string> > urlParams = null;
            var requestParams = request.GetQueryNameValuePairs();
            var origParams    = requestParams.Where(p => p.Key == "originalparameters").ToList();

            if (origParams.Any())
            {
                var paramSet = origParams.First().Value;
                var items    = Json.Deserialize <List <KeyValuePair <string, string> > >(paramSet);
                urlParams = items.ToList();
                //urlParams = requestParams
                //    .Where(keyValuePair => keyValuePair.Key.IndexOf("orig", StringComparison.Ordinal) == 0)
                //    .Select(pair => new KeyValuePair<string, string>(pair.Key.Substring(4), pair.Value))
                //    .ToList();
            }
            // first, check the special overrides
            //var origparams = requestParams.Select(np => np.Key == "urlparameters").ToList();
            //if (origparams.Any())
            //{
            //    var paramSet = origparams.First();
            //}

            // then add remaining params


            IContentBlock contentBlock = new ModuleContentBlock(moduleInfo, urlParams);

            // check if we need an inner block
            if (request.Headers.Contains(cbidHeader))
            {
                var cbidh = request.Headers.GetValues(cbidHeader).FirstOrDefault();
                int cbid;
                int.TryParse(cbidh, out cbid);
                if (cbid < 0)   // negative id, so it's an inner block
                {
                    contentBlock = new EntityContentBlock(contentBlock, cbid);
                }
            }

            return(contentBlock.SxcInstance);
        }
コード例 #4
0
ファイル: Helpers.cs プロジェクト: webworkadmin/2sxc
        internal static SxcInstance GetSxcOfApiRequest(HttpRequestMessage request, bool allowNoContextFound = false, Log log = null)
        {
            var cbidHeader = "ContentBlockId";
            var moduleInfo = request.FindModuleInfo();


            // get url parameters and provide override values to ensure all configuration is
            // preserved in AJAX calls
            List <KeyValuePair <string, string> > urlParams = null;
            var requestParams = request.GetQueryNameValuePairs();
            var origParams    = requestParams.Where(p => p.Key == "originalparameters").ToList();

            if (origParams.Any())
            {
                var paramSet = origParams.First().Value;

                // Workaround for deserializing KeyValuePair -it requires lowercase properties(case sensitive), which seems to be a bug in some Newtonsoft.Json versions: http://stackoverflow.com/questions/11266695/json-net-case-insensitive-property-deserialization
                var items = Json.Deserialize <List <UpperCaseStringKeyValuePair> >(paramSet);
                urlParams = items.Select(a => new KeyValuePair <string, string>(a.Key, a.Value)).ToList();
            }

            if (allowNoContextFound & moduleInfo == null)
            {
                return(null);
            }

            var tenant = moduleInfo == null
                ? new DnnTenant(null)
                : new DnnTenant(new PortalSettings(moduleInfo.OwnerPortalID));
            IContentBlock contentBlock = new ModuleContentBlock(new DnnInstanceInfo(moduleInfo), log, tenant, urlParams);

            // check if we need an inner block
            if (request.Headers.Contains(cbidHeader))
            {
                var cbidh = request.Headers.GetValues(cbidHeader).FirstOrDefault();
                int.TryParse(cbidh, out var cbid);
                if (cbid < 0)   // negative id, so it's an inner block
                {
                    contentBlock = new EntityContentBlock(contentBlock, cbid, log);
                }
            }

            return(contentBlock.SxcInstance);
        }
コード例 #5
0
        internal static SxcInstance GetSxcOfModuleContext(this HttpRequestMessage request)
        {
            string        cbidHeader   = "ContentBlockId";
            var           moduleInfo   = request.FindModuleInfo();
            IContentBlock contentBlock = new ModuleContentBlock(moduleInfo);

            // check if we need an inner block
            if (request.Headers.Contains(cbidHeader))
            {
                var cbidh = request.Headers.GetValues(cbidHeader).FirstOrDefault();
                int cbid;
                int.TryParse(cbidh, out cbid);
                if (cbid < 0)   // negative id, so it's an inner block
                {
                    contentBlock = new EntityContentBlock(contentBlock, cbid);
                }
            }

            return(contentBlock.SxcInstance);
        }
コード例 #6
0
ファイル: SearchController.cs プロジェクト: webworkadmin/2sxc
        /// <summary>
        /// Get search info for each dnn module containing 2sxc data
        /// </summary>
        /// <returns></returns>
        public IList <SearchDocument> GetModifiedSearchDocuments(IInstanceInfo instance, DateTime beginDate)
        {
            var searchDocuments = new List <SearchDocument>();
            var dnnModule       = (instance as EnvironmentInstance <ModuleInfo>)?.Original;

            // always log with method, to ensure errors are cought
            Log.Add($"start search for mod#{dnnModule?.ModuleID}");

            History.Add("dnn-search", Log);

            if (dnnModule == null)
            {
                return(searchDocuments);
            }

            var isContentModule = dnnModule.DesktopModule.ModuleName == "2sxc";

            // New Context because PortalSettings.Current is null
            var zoneId = new DnnEnvironment(Log).ZoneMapper.GetZoneId(dnnModule.OwnerPortalID);

            var appId = !isContentModule
                ? new DnnMapAppToInstance(Log).GetAppIdFromInstance(instance, zoneId)
                : new ZoneRuntime(zoneId, Log).DefaultAppId;

            if (!appId.HasValue)
            {
                return(searchDocuments);
            }

            // As PortalSettings.Current is null, instanciate with modules' portal id
            var portalSettings = new PortalSettings(dnnModule.OwnerPortalID);

            // Ensure cache builds up with correct primary language
            var cache = Eav.Factory.Resolve <ICache>();

            ((BaseCache)cache).ZoneId = zoneId;
            ((BaseCache)cache).AppId  = appId.Value;
            cache.PreLoadCache(portalSettings.DefaultLanguage.ToLower());

            // must find tenant through module, as the PortalSettings.Current is null in search mode
            var tenant = new DnnTenant(portalSettings);
            var mcb    = new ModuleContentBlock(instance, Log, tenant);
            var sexy   = mcb.SxcInstance;

            var language = dnnModule.CultureCode;

            var contentGroup = sexy.App.ContentGroupManager.GetInstanceContentGroup(dnnModule.ModuleID, dnnModule.TabID);

            var template = contentGroup.Template;

            // This list will hold all EAV entities to be indexed
            var dataSource = sexy.Data;

            if (template == null)
            {
                return(searchDocuments);
            }

            var engine = EngineFactory.CreateEngine(template);

            engine.Init(template, sexy.App, new DnnInstanceInfo(dnnModule), dataSource, InstancePurposes.IndexingForSearch, sexy, Log);

            // see if data customization inside the cshtml works
            try
            {
                engine.CustomizeData();
            }
            catch (Exception e) // Catch errors here, because of references to Request etc.
            {
                Exceptions.LogException(new SearchIndexException(dnnModule, e));
            }


            var searchInfoDictionary = new Dictionary <string, List <ISearchInfo> >();

            // Get DNN SearchDocuments from 2Sexy SearchInfos
            foreach (var stream in dataSource.Out.Where(p => p.Key != AppConstants.Presentation && p.Key != AppConstants.ListPresentation))
            {
                var entities       = stream.Value.List;
                var searchInfoList = searchInfoDictionary[stream.Key] = new List <ISearchInfo>();

                searchInfoList.AddRange(entities.Select(entity =>
                {
                    var searchInfo = new SearchInfo
                    {
                        Entity          = entity,
                        Url             = "",
                        Description     = "",
                        Body            = GetJoinedAttributes(entity, language),
                        Title           = entity.Title?[language]?.ToString() ?? "(no title)",
                        ModifiedTimeUtc = (entity.Modified == DateTime.MinValue ? DateTime.Now.Date.AddHours(DateTime.Now.Hour) : entity.Modified).ToUniversalTime(),
                        UniqueKey       = "2sxc-" + dnnModule.ModuleID + "-" + (entity.EntityGuid != new Guid() ? entity.EntityGuid.ToString() : (stream.Key + "-" + entity.EntityId)),
                        IsActive        = true,
                        TabId           = dnnModule.TabID,
                        PortalId        = dnnModule.PortalID
                    };

                    // Take the newest value (from ContentGroupItem and Entity)
                    if (entity is IHasEditingData typed)
                    {
                        var contentGroupItemModifiedUtc = typed.ContentGroupItemModified.ToUniversalTime();
                        searchInfo.ModifiedTimeUtc      = searchInfo.ModifiedTimeUtc > contentGroupItemModifiedUtc
                            ? searchInfo.ModifiedTimeUtc
                            : contentGroupItemModifiedUtc;
                    }

                    return(searchInfo);
                }));
            }

            // check if the cshtml has search customizations
            try
            {
                engine.CustomizeSearch(searchInfoDictionary, new DnnInstanceInfo(dnnModule), beginDate);
            }
            catch (Exception e)
            {
                Exceptions.LogException(new SearchIndexException(dnnModule, e));
            }

            // reduce load by only keeping recently modified ites
            foreach (var searchInfoList in searchInfoDictionary)
            {
                // Filter by Date - take only SearchDocuments that changed since beginDate
                var searchDocumentsToAdd = searchInfoList.Value.Where(p => p.ModifiedTimeUtc >= beginDate.ToUniversalTime()).Select(p => (SearchDocument)p);

                searchDocuments.AddRange(searchDocumentsToAdd);
            }

            return(searchDocuments);
        }
コード例 #7
0
        public static ISxcInstance SxcInstanceForModule(ModuleInfo moduleInfo)
        {
            ModuleContentBlock mcb = new ModuleContentBlock(moduleInfo, parentLog: null);

            return(mcb.SxcInstance);
        }
コード例 #8
0
        /// <summary>
        /// Get search info for each dnn module containing 2sxc data
        /// </summary>
        /// <param name="moduleInfo"></param>
        /// <param name="beginDate"></param>
        /// <returns></returns>
        public IList <SearchDocument> GetModifiedSearchDocuments(ModuleInfo moduleInfo, DateTime beginDate)
        {
            // always log with method, to ensure errors are cought
            Log.Add(() => $"start search for mod#{moduleInfo.ModuleID}");
            var searchDocuments = new List <SearchDocument>();
            var isContentModule = moduleInfo.DesktopModule.ModuleName == "2sxc";

            // New Context because PortalSettings.Current is null
            var zoneId = new Environment.DnnEnvironment(Log).ZoneMapper.GetZoneId(moduleInfo.OwnerPortalID);

            //if (!zoneId.HasValue)
            //    return searchDocuments;

            int?appId = new ZoneRuntime(zoneId, Log).DefaultAppId;

            if (!isContentModule)
            {
                appId = AppHelpers.GetAppIdFromModule(moduleInfo, zoneId);
                if (!appId.HasValue)
                {
                    return(searchDocuments);
                }
            }

            // new 2016-03-27
            var mcb  = new ModuleContentBlock(moduleInfo, Log);
            var sexy = mcb.SxcInstance;

            // old 2016-03-27
            var language = moduleInfo.CultureCode;
            //var contentGroup = sexy.App.ContentGroupManager./*AppContentGroups.*/GetContentGroupForModule(moduleInfo.ModuleID, moduleInfo.TabID);
            var res = sexy.App.ContentGroupManager.GetContentGroupForModule(moduleInfo.ModuleID, moduleInfo.TabID);
            var contentGroupGuid    = res.Item1;
            var previewTemplateGuid = res.Item2;
            var contentGroup        = sexy.App.ContentGroupManager.GetContentGroupOrGeneratePreview(contentGroupGuid, previewTemplateGuid);

            var template = contentGroup.Template;

            // This list will hold all EAV entities to be indexed
            // before 2016-02-27 2dm: var dataSource = sexy.GetViewDataSource(moduleInfo.ModuleID, false, template);
            var dataSource = sexy.Data;// ViewDataSource.ForModule(moduleInfo.ModuleID, false, template, sexy);

            if (template == null)
            {
                return(searchDocuments);
            }

            var engine = EngineFactory.CreateEngine(template);

            engine.Init(template, sexy.App, moduleInfo, dataSource, InstancePurposes.IndexingForSearch, sexy, Log);

            // see if data customization inside the cshtml works
            try
            {
                engine.CustomizeData();
            }
            catch (Exception e) // Catch errors here, because of references to Request etc.
            {
                Exceptions.LogException(new SearchIndexException(moduleInfo, e));
            }


            var searchInfoDictionary = new Dictionary <string, List <ISearchInfo> >();

            // Get DNN SearchDocuments from 2Sexy SearchInfos
            foreach (var stream in dataSource.Out.Where(p => p.Key != AppConstants.Presentation && p.Key != AppConstants.ListPresentation))
            {
                var entities       = stream.Value.List.Select(p => p.Value);
                var searchInfoList = searchInfoDictionary[stream.Key] = new List <ISearchInfo>();

                searchInfoList.AddRange(entities.Select(entity =>
                {
                    var searchInfo = new SearchInfo
                    {
                        Entity          = entity,
                        Url             = "",
                        Description     = "",
                        Body            = GetJoinedAttributes(entity, language),
                        Title           = entity.Title != null && entity.Title[language] != null ? entity.Title[language].ToString() : "(no title)",
                        ModifiedTimeUtc = (entity.Modified == DateTime.MinValue ? DateTime.Now.Date.AddHours(DateTime.Now.Hour) : entity.Modified).ToUniversalTime(),
                        UniqueKey       = "2sxc-" + moduleInfo.ModuleID + "-" + (entity.EntityGuid != new Guid() ? entity.EntityGuid.ToString() : (stream.Key + "-" + entity.EntityId)),
                        IsActive        = true,
                        TabId           = moduleInfo.TabID,
                        PortalId        = moduleInfo.PortalID
                    };

                    // Take the newest value (from ContentGroupItem and Entity)
                    if (entity is IHasEditingData)
                    {
                        var contentGroupItemModifiedUtc = ((IHasEditingData)entity).ContentGroupItemModified.ToUniversalTime();
                        searchInfo.ModifiedTimeUtc      = searchInfo.ModifiedTimeUtc > contentGroupItemModifiedUtc
                            ? searchInfo.ModifiedTimeUtc
                            : contentGroupItemModifiedUtc;
                    }

                    return(searchInfo);
                }));
            }

            // check if the cshtml has search customizations
            try
            {
                engine.CustomizeSearch(searchInfoDictionary, moduleInfo, beginDate);
            }
            catch (Exception e)
            {
                Exceptions.LogException(new SearchIndexException(moduleInfo, e));
            }

            // reduce load by only keeping recently modified ites
            foreach (var searchInfoList in searchInfoDictionary)
            {
                // Filter by Date - take only SearchDocuments that changed since beginDate
                var searchDocumentsToAdd = searchInfoList.Value.Where(p => p.ModifiedTimeUtc >= beginDate.ToUniversalTime()).Select(p => (SearchDocument)p);

                searchDocuments.AddRange(searchDocumentsToAdd);
            }

            return(searchDocuments);
        }
コード例 #9
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 DnnInstanceInfo(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 ModuleContentBlock(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, "Default");
                    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 EntityInContentGroup)?.Presentation != null)
                                            .Select(e => ((EntityInContentGroup)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 ContentGroup as well - if there already is one
                    if (cb.ContentGroup != null)
                    {
                        Log.Add($"add group id:{cb.ContentGroup.ContentGroupId}");
                        ids.Add(cb.ContentGroup.ContentGroupId);
                    }

                    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 ModuleVersions(instanceId, Log).PublishLatestVersion();
                Log.Add("publish completed");
            }
            catch (Exception ex)
            {
                Logging.LogToDnn("exception", "publishing", Log, force: true);
                DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
                throw;
            }
        }