Component Page /FormOperation.cs (C#)
1: using System;  
2: using System.Collections.Generic;  
3: using System.Linq;  
4: using System.Web.Caching;  
5:   
6: namespace QuizNetOnline.Logic  
7: {  
8:     public class FormOperation  
9:     {  
10:         public static List<int> GetQuestionListFromCache(bool unlimitedQuestions, string cacheKey, List<int> arrayCache, string topic, string userName, Cache cache, string additionalOptions,string tagOptions, bool isCacheQuestionList)  
11:         {  
12:             var webFunctions = new WebFunctions();  
13:             var quizNetSystem = new QuizNetSystem();  
14:   
15:             //Don't cache the questionlist  
16:             if (!isCacheQuestionList)  
17:             {  
18:                 return GetArrayCache(topic, unlimitedQuestions, additionalOptions,tagOptions, userName, webFunctions, quizNetSystem);  
19:             }  
20:   
21:             //Cache the questionlist  
22:             if (cacheKey != null)  
23:             {  
24:                 arrayCache = cache[cacheKey] as List<int>;  
25:             }  
26:             if (arrayCache == null)  
27:             {  
28:                 //Create question list  
29:                 if (userName != null)  
30:                     arrayCache = GetArrayCache(topic, unlimitedQuestions, additionalOptions,tagOptions, userName, webFunctions, quizNetSystem);  
31:                 if (arrayCache != null)  
32:                     if (cacheKey != null)  
33:                         cache.Insert(cacheKey, arrayCache, null, Cache.NoAbsoluteExpiration, TimeSpan.FromHours(24), CacheItemPriority.High, null);  
34:             }  
35:             return arrayCache;  
36:         }  
37:   
38:         public static List<Question> SearchQuestionsCache(Cache cache, string searchString, int searchOption, int pageSize, int pageIndex)  
39:         {  
40:             List<Question> questions = SearchQuestionsCache(cache, searchString, searchOption);  
41:   
42:             List<Question> questionsPaged = questions.Skip(pageSize * pageIndex).Take(pageSize).Select(x => x).ToList();  
43:   
44:             return questionsPaged;  
45:         }  
46:   
47:         public static List<Question> SearchQuestionsCache(Cache cache, string searchString, int searchOption)  
48:         {  
49:             var arrayCache = new List<Question>();  
50:   
51:             //Cache the questionlist  
52:             if (searchString != null)  
53:             {  
54:                 arrayCache = cache[searchString] as List<Question>;  
55:             }  
56:             if (arrayCache == null)  
57:             {  
58:                 arrayCache = GetSearchCache(searchString, searchOption);  
59:                 if (arrayCache != null)  
60:                     cache.Insert(searchString, arrayCache, null, Cache.NoAbsoluteExpiration, TimeSpan.FromHours(24), CacheItemPriority.High, null);  
61:   
62:             }  
63:             return arrayCache;  
64:         }  
65:   
66:         private static List<int> GetArrayCache(string topic, bool unlimitedQuestions, string additionalOptions,string tagOptions, string userName, WebFunctions webFunctions, QuizNetSystem quizNetSystem)  
67:         {  
68:   
69:             List<int> arrayCache = webFunctions.SetupQuestionList(topic, unlimitedQuestions, userName, quizNetSystem, additionalOptions, tagOptions);  
70:             return arrayCache;  
71:         }  
72:   
73:         private static List<Question> GetSearchCache(string searchString, int searchOption)  
74:         {  
75:             var quizNetSystem = new QuizNetSystem();  
76:             return quizNetSystem.SearchQuestions(searchString, searchOption, null);  
77:         }  
78:     }  
79: }  

.NET Documentation Tool is © 2002 - 2009 Winnersh Triangle Web Solutions Limited.