⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atlasruntime.js

📁 《圣殿祭司的ASP.NET 2.0开发详解——使用C#》光盘内容.包含了书籍所含的源代码.非常经典的一本asp.net2.0的书籍
💻 JS
📖 第 1 页 / 共 5 页
字号:
                        case '\b':
                            stringBuilder.append('\\b');
                            break;
                        case '\f':
                            stringBuilder.append('\\f');
                            break;
                        case '\n':
                            stringBuilder.append('\\n');
                            break;
                        case '\r':
                            stringBuilder.append('\\r');
                            break;
                        case '\t':
                            stringBuilder.append('\\t');
                            break;
                        default:
                                                        stringBuilder.append('\\u00');
                            stringBuilder.append(curChar.charCodeAt().toString(16));
                    }
                }
            }
            stringBuilder.append('"');
            break;
 
        case 'boolean':
            stringBuilder.append(object.toString());
            break;
 
        default:
            stringBuilder.append('null');
            break;
        }
    }

    this.serialize = function(object) { 
        var stringBuilder = new Web.StringBuilder();
        serializeWithBuilder(object, stringBuilder);
        return stringBuilder.toString();
    }

    this.deserialize = function(data) {
        return eval('(' + data + ')');
    }
}


Type.registerNamespace('Web.Net');

Web.Net.WebResponse = function(requestor, userContext) {

    var _requestor = requestor;
    var _userContext = userContext;
    var _resultObject;
    
    this.get_data = function() {
        return _requestor.responseText;
    }
    
    this.get_object = function() {
        if (!_resultObject) {
            var data = this.get_data();
            _resultObject = Web.Serialization.JSON.deserialize(data);
        }
        return _resultObject;
    }
    
    this.get_statusCode = function() {
        return _requestor.status;
    }
    
    this.get_statusText = function() {
        return _requestor.statusText;
    }
    
    this.get_userContext = function() {
        return _userContext;
    }
    
    this.get_xml = function() {
        return _requestor.responseXML;
    }
    
    this.getDescriptor = function() {
        var td = new Web.TypeDescriptor();
        
        td.addProperty('data', String, true);
        td.addProperty('object', Object, true);
        td.addProperty('statusCode', Number, true);
        td.addProperty('statusText', String, true);
        td.addProperty('xml', Object, true);
        
        return td;
    }
}
Type.registerClass('Web.Net.WebResponse', null, Web.ITypeDescriptorProvider);

Web.Net.WebRequest = function() {
    Web.Net.WebRequest.initializeBase(this, [true]);

    var _url = null;
    var _effectiveUrl;
    var _timeoutInterval = 0;
    var _headers = null;
    var _body = null;
    var _userContext = null;
    
    var _requestor = null;
    var _timer = null;
    var _isComplete = true;
    var _timedOut = false;
    var _aborted = false;
    
    var _response;
    
    this.get_aborted = function() {
        return _aborted;
    }
    
    this.get_isActive = function() {
        return !_isComplete;
    }

    this.get_body = function() {
        return _body;
    }
    this.set_body = function(value) {
        _body = value;
    }
    
    this.get_headers = function() {
        if (_headers == null) {
            _headers = { };
        }
        return _headers;
    }
    
    this.get_response = function() {
        if (_isComplete && _requestor && !_response) {
            _response = new Web.Net.WebResponse(_requestor, _userContext);
            _requestor = null;
        }
        return _response;
    }
    Web.Net.WebRequest.registerBaseMethod(this, 'get_response');
    
    this.get_timeoutInterval = function() {
        return _timeoutInterval;
    }
    this.set_timeoutInterval = function(value) {
        _timeoutInterval = value;
    }
    
    this.get_timedOut = function() {
        return _timedOut;
    }
    
    this.get_url = function() {
        return _url;
    }
    this.set_url = function(value) {
        if (!_effectiveUrl) {
            _url = value;
        }
    }
    
    this.aborted = this.createEvent();
    
    this.completed = this.createEvent();
    
    this.timeout = this.createEvent();
    
    this.abort = function() {
        if (_timer != null) {
            window.clearTimeout(_timer);
            _timer = null;
        }
        
        if (_requestor != null) {
            _requestor.onreadystatechange = Function.emptyMethod;
            _requestor.abort();
            
            if (_isComplete == false) {
                _aborted = true;
                _isComplete = true;
                
                this.aborted.invoke(this, Web.EventArgs.Empty);
            }
            _requestor = null;
        }
        
        _response = null;
        _userContext = null;
    }
    Web.Net.WebRequest.registerBaseMethod(this, 'abort');
    
    this.dispose = function() {
        if (this.completed) {
            this.completed.dispose();
            this.completed = null;
        }
        if (this.timeout) {
            this.timeout.dispose();
            this.timeout = null;
        }
        
        this.abort();
        
        Web.Net.WebRequest.callBaseMethod(this, 'dispose');
    }
    Web.Net.WebRequest.registerBaseMethod(this, 'dispose');

    this.getDescriptor = function() {
        var td = Web.Net.WebRequest.callBaseMethod(this, 'getDescriptor');
        
        td.addProperty('isActive', Boolean, true);
        td.addProperty('response', Web.Net.WebResponse, true);
        td.addProperty('url', String);
        td.addProperty('timeoutInterval', Number);
        td.addEvent('aborted', true);
        td.addEvent('completed', true);
        td.addEvent('timeout', true);
        td.addMethod('invoke');
        td.addMethod('abort');
        return td;
    }
    Web.Net.WebRequest.registerBaseMethod(this, 'getDescriptor');

    this.getEffectiveUrl = function() {
        return _url;
    }
    Web.Net.WebRequest.registerBaseMethod(this, 'getEffectiveUrl');

    this.invoke = function(userContext) {
        if (_isComplete == false) {
            this.abort();
        }
        _isComplete = false;
        _aborted = false;
        _timedOut = false;
        _response = null;

        _userContext = userContext;


        _requestor = new XMLHttpRequest();
        _requestor.onreadystatechange = Function.createCallback(onReadyStateChange, this);
        
        if (!_effectiveUrl) {
            _effectiveUrl = this.getEffectiveUrl();
        }
        if (_body != null) {
            _requestor.open('POST', _effectiveUrl, true);
            if ((_headers == null) || !_headers['Content-Type']) {
                _requestor.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            }
        }
        else {
            _requestor.open('GET', _effectiveUrl, true);
        }
        
        if (_headers != null) {
            for (var header in _headers) {
                _requestor.setRequestHeader(header, _headers[header]);
            }
        }
        
        if (_timeoutInterval != 0) {
            _timer = window.setTimeout(Function.createCallback(onTimeout, this), _timeoutInterval);
        }

        _requestor.send(_body);
    }
    Web.Net.WebRequest.registerBaseMethod(this, 'invoke');
    
    function onReadyStateChange(context) {
        if (_requestor.readyState == 4) {
            if (_timer != null) {
                window.clearTimeout(_timer);
                _timer = null;
            }
            
            _isComplete = true;
            _requestor.onreadystatechange = Function.emptyMethod;
            
            context.completed.invoke(context, Web.EventArgs.Empty);
            
            _requestor = null;
            _userContext = null;
        }
    }
    
    function onTimeout(context) {
        if (_isComplete == false) {
            if (_timer != null) {
                window.clearTimeout(_timer);
                _timer = null;
            }
            
            _timedOut = true;
            _isComplete = true;
            
            _requestor.onreadystatechange = Function.emptyMethod;
            _requestor.abort();
            
            context.timeout.invoke(context, Web.EventArgs.Empty);
            
            _requestor = null;
            _userContext = null;
        }
    }
}
Type.registerClass('Web.Net.WebRequest', Web.Component);

Web.Net.WebRequest.createQueryString = function(queryString, encodeMethod) {

        if (encodeMethod == null)
        encodeMethod = encodeURIComponent;
        
    var sb = new Web.StringBuilder();

    var i = 0;    
    for (var arg in queryString) {
        if (i != 0) {
            sb.append('&');
        }
        
        sb.append(arg);
        sb.append('=');
        sb.append(encodeMethod(queryString[arg]));
        
        i++;
    }
    
    return sb.toString();
}

Web.Net.WebRequest.createUrl = function(url, queryString) {
    if (!queryString) {
        return url;
    }
    
    return url + '?' + Web.Net.WebRequest.createQueryString(queryString);
}
Web.Net.MethodRequest = function() {
    Web.Net.MethodRequest.initializeBase(this);

    var _methodName = null;
    var _parameters = null;

    this.get_methodName = function() {
        return _methodName;
    }
    this.set_methodName = function(value) {
        _methodName = value;
    }
    
    this.get_parameters = function() {
        if (_parameters == null) {
            _parameters = { };
        }
        return _parameters;
    }
    
    this.getDescriptor = function() {
        var td = Web.Net.MethodRequest.callBaseMethod(this, 'getDescriptor');
        
        td.addProperty('methodName', String);
        td.addProperty('parameters', Object, true);
        return td;
    }
    Web.Net.MethodRequest.registerBaseMethod(this, 'getDescriptor');
}
Type.registerAbstractClass('Web.Net.MethodRequest', Web.Net.WebRequest);

Web.Net.MethodRequest.callMethod = function(request, methodName,
    params, onMethodComplete, onMethodTimeout, onMethodError, userContext) {
    
    function onMethodCompleteInternal(sender, eventArgs) {
        var response = sender.get_response();
        var statusCode = response.get_statusCode();
        var result = null;

        try {        
            result = response.get_object();
        }
        catch (ex) {
        }

        if (((statusCode < 200) || (statusCode >= 300)) ||
            Web.Net.MethodRequestError.isInstanceOfType(result)) {

            if (onMethodError) {
                onMethodError(result, response, userContext);
            }
        }
        else if (onMethodComplete) {
            onMethodComplete(result, response, userContext);
        }
        
        request.dispose();
    }

    function onMethodTimeoutInternal(sender, eventArgs) {
        onMethodTimeout(userContext);

        request.dispose();
    }

    function onMethodErrorInternal(sender, eventArgs) {
        onMethodError(sender.get_response(), userContext);

        request.dispose();
    }

    request.set_methodName(methodName);
    if (onMethodComplete || onMethodError) {
        request.completed.add(onMethodCompleteInternal);
    }
    if (onMethodTimeout) {
        request.timeout.add(onMethodTimeoutInternal);
    }
    
    if (params) {    
        var requestParams = request.get_parameters();
        
        for (var param in params) {
            requestParams[param] = params[param];
        }
    }

    request.invoke(userContext);
    
        return request;
}

Web.Net.MethodRequest.generateTypedConstructor = function(serverType) {
    return function(properties) {
        this.__serverType = serverType;
        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -