/// <summary>
        /// create express like: ((a=1) or (a=2) or (b=3))
        /// </summary>
        public static IContentQuery <TextContent> WhereOrs(this IContentQuery <TextContent> textContents, Dictionary <string, object> args)
        {
            var        textContent = textContents.FirstOrDefault();
            Repository repository  = textContent == null ? Repository.Current : new Repository(textContent.Repository);
            var        folder      = new TextFolder(repository, textContent.FolderName);

            folder = folder.AsActual();
            var query = folder.CreateQuery();

            foreach (var arg in args)
            {
                query = query.Or(new WhereContainsExpression(null, arg.Key, arg.Value));
            }
            return(textContents.Where((IWhereExpression)query.Expression));
        }
        public static IContentQuery <TextContent> WhereCategory(this IContentQuery <TextContent> textContents, string categoryFolderName, string[] categoryUUIDs)
        {
            var        textContent = textContents.FirstOrDefault();
            Repository repository  = null;

            if (textContent != null)
            {
                repository = new Repository(textContent.Repository);
            }
            else
            {
                repository = Repository.Current;
            }

            var categoryFolder = new TextFolder(repository, categoryFolderName);
            var categoryQuery  = categoryFolder.CreateQuery().WhereIn(SystemFieldNames.UUID, categoryUUIDs);

            return(textContents.WhereCategory(categoryQuery));
        }
Ejemplo n.º 3
0
        private static object GetData(DataRuleSetting dataRuleSetting, IContentQuery <TextContent> contentQuery)
        {
            if (dataRuleSetting.CachingDuration > 0)
            {
                var policy = new CacheItemPolicy()
                {
                    SlidingExpiration = TimeSpan.FromSeconds(dataRuleSetting.CachingDuration)
                };
                switch (dataRuleSetting.TakeOperation)
                {
                case TakeOperation.First:
                    var lazyFirst = contentQuery.LazyFirstOrDefault();
                    return(GetCacheData(dataRuleSetting.TakeOperation, contentQuery, policy, () => lazyFirst.Value));

                case TakeOperation.Count:
                    var lazyCount = contentQuery.LazyCount();
                    return(GetCacheData(dataRuleSetting.TakeOperation, contentQuery, policy, () => lazyCount.Value));

                case TakeOperation.List:
                default:
                    return(GetCacheData(dataRuleSetting.TakeOperation, contentQuery, policy, () => contentQuery.ToArray()));
                }
            }
            else
            {
                switch (dataRuleSetting.TakeOperation)
                {
                case TakeOperation.First:
                    return(contentQuery.FirstOrDefault());

                case TakeOperation.Count:
                    return(contentQuery.Count());

                case TakeOperation.List:
                default:
                    return(contentQuery.ToArray());
                }
            }
        }
Ejemplo n.º 4
0
 private static object GetData(DataRuleSetting dataRuleSetting, IContentQuery<TextContent> contentQuery)
 {
     if (dataRuleSetting.CachingDuration > 0)
     {
         var policy = new CacheItemPolicy() { SlidingExpiration = TimeSpan.FromSeconds(dataRuleSetting.CachingDuration) };
         switch (dataRuleSetting.TakeOperation)
         {
             case TakeOperation.First:
                 var lazyFirst = contentQuery.LazyFirstOrDefault();
                 return GetCacheData(dataRuleSetting.TakeOperation, contentQuery, policy, () => lazyFirst.Value);
             case TakeOperation.Count:
                 var lazyCount = contentQuery.LazyCount();
                 return GetCacheData(dataRuleSetting.TakeOperation, contentQuery, policy, () => lazyCount.Value);
             case TakeOperation.List:
             default:
                 return GetCacheData(dataRuleSetting.TakeOperation, contentQuery, policy, () => contentQuery.ToArray());
         }
     }
     else
     {
         switch (dataRuleSetting.TakeOperation)
         {
             case TakeOperation.First:
                 return contentQuery.FirstOrDefault();
             case TakeOperation.Count:
                 return contentQuery.Count();
             case TakeOperation.List:
             default:
                 return contentQuery.ToArray();
         }
     }
 }
Ejemplo n.º 5
0
 public static Lazy <T> LazyFirstOrDefault <T>(this IContentQuery <T> contentQuery)
     where T : ContentBase
 {
     contentQuery = contentQuery.Create(new CallExpression(contentQuery.Expression, CallType.FirstOrDefault));
     return(new Lazy <T>(() => contentQuery.FirstOrDefault()));
 }