Component Page /BusinessClasses/FormOperations.cs (C#)
1: using System;  
2: using System.Collections.Generic;  
3: using System.Configuration;  
4: using System.Security.Principal;  
5: using System.Web.Caching;  
6: using System.Web;  
7: using System.Web.UI;  
8: using QuizNetOnline.Logic;  
9: using IPaddress = System.Net.IPAddress;  
10: using Microsoft.ApplicationBlocks.Data;  
11: using System.Collections.Specialized;  
12:   
13: namespace QuiznetOnline.Web.UI.BusinessClasses  
14: {  
15:     public class FormOperations  
16:     {  
17:         public static DateTime? GetClientDateTimeFromCookieUpdate(HttpRequest Httprequest)  
18:         {  
19:             NameValueCollection headers = Httprequest.Headers;  
20:             int startpos = 0;  
21:             //int endpos = 0;  
22:             for (int i = 0; i < headers.Count; i++)  
23:             {  
24:                 string key=headers.GetKey(i).ToUpper();  
25:                 if (key == "COOKIE")  
26:                 {  
27:                     string value = headers.Get(i).ToUpper();  
28:                     startpos = value.IndexOf("CLIENTTIME=") + "CLIENTTIME=".Length;  
29:   
30:                     if (startpos > 0)  
31:                     {  
32:                         value = value.Substring(startpos);  
33:                         value=HttpUtility.UrlDecode(value);  
34:                     }  
35:                 }  
36:             }  
37:   
38:             return null;  
39:         }  
40:   
41:         public static Control FindControlRecursive(Control root, string id)  
42:         {  
43:             if (root.ID == id)  
44:             {  
45:                 return root;  
46:             }  
47:   
48:             foreach (Control c in root.Controls)  
49:             {  
50:                 Control t = FindControlRecursive(c, id);  
51:                 if (t != null)  
52:                 {  
53:                     return t;  
54:                 }  
55:             }  
56:   
57:             return null;  
58:         }  
59:   
60:         public static bool IsWebServerLocalHost(string URL)  
61:         {  
62:             return URL.ToUpper().IndexOf("LOCALHOST") >= 0 || URL.ToUpper().IndexOf("127.0.0.1") >= 0;  
63:         }  
64:   
65:   
66:         public static void LogError(string ipAddress, Exception ex)  
67:         {  
68:             Log log = new Log  
69:             {  
70:                 LogArea = "SetupQuestionList Error-" + ex.StackTrace,  
71:                 LogIp = ipAddress  
72:             };  
73:             log.Save(new SqlWrapper());  
74:         }  
75:   
76:         public static void LogTestBeingTaken(string ipAddress, string referrer, string username, string group)  
77:         {  
78:             Log log;  
79:             if (referrer != null && referrer != "Referrer Unknown" && referrer.IndexOf("http://www.quiznetonline.com/")<0)  
80:             {  
81:                 log = new Log  
82:                 {  
83:                     LogIp = ipAddress,  
84:                     LogArea = username + " | Referral-" + referrer  
85:                 };  
86:                 //log.Save();  
87:             }  
88:         }  
89:   
90:         public static void SaveToQuestionLog(Question currentQuestion, bool isAnswerCorrect, UserWeb userWeb, string remotehost, bool isUserGuest,int QuestionNumber)  
91:         {  
92:             QuestionLog questionLog = new QuestionLog();  
93:   
94:             string ipaddress = remotehost;  
95:   
96:             questionLog.Location = userWeb.UserLocation.CountryName + ", " + userWeb.UserLocation.City;  
97:             questionLog.Longitude = userWeb.UserLocation.Longitude;  
98:             questionLog.Latitude = userWeb.UserLocation.Latitude;  
99:             questionLog.QuestionId = currentQuestion.QuestionId;  
100:             questionLog.IpAddress = ipaddress;  
101:   
102:             questionLog.IsCorrect = isAnswerCorrect;  
103:             questionLog.IsUserGuest = isUserGuest;  
104:             questionLog.QuestionNumber = QuestionNumber;  
105:             questionLog.Save(new SqlWrapper());  
106:         }  
107:   
108:   
109:         public static Question GetQuestion(int questionID)  
110:         {  
111:             Question question = new Question();  
112:             question.LoadQuestion(questionID, new Topic(), new SqlWrapper(),new Question());  
113:   
114:             return question;  
115:         }  
116:   
117:   
118:         public static List<int> SetupQuestionList(string remoteHost, string referrer, string username, string group, Cache cache, string AdditionalOptions,string TagOptions, bool isCacheQuestionList)  
119:         {  
120:             string ipAddress = string.Empty;  
121:             var userSetting = new UserSetting();  
122:             SqlWrapper sqlWrapper = new SqlWrapper();  
123:   
124:             ErrorLog error = new ErrorLog();  
125:   
126:             try  
127:             {  
128:   
129:                 if (string.IsNullOrEmpty(username))  
130:                     error.Save("SetupQuestionList-User is null", sqlWrapper);  
131:                 else  
132:                 {  
133:                     userSetting.Load(username, new SqlWrapper());  
134:                 }  
135:   
136:                 ipAddress = remoteHost ?? "IP Unknown";  
137:   
138:                 //Log where the user came from  
139:                 LogTestBeingTaken(ipAddress, referrer, username, group);  
140:   
141:                 //We dont want to cache the question list for favs as they can often change  
142:                 if (group == "fav")  
143:                     isCacheQuestionList = false;  
144:   
145:                 //Implement caching  
146:                 string cacheKey = group + userSetting.UnlimitedQuestions + AdditionalOptions + TagOptions;  
147:                 List<int> arrayCache = null;  
148:   
149:                 List<int> questionIDs = FormOperation.GetQuestionListFromCache(userSetting.UnlimitedQuestions, cacheKey, arrayCache, group, userSetting.UserName, cache, AdditionalOptions,TagOptions, isCacheQuestionList);  
150:   
151: There is a limit of 150 source code lines in the evaluation version
152: There is a limit of 150 source code lines in the evaluation version
153: There is a limit of 150 source code lines in the evaluation version
154: There is a limit of 150 source code lines in the evaluation version
155: There is a limit of 150 source code lines in the evaluation version
156: There is a limit of 150 source code lines in the evaluation version
157: There is a limit of 150 source code lines in the evaluation version
158: There is a limit of 150 source code lines in the evaluation version
159: There is a limit of 150 source code lines in the evaluation version
160: There is a limit of 150 source code lines in the evaluation version
161: There is a limit of 150 source code lines in the evaluation version
162: There is a limit of 150 source code lines in the evaluation version

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