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

📄 registrationservice.js

📁 Bindows 1.01 完全版 Bindows 框架提供给你: 基于类的面向对象 API; 一个完整的窗口系统
💻 JS
字号:
// This is a proxy class for the registration service// This class is a singleton, which means that there is only ever one instancefunction RegistrationService() {	// check for existing instance	if (RegistrationService._singleton) {		RegistrationService._referenceCount++;		return RegistrationService._singleton;	}	// call super()	BiEventTarget.call(this);	// this array is used to map loaders to the methods names	this._methodNames = {};	// we keep the loader instances in a hash to allow more than one call at	// the time	this._loaders = {};	// set this as the singleton instance	RegistrationService._singleton = this;	RegistrationService._referenceCount = 1;}// make RegistrationService extend BiEventTargetvar _p = RegistrationService.prototype = new BiEventTarget;// Set friendly class name to allow friendly toString (functionality inherited from BiObject)_p._className = "RegistrationService";_p._sessionId = null;// keep count of the number of instances so we can dispose correctlyRegistrationService._referenceCount = 0;_p.serviceUri = String( new BiUri( application.getAdfPath(),							    "../../../services/RegistrationService.aspx" ) );//_p.serviceUri = "http://www.bindows.net/services/RegistrationService.aspx";// define the methods that map directly to the web methods_p.login = function ( sUserName, sPassword ){	this._call( "Login", {fullName: sUserName, password: sPassword} );};_p.register = function ( sFullName, sPassword, sEmail, sCompany, sHomePage, bAllowEmail ){	this._call( "Register", {		fullName:	sFullName,		password:	sPassword,		email:		sEmail,		company:	sCompany,		homePage:	sHomePage,		allowEmail:	bAllowEmail} );};_p.logout = function (){	this._call( "Logout", {sessionId: this.getSessionId()} );};_p.isLoggedIn = function (){	this._call( "IsLoggedIn", {sessionId: this.getSessionId()} );};_p.download = function (){	this._call( "Download", {sessionId: this.getSessionId()} );};// end definition of web method proxies_p.getSessionId = function (){	return CookieManager.getCookie( "sessionid" ) || this._sessionId;};_p.setSessionId = function ( s ){	this._sessionId = s;	CookieManager.setCookie( "sessionid", s );};_p.isReady = function (){	// this is always ready now that we are not using a web sevice any more	return true;};_p._call = function ( sMethodName, oArgs ){	var doc = this.buildCallDocument( sMethodName, oArgs );	var l = new BiXmlLoader;	l.open( "POST", this.serviceUri, true );	l.addEventListener( "load", this.onCallResult, this );	l.addEventListener( "error", this.onCallResult, this );	this._loaders[ l.toHashCode() ] = l;	this._methodNames[ l.toHashCode() ] = sMethodName;	l.send( doc );};_p.onCallResult = function ( e ){	var l = e.getTarget();	var type = this._methodNames[ l.toHashCode() ];	var error = false;	var value;	if ( l.getError() )		error = true;	else	{		value = this.getResponseObject( l.getDocument() );		error = value.ErrorCode != 0;	}	if ( !error )	{		// update session id		if ( type != "IsLoggedIn" )		{			if ( value.SessionId )				this.setSessionId( value.SessionId );			else				this.setSessionId("");		}		// the ws api returned boolean for IsLoggedIn		else		{			value = value == "true";		}	}	// use the method name to lower case as the name	if ( type )		type = type.toLowerCase() + (error ? "error" : "");	else if ( error )		// if not found and error		type = "result";	else		// if not found we use a "result" event		type = "result";	var oEvent = new BiEvent(type);	// bind the result object to the event	oEvent.result = {		value:	value,		error:	error,		errorDetail: {	// map the error message			string:	error ? value.Message : ""		}	};	this.dispatchEvent(oEvent);	oEvent.result = null;	oEvent.dispose();	delete this._loaders[ l.toHashCode() ];	delete this._methodNames[ l.toHashCode() ];	l.dispose();};// This builds an XML document that is then posted to the web server_p.buildCallDocument = function ( sMethodName, oArgs ){	var doc = new BiXmlDocument;	var docEl = doc.createElement( "RegistrationCall" );	docEl.setAttribute( "methodName", sMethodName );	doc.appendChild( docEl );	var argEl;	for ( var name in oArgs )	{		argEl = doc.createElement( "Argument" );		argEl.setAttribute( "name", name );		argEl.setAttribute( "value", String(oArgs[name]) );		docEl.appendChild( argEl )	}	return doc;};// use PascalCasing to be backwards compatible_p.getResponseObject = function ( oDoc ){	var n = oDoc.selectSingleNode( "RegistrationResponse/ErrorCode" );	var res = {		ErrorCode:	0,		Message:	"Could parse result message",		SessionId:	""	};	if ( n )		res.ErrorCode = Number(n.text);	n = oDoc.selectSingleNode( "RegistrationResponse/Message" );	if ( n )		res.Message= n.text;	n = oDoc.selectSingleNode( "RegistrationResponse/SessionId" );	if ( n )		res.SessionId = n.text;	return res;};// we should dispose the instance when we have no more references to the service// Although JS does provide Garbage collection there are bugs in Internet Explorer// and therefore it is needed to break references between DOM/COM objects and JS// objects. If this is forgotten the application might leak memory. Usually this// is not a big deal for non core classes but it is always a good practice to clean// up after using a web service_p.dispose = function (){	if ( this.getDisposed() )		return;	RegistrationService._referenceCount--;	if ( RegistrationService._referenceCount > 0 )		return;	BiEventTarget.prototype.dispose.call( this );	for ( var hc in this._loaders )	{		this._loaders[hc].dispose();		delete this._loaders[hc];	}};

⌨️ 快捷键说明

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