当前位置: 首页>>代码示例>>C#>>正文


C# Item.GetCurrentItem方法代码示例

本文整理汇总了C#中System.Item.GetCurrentItem方法的典型用法代码示例。如果您正苦于以下问题:C# Item.GetCurrentItem方法的具体用法?C# Item.GetCurrentItem怎么用?C# Item.GetCurrentItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Item的用法示例。


在下文中一共展示了Item.GetCurrentItem方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetCurrentBlogEntry

        /// <summary>
        /// Gets the current context item as a blog entry
        /// </summary>
        /// <param name="item">The item to find the current entry item for</param>
        /// <returns>The current blog entry</returns>
        public EntryItem GetCurrentBlogEntry(Item item)
        {
            var entryItem = item.GetCurrentItem(Settings.EntryTemplateIDString);

            if (entryItem != null)
                return new Items.WeBlog.EntryItem(entryItem);
            else
                return null;
        }
开发者ID:KerwinMa,项目名称:WeBlog,代码行数:14,代码来源:EntryManager.cs

示例2: GetCurrentBlog

        /// <summary>
        /// Gets the current blog for the item
        /// </summary>
        /// <param name="item">The item to find the current blog for</param>
        /// <returns>The current blog if found, otherwise null</returns>
        public Items.WeBlog.BlogHomeItem GetCurrentBlog(Item item)
        {
            var blogItem = item.GetCurrentItem(Settings.BlogTemplateIDString);

            if (blogItem != null)
                return new Items.WeBlog.BlogHomeItem(blogItem);
            else
                return null;
        }
开发者ID:KerwinMa,项目名称:WeBlog,代码行数:14,代码来源:BlogManager.cs

示例3: GetBlogEntries

        /// <summary>
        /// Gets blog entries for the given blog up to the maximum number given
        /// </summary>
        /// <param name="blog">The blog item to get the entries for</param>
        /// <param name="maxNumber">The maximum number of entries to retrieve</param>
        /// <param name="tag">A tag the entry must contain</param>
        /// <param name="category">A category the entry must contain</param>
        /// <returns></returns>
        public EntryItem[] GetBlogEntries(Item blog, int maxNumber, string tag, string category, string datePrefix = null)
        {
            if (blog == null || maxNumber <= 0)
            {
                return new EntryItem[0];
            }

            BlogHomeItem customBlogItem = null;
            if (blog.TemplateIsOrBasedOn(Settings.BlogTemplateID))
            {
                customBlogItem = blog;
            }
            else
            {
                customBlogItem = blog.GetCurrentItem(Settings.BlogTemplateIDString);
            }
            if (customBlogItem == null)
            {
                return new EntryItem[0];
            }

            List<EntryItem> result = new List<EntryItem>();
            #if FEATURE_CONTENT_SEARCH
            var indexName = Settings.SearchIndexName;
            if (!string.IsNullOrEmpty(indexName))
            {

                using (var context = ContentSearchManager.GetIndex(indexName).CreateSearchContext())
                {
                    var builder = PredicateBuilder.True<EntryResultItem>();
                    var id = Settings.EntryTemplateID;
                    builder = builder.And(i => i.TemplateId==id);
                    // Tag
                    if (!String.IsNullOrEmpty(tag))
                    {
                        builder = builder.And(PredicateController.BlogTags(tag));
                    }
                    // Categories
                    if (!string.IsNullOrEmpty(category))
                    {
                        builder = builder.And(PredicateController.BlogCategory(category));
                    }
                    var indexresults = context.GetQueryable<EntryResultItem>().Where(builder);
                    if (indexresults.Any())
                    {
                        result = indexresults.Select(i => new EntryItem(i.GetItem())).ToList();
                        result = result.OrderByDescending(post => post.Created).Take(maxNumber).ToList();
                    }
                }
            }
            #else
            var query = new CombinedQuery();
            //query.Add(new FieldQuery(Constants.Index.Fields.BlogID, blog.ID.ToShortID().ToString().ToLower()), QueryOccurance.Must);
            query.Add(new FieldQuery(Sitecore.Search.BuiltinFields.Path, customBlogItem.ID.ToShortID().ToString()), QueryOccurance.Must);
            query.Add(new FieldQuery(Constants.Index.Fields.Template, customBlogItem.BlogSettings.EntryTemplateID.ToShortID().ToString().ToLower()), QueryOccurance.Must);

            if (!string.IsNullOrEmpty(tag))
            {
                query.Add(new FieldQuery(Constants.Index.Fields.Tags, DatabaseCrawler.TransformCSV(tag)), QueryOccurance.Must);
            }

            if (!string.IsNullOrEmpty(category))
            {
                var categoryItem = ManagerFactory.CategoryManagerInstance.GetCategory(blog, category);
                ID id = ID.Null;

                if (categoryItem != null)
                    id = categoryItem.ID;

                query.Add(new FieldQuery(Constants.Index.Fields.Category, id.ToShortID().ToString().ToLower()), QueryOccurance.Must);
            }

            if (!string.IsNullOrEmpty(datePrefix))
            {
                query.Add(new FieldQuery(Constants.Index.Fields.Created, datePrefix + "*"), QueryOccurance.Must);
            }

            var searcher = new Searcher();
            result = searcher.Execute<EntryItem>(query, maxNumber, (list, item) => list.Add((EntryItem)item), Constants.Index.Fields.EntryDate, true).ToList();
            #endif
            return result.ToArray();
        }
开发者ID:shamrox,项目名称:WeBlog,代码行数:90,代码来源:EntryManager.cs

示例4: GetBlogEntries

        /// <summary>
        /// Gets blog entries for the given blog up to the maximum number given
        /// </summary>
        /// <param name="blog">The blog item to get the entries for</param>
        /// <param name="maxNumber">The maximum number of entries to retrieve</param>
        /// <param name="tag">A tag the entry must contain</param>
        /// <param name="category">A category the entry must contain</param>
        /// <param name="minimumDate">The minimum date for entries</param>
        /// <param name="maximumDate">The maximum date for the entries</param>
        /// <returns></returns>
        public EntryItem[] GetBlogEntries(Item blog, int maxNumber, string tag, string category, DateTime? minimumDate = null, DateTime? maximumDate = null)
        {
            if (blog == null || maxNumber <= 0)
            {
                return new EntryItem[0];
            }

            BlogHomeItem customBlogItem = null;
            if (blog.TemplateIsOrBasedOn(Settings.BlogTemplateID))
            {
                customBlogItem = blog;
            }
            else
            {
                customBlogItem = blog.GetCurrentItem(Settings.BlogTemplateIDString);
            }
            if (customBlogItem == null)
            {
                return new EntryItem[0];
            }


            List<EntryItem> result = new List<EntryItem>();
#if FEATURE_CONTENT_SEARCH
            var indexName = Settings.SearchIndexName;
            if (!string.IsNullOrEmpty(indexName))
            {

              using (var context = ContentSearchManager.GetIndex(indexName).CreateSearchContext(SearchSecurityOptions.DisableSecurityCheck))
                {
                    var builder = PredicateBuilder.True<EntryResultItem>();
                
                    var id = customBlogItem.BlogSettings.EntryTemplateID;
                    builder = builder.And(i => i.TemplateId == id);
                    builder = builder.And(i => i.Paths.Contains(customBlogItem.ID));
                    builder = builder.And(i => i.Language.Equals(customBlogItem.InnerItem.Language.Name, StringComparison.InvariantCulture));
                    builder = builder.And(item => item.DatabaseName.Equals(Context.Database.Name, StringComparison.InvariantCulture));

                    // Tag
                    if (!string.IsNullOrEmpty(tag))
                    {
                        builder = builder.And(i => i.Tags.Contains(tag));
                    }

                    // Categories
                    if (!string.IsNullOrEmpty(category))
                    {
                      var categoryItem = ManagerFactory.CategoryManagerInstance.GetCategory(customBlogItem, category);

                      // If the category is unknown, don't return any results.
                      if (categoryItem == null)
                          return new EntryItem[0];
#if SC70
                      var normalizedID = Sitecore.ContentSearch.Utilities.IdHelper.NormalizeGuid(categoryItem.ID);
                      builder = builder.And(i => i.Category.Contains(normalizedID));
#else
                      builder = builder.And(i => i.Category.Contains(categoryItem.ID));
#endif
                        
                    }

                    if (minimumDate != null)
                      builder = builder.And(i => i.CreatedDate >= minimumDate);

                    if(maximumDate != null)
                      builder = builder.And(i => i.CreatedDate < maximumDate);
                    
                    var indexresults = context.GetQueryable<EntryResultItem>().Where(builder);
                
                    if (indexresults.Any())
                    {
                        result = indexresults.Select(i => new EntryItem(i.GetItem())).ToList();
                        result = result.OrderByDescending(post => post.EntryDate.DateTime).Take(maxNumber).ToList();
                    }
                }
            }
#else
            var query = new CombinedQuery();
            //query.Add(new FieldQuery(Constants.Index.Fields.BlogID, blog.ID.ToShortID().ToString().ToLower()), QueryOccurance.Must);
            query.Add(new FieldQuery(Sitecore.Search.BuiltinFields.Path, customBlogItem.ID.ToShortID().ToString()), QueryOccurance.Must);
            query.Add(new FieldQuery(Constants.Index.Fields.Template, customBlogItem.BlogSettings.EntryTemplateID.ToShortID().ToString().ToLower()), QueryOccurance.Must);

            if (!string.IsNullOrEmpty(tag))
            {
                query.Add(new FieldQuery(Constants.Index.Fields.Tags, DatabaseCrawler.TransformCSV(tag)), QueryOccurance.Must);
            }

            if (!string.IsNullOrEmpty(category))
            {
                var categoryItem = ManagerFactory.CategoryManagerInstance.GetCategory(blog, category);
//.........这里部分代码省略.........
开发者ID:KerwinMa,项目名称:WeBlog,代码行数:101,代码来源:EntryManager.cs

示例5: GetBlogEntries

        /// <summary>
        /// Gets blog entries for the given blog up to the maximum number given
        /// </summary>
        /// <param name="blog">The blog item to get the entries for</param>
        /// <param name="maxNumber">The maximum number of entries to retrieve</param>
        /// <param name="tag">A tag the entry must contain</param>
        /// <param name="category">A category the entry must contain</param>
        /// <returns></returns>
        public EntryItem[] GetBlogEntries(Item blog, int maxNumber, string tag, string category, string datePrefix = null)
        {
            if (blog == null || maxNumber <= 0)
            {
                return new EntryItem[0];
            }

            BlogHomeItem customBlogItem = null;
            if (blog.TemplateIsOrBasedOn(Settings.BlogTemplateID))
            {
                customBlogItem = blog;
            }
            else
            {
                customBlogItem = blog.GetCurrentItem(Settings.BlogTemplateIDString);
            }
            if (customBlogItem == null)
            {
                return new EntryItem[0];
            }

            var query = new CombinedQuery();
            //query.Add(new FieldQuery(Constants.Index.Fields.BlogID, blog.ID.ToShortID().ToString().ToLower()), QueryOccurance.Must);
            query.Add(new FieldQuery(Sitecore.Search.BuiltinFields.Path, customBlogItem.ID.ToShortID().ToString()), QueryOccurance.Must);
            query.Add(new FieldQuery(Constants.Index.Fields.Template, customBlogItem.BlogSettings.EntryTemplateID.ToShortID().ToString().ToLower()), QueryOccurance.Must);

            if (!string.IsNullOrEmpty(tag))
            {
                query.Add(new FieldQuery(Constants.Index.Fields.Tags, DatabaseCrawler.TransformCSV(tag)), QueryOccurance.Must);
            }

            if (!string.IsNullOrEmpty(category))
            {
                var categoryItem = ManagerFactory.CategoryManagerInstance.GetCategory(blog, category);
                ID id = ID.Null;

                if (categoryItem != null)
                    id = categoryItem.ID;

                query.Add(new FieldQuery(Constants.Index.Fields.Category, id.ToShortID().ToString().ToLower()), QueryOccurance.Must);
            }

            if (!string.IsNullOrEmpty(datePrefix))
            {
                query.Add(new FieldQuery(Constants.Index.Fields.Created, datePrefix + "*"), QueryOccurance.Must);
            }

            var searcher = new Searcher();
            var result = searcher.Execute<EntryItem>(query, maxNumber, (list, item) => list.Add((EntryItem)item), Constants.Index.Fields.EntryDate, true);

            return result;
        }
开发者ID:Quatra,项目名称:WeBlog,代码行数:60,代码来源:EntryManager.cs


注:本文中的System.Item.GetCurrentItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。