1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/src/backend/model/ObjectManagers.ts

169 lines
5.9 KiB
TypeScript
Raw Normal View History

import {IUserManager} from './database/interfaces/IUserManager';
import {IGalleryManager} from './database/interfaces/IGalleryManager';
import {ISearchManager} from './database/interfaces/ISearchManager';
import {SQLConnection} from './database/sql/SQLConnection';
import {ISharingManager} from './database/interfaces/ISharingManager';
2018-03-31 03:30:30 +08:00
import {Logger} from '../Logger';
import {IIndexingManager} from './database/interfaces/IIndexingManager';
import {IPersonManager} from './database/interfaces/IPersonManager';
import {IVersionManager} from './database/interfaces/IVersionManager';
2019-12-24 19:22:25 +08:00
import {IJobManager} from './database/interfaces/IJobManager';
import {LocationManager} from './database/LocationManager';
2016-04-22 19:23:44 +08:00
export class ObjectManagers {
2016-05-09 23:04:56 +08:00
private static instance: ObjectManagers = null;
private galleryManager: IGalleryManager;
private userManager: IUserManager;
private searchManager: ISearchManager;
private sharingManager: ISharingManager;
private indexingManager: IIndexingManager;
private personManager: IPersonManager;
private versionManager: IVersionManager;
private jobManager: IJobManager;
private locationManager: LocationManager;
get VersionManager(): IVersionManager {
return this.versionManager;
}
set VersionManager(value: IVersionManager) {
this.versionManager = value;
}
2019-01-14 00:38:39 +08:00
get LocationManager(): LocationManager {
return this.locationManager;
}
set LocationManager(value: LocationManager) {
this.locationManager = value;
}
2019-01-14 00:38:39 +08:00
get PersonManager(): IPersonManager {
return this.personManager;
2019-01-14 00:38:39 +08:00
}
set PersonManager(value: IPersonManager) {
this.personManager = value;
2019-01-14 00:38:39 +08:00
}
2016-04-22 19:23:44 +08:00
2017-07-26 03:09:37 +08:00
get IndexingManager(): IIndexingManager {
return this.indexingManager;
}
2017-07-26 03:09:37 +08:00
set IndexingManager(value: IIndexingManager) {
this.indexingManager = value;
}
2016-05-09 23:04:56 +08:00
2016-04-22 19:23:44 +08:00
2017-07-04 01:17:49 +08:00
get GalleryManager(): IGalleryManager {
return this.galleryManager;
}
2016-04-22 19:23:44 +08:00
2017-07-04 01:17:49 +08:00
set GalleryManager(value: IGalleryManager) {
this.galleryManager = value;
}
2016-04-22 19:23:44 +08:00
2017-07-04 01:17:49 +08:00
get UserManager(): IUserManager {
return this.userManager;
}
2016-04-22 19:23:44 +08:00
2017-07-04 01:17:49 +08:00
set UserManager(value: IUserManager) {
this.userManager = value;
}
2016-04-22 19:23:44 +08:00
2017-07-04 01:17:49 +08:00
get SearchManager(): ISearchManager {
return this.searchManager;
}
2016-05-05 00:34:54 +08:00
2017-07-04 01:17:49 +08:00
set SearchManager(value: ISearchManager) {
this.searchManager = value;
}
2016-05-05 00:34:54 +08:00
2017-07-04 01:17:49 +08:00
get SharingManager(): ISharingManager {
return this.sharingManager;
2017-07-04 01:17:49 +08:00
}
set SharingManager(value: ISharingManager) {
this.sharingManager = value;
2017-07-04 01:17:49 +08:00
}
2019-12-24 19:22:25 +08:00
get JobManager(): IJobManager {
return this.jobManager;
2019-07-28 04:56:12 +08:00
}
2019-12-24 19:22:25 +08:00
set JobManager(value: IJobManager) {
this.jobManager = value;
2019-07-28 04:56:12 +08:00
}
public static getInstance(): ObjectManagers {
if (this.instance === null) {
this.instance = new ObjectManagers();
2019-01-14 00:38:39 +08:00
}
return this.instance;
2019-01-14 00:38:39 +08:00
}
public static async reset(): Promise<void> {
2021-01-04 17:32:19 +08:00
if (ObjectManagers.getInstance().IndexingManager &&
ObjectManagers.getInstance().IndexingManager.IsSavingInProgress) {
await ObjectManagers.getInstance().IndexingManager.SavingReady;
}
2019-12-24 19:22:25 +08:00
if (ObjectManagers.getInstance().JobManager) {
ObjectManagers.getInstance().JobManager.stopSchedules();
}
2019-01-14 00:38:39 +08:00
await SQLConnection.close();
this.instance = null;
2019-01-14 00:38:39 +08:00
}
public static async InitCommonManagers(): Promise<void> {
2019-12-24 19:22:25 +08:00
const JobManager = require('./jobs/JobManager').JobManager;
ObjectManagers.getInstance().JobManager = new JobManager();
}
public static async InitMemoryManagers(): Promise<void> {
await ObjectManagers.reset();
const GalleryManager = require('./database/memory/GalleryManager').GalleryManager;
const UserManager = require('./database/memory/UserManager').UserManager;
const SearchManager = require('./database/memory/SearchManager').SearchManager;
const SharingManager = require('./database/memory/SharingManager').SharingManager;
const IndexingManager = require('./database/memory/IndexingManager').IndexingManager;
const PersonManager = require('./database/memory/PersonManager').PersonManager;
const VersionManager = require('./database/memory/VersionManager').VersionManager;
ObjectManagers.getInstance().GalleryManager = new GalleryManager();
ObjectManagers.getInstance().UserManager = new UserManager();
ObjectManagers.getInstance().SearchManager = new SearchManager();
ObjectManagers.getInstance().SharingManager = new SharingManager();
ObjectManagers.getInstance().IndexingManager = new IndexingManager();
ObjectManagers.getInstance().PersonManager = new PersonManager();
ObjectManagers.getInstance().VersionManager = new VersionManager();
ObjectManagers.getInstance().LocationManager = new LocationManager();
this.InitCommonManagers();
2017-07-26 03:09:37 +08:00
}
public static async InitSQLManagers(): Promise<void> {
await ObjectManagers.reset();
2017-07-26 03:09:37 +08:00
await SQLConnection.init();
const GalleryManager = require('./database/sql/GalleryManager').GalleryManager;
const UserManager = require('./database/sql/UserManager').UserManager;
const SearchManager = require('./database/sql/SearchManager').SearchManager;
const SharingManager = require('./database/sql/SharingManager').SharingManager;
const IndexingManager = require('./database/sql/IndexingManager').IndexingManager;
const PersonManager = require('./database/sql/PersonManager').PersonManager;
const VersionManager = require('./database/sql/VersionManager').VersionManager;
ObjectManagers.getInstance().GalleryManager = new GalleryManager();
ObjectManagers.getInstance().UserManager = new UserManager();
ObjectManagers.getInstance().SearchManager = new SearchManager();
ObjectManagers.getInstance().SharingManager = new SharingManager();
ObjectManagers.getInstance().IndexingManager = new IndexingManager();
ObjectManagers.getInstance().PersonManager = new PersonManager();
ObjectManagers.getInstance().VersionManager = new VersionManager();
ObjectManagers.getInstance().LocationManager = new LocationManager();
this.InitCommonManagers();
2018-03-31 03:30:30 +08:00
Logger.debug('SQL DB inited');
2017-07-26 03:09:37 +08:00
}
}