Flat File Import says command not found on first run (#10081) (#10184)

* Changed the activation event from onCommand to startup "*"

* Refractored some code to fix the issue

* Made some PR related changes and fixed a condition where the same error was occurring when the flatFileImport has to download binaries from the internet.

* Reverted activation event back to previous state as it had no effect.

* Made changes mentioned in the PR

Co-authored-by: Aasim Shahnawaz Khan <aaskhan@microsoft.com>
This commit is contained in:
Aasim Khan
2020-04-28 18:15:20 -07:00
committed by GitHub
parent 793f189a83
commit 046995f2a5
3 changed files with 44 additions and 55 deletions

View File

@@ -25,17 +25,19 @@ export default class MainController extends ControllerBase {
public deactivate(): void { public deactivate(): void {
} }
public activate(): Promise<boolean> { public async activate(): Promise<boolean> {
const outputChannel = vscode.window.createOutputChannel(constants.serviceName); return new Promise<boolean>(async (resolve) => {
new ServiceClient(outputChannel).startService(this._context); const outputChannel = vscode.window.createOutputChannel(constants.serviceName);
managerInstance.onRegisteredApi<FlatFileProvider>(ApiType.FlatFileProvider)(provider => {
managerInstance.onRegisteredApi<FlatFileProvider>(ApiType.FlatFileProvider)(provider => { this.initializeFlatFileProvider(provider);
this.initializeFlatFileProvider(provider); resolve(true);
});
await new ServiceClient(outputChannel).startService(this._context);
}); });
return Promise.resolve(true);
} }
private initializeFlatFileProvider(provider: FlatFileProvider) { private initializeFlatFileProvider(provider: FlatFileProvider) {
azdata.tasks.registerTask('flatFileImport.start', (profile: azdata.IConnectionProfile, ...args: any[]) => new FlatFileWizard(provider).start(profile, args)); azdata.tasks.registerTask('flatFileImport.start', (profile: azdata.IConnectionProfile, ...args: any[]) => new FlatFileWizard(provider).start(profile, args));
} }

View File

@@ -10,24 +10,13 @@ import MainController from './controllers/mainController';
let controllers: ControllerBase[] = []; let controllers: ControllerBase[] = [];
export function activate(context: vscode.ExtensionContext) { export async function activate(context: vscode.ExtensionContext): Promise<boolean> {
let activations: Promise<boolean>[] = [];
// Start the main controller // Start the main controller
let mainController = new MainController(context); let mainController = new MainController(context);
controllers.push(mainController); controllers.push(mainController);
context.subscriptions.push(mainController); context.subscriptions.push(mainController);
activations.push(mainController.activate()); await mainController.activate();
return true;
return Promise.all(activations)
.then((results: boolean[]) => {
for (let result of results) {
if (!result) {
return false;
}
}
return true;
});
} }
export function deactivate() { export function deactivate() {

View File

@@ -30,45 +30,43 @@ export class ServiceClient {
config.installDirectory = path.join(context.extensionPath, config.installDirectory); config.installDirectory = path.join(context.extensionPath, config.installDirectory);
config.proxy = vscode.workspace.getConfiguration('http').get('proxy'); config.proxy = vscode.workspace.getConfiguration('http').get('proxy');
config.strictSSL = vscode.workspace.getConfiguration('http').get('proxyStrictSSL') || true; config.strictSSL = vscode.workspace.getConfiguration('http').get('proxyStrictSSL') || true;
const serverdownloader = new ServerProvider(config); const serverdownloader = new ServerProvider(config);
serverdownloader.eventEmitter.onAny(this.generateHandleServerProviderEvent()); serverdownloader.eventEmitter.onAny(this.generateHandleServerProviderEvent());
let clientOptions: ClientOptions = this.createClientOptions(); let clientOptions: ClientOptions = this.createClientOptions();
const installationStart = Date.now(); try {
let client: SqlOpsDataClient; const installationStart = Date.now();
return new Promise((resolve, reject) => { let client: SqlOpsDataClient;
serverdownloader.getOrDownloadServer().then(e => { let serviceBinaries = await serverdownloader.getOrDownloadServer();
const installationComplete = Date.now(); const installationComplete = Date.now();
let serverOptions = this.generateServerOptions(e, context); let serverOptions = this.generateServerOptions(serviceBinaries, context);
client = new SqlOpsDataClient(Constants.serviceName, serverOptions, clientOptions); client = new SqlOpsDataClient(Constants.serviceName, serverOptions, clientOptions);
const processStart = Date.now(); const processStart = Date.now();
client.onReady().then(() => { client.onReady().then(() => {
const processEnd = Date.now(); const processEnd = Date.now();
this.statusView.text = localize('serviceStarted', "{0} Started", Constants.serviceName); this.statusView.text = localize('serviceStarted', "{0} Started", Constants.serviceName);
setTimeout(() => { setTimeout(() => {
this.statusView.hide(); this.statusView.hide();
}, 1500); }, 1500);
Telemetry.sendTelemetryEvent('startup/LanguageClientStarted', { Telemetry.sendTelemetryEvent('startup/LanguageClientStarted', {
installationTime: String(installationComplete - installationStart), installationTime: String(installationComplete - installationStart),
processStartupTime: String(processEnd - processStart), processStartupTime: String(processEnd - processStart),
totalTime: String(processEnd - installationStart), totalTime: String(processEnd - installationStart),
beginningTimestamp: String(installationStart) beginningTimestamp: String(installationStart)
});
}); });
this.statusView.show();
this.statusView.text = localize('serviceStarting', "Starting {0}", Constants.serviceName);
let disposable = client.start();
context.subscriptions.push(disposable);
resolve(client);
}, e => {
Telemetry.sendTelemetryEvent('ServiceInitializingFailed');
vscode.window.showErrorMessage(localize('flatFileImport.serviceStartFailed', "Failed to start {0}: {1}", Constants.serviceName, e));
// Just resolve to avoid unhandled promise. We show the error to the user.
resolve(undefined);
}); });
}); this.statusView.show();
this.statusView.text = localize('serviceStarting', "Starting {0}", Constants.serviceName);
let disposable = client.start();
context.subscriptions.push(disposable);
return client;
}
catch (error) {
Telemetry.sendTelemetryEvent('ServiceInitializingFailed');
vscode.window.showErrorMessage(localize('flatFileImport.serviceStartFailed', "Failed to start {0}: {1}", Constants.serviceName, error));
// Just resolve to avoid unhandled promise. We show the error to the user.
return undefined;
}
} }
private createClientOptions(): ClientOptions { private createClientOptions(): ClientOptions {