public static void Register(TakeOperation operation, IDataRuleCodeSnippet codeSnippet) { lock (hashtable) { hashtable[operation] = codeSnippet; } }
public static void Register(TakeOperation operation, IDataRuleCodeSnippet codeSnippet) { lock (hashtable) { hashtable[operation] = codeSnippet; } }
public object Execute(DataRuleContext dataRuleContext, TakeOperation operation, int cacheDuration) { var url = EvaluateStringFormulas(this.URL, dataRuleContext); NameValueCollection form = KeyValuesToNameValueCollection(dataRuleContext, this.FormData); NameValueCollection headers = KeyValuesToNameValueCollection(dataRuleContext, this.Headers); var httpDataRequest = Kooboo.CMS.Common.Runtime.EngineContext.Current.Resolve <IHttpDataRequest>(); return(httpDataRequest.GetData(url, this.HttpMethod, ContentType, form, headers)); }
private static object GetCacheData(TakeOperation operation, IContentQuery <TextContent> contentQuery, CacheItemPolicy policy, Func <object> getData) { string cacheKey = "TakeOperation:" + operation.ToString() + " " + TextTranslator.Translate(contentQuery); var data = ObjectCache.Get(cacheKey, CacheRegionName); if (data == null) { data = getData(); ObjectCache.AddOrGetExisting(cacheKey, data, policy, CacheRegionName); } return(data); }
public IDataRuleCodeSnippet GetDataRuleCodeSnippet(TakeOperation takeOperation) { switch (takeOperation) { case TakeOperation.List: return new WebFormListCodeSnippet(); case TakeOperation.First: return new WebFormDetailCodeSnippet(); default: return null; } }
public Kooboo.CMS.Sites.View.CodeSnippet.IDataRuleCodeSnippet GetDataRuleCodeSnippet(TakeOperation takeOperation) { switch (takeOperation) { case TakeOperation.List: return new NVelocityListCodeSnippet(); case TakeOperation.First: return new NVelocityDetailCodeSnippet(); case TakeOperation.Count: default: return null; } }
public IDataRuleCodeSnippet GetDataRuleCodeSnippet(TakeOperation takeOperation) { switch (takeOperation) { case TakeOperation.List: return new RazorListCodeSnippet(); case TakeOperation.First: return new RazorDetailCodeSnippet(); case TakeOperation.Count: default: return null; } }
public IDataRuleCodeSnippet GetDataRuleCodeSnippet(TakeOperation takeOperation) { switch (takeOperation) { case TakeOperation.List: return(new WebFormListCodeSnippet()); case TakeOperation.First: return(new WebFormDetailCodeSnippet()); default: return(null); } }
public IDataRuleCodeSnippet GetDataRuleCodeSnippet(TakeOperation takeOperation) { switch (takeOperation) { case TakeOperation.List: return(new RazorListCodeSnippet()); case TakeOperation.First: return(new RazorDetailCodeSnippet()); case TakeOperation.Count: default: return(null); } }
private static object GetData(IContentQuery <TextContent> contentQuery, TakeOperation operation, int cacheDuration) { if (cacheDuration > 0) { var policy = new CacheItemPolicy() { SlidingExpiration = TimeSpan.FromSeconds(cacheDuration) }; switch (operation) { case TakeOperation.First: var lazyFirst = contentQuery.LazyFirstOrDefault(); return(GetCacheData(contentQuery, operation, policy, () => lazyFirst.Value)); case TakeOperation.Count: var lazyCount = contentQuery.LazyCount(); return(GetCacheData(contentQuery, operation, policy, () => lazyCount.Value)); case TakeOperation.List: default: return(GetCacheData(contentQuery, operation, policy, () => contentQuery.ToArray())); } } else { switch (operation) { case TakeOperation.First: return(contentQuery.FirstOrDefault()); case TakeOperation.Count: return(contentQuery.Count()); case TakeOperation.List: default: return(contentQuery.ToArray()); } } }
public Kooboo.CMS.Sites.View.CodeSnippet.IDataRuleCodeSnippet GetDataRuleCodeSnippet(TakeOperation takeOperation) { switch (takeOperation) { case TakeOperation.List: return(new NVelocityListCodeSnippet()); case TakeOperation.First: return(new NVelocityDetailCodeSnippet()); case TakeOperation.Count: default: return(null); } }
private static object GetCacheData(TakeOperation operation, IContentQuery<TextContent> contentQuery, CacheItemPolicy policy, Func<object> getData) { string cacheKey = "TakeOperation:" + operation.ToString() + " " + TextTranslator.Translate(contentQuery); var data = ObjectCache.Get(cacheKey, CacheRegionName); if (data == null) { data = getData(); ObjectCache.AddOrGetExisting(cacheKey, data, policy, CacheRegionName); } return data; }
private static object GetData(IContentQuery<TextContent> contentQuery, TakeOperation operation, int cacheDuration) { if (cacheDuration > 0) { var policy = new CacheItemPolicy() {SlidingExpiration = TimeSpan.FromSeconds(cacheDuration)}; switch (operation) { case TakeOperation.First: var lazyFirst = contentQuery.LazyFirstOrDefault(); return GetCacheData(contentQuery, operation, policy, () => lazyFirst.Value); case TakeOperation.Count: var lazyCount = contentQuery.LazyCount(); return GetCacheData(contentQuery, operation, policy, () => lazyCount.Value); case TakeOperation.List: default: return GetCacheData(contentQuery, operation, policy, () => contentQuery.ToArray()); } } else { switch (operation) { case TakeOperation.First: return contentQuery.FirstOrDefault(); case TakeOperation.Count: return contentQuery.Count(); case TakeOperation.List: default: return contentQuery.ToArray(); } } }
public object Execute(DataRuleContext dataRuleContext, TakeOperation operation, int cacheDuration) { var contentQuery = this.GetContentQuery(dataRuleContext); object data = contentQuery; if (!string.IsNullOrEmpty(this.SortField)) { if (this.SortDirection == DataRule.SortDirection.Ascending) { contentQuery = contentQuery.OrderBy(this.SortField); } else { contentQuery = contentQuery.OrderByDescending(this.SortField); } } if (this.EnablePaging.Value) { string pageIndexParameterName; var pageIndexValue = ParameterizedFieldValue.GetFieldValue(this.PageIndex, dataRuleContext.ValueProvider, out pageIndexParameterName); var intPageIndexValue = 1; int.TryParse(pageIndexValue, out intPageIndexValue); if (intPageIndexValue < 1) { intPageIndexValue = 1; } var intPageSize = 10; if (string.IsNullOrEmpty(this.Top)) { string pageSizeParameterName; var pageSizeValue = ParameterizedFieldValue.GetFieldValue(this.PageSize, dataRuleContext.ValueProvider, out pageSizeParameterName); int.TryParse(pageSizeValue, out intPageSize); if (intPageSize < 1) { intPageSize = 10; } } else { string fieldName; var topValue = ParameterizedFieldValue.GetFieldValue(this.Top, dataRuleContext.ValueProvider, out fieldName); int.TryParse(topValue, out intPageSize); } var totalCount = contentQuery.Count(); data = new DataRulePagedList(contentQuery.Skip((intPageIndexValue - 1)*intPageSize).Take(intPageSize) , intPageIndexValue , intPageSize , totalCount) { PageIndexParameterName = pageIndexParameterName }; } else if (!string.IsNullOrEmpty(this.Top)) { string fieldName; var topValue = ParameterizedFieldValue.GetFieldValue(this.Top, dataRuleContext.ValueProvider, out fieldName); var intTopValue = 1; int.TryParse(topValue, out intTopValue); data = contentQuery.Take(intTopValue); } else { data = contentQuery; } if (data is IContentQuery<ContentBase>) { data = GetData((IContentQuery<TextContent>) data, operation, cacheDuration); } return data; }
public object Execute(DataRuleContext dataRuleContext, TakeOperation operation, int cacheDuration) { var url = EvaluateStringFormulas(this.URL, dataRuleContext); NameValueCollection form = KeyValuesToNameValueCollection(dataRuleContext, this.FormData); NameValueCollection headers = KeyValuesToNameValueCollection(dataRuleContext, this.Headers); var httpDataRequest = Bsc.Dmtds.Core.Runtime.EngineContext.Current.Resolve<IHttpDataRequest>(); return httpDataRequest.GetData(url, this.HttpMethod, ContentType, form, headers); }
public object Execute(DataRuleContext dataRuleContext, TakeOperation operation, int cacheDuration) { var contentQuery = this.GetContentQuery(dataRuleContext); object data = contentQuery; if (!string.IsNullOrEmpty(this.SortField)) { if (this.SortDirection == DataRule.SortDirection.Ascending) { contentQuery = contentQuery.OrderBy(this.SortField); } else { contentQuery = contentQuery.OrderByDescending(this.SortField); } } if (this.EnablePaging.Value) { string pageIndexParameterName; var pageIndexValue = ParameterizedFieldValue.GetFieldValue(this.PageIndex, dataRuleContext.ValueProvider, out pageIndexParameterName); var intPageIndexValue = 1; int.TryParse(pageIndexValue, out intPageIndexValue); if (intPageIndexValue < 1) { intPageIndexValue = 1; } string pageSizeParameterName; var pageSizeValue = ParameterizedFieldValue.GetFieldValue(this.PageSize, dataRuleContext.ValueProvider, out pageSizeParameterName); var intPageSize = 10; int.TryParse(pageSizeValue, out intPageSize); if (intPageSize < 1) { intPageSize = 10; } var totalCount = contentQuery.Count(); data = new DataRulePagedList(contentQuery.Skip((intPageIndexValue - 1) * intPageSize).Take(intPageSize) , intPageIndexValue , intPageSize , totalCount) { PageIndexParameterName = pageIndexParameterName }; } else if (!string.IsNullOrEmpty(this.Top)) { string fieldName; var topValue = ParameterizedFieldValue.GetFieldValue(this.Top, dataRuleContext.ValueProvider, out fieldName); var intTopValue = 1; int.TryParse(topValue, out intTopValue); data = contentQuery.Take(intTopValue); } else { data = contentQuery; } if (data is IContentQuery <ContentBase> ) { data = GetData((IContentQuery <TextContent>)data, operation, cacheDuration); } return(data); }