當前位置: 首頁>>代碼示例>>C#>>正文


C# Item.TemplateIsOrBasedOn方法代碼示例

本文整理匯總了C#中System.Item.TemplateIsOrBasedOn方法的典型用法代碼示例。如果您正苦於以下問題:C# Item.TemplateIsOrBasedOn方法的具體用法?C# Item.TemplateIsOrBasedOn怎麽用?C# Item.TemplateIsOrBasedOn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Item的用法示例。


在下文中一共展示了Item.TemplateIsOrBasedOn方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: 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

示例2: 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

示例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];
            }

            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

示例4: GetEntryComments

        /// <summary>
        /// Gets the comments for the given blog entry
        /// </summary>
        /// <param name="entryItem">The blog entry to get the comments for</param>
        /// <param name="maximumCount">The maximum number of comments to retrieve</param>
        /// <returns>The comments for the blog entry</returns>
        public CommentItem[] GetEntryComments(Item entryItem, int maximumCount)
        {
            if (entryItem != null)
            {
                var template = GetDatabase().GetTemplate(Settings.EntryTemplateIDString);
                if (entryItem.TemplateIsOrBasedOn(template))
                {
                    return GetCommentsFor(entryItem, maximumCount, true);
                }
            }

            return new CommentItem[0];
        }
開發者ID:kaytee821,項目名稱:WeBlog,代碼行數:19,代碼來源:CommentManager.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>
        /// <param name="minimumDate">The minimum date for entries</param>
        /// <param name="maximumDate">The maximum date for the entries</param>
        /// <returns></returns>
        public virtual 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];
            }

            var customBlogItem = (from templateId in Settings.BlogTemplateIds
                                  where blog.TemplateIsOrBasedOn(templateId)
                                  select (BlogHomeItem)blog).FirstOrDefault();

            if (customBlogItem == null)
            {
                customBlogItem = (from templateId in Settings.BlogTemplateIds
                                  let item = blog.FindAncestorByTemplate(templateId)
                                  where item != null
                                  select (BlogHomeItem)item).FirstOrDefault();
            }

            if (customBlogItem == null)
            {
                return new EntryItem[0];
            }

            List<EntryItem> result = new List<EntryItem>();
            var indexName = Settings.SearchIndexName;

            if (!string.IsNullOrEmpty(indexName))
            {

                using (var context = ContentSearchManager.GetIndex(indexName + "-" + blog.Database.Name).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.EntryDate >= minimumDate);

                    if (maximumDate != null)
                        builder = builder.And(i => i.EntryDate < maximumDate);

                    var indexresults = context.GetQueryable<EntryResultItem>().Where(builder);

                    if (indexresults.Any())
                    {
                        var itemResults = indexresults.Select(indexresult => indexresult.GetItem()).ToList();
                        result = itemResults.Where(item => item != null).Select(i => new EntryItem(i)).ToList();
                        result = result.OrderByDescending(post => post.EntryDate.DateTime).ThenBy(post => post.Created).Take(maxNumber).ToList();
                    }
                }
            }

            return result.ToArray();
        }
開發者ID:WeTeam,項目名稱:WeBlog,代碼行數:92,代碼來源:EntryManager.cs


注:本文中的System.Item.TemplateIsOrBasedOn方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。