Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -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;
}
}
}
}

View File

@@ -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() {
}
}
}

View File

@@ -0,0 +1,44 @@
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;
try {
_callback(this);
} catch {}
}
}
}

View File

@@ -0,0 +1,38 @@
thisdir = class/System.Web/Test/TestMonoWeb
SUBDIRS =
include ../../../../build/rules.make
LOCAL_MCS_FLAGS = /nowarn:0168 /nowarn:0162 /unsafe \
/r:System.dll /r:System.Web.dll \
/r:System.Drawing.dll /r:System.Xml.dll
all-local install-local uninstall-local doc-update-local csproj-local:
# it doesn't compile for me.
# test-local: TestMonoWeb.exe
test-local:
# ??? What do we run here?
run-test-local run-test-ondotnet-local:
clean-local:
rm -f *.exe
sources = \
AsyncHandler.cs \
AsyncModule.cs \
AsyncOperation.cs \
SyncHandler.cs \
SyncModule.cs \
Test1.cs
DISTFILES = $(sources) README
dist-local: dist-default
# The thingie
TestMonoWeb.exe: $(sources)
$(CSCOMPILE) /target:exe /out:$@ $(sources)

View File

@@ -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

View File

@@ -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; }
}
}
}

View File

@@ -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() {
}
}
}

View File

@@ -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();
*/
}
}
}