public static string GenerateCodeSnippet(Repository repository, DataRuleSetting dataRule)
 {
     var codeSnippet = (IDataRuleCodeSnippet)hashtable[dataRule.TakeOperation];
     if (codeSnippet == null)
     {
         return "";
     }
     return codeSnippet.Generate(repository, dataRule);
 }
Beispiel #2
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();
         }
     }
 }