UNPKG

rhamt-vscode-extension

Version:

RHAMT VSCode extension

182 lines (159 loc) 6.52 kB
import { RhamtConfiguration, Protocol } from 'raas-core'; import { Editor } from './editor'; import { RaasClient } from 'raas-client'; export class EditorClientController { private config: RhamtConfiguration; private editor: Editor; private raasClient: RaasClient; constructor( config: RhamtConfiguration, editor: Editor, raasClient: RaasClient) { this.config = config; this.editor = editor; this.raasClient = raasClient; this.addRaasClientListeners(); this.listen(); } connectRaasClient(): void { const host = this.config.server.host; const port = this.config.server.port; if (host === this.raasClient.host && port === this.raasClient.port) { if (this.raasClient.connected) { this.editor.raasClientConnected(this.raasClient); } else if (this.raasClient.starting) { this.editor.raasClientStarting(this.raasClient); } else { this.doConnectRaasClient(); } } else { this.doConnectRaasClient(); } } private doConnectRaasClient(): void { this.raasClient.disconnect(); this.addRaasClientListeners(); this.raasClient.connect(undefined, this.config.server.host, this.config.server.port).catch(e => { console.log(e); this.editor.unableToConnectRaasClient(this.raasClient); }); } addRaasClientListeners(): void { this.raasClient.onDiscoveryPathAdded(this.onDiscoveryPathAdded.bind(this)); this.raasClient.onDiscoveryPathRemoved(this.onDiscoveryPathRemoved.bind(this)); this.raasClient.onServerAdded(this.onServerAdded.bind(this)); this.raasClient.onServerRemoved(this.onServerRemoved.bind(this)); this.raasClient.onServerStateChange(this.onServerStateChange.bind(this)); this.raasClient.onServerOutputAppended(this.onServerOutputAppended.bind(this)); this.raasClient.onServerAttributeChange(this.onServerAttributeChange.bind(this)); this.raasClient.onServerProcessCreated(this.onServerProcessCreated.bind(this)); this.raasClient.onServerProcessTerminated(this.onServerProcessTerminated.bind(this)); this.raasClient.onConnected(this.onConnected.bind(this)); this.raasClient.onDisconnected(this.onDisconnected.bind(this)); this.raasClient.onAnalaysisMessage(this.onAnalysisMessage.bind(this)); } onDiscoveryPathAdded(arg: Protocol.DiscoveryPath): void { } onDiscoveryPathRemoved(arg: Protocol.DiscoveryPath): void { } onServerAdded(arg: Protocol.ServerConfig): void { } onServerRemoved(arg: Protocol.ServerConfig): void { } onServerStateChange(arg: Protocol.ServerConfig): void { console.log('server changed notification.'); console.log(arg); } onServerOutputAppended(arg: Protocol.ServerOutput): void { console.log('###server process output: '); console.log(arg.output); } onServerAttributeChange(arg: Protocol.ServerConfig): void { } onServerProcessCreated(arg: Protocol.ServerConfig): void { } onServerProcessTerminated(arg: Protocol.ServerConfig): void { } onConnected(): void { console.log('raasClient connected'); this.editor.raasClientConnected(this.raasClient); } onDisconnected(raasClient: RaasClient): void { // this.editor.raasClientDisconnected(raasClient); } onAnalysisMessage(arg: Protocol.ServerOutput): void { console.log('###onAnalysisMessage'); console.log(arg.output); } private created: boolean = false; private started: boolean = false; private serverConfig = new Protocol.ServerConfigImpl(); onStartAnalysis(): void { if (this.started) { this.raasClient.startAnalysis(this.config, this.serverConfig).then(result => { console.log('analysis started'); console.log(result); }).catch(e => { console.log('error starting analysis'); console.log(e); }); return; } if (this.created) { console.log('server already created. starting now'); this.raasClient.startServerAsync(this.serverConfig).then(result => { console.log('SUCCESSFULLY started server!!!'); console.log(result); this.started = true; }).catch(e => { console.log('ERROR starting server.'); console.log(e); }); return; } this.serverConfig.id = '1'; this.serverConfig.installation = new Protocol.ServerInstallationImpl(); this.serverConfig.installation.location = '/Users/johnsteele/Desktop/git/windup-eclipse-plugin/plugins/org.jboss.tools.windup.runtime/windup/rhamt-cli-4.2.0-SNAPSHOT/bin/rhamt-cli'; this.serverConfig.attributes = {}; this.serverConfig.attributes['rhamt.host'] = 'localhost'; this.serverConfig.attributes['rhamt.port'] = 61437; this.raasClient.createServerAsync(this.serverConfig).then(result => { console.log('SUCCESSFULLY created server !!!!'); console.log(result); this.created = true; }).catch(m => { console.log('ERROR creating server.'); console.log(m); this.created = false; }); } private listen(): void { const delegate = this.editor.delegate; delegate.onOptionChanged.on(data => {}); delegate.onOptionAdded.on(data => {}); delegate.onRaasClientChanged.on(data => { }); delegate.onConnectRaasClient.on(() => { console.log('controller received connectRaasClient'); this.connectRaasClient(); }); delegate.onDisconnectRaasClient.on(() => { if (this.raasClient) { this.editor.raasClientDisconnected(this.raasClient); } }); delegate.onStartAnalaysis.on(() => { this.onStartAnalysis(); }); delegate.onCancelAnalaysis.on(() => {}); delegate.onCliChanged.on(data => {}); delegate.onAddInstallation.on(data => {}); delegate.onJavaHomeChanged.on(data => {}); delegate.onDisposed.on(() => { this.raasClient.disconnect(); }); } }