📄 registrationservice.old.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); // hook up IE web service behavior var oThis = this; var ws = this.webService = new BiWebService; ws.onreadystatechange = function () { if (ws.readyState == "complete") { oThis._onReadyStateChange(); } }; ws.onresult = function () { oThis._onResult(window.event); }; // the queue is used to allow calls before the web service behavior is loaded this._queue = []; // this array is used to map call ids to the methods names this._callIds = []; // 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;// Define where to find the web servise description. WSDL URIs must be absolute_p.wsdlUri = String( new BiUri( application.getAdfPath(), "../../../services/RegistrationService.asmx?WSDL" ) );//_p.wsdlUri = "http://www.bindows.net/services/RegistrationService.asmx?WSDL";// set the name of the service to use. This can be any valid identifier string_p.serviceName = "RegistrationService";// define the methods that map directly to the web methods_p.login = function (sUserName, sPassword) { this._call(["Login", sUserName, sPassword]);};_p.register = function (sFullName, sPassword, sEmail, sCompany, sHomePage) { this._call(["Register", sFullName, sPassword, sEmail, sCompany, sHomePage]);};_p.logout = function () { this._call(["Logout", this.getSessionId()]);};_p.isLoggedIn = function () { this._call(["IsLoggedIn", 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 () { return this.webService.readyState == "complete";};// this calls the web service if ready, otherwise it stores the call for future use_p._call = function (args) { if (this.isReady()) { this.__call(args); } else this._addQueued(args);};// this calls the web service and stores the call id <-> method name relation_p.__call = function (args) { var ws = this.webService[this.serviceName]; var id = ws.callService.apply(ws, args); this._callIds[id] = args[0];}_p._addQueued = function (args) { this._queue.push(args);};// this loops through all the queued calls and does them now_p._callQueued = function () { if (this.isReady()) { for (var i = 0; i < this._queue.length; i++) { this.__call(this._queue[i]); this._queue[i] = null; } this._queue = []; }};// called when the web service behavior has loaded_p._onReadyStateChange = function () { this.webService.useService(this.wsdlUri, this.serviceName); this._callQueued();};// this is called when we get a response from the web service// this maps the results to events_p._onResult = function (e) { var result = e.result; var type = this._callIds[result.id]; if (!result.error && type != "IsLoggedIn") { if (result.value.SessionId) this.setSessionId(result.value.SessionId); else this.setSessionId(""); } // use the method name to lower case as the name if (type) type = type.toLowerCase() + (result.error ? "error" : ""); else if (result.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 = result; this.dispatchEvent(oEvent); oEvent.result = null; oEvent.dispose();};// 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); this.webService.onreadystatechange = null; this.webService.onresult = null; this.webService = null;};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -