用于Atlas June CTP的Web Service调用封装
2006-10-29 14:34 Cat Chen 阅读(517) 评论(0) 编辑 收藏 举报
Type.registerNamespace("Cattism.BodyMaintainer.Web.Services");
// Cattism.BodyMaintainer.Web.Services
Cattism.BodyMaintainer.Web.Services._requests = new Array();
Cattism.BodyMaintainer.Web.Services._busyIndicator = new Sys.UI.Label($("busyIndicator"));
Cattism.BodyMaintainer.Web.Services.call = function()
{
var service = arguments[0];
var configuration = arguments[arguments.length - 1]
var configurationWrap = Cattism.BodyMaintainer.Web.Services.createConfiguration(Cattism.BodyMaintainer.Web.Services._onComplete, Cattism.BodyMaintainer.Web.Services._onTimeout, Cattism.BodyMaintainer.Web.Services._onError, Cattism.BodyMaintainer.Web.Services._onAborted, configuration, configuration.timeoutInterval);
var args = new Array();
for (var i = 1; i < arguments.length - 1; i++)
{
args.push(arguments[i]);
}
args.push(configurationWrap);
if (Cattism.BodyMaintainer.Web.Services._requests.length == 0)
{
Cattism.BodyMaintainer.Web.Services._busyIndicator.set_visible(true);
}
var request = service.apply(this, args);
Cattism.BodyMaintainer.Web.Services._addRequest(request)
}
Cattism.BodyMaintainer.Web.Services.createConfiguration = function(onComplete, onTimeout, onError, onAborted, context, timeout)
{
if (!timeout)
{
timeout = 30000;
}
return {
onMethodComplete: onComplete,
onMethodTimeout: onTimeout,
onMethodError: onError,
onMethodAborted: onAborted,
userContext: context,
timeoutInterval: timeout
};
}
Cattism.BodyMaintainer.Web.Services._onComplete = function(result, response, userContext)
{
var request = response.get_webRequest();
Cattism.BodyMaintainer.Web.Services._removeRequest(request);
userContext.onMethodComplete.call(this, result, response, userContext.userContext);
}
Cattism.BodyMaintainer.Web.Services._onTimeout = function(request, userContext)
{
Cattism.BodyMaintainer.Web.Services._removeRequest(request);
if (userContext.onMethodTimeout)
{
userContext.onMethodTimeout.call(this, request, userContext.userContext);
}
else
{
alert("Operation timeout.\r\nPlease retry later.");
//debug.trace("<b>Timeout: </b>" + request.get_resolvedUrl());
}
}
Cattism.BodyMaintainer.Web.Services._onError = function(result, response, userContext)
{
var request = response.get_webRequest();
Cattism.BodyMaintainer.Web.Services._removeRequest(request);
if (userContext.onMethodError)
{
userContext.onMethodError.call(this, result, response, userContext.userContext);
}
else
{
alert("Operation error:\r\n" + result.get_message());
//debug.trace("<b>Message: </b>" + result.get_message());
//debug.trace("<b>Stack Trace: </b>" + result.get_stackTrace());
//debug.trace("<b>Exception Type: </b>" + result.get_exceptionType());
}
}
Cattism.BodyMaintainer.Web.Services._onAborted = function(request, userContext)
{
Cattism.BodyMaintainer.Web.Services._removeRequest(request);
if (userContext.onMethodAborted)
{
userContext.onMethodAborted.call(this, request, userContext.userContext);
}
else
{
}
}
Cattism.BodyMaintainer.Web.Services._addRequest = function(request)
{
Cattism.BodyMaintainer.Web.Services._requests.push(request);
}
Cattism.BodyMaintainer.Web.Services._removeRequest = function(request)
{
for (var i = 0; i < Cattism.BodyMaintainer.Web.Services._requests.length; i++)
{
if (Cattism.BodyMaintainer.Web.Services._requests[i] == request)
{
Cattism.BodyMaintainer.Web.Services._requests.splice(i, 1);
break;
}
}
if (Cattism.BodyMaintainer.Web.Services._requests.length == 0)
{
Cattism.BodyMaintainer.Web.Services._busyIndicator.set_visible(false);
}
}
// Cattism.BodyMaintainer.Web.Services
Cattism.BodyMaintainer.Web.Services._requests = new Array();
Cattism.BodyMaintainer.Web.Services._busyIndicator = new Sys.UI.Label($("busyIndicator"));
Cattism.BodyMaintainer.Web.Services.call = function()
{
var service = arguments[0];
var configuration = arguments[arguments.length - 1]
var configurationWrap = Cattism.BodyMaintainer.Web.Services.createConfiguration(Cattism.BodyMaintainer.Web.Services._onComplete, Cattism.BodyMaintainer.Web.Services._onTimeout, Cattism.BodyMaintainer.Web.Services._onError, Cattism.BodyMaintainer.Web.Services._onAborted, configuration, configuration.timeoutInterval);
var args = new Array();
for (var i = 1; i < arguments.length - 1; i++)
{
args.push(arguments[i]);
}
args.push(configurationWrap);
if (Cattism.BodyMaintainer.Web.Services._requests.length == 0)
{
Cattism.BodyMaintainer.Web.Services._busyIndicator.set_visible(true);
}
var request = service.apply(this, args);
Cattism.BodyMaintainer.Web.Services._addRequest(request)
}
Cattism.BodyMaintainer.Web.Services.createConfiguration = function(onComplete, onTimeout, onError, onAborted, context, timeout)
{
if (!timeout)
{
timeout = 30000;
}
return {
onMethodComplete: onComplete,
onMethodTimeout: onTimeout,
onMethodError: onError,
onMethodAborted: onAborted,
userContext: context,
timeoutInterval: timeout
};
}
Cattism.BodyMaintainer.Web.Services._onComplete = function(result, response, userContext)
{
var request = response.get_webRequest();
Cattism.BodyMaintainer.Web.Services._removeRequest(request);
userContext.onMethodComplete.call(this, result, response, userContext.userContext);
}
Cattism.BodyMaintainer.Web.Services._onTimeout = function(request, userContext)
{
Cattism.BodyMaintainer.Web.Services._removeRequest(request);
if (userContext.onMethodTimeout)
{
userContext.onMethodTimeout.call(this, request, userContext.userContext);
}
else
{
alert("Operation timeout.\r\nPlease retry later.");
//debug.trace("<b>Timeout: </b>" + request.get_resolvedUrl());
}
}
Cattism.BodyMaintainer.Web.Services._onError = function(result, response, userContext)
{
var request = response.get_webRequest();
Cattism.BodyMaintainer.Web.Services._removeRequest(request);
if (userContext.onMethodError)
{
userContext.onMethodError.call(this, result, response, userContext.userContext);
}
else
{
alert("Operation error:\r\n" + result.get_message());
//debug.trace("<b>Message: </b>" + result.get_message());
//debug.trace("<b>Stack Trace: </b>" + result.get_stackTrace());
//debug.trace("<b>Exception Type: </b>" + result.get_exceptionType());
}
}
Cattism.BodyMaintainer.Web.Services._onAborted = function(request, userContext)
{
Cattism.BodyMaintainer.Web.Services._removeRequest(request);
if (userContext.onMethodAborted)
{
userContext.onMethodAborted.call(this, request, userContext.userContext);
}
else
{
}
}
Cattism.BodyMaintainer.Web.Services._addRequest = function(request)
{
Cattism.BodyMaintainer.Web.Services._requests.push(request);
}
Cattism.BodyMaintainer.Web.Services._removeRequest = function(request)
{
for (var i = 0; i < Cattism.BodyMaintainer.Web.Services._requests.length; i++)
{
if (Cattism.BodyMaintainer.Web.Services._requests[i] == request)
{
Cattism.BodyMaintainer.Web.Services._requests.splice(i, 1);
break;
}
}
if (Cattism.BodyMaintainer.Web.Services._requests.length == 0)
{
Cattism.BodyMaintainer.Web.Services._busyIndicator.set_visible(false);
}
}