rhamt-core
Version:
143 lines (140 loc) • 4.18 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class ProgressMonitor {
constructor(delegate, closeHandler) {
this.delegate = delegate;
this.closeHandler = closeHandler;
this.isCancelled = false;
this._done = false;
this.preWork = 0;
this.totalWork = 0;
this.title = '';
this.started = false;
this.finalizing = false;
}
handleMessage(err, msg) {
console.log('progressMonitor recieved message: ' + JSON.stringify(msg.body));
this.delegateMessage(msg.body);
}
delegateMessage(msg) {
if (msg.op === 'beginTask') {
const task = msg.task;
const work = msg.totalWork;
this.beginTask(task, work);
return;
}
const value = msg.value;
switch (msg.op) {
case 'logMessage':
this.logMessage(value);
break;
case 'done':
this.done();
break;
case 'setTaskName':
this.setTaskName(value);
break;
case 'subTask':
this.subTask(value);
break;
case 'worked':
this.worked(value);
break;
}
if (!this.started) {
this.started = true;
this.report('Launching analysis...');
}
}
doClose() {
this.closeHandler();
}
stop() {
this.doClose();
}
logMessage(message) {
}
beginTask(task, total) {
this.title = 'Migration assessment in progress';
this.totalWork = total;
this.setTitle(this.title);
}
done() {
this.report('Done');
this._done = true;
this.doClose();
}
isDone() {
return this._done;
}
setCancelled() {
this.report('Cancelled');
this.isCancelled = true;
this.doClose();
}
setTaskName(task) {
this.report(task);
}
subTask(name) {
/*let phase = Phase.find(name);
if (phase) {
let title = this.computeTitle() + ' - ' + phase;
this.setTitle(title);
}*/
}
worked(worked) {
this.preWork += worked;
this.setTitle(this.computeTitle());
}
getPercentangeDone() {
return Math.trunc(Math.min((this.preWork * 100 / this.totalWork), 100));
}
computeTitle() {
const done = this.getPercentangeDone();
let label = this.title;
if (done > 0) {
label += ` (${done} % done)`;
}
return label;
}
setTitle(value) {
this.report(value);
}
report(msg) {
if (!this.isDone && !this.isCancelled && !this.finalizing) {
if (this.getPercentangeDone() === 99) {
this.finalizing = true;
setTimeout(() => null, 500);
msg = 'Finalizing assessment...';
}
this.delegate.report({ message: msg });
}
else {
console.log('progress done or cancelled, cannot report: ' + msg);
}
}
}
exports.ProgressMonitor = ProgressMonitor;
/*class Phase {
private static phases: Array<{id: string, desc: string}> = [
{id: 'InitializationPhase', desc: 'Initializing'},
{id: 'DiscoveryPhase', desc: 'Gathering rules'},
{id: 'InitialAnalysisPhase', desc: 'Rules loaded. Preparing to process'},
{id: 'MigrationRulesPhase', desc: 'Analyzing'},
{id: 'ReportGenerationPhase', desc: 'Analysis complete. Preparing report'},
{id: 'ReportRenderingPhase', desc: 'Generating report'},
{id: 'PostFinalizePhasePhase', desc: 'Finalizing. One moment'}
];
private static matches(task: string, id: string): boolean {
return task.indexOf(id) !== -1;
}
public static find(task: string): string | undefined {
for (var phase of Phase.phases) {
if (Phase.matches(task, phase.id)) {
return phase.desc;
}
}
return undefined;
}
}*/
//# sourceMappingURL=progress.js.map