12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- import { Observable, Subject } from "rxjs";
- import { BaseMessage } from "../dependencies/fisappmessagejsutilty/dependencies/dependencies";
- import { LoggingService } from "../dependencies/fisloggingservice/services/logging-service";
- import { MessageSynchronisationServiceInterface, MessageSynchronisationServiceSetting } from "../type/datatype";
- export class MessageSyncrhonizationService implements MessageSynchronisationServiceInterface {
- settings: MessageSynchronisationServiceSetting
- sourceSrc: LoggingService = new LoggingService()
- targetSrc: LoggingService = new LoggingService()
- public async init(settings: MessageSynchronisationServiceSetting): Promise<void> {
- this.settings = settings;
- // Wrap promise so that init must be instantiated with resolve before proceeding with subscribe method
- let promiseInit: Promise<void> = new Promise((resolve, reject) => {
- try {
- this.sourceSrc.init(settings.incomingSource).then((data) => {
- if (!data) reject()
- console.log(`File Storage:`)
- data.forEach(e => console.log(e.appLogLocId))
- }).then(() => {
- this.targetSrc.init(settings.target).then((data) => {
- if (!data) reject()
- console.log(`Mongo Storage`)
- data.forEach(e => console.log(e.appLogLocId))
- resolve()
- })
- })
- }
- catch (e) {
- console.error(e)
- }
- })
- return promiseInit
- }
- public subscribe(obs: Observable<string>): Observable<any> {
- let subjectOutput = new Subject()
- // filter all source tags[0] log data
- let set1 = this.sourceSrc.filter({ msgTag: this.settings.incomingSource.tags[0] })
- set1.then((data) => console.log(data.length))
- let set2 = this.targetSrc.filter({ msgTag: this.settings.target.tags[0] })
- set2.then((data) => console.log(data.length))
- // this.compareResult(set1, set2).then((data) => {
- // data.forEach(element => {
- // subjectOutput.next(element)
- // })
- // })
- return subjectOutput.asObservable()
- }
- // compare results and return differences
- private async compareResult(args: Promise<any>, args2: Promise<any>): Promise<any> {
- let arr1 = []
- let arr2 = []
- args.then((element) => {
- arr1.push(element)
- })
- args2.then((element) => {
- arr2.push(element)
- })
- console.log(arr1)
- console.log(arr2)
- return arr1
- }
- }
|