Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mcs/class/System.Web/Test/TestMonoWeb')
-rw-r--r--mcs/class/System.Web/Test/TestMonoWeb/AsyncHandler.cs103
-rw-r--r--mcs/class/System.Web/Test/TestMonoWeb/AsyncModule.cs36
-rw-r--r--mcs/class/System.Web/Test/TestMonoWeb/AsyncOperation.cs42
-rw-r--r--mcs/class/System.Web/Test/TestMonoWeb/README5
-rw-r--r--mcs/class/System.Web/Test/TestMonoWeb/SyncHandler.cs16
-rw-r--r--mcs/class/System.Web/Test/TestMonoWeb/SyncModule.cs37
-rw-r--r--mcs/class/System.Web/Test/TestMonoWeb/Test1.cs46
-rw-r--r--mcs/class/System.Web/Test/TestMonoWeb/TestMonoWeb.build26
8 files changed, 311 insertions, 0 deletions
diff --git a/mcs/class/System.Web/Test/TestMonoWeb/AsyncHandler.cs b/mcs/class/System.Web/Test/TestMonoWeb/AsyncHandler.cs
new file mode 100644
index 00000000000..cab2351e1ed
--- /dev/null
+++ b/mcs/class/System.Web/Test/TestMonoWeb/AsyncHandler.cs
@@ -0,0 +1,103 @@
+using System;
+using System.Threading;
+using System.Web;
+
+namespace TestMonoWeb {
+ /// <summary>
+ /// Summary description for AsyncHandler.
+ /// </summary>
+ public class AsyncHandler : IHttpAsyncHandler {
+ private HttpContext _context;
+ public bool IsReusable {
+ get {
+ //To enable pooling, return true here.
+ //This keeps the handler in memory.
+ return false;
+ }
+ }
+
+ public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) {
+ AsynchOperation asynch = new AsynchOperation(cb, context, null);
+ asynch.StartAsyncWork();
+
+ context.Response.Write("AsyncHandler.BeginProcessRequest<br>\n");
+ context.Response.Flush();
+
+ //Signal the application that asynchronous
+ //processing is being performed.
+ SomeResult asynchForBegin = new SomeResult();
+
+ //Processing is not synchronous.
+ asynchForBegin.SetSynch(false);
+
+ //Processing is not complete.
+ asynchForBegin.SetCompleted(false);
+
+ _context = context;
+
+ return new SomeResult();
+ }
+
+ public void EndProcessRequest(IAsyncResult result) {
+ _context.Response.Write("AsyncHandler.EndProcessRequest<br>\n");
+ }
+
+ //This method is required but is not called.
+ public void ProcessRequest(HttpContext context) {
+ }
+
+ }//end class
+
+ public class SomeResult : IAsyncResult {
+
+ /*
+ An instance of this class is returned to the application.
+ This class lets the application know how the BeginEventHandler method has been handled. The application checks the CompletedSynchronously method.
+ */
+
+ private bool _blnIsCompleted = false;
+ private Mutex myMutex = null;
+ private Object myAsynchStateObject = null;
+ private bool _blnCompletedSynchronously = false;
+
+ public void SetCompleted(bool blnTrueOrFalse) {
+ _blnIsCompleted = blnTrueOrFalse;
+ }
+
+ public void SetSynch(bool blnTrueOrFalse) {
+ _blnCompletedSynchronously = blnTrueOrFalse;
+ }
+
+ public bool IsCompleted {
+ /*
+ This is not called by the application. However, set it to true.
+ */
+ get {
+ return _blnIsCompleted;
+ }
+ }
+
+ public WaitHandle AsyncWaitHandle {
+ //The application does not call this method.
+ get {
+ return myMutex;
+ }
+ }
+
+ public Object AsyncState {
+ //The application does not call this method because
+ //null is passed in as the last parameter to BeginEventHandler.
+ get {
+ return myAsynchStateObject;
+ }
+ }
+
+ public bool CompletedSynchronously {
+ //The application wants to know if this is synchronous.
+ //Return true if the Begin method was called synchronously.
+ get {
+ return _blnCompletedSynchronously;
+ }
+ }
+ }
+}
diff --git a/mcs/class/System.Web/Test/TestMonoWeb/AsyncModule.cs b/mcs/class/System.Web/Test/TestMonoWeb/AsyncModule.cs
new file mode 100644
index 00000000000..839297b1c9e
--- /dev/null
+++ b/mcs/class/System.Web/Test/TestMonoWeb/AsyncModule.cs
@@ -0,0 +1,36 @@
+using System;
+using System.Web;
+
+namespace TestMonoWeb
+{
+ /// <summary>
+ /// Summary description for AsyncModule.
+ /// </summary>
+ public class AsyncModule : IHttpModule
+ {
+ HttpApplication _app;
+
+ public void Init(HttpApplication app) {
+ app.AddOnPreRequestHandlerExecuteAsync(
+ new BeginEventHandler(this.BeginPreHandlerExecute),
+ new EndEventHandler(this.EndPreHandlerExecute));
+
+ _app = app;
+ }
+
+ IAsyncResult BeginPreHandlerExecute(Object source, EventArgs e, AsyncCallback cb, Object extraData) {
+ ((HttpApplication) source).Context.Response.Write("AsyncModule.BeginPreHandlerExecute()<br>\n");
+
+ AsynchOperation asynch = new AsynchOperation(cb, _app.Context, extraData);
+ asynch.StartAsyncWork();
+ return asynch;
+ }
+
+ void EndPreHandlerExecute(IAsyncResult ar) {
+ ((AsynchOperation) ar).Context.Response.Write("AsyncModule.EndPreHandlerExecute()<br>\n");
+ }
+
+ public void Dispose() {
+ }
+ }
+}
diff --git a/mcs/class/System.Web/Test/TestMonoWeb/AsyncOperation.cs b/mcs/class/System.Web/Test/TestMonoWeb/AsyncOperation.cs
new file mode 100644
index 00000000000..46b0ff1f722
--- /dev/null
+++ b/mcs/class/System.Web/Test/TestMonoWeb/AsyncOperation.cs
@@ -0,0 +1,42 @@
+using System;
+using System.Threading;
+using System.Web;
+
+namespace TestMonoWeb
+{
+ class AsynchOperation : IAsyncResult {
+ private bool _completed;
+ private Object _state;
+ private AsyncCallback _callback;
+ private HttpContext _context;
+
+ bool IAsyncResult.IsCompleted { get { return _completed; } }
+ WaitHandle IAsyncResult.AsyncWaitHandle { get { return null; } }
+ Object IAsyncResult.AsyncState { get { return _state; } }
+ bool IAsyncResult.CompletedSynchronously { get { return false; } }
+
+ public HttpContext Context {
+ get {
+ return _context;
+ }
+ }
+
+ public AsynchOperation(AsyncCallback callback, HttpContext context, Object state) {
+ _callback = callback;
+ _context = context;
+ _state = state;
+ _completed = false;
+ }
+
+ public void StartAsyncWork() {
+ ThreadPool.QueueUserWorkItem(new WaitCallback(DoSomething), null /*workItemState*/);
+ }
+
+ private void DoSomething(Object workItemState) {
+ // Just for testing..
+ Thread.Sleep(100);
+ _completed = true;
+ _callback(this);
+ }
+ }
+}
diff --git a/mcs/class/System.Web/Test/TestMonoWeb/README b/mcs/class/System.Web/Test/TestMonoWeb/README
new file mode 100644
index 00000000000..1d4950d8036
--- /dev/null
+++ b/mcs/class/System.Web/Test/TestMonoWeb/README
@@ -0,0 +1,5 @@
+This small test program tests HttpModule and HttpHandler. The test program can both handle async and sync tests.
+
+This program uses the temporary configuration for modules and handlers.
+
+- Patrik Torstensson \ No newline at end of file
diff --git a/mcs/class/System.Web/Test/TestMonoWeb/SyncHandler.cs b/mcs/class/System.Web/Test/TestMonoWeb/SyncHandler.cs
new file mode 100644
index 00000000000..7dd01bb65ab
--- /dev/null
+++ b/mcs/class/System.Web/Test/TestMonoWeb/SyncHandler.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Web;
+
+namespace TestMonoWeb
+{
+ public class SyncHandler : IHttpHandler {
+
+ public void ProcessRequest(HttpContext context) {
+ context.Response.Write("SyncHandler.ProcessRequest<br>\n");
+ }
+
+ public bool IsReusable {
+ get { return false; }
+ }
+ }
+}
diff --git a/mcs/class/System.Web/Test/TestMonoWeb/SyncModule.cs b/mcs/class/System.Web/Test/TestMonoWeb/SyncModule.cs
new file mode 100644
index 00000000000..7fddb06a8bf
--- /dev/null
+++ b/mcs/class/System.Web/Test/TestMonoWeb/SyncModule.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Collections;
+using System.Web;
+
+namespace TestMonoWeb
+{
+ public class SyncModule : IHttpModule {
+ public String ModuleName {
+ get { return "HelloWorldModule"; }
+ }
+ //In the Init function, register for HttpApplication
+ //events by adding your handlers.
+ public void Init(HttpApplication application) {
+ application.BeginRequest += (new EventHandler(this.Application_BeginRequest));
+ application.EndRequest += (new EventHandler(this.Application_EndRequest));
+ }
+
+ //Your BeginRequest event handler.
+ private void Application_BeginRequest(Object source, EventArgs e) {
+ HttpApplication application = (HttpApplication)source;
+ HttpContext context = application.Context;
+
+ context.Response.Write("SyncModule.Application_BeginRequest()<br>\n");
+ }
+
+ //Your EndRequest event handler.
+ private void Application_EndRequest(Object source, EventArgs e) {
+ HttpApplication application = (HttpApplication)source;
+ HttpContext context = application.Context;
+
+ context.Response.Write("SyncModule.Application_EndRequest()<br>\n");
+ }
+
+ public void Dispose() {
+ }
+ }
+}
diff --git a/mcs/class/System.Web/Test/TestMonoWeb/Test1.cs b/mcs/class/System.Web/Test/TestMonoWeb/Test1.cs
new file mode 100644
index 00000000000..b453cd8b170
--- /dev/null
+++ b/mcs/class/System.Web/Test/TestMonoWeb/Test1.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Web;
+using System.Web.Hosting;
+using System.Web.Configuration;
+
+namespace TestMonoWeb
+{
+ public class MyHost : MarshalByRefObject {
+ public MyHost() {
+ }
+ }
+ /// <summary>
+ /// Summary description for Test1.
+ /// </summary>
+ public class Test1
+ {
+ static void Main(string[] args) {
+ // Create the application host
+ object host = ApplicationHost.CreateApplicationHost(typeof(MyHost), "/", "c:\\");
+
+ int request_count = 10;
+ SimpleWorkerRequest [] requests = new SimpleWorkerRequest[request_count];
+
+ int pos;
+ for (pos = 0; pos != request_count; pos++) {
+ requests[pos] = new SimpleWorkerRequest("test.aspx", "", Console.Out);
+ }
+
+ ModulesConfiguration.Add("syncmodule", typeof(SyncModule).AssemblyQualifiedName);
+ ModulesConfiguration.Add("asyncmodule", typeof(AsyncModule).AssemblyQualifiedName);
+
+ HandlerFactoryConfiguration.Add("get", "/", typeof(AsyncHandler).AssemblyQualifiedName);
+ //HandlerFactoryConfiguration.Add("get", "/", typeof(SyncHandler).AssemblyQualifiedName);
+
+ for (pos = 0; pos != request_count; pos++)
+ HttpRuntime.ProcessRequest(requests[pos]);
+
+ HttpRuntime.Close();
+/*
+ Console.Write("Press Enter to quit.");
+ Console.WriteLine();
+ Console.ReadLine();
+*/
+ }
+ }
+}
diff --git a/mcs/class/System.Web/Test/TestMonoWeb/TestMonoWeb.build b/mcs/class/System.Web/Test/TestMonoWeb/TestMonoWeb.build
new file mode 100644
index 00000000000..98ecbcc49c3
--- /dev/null
+++ b/mcs/class/System.Web/Test/TestMonoWeb/TestMonoWeb.build
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<project name="System" default="build">
+ <property name="debug" value="false"/>
+
+ <target name="build">
+ <csc target="exe" output="TestMonoWeb.exe" debug="${debug}">
+ <arg value="/nowarn:1595"/>
+ <arg value="/nowarn:0169"/>
+ <arg value="/nowarn:0649"/> <!-- always default value -->
+ <arg value="/nowarn:0067"/> <!-- event never used -->
+ <arg value="/nowarn:0679"/> <!-- internal virual -->
+ <arg value="/nowarn:0168"/> <!-- never used variable -->
+ <arg value="/nowarn:0162"/> <!-- unreachable code -->
+ <arg value="/unsafe"/>
+ <arg value="/noconfig"/>
+ <arg value="/debug"/>
+ <arg value="/r:System.dll"/>
+ <arg value="/r:System.Web.dll"/>
+ <arg value="/r:System.Drawing.dll"/>
+ <arg value="/r:System.Xml.dll"/>
+ <sources>
+ <includes name="**/*.cs"/>
+ </sources>
+ </csc>
+ </target>
+</project>