Page.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. //
  2. // System.Web.UI.Page
  3. //
  4. // Authors:
  5. // Duncan Mak ([email protected])
  6. // Gonzalo Paniagua ([email protected])
  7. //
  8. // (C) 2002 Ximian, Inc. (http://www.ximian.com)
  9. //
  10. using System;
  11. using System.Collections;
  12. using System.Collections.Specialized;
  13. using System.IO;
  14. using System.Reflection;
  15. using System.Security.Principal;
  16. using System.Text;
  17. using System.Web;
  18. using System.Web.Caching;
  19. using System.Web.SessionState;
  20. namespace System.Web.UI
  21. {
  22. public class Page : TemplateControl, IHttpHandler
  23. {
  24. private string _culture;
  25. private bool _viewState = true;
  26. private bool _viewStateMac = false;
  27. private string _errorPage;
  28. private ArrayList _fileDependencies;
  29. private string _ID;
  30. private bool _isPostBack;
  31. private bool _isValid;
  32. private HttpServerUtility _server;
  33. private bool _smartNavigation = false;
  34. private TraceContext _trace;
  35. private bool _traceEnabled;
  36. private TraceMode _traceModeValue;
  37. private int _transactionMode;
  38. private string _UICulture;
  39. private HttpContext _context;
  40. private ValidatorCollection _validators;
  41. private bool _visible;
  42. private string _responseEncoding;
  43. private HttpSessionState _session;
  44. #region Fields
  45. protected const string postEventArgumentID = ""; //FIXME
  46. protected const string postEventSourceID = "";
  47. #endregion
  48. #region Constructor
  49. public Page ()
  50. {
  51. }
  52. #endregion
  53. #region Properties
  54. [MonoTODO]
  55. public HttpApplicationState Application
  56. {
  57. get { throw new NotImplementedException (); }
  58. }
  59. bool AspCompatMode
  60. {
  61. set { throw new NotImplementedException (); }
  62. }
  63. [MonoTODO]
  64. bool Buffer
  65. {
  66. set { throw new NotImplementedException (); }
  67. }
  68. [MonoTODO]
  69. public Cache Cache
  70. {
  71. get { throw new NotImplementedException (); }
  72. }
  73. [MonoTODO]
  74. public string ClientTarget
  75. {
  76. get { throw new NotImplementedException (); }
  77. set { throw new NotImplementedException (); }
  78. }
  79. [MonoTODO]
  80. int CodePage
  81. {
  82. set { throw new NotImplementedException (); }
  83. }
  84. [MonoTODO]
  85. string ContentType
  86. {
  87. set { throw new NotImplementedException (); }
  88. }
  89. protected override HttpContext Context
  90. {
  91. get { return _context; }
  92. }
  93. string Culture
  94. {
  95. set { _culture = value; }
  96. }
  97. public override bool EnableViewState
  98. {
  99. get { return _viewState; }
  100. set { _viewState = value; }
  101. }
  102. protected bool EnableViewStateMac
  103. {
  104. get { return _viewStateMac; }
  105. set { _viewStateMac = value; }
  106. }
  107. public string ErrorPage
  108. {
  109. get { return _errorPage; }
  110. set { _errorPage = value; }
  111. }
  112. public ArrayList FileDependencies
  113. {
  114. set { _fileDependencies = value; }
  115. }
  116. public override string ID
  117. {
  118. get { return _ID; }
  119. set { _ID = value; }
  120. }
  121. public bool IsPostBack
  122. {
  123. get { return _isPostBack; }
  124. }
  125. [MonoTODO]
  126. public bool IsReusable
  127. {
  128. get { throw new NotImplementedException (); }
  129. }
  130. public bool IsValid
  131. {
  132. get { return _isValid; }
  133. }
  134. [MonoTODO]
  135. int LCID {
  136. set { throw new NotImplementedException (); }
  137. }
  138. public HttpRequest Request
  139. {
  140. get { return _context.Request; }
  141. }
  142. public HttpResponse Response
  143. {
  144. get { return _context.Response; }
  145. }
  146. string ResponseEncoding
  147. {
  148. set { _responseEncoding = value; }
  149. }
  150. public HttpServerUtility Server
  151. {
  152. get { return _server; }
  153. }
  154. public virtual HttpSessionState Session
  155. {
  156. get { return _session; }
  157. }
  158. public bool SmartNavigation
  159. {
  160. get { return _smartNavigation; }
  161. set { _smartNavigation = value; }
  162. }
  163. public TraceContext Trace
  164. {
  165. get { return _trace; }
  166. }
  167. bool TraceEnabled
  168. {
  169. set { _traceEnabled = value; }
  170. }
  171. TraceMode TraceModeValue
  172. {
  173. set { _traceModeValue = value; }
  174. }
  175. int TransactionMode
  176. {
  177. set { _transactionMode = value; }
  178. }
  179. string UICulture
  180. {
  181. set { _UICulture = value; }
  182. }
  183. public IPrincipal User
  184. {
  185. get { return _context.User; }
  186. }
  187. public ValidatorCollection Validators
  188. {
  189. get {
  190. if (_validators == null)
  191. _validators = new ValidatorCollection ();
  192. return _validators;
  193. }
  194. }
  195. public override bool Visible
  196. {
  197. get { return _visible; }
  198. set { _visible = value; }
  199. }
  200. #endregion
  201. #region Methods
  202. [MonoTODO]
  203. protected IAsyncResult AspCompatBeginProcessRequest (HttpContext context,
  204. AsyncCallback cb,
  205. object extraData)
  206. {
  207. throw new NotImplementedException ();
  208. }
  209. [MonoTODO]
  210. protected void AspcompatEndProcessRequest (IAsyncResult result)
  211. {
  212. throw new NotImplementedException ();
  213. }
  214. protected virtual HtmlTextWriter CreateHtmlTextWriter (TextWriter tw)
  215. {
  216. return new HtmlTextWriter (tw);
  217. }
  218. [MonoTODO]
  219. public void DesignerInitialize ()
  220. {
  221. throw new NotImplementedException ();
  222. }
  223. [MonoTODO]
  224. protected virtual NameValueCollection DeterminePostBackMode ()
  225. {
  226. /* Why does this not compile? HttpSessionState has IsNewSession...
  227. if (_session.IsNewSession)
  228. return null;
  229. */
  230. if (IsPostBack)
  231. return _context.Request.Form; //FIXME: is this enough?
  232. throw new NotImplementedException ("GET method got to parse Request.QueryString");
  233. }
  234. [MonoTODO]
  235. public string GetPostBackClientEvent (Control control, string argument)
  236. {
  237. // Don't throw the exception. keep going
  238. //throw new NotImplementedException ();
  239. StringBuilder result = new StringBuilder ();
  240. result.AppendFormat ("GetPostBackClientEvent ('{0}', '{1}')", control.ID, argument);
  241. return result.ToString ();
  242. }
  243. [MonoTODO]
  244. public string GetPostBackClientHyperlink (Control control, string argument)
  245. {
  246. throw new NotImplementedException ();
  247. }
  248. [MonoTODO]
  249. public string GetPostBackEventReference (Control control)
  250. {
  251. // Don't throw the exception. keep going
  252. //throw new NotImplementedException ();
  253. return GetPostBackEventReference (control, "");
  254. }
  255. [MonoTODO]
  256. public string GetPostBackEventReference (Control control, string argument)
  257. {
  258. // Don't throw the exception. keep going
  259. //throw new NotImplementedException ();
  260. StringBuilder result = new StringBuilder ();
  261. result.AppendFormat ("GetPostBackEventReference ('{0}', '{1}')", control.ID, argument);
  262. return result.ToString ();
  263. }
  264. public virtual int GetTypeHashCode ()
  265. {
  266. return this.GetHashCode ();
  267. }
  268. [MonoTODO]
  269. protected virtual void InitOutputCache (int duration,
  270. string varyByHeader,
  271. string varyByCustom,
  272. OutputCacheLocation location,
  273. string varyByParam)
  274. {
  275. throw new NotImplementedException ();
  276. }
  277. [MonoTODO]
  278. public bool IsClientScriptBlockRegistered (string key)
  279. {
  280. throw new NotImplementedException ();
  281. }
  282. [MonoTODO]
  283. public bool IsStartupScriptRegistered (string key)
  284. {
  285. throw new NotImplementedException ();
  286. }
  287. [MonoTODO]
  288. protected virtual object LoadPageStateFromPersistenceMedium ()
  289. {
  290. throw new NotImplementedException ();
  291. }
  292. [MonoTODO]
  293. public string MapPath (string virtualPath)
  294. {
  295. throw new NotImplementedException ();
  296. }
  297. private void InvokeEventMethod (string m_name, object sender, EventArgs e)
  298. {
  299. Type [] types = new Type [] {typeof (object), typeof (EventArgs)};
  300. MethodInfo evt_method = GetType ().GetMethod (m_name, types);
  301. if (evt_method != null){
  302. object [] parms = new object [2];
  303. parms [0] = sender;
  304. parms [1] = e;
  305. evt_method.Invoke (this, parms);
  306. }
  307. }
  308. private void _Page_Init (object sender, EventArgs e)
  309. {
  310. InvokeEventMethod ("Page_Init", sender, e);
  311. }
  312. private void _Page_Load (object sender, EventArgs e)
  313. {
  314. InvokeEventMethod ("Page_Load", sender, e);
  315. }
  316. public void ProcessRequest (HttpContext context)
  317. {
  318. FrameworkInitialize ();
  319. // This 2 should depend on AutoEventWireUp in Page directive. Defaults to true.
  320. Init += new EventHandler (_Page_Init);
  321. Load += new EventHandler (_Page_Load);
  322. //-- Control execution lifecycle in the docs
  323. OnInit (EventArgs.Empty);
  324. //LoadViewState ();
  325. //if (this is IPostBackDataHandler)
  326. // LoadPostData ();
  327. OnLoad (EventArgs.Empty);
  328. //if (this is IPostBackDataHandler)
  329. // RaisePostBackEvent ();
  330. OnPreRender (EventArgs.Empty);
  331. //--
  332. _context = context;
  333. HtmlTextWriter output = new HtmlTextWriter (context.Response.Output);
  334. foreach (Control ctrl in Controls){
  335. ctrl.Page = this;
  336. ctrl.RenderControl (output);
  337. }
  338. }
  339. protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
  340. {
  341. sourceControl.RaisePostBackEvent (eventArgument);
  342. }
  343. [MonoTODO]
  344. public void RegisterArrayDeclaration (string arrayName, string arrayValue)
  345. {
  346. throw new NotImplementedException ();
  347. }
  348. [MonoTODO]
  349. public virtual void RegisterClientScriptBlock (string key, string script)
  350. {
  351. throw new NotImplementedException ();
  352. }
  353. [MonoTODO]
  354. public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
  355. {
  356. throw new NotImplementedException ();
  357. }
  358. [MonoTODO]
  359. public void RegisterClientScriptFile (string a, string b, string c)
  360. {
  361. throw new NotImplementedException ();
  362. }
  363. [MonoTODO]
  364. public void RegisterOnSubmitStatement (string key, string script)
  365. {
  366. throw new NotImplementedException ();
  367. }
  368. [MonoTODO]
  369. public void RegisterRequiresPostBack (Control control)
  370. {
  371. // Don't throw the exception. keep going
  372. //throw new NotImplementedException ();
  373. }
  374. [MonoTODO]
  375. public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
  376. {
  377. throw new NotImplementedException ();
  378. }
  379. [MonoTODO]
  380. public void RegisterViewStateHandler ()
  381. {
  382. throw new NotImplementedException ();
  383. }
  384. [MonoTODO]
  385. protected virtual void SavePageStatetoPersistenceMedium (object viewState)
  386. {
  387. throw new NotImplementedException ();
  388. }
  389. public virtual void Validate ()
  390. {
  391. bool all_valid = true;
  392. foreach (IValidator v in _validators){
  393. v.Validate ();
  394. if (v.IsValid == false)
  395. all_valid = false;
  396. }
  397. if (all_valid)
  398. _isValid = true;
  399. }
  400. [MonoTODO]
  401. public virtual void VerifyRenderingInServerForm (Control control)
  402. {
  403. return;
  404. }
  405. #endregion
  406. }
  407. }