- ajaxiontest1.0_net1.1_src.zip
- AjaxionTest
- ajaxiontest1.0_net2.0_src.zip
- ajaxiontest1.0_java_src.zip
- ajaxionTest.jpr
- ajaxionTest.jpr.bak
- AjaxionTest.jws
- classes
- ajaxionTest.cdi
- pw
- ajaxion
- AjaxionEventConsumer.class
- log
- FileLog.class
- servlet.cdi
- servlet
- ajaxionTest.class
- public_html
- pw.ajaxion
- classes
- pw.ajaxion.cdi
- pw
- ajaxion
- AjaxionEventConsumer.class
- AjaxionEventHandler.class
- pw.ajaxion.jpr
- src
- pw
- ajaxion
- pw.log
- classes
- audit.log
- pw.log.cdi
- pw
- log
- FileLog.class
- test
- pw.log.jpr
- src
- src
- servlet
|
using System;
using System.Threading;
using System.Collections;
using System.Web;
using System.Web.UI;
namespace Ajaxion
{
/// <summary>
/// AjaxionEventConsumer.
/// </summary>
/// <example>
/// AjaxionEventConsumer consumer = new AjaxionEventConsumer(this.Context, "imageGifUrl", "image/GIF");
/// consumer.ConsumeEvent("images/" + consumer.EventParameters);
///</example>
public class AjaxionEventConsumer
{
private const string URL_EVENT = "e";
private const string URL_PARAM = "p";
//private const string URL_DATE = "d";
protected HttpContext contextHttp;
protected string eventId;
protected string parameters;
public string EventId
{
get
{
return eventId;
}
}
public string Parameters
{
get
{
return parameters;
}
}
public HttpRequest Request
{
get
{
return contextHttp.Request;
}
}
public HttpResponse Response
{
get
{
return contextHttp.Response;
}
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="contextHttp">Caller HttpContext</param>
/// <param name="eventId">Allowed callback events, as pairs of event id / content type</param>
public AjaxionEventConsumer(HttpContext contextHttp)
: this(contextHttp, 0)
{}
/// <summary>
/// Constructor
/// </summary>
/// <param name="contextHttp">Caller HttpContext</param>
/// <param name="eventId">Allowed callback events, as pairs of event id / content type</param>
/// <param name="sleep">Miliseconds to sleep before consuming calls
/// - mostly for demo, we do not want delays!</param>
public AjaxionEventConsumer(HttpContext contextHttp, int sleep)
{
this.contextHttp = contextHttp;
eventId = contextHttp.Request.QueryString[URL_EVENT];
parameters = contextHttp.Request.QueryString[URL_PARAM];
if (parameters == null)
parameters = string.Empty;
if (sleep > 0)
Thread.Sleep(sleep);
}
public void ConsumeEvent(string responseData, string responseContentType)
{
BeginResponse(responseContentType);
contextHttp.Response.Write(responseData);
EndResponse();
}
public void ConsumeEvent(byte[] responseData, string responseContentType)
{
BeginResponse(responseContentType);
contextHttp.Response.Write(responseData);
EndResponse();
}
public void BeginResponse(string contentType)
{
contextHttp.Response.ContentType = contentType;
contextHttp.Response.Flush();
}
public void RespondString(string responseData)
{
if (contextHttp.Response.ContentType.IndexOf("text") > -1)
{
contextHttp.Response.Write(responseData);
contextHttp.Response.Flush();
}
else
throw new HttpException("Unexpected content type...");
}
public void RespondBytes(byte[] responseData, string contentType)
{
if (contextHttp.Response.ContentType.IndexOf("text") == -1)
{
contextHttp.Response.Write(responseData);
contextHttp.Response.Flush();
}
else
throw new HttpException("Unexpected content type...");
}
public void EndResponse()
{
contextHttp.Response.Flush();
contextHttp.Response.End();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.