Fix RW to file

This commit is contained in:
David Majdandžić
2023-03-29 21:27:56 +02:00
parent c61ef86a91
commit eaa67eeb71
4 changed files with 17 additions and 17 deletions

View File

@@ -111,8 +111,8 @@ export class Center extends SmppSession {
username: this.username, username: this.username,
password: this.password, password: this.password,
status: this.status, status: this.status,
defaultSingleJob: this.defaultSingleJob, defaultSingleJob: this.defaultSingleJob.serialize(),
defaultMultipleJob: this.defaultMultipleJob, defaultMultipleJob: this.defaultMultipleJob.serialize(),
processors: this.pduProcessors.map(p => p.serialize()), processors: this.pduProcessors.map(p => p.serialize()),
}; };
} }

View File

@@ -43,8 +43,8 @@ export class Client extends SmppSession {
this.password = password; this.password = password;
this.url = url; this.url = url;
this.setDefaultSingleJob(Job.createEmptySingle()); this.defaultSingleJob = Job.createEmptySingle();
this.setDefaultMultipleJob(Job.createEmptyMultiple()); this.defaultMultipleJob = Job.createEmptyMultiple();
this.logger = new Logger(`Client-${id}`); this.logger = new Logger(`Client-${id}`);
} }
@@ -96,8 +96,8 @@ export class Client extends SmppSession {
username: this.username, username: this.username,
password: this.password, password: this.password,
status: this.status, status: this.status,
defaultSingleJob: this.defaultSingleJob, defaultSingleJob: this.defaultSingleJob.serialize(),
defaultMultipleJob: this.defaultMultipleJob, defaultMultipleJob: this.defaultMultipleJob.serialize(),
processors: this.pduProcessors.map(p => p.serialize()), processors: this.pduProcessors.map(p => p.serialize()),
}; };
} }

View File

@@ -46,11 +46,11 @@ export class Job {
} }
static deserialize(serialized: any): Job { static deserialize(serialized: any): Job {
if (!serialized._pdu) { if (!serialized.pdu || !serialized.pdu.command) {
return Job.createEmptyMultiple(); return Job.createEmptyMultiple();
} }
let pdu: any = new smpp.PDU(serialized._pdu.command, serialized._pdu); let pdu: any = new smpp.PDU(serialized.pdu.command, serialized.pdu);
return new Job(pdu, serialized._perSecond, serialized._count); return new Job(pdu, serialized.perSecond, serialized.count);
} }
static createEmptySingle(): Job { static createEmptySingle(): Job {
@@ -63,7 +63,7 @@ export class Job {
serialize(): object { serialize(): object {
return { return {
pdu: JSON.stringify(this.pdu), pdu: this.pdu,
perSecond: this.perSecond, perSecond: this.perSecond,
count: this.count count: this.count
}; };

View File

@@ -57,13 +57,6 @@ export abstract class SessionManager {
}); });
} }
serialize(): object {
this.logger.log1(`Serializing ${this.sessions.length} clients`);
return this.sessions.map((session: SmppSession) => {
return session.serialize();
});
}
createSession(arg: any, username: string, password: string): Promise<SmppSession> { createSession(arg: any, username: string, password: string): Promise<SmppSession> {
return new Promise<SmppSession>((resolve, reject) => { return new Promise<SmppSession>((resolve, reject) => {
this.logger.log1(`Creating session of type ${this.ManagedSessionClass.name} with arg ${arg}`); this.logger.log1(`Creating session of type ${this.ManagedSessionClass.name} with arg ${arg}`);
@@ -113,6 +106,13 @@ export abstract class SessionManager {
fs.writeFileSync(this.StorageFile, JSON.stringify(this.serialize(), null, 4)); fs.writeFileSync(this.StorageFile, JSON.stringify(this.serialize(), null, 4));
} }
serialize(): object {
this.logger.log1(`Serializing ${this.sessions.length} clients`);
return this.sessions.map((session: SmppSession) => {
return session.serialize();
});
}
getExisting(arg: any): Promise<SmppSession> { getExisting(arg: any): Promise<SmppSession> {
return new Promise<SmppSession>((resolve, reject) => { return new Promise<SmppSession>((resolve, reject) => {
this.logger.log1(`Looking for session with arg ${arg}...`); this.logger.log1(`Looking for session with arg ${arg}...`);