2016-12-27 23:09:47 +08:00
|
|
|
import {IUserManager} from "./interfaces/IUserManager";
|
|
|
|
import {IGalleryManager} from "./interfaces/IGalleryManager";
|
|
|
|
import {ISearchManager} from "./interfaces/ISearchManager";
|
|
|
|
import {MySQLConnection} from "./mysql/MySQLConnection";
|
2016-04-22 19:23:44 +08:00
|
|
|
|
2016-05-09 23:04:56 +08:00
|
|
|
export class ObjectManagerRepository {
|
|
|
|
|
2016-12-27 23:09:47 +08:00
|
|
|
private _galleryManager: IGalleryManager;
|
|
|
|
private _userManager: IUserManager;
|
|
|
|
private _searchManager: ISearchManager;
|
|
|
|
private static _instance: ObjectManagerRepository = null;
|
2016-04-22 19:23:44 +08:00
|
|
|
|
|
|
|
|
2016-12-27 23:09:47 +08:00
|
|
|
public static InitMemoryManagers() {
|
|
|
|
const GalleryManager = require("./memory/GalleryManager").GalleryManager;
|
|
|
|
const UserManager = require("./memory/UserManager").UserManager;
|
|
|
|
const SearchManager = require("./memory/SearchManager").SearchManager;
|
2016-04-22 19:23:44 +08:00
|
|
|
ObjectManagerRepository.getInstance().setGalleryManager(new GalleryManager());
|
|
|
|
ObjectManagerRepository.getInstance().setUserManager(new UserManager());
|
2016-05-05 00:34:54 +08:00
|
|
|
ObjectManagerRepository.getInstance().setSearchManager(new SearchManager());
|
2016-04-22 19:23:44 +08:00
|
|
|
}
|
2016-05-09 23:04:56 +08:00
|
|
|
|
2016-12-27 23:09:47 +08:00
|
|
|
public static InitMySQLManagers(): Promise<boolean> {
|
|
|
|
return new Promise<boolean>((resolve, reject) => {
|
|
|
|
MySQLConnection.init().then(() => {
|
|
|
|
const GalleryManager = require("./memory/GalleryManager").GalleryManager;
|
|
|
|
const UserManager = require("./mysql/UserManager").UserManager;
|
|
|
|
const SearchManager = require("./memory/SearchManager").SearchManager;
|
|
|
|
ObjectManagerRepository.getInstance().setGalleryManager(new GalleryManager());
|
|
|
|
ObjectManagerRepository.getInstance().setUserManager(new UserManager());
|
|
|
|
ObjectManagerRepository.getInstance().setSearchManager(new SearchManager());
|
|
|
|
resolve(true);
|
|
|
|
}).catch(err => reject(err));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-05-09 23:04:56 +08:00
|
|
|
public static getInstance() {
|
|
|
|
if (this._instance === null) {
|
2016-04-22 19:23:44 +08:00
|
|
|
this._instance = new ObjectManagerRepository();
|
|
|
|
}
|
|
|
|
return this._instance;
|
|
|
|
}
|
|
|
|
|
2016-05-26 02:17:42 +08:00
|
|
|
public static reset() {
|
|
|
|
this._instance = null;
|
|
|
|
}
|
|
|
|
|
2016-04-22 19:23:44 +08:00
|
|
|
|
2016-12-27 23:09:47 +08:00
|
|
|
getGalleryManager(): IGalleryManager {
|
2016-04-22 19:23:44 +08:00
|
|
|
return this._galleryManager;
|
|
|
|
}
|
|
|
|
|
2016-12-27 23:09:47 +08:00
|
|
|
setGalleryManager(value: IGalleryManager) {
|
2016-04-22 19:23:44 +08:00
|
|
|
this._galleryManager = value;
|
|
|
|
}
|
|
|
|
|
2016-12-27 23:09:47 +08:00
|
|
|
getUserManager(): IUserManager {
|
2016-04-22 19:23:44 +08:00
|
|
|
return this._userManager;
|
|
|
|
}
|
|
|
|
|
2016-12-27 23:09:47 +08:00
|
|
|
setUserManager(value: IUserManager) {
|
2016-04-22 19:23:44 +08:00
|
|
|
this._userManager = value;
|
|
|
|
}
|
2016-05-05 00:34:54 +08:00
|
|
|
|
2016-12-27 23:09:47 +08:00
|
|
|
getSearchManager(): ISearchManager {
|
2016-05-05 00:34:54 +08:00
|
|
|
return this._searchManager;
|
|
|
|
}
|
|
|
|
|
2016-12-27 23:09:47 +08:00
|
|
|
setSearchManager(value: ISearchManager) {
|
2016-05-05 00:34:54 +08:00
|
|
|
this._searchManager = value;
|
|
|
|
}
|
|
|
|
|
2016-04-22 19:23:44 +08:00
|
|
|
}
|