ajsfw
Version:
Ajs Framework
121 lines (120 loc) • 6.09 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var logger = require("ajsfw/dbg/logger");
var resources = require("ajsfw/resources");
var consts = require("./constants");
var StateManager = (function () {
function StateManager(resourceManager) {
logger.log(logger.LogType.Constructor, 0, "ajs.state", this);
this.__resourceManager = resourceManager;
logger.log(logger.LogType.Exit, 0, "ajs.state", this);
}
StateManager.prototype.setAppState = function (key, value) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
logger.log(logger.LogType.Enter, 0, "ajs.state", this);
logger.log(logger.LogType.Info, 0, "ajs.state", this, "Setting the application state: " + key + " : " + value);
return [4, this.__resourceManager.setCachedResource(consts.APP_STATE_PREFIX + key, value, resources.StorageType.Local, resources.CachePolicy.Permanent)];
case 1:
_a.sent();
logger.log(logger.LogType.Exit, 0, "ajs.state", this);
return [2];
}
});
});
};
StateManager.prototype.getAppState = function (key) {
return __awaiter(this, void 0, void 0, function () {
var resource;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
logger.log(logger.LogType.Enter, 0, "ajs.state", this);
logger.log(logger.LogType.Info, 0, "ajs.state", this, "Retrieving the application state " + key);
return [4, this.__resourceManager.getCachedResource(consts.APP_STATE_PREFIX + key, resources.StorageType.Local)];
case 1:
resource = _a.sent();
if (resource !== null) {
logger.log(logger.LogType.Exit, 0, "ajs.state", this);
return [2, resource.data];
}
logger.log(logger.LogType.Exit, 0, "ajs.state", this);
return [2, null];
}
});
});
};
StateManager.prototype.removeAppState = function (key) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
logger.log(logger.LogType.Enter, 0, "ajs.state", this);
logger.log(logger.LogType.Info, 0, "ajs.state", this, "Removing the application state " + key);
return [4, this.__resourceManager.removeCachedResource(key, resources.StorageType.Local)];
case 1:
_a.sent();
logger.log(logger.LogType.Exit, 0, "ajs.state", this);
return [2];
}
});
});
};
StateManager.prototype.setSessionState = function (key, value) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
logger.log(logger.LogType.Enter, 0, "ajs.state", this);
logger.log(logger.LogType.Info, 0, "ajs.state", this, "Setting the session state " + key + " : " + value);
return [4, this.__resourceManager.setCachedResource(consts.SESS_STATE_PREFIX + key, value, resources.StorageType.Session, resources.CachePolicy.Permanent)];
case 1:
_a.sent();
logger.log(logger.LogType.Exit, 0, "ajs.state", this);
return [2];
}
});
});
};
StateManager.prototype.getSessionState = function (key) {
return __awaiter(this, void 0, void 0, function () {
var resource;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
logger.log(logger.LogType.Enter, 0, "ajs.state", this);
logger.log(logger.LogType.Info, 0, "ajs.state", this, "Retireving the session state " + key);
return [4, this.__resourceManager.getCachedResource(consts.SESS_STATE_PREFIX + key, resources.StorageType.Session)];
case 1:
resource = _a.sent();
if (resource !== null) {
logger.log(logger.LogType.Exit, 0, "ajs.state", this);
return [2, resource.data];
}
logger.log(logger.LogType.Exit, 0, "ajs.state", this);
return [2, null];
}
});
});
};
StateManager.prototype.removeSessionState = function (key) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
logger.log(logger.LogType.Enter, 0, "ajs.state", this);
logger.log(logger.LogType.Info, 0, "ajs.state", this, "Removing the session state " + key);
return [4, this.__resourceManager.removeCachedResource(key, resources.StorageType.Session)];
case 1:
_a.sent();
logger.log(logger.LogType.Exit, 0, "ajs.state", this);
return [2];
}
});
});
};
return StateManager;
}());
exports.StateManager = StateManager;