"use strict"; var CloudExperienceHost; (function (CloudExperienceHost) { (function (WebAppExecutionState) { WebAppExecutionState[WebAppExecutionState["Running"] = 0] = "Running"; WebAppExecutionState[WebAppExecutionState["Closed"] = 1] = "Closed"; })(CloudExperienceHost.WebAppExecutionState || (CloudExperienceHost.WebAppExecutionState = {})); var WebAppExecutionState = CloudExperienceHost.WebAppExecutionState; var WebAppState = (function () { function WebAppState(cxid, state, result) { this.cxid = cxid; this.state = state; this.result = result; } return WebAppState; })(); CloudExperienceHost.WebAppState = WebAppState; var AppExecutionState = (function () { function AppExecutionState() { this.source = null; this.current = null; } return AppExecutionState; })(); var StateManager = (function () { function StateManager() { this._appState = null; this._webAppState = null; if (!StateManager._allowInstantiation) { throw new Error("Error: Instantiation failed: Use getInstance() instead of new."); } if (WinJS.Application.sessionState.appState) { this._appState = WinJS.Application.sessionState.appState; } else { this._appState = new AppExecutionState(); WinJS.Application.sessionState.appState = this._appState; } if (WinJS.Application.sessionState.webAppState) { this._webAppState = WinJS.Application.sessionState.webAppState; } else { this._webAppState = new Object(); WinJS.Application.sessionState.webAppState = this._webAppState; } } StateManager.getInstance = function () { if (StateManager._instance === null) { StateManager._allowInstantiation = true; StateManager._instance = new StateManager(); StateManager._allowInstantiation = false; } return StateManager._instance; }; StateManager.prototype.isValid = function (source) { return (this._appState.source && (this._appState.source.toLocaleLowerCase() === source.toLocaleLowerCase())); }; StateManager.prototype.setSource = function (source) { this._appState.source = source; }; StateManager.prototype.onNavigate = function (node) { this._appState.current = new WebAppState(node.cxid, 0 , null); }; StateManager.prototype.onDone = function (node, appResult) { this._appState.current.result = appResult; this._appState.current.state = 1 ; }; StateManager.prototype.getNextCXID = function () { var cxid = null; if (this._appState.current && this._appState.current.state === 0 ) { cxid = this._appState.current.cxid; } return cxid; }; StateManager.prototype.clean = function () { WinJS.Application.sessionState = null; }; StateManager.prototype.setWebAppState = function (cxid, value) { this._webAppState[cxid] = value; }; StateManager.prototype.getWebAppState = function (cxid) { return this._webAppState[cxid]; }; StateManager._instance = null; return StateManager; })(); CloudExperienceHost.StateManager = StateManager; WinJS.Namespace.define("CloudExperienceHost.SessionState", { setState: function (value) { StateManager.getInstance().setWebAppState(CloudExperienceHost.getCurrentNode().cxid, value); }, getState: function () { return StateManager.getInstance().getWebAppState(CloudExperienceHost.getCurrentNode().cxid); } }); })(CloudExperienceHost || (CloudExperienceHost = {}));