2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.Web / Test / TestMonoWeb / AsyncHandler.cs
1 using System;\r
2 using System.Threading;\r
3 using System.Web;\r
4 \r
5 namespace TestMonoWeb {\r
6         /// <summary>\r
7         /// Summary description for AsyncHandler.\r
8         /// </summary>\r
9         public class AsyncHandler : IHttpAsyncHandler {\r
10                 private HttpContext _context;\r
11                 public bool IsReusable {\r
12                         get {\r
13                                 //To enable pooling, return true here.\r
14                                 //This keeps the handler in memory.\r
15                                 return false;\r
16                         }\r
17                 }\r
18 \r
19                 public IAsyncResult BeginProcessRequest(HttpContext context,    AsyncCallback cb, Object extraData) {\r
20                         AsynchOperation asynch = new AsynchOperation(cb, context, null);\r
21                         asynch.StartAsyncWork();\r
22 \r
23                         context.Response.Write("AsyncHandler.BeginProcessRequest<br>\n");\r
24                         context.Response.Flush();\r
25 \r
26                         //Signal the application that asynchronous \r
27                         //processing is being performed. \r
28                         SomeResult asynchForBegin = new SomeResult();\r
29 \r
30                         //Processing is not synchronous.\r
31                         asynchForBegin.SetSynch(false);\r
32 \r
33                         //Processing is not complete.\r
34                         asynchForBegin.SetCompleted(false);\r
35 \r
36                         _context = context;\r
37 \r
38                         return new SomeResult();\r
39                 }\r
40 \r
41                 public void EndProcessRequest(IAsyncResult result) {\r
42                         _context.Response.Write("AsyncHandler.EndProcessRequest<br>\n");\r
43                 }\r
44 \r
45                 //This method is required but is not called.\r
46                 public void ProcessRequest(HttpContext context) {\r
47                 }\r
48 \r
49         }//end class\r
50 \r
51         public class SomeResult : IAsyncResult {\r
52 \r
53                 /*\r
54                 An instance of this class is returned to the application.\r
55                 This class lets the application know how the BeginEventHandler method has been handled. The application checks the CompletedSynchronously method.\r
56                 */\r
57 \r
58                 private bool _blnIsCompleted = false;\r
59                 private Mutex myMutex = null;\r
60                 private Object myAsynchStateObject = null;\r
61                 private bool _blnCompletedSynchronously = false;\r
62 \r
63                 public void SetCompleted(bool blnTrueOrFalse) {\r
64                         _blnIsCompleted = blnTrueOrFalse;\r
65                 }\r
66 \r
67                 public void SetSynch(bool blnTrueOrFalse) {\r
68                         _blnCompletedSynchronously = blnTrueOrFalse;\r
69                 }\r
70 \r
71                 public bool IsCompleted {\r
72                         /*\r
73                           This is not called by the application. However, set it to true. \r
74                         */\r
75                         get {\r
76                                 return _blnIsCompleted;\r
77                         }\r
78                 }\r
79 \r
80                 public WaitHandle AsyncWaitHandle {\r
81                         //The application does not call this method.         \r
82                         get {\r
83                                 return myMutex;\r
84                         }\r
85                 }\r
86 \r
87                 public Object AsyncState {\r
88                         //The application does not call this method because\r
89                         //null is passed in as the last parameter to BeginEventHandler.\r
90                         get {\r
91                                 return myAsynchStateObject;\r
92                         }\r
93                 }\r
94 \r
95                 public bool CompletedSynchronously {\r
96                         //The application wants to know if this is synchronous.\r
97                         //Return true if the Begin method was called synchronously.\r
98                         get { \r
99                                 return _blnCompletedSynchronously;\r
100                         }\r
101                 }\r
102         }       \r
103 }\r