コード例 #1
0
 /// <summary>
 /// Get items via a query
 /// </summary>
 /// <typeparam name="T">return type, this can be a summmary type, a content type, or a class from which several content types inherit.  The query will be applied across all content types which could output an item of this type.</typeparam>
 /// <typeparam name="TQuery">the type in terms of which the query is expressed: the content type or possibly a class from which several content types inherit</typeparam>
 /// <param name="queryBody">a function which takes an iqueryable and adds the query to the end of it</param>
 /// <returns>list of items of (or cast to) return type</returns>
 public IEnumerable <T> Get <T, TQuery>(Func <IQueryable <TQuery>, IQueryable <TQuery> > queryBody)
     where T : class
     where TQuery : class
 {
     if (typeof(Summary).IsAssignableFrom(typeof(T)))
     {
         return(Get <T, TQuery>(ContentTypeHierarchy.GetSummaryContainers(typeof(T)), queryBody));
     }
     else
     {
         return(Get <T, TQuery>(ContentTypeHierarchy.GetAssignableContentTypes(this, typeof(T)), queryBody));
     }
 }
コード例 #2
0
        /// <summary>
        /// Process all content items using a contentProcessor
        /// </summary>
        /// <typeparam name="T">Type to which all content items must be assigned</typeparam>
        /// <param name="contentProcessor">Set of methods for processing content</param>
        public static void ProcessLoop <T>(this IContentProcessor contentProcessor) where T : class
        {
            log.InfoFormat("**Process all for {0} begins", contentProcessor.Name);

            var contentTypes = ContentTypeHierarchy.GetAssignableContentTypes(typeof(T));

            foreach (Type t in contentTypes)
            {
                Debug.WriteLine("Processing: " + t.FullName);

                foreach (object content in Collator.Instance.Get <object, object>(new Type[] { t }, iq => iq))
                {
                    try
                    {
                        contentProcessor.Process(content);
                        Collator.Instance.Set(null, content, new Dictionary <string, object> {
                            { "setAudit", false }
                        });
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            Summary s = Collator.Instance.GetSummary <Summary>(content);
                            log.Error("Error processing content item " + s.Title + " for " + contentProcessor.Name, ex);
                        }
                        catch
                        {
                            log.Error("Error processing unidentified content item for " + contentProcessor.Name, ex);
                        }
                    }
                }
            }

            log.InfoFormat("**Process all for {0} ends", contentProcessor.Name);
        }