SQL Operations Studio Public Preview 1 (0.23) release source code

This commit is contained in:
Karl Burtram
2017-11-09 14:30:27 -08:00
parent b88ecb8d93
commit 3cdac41339
8829 changed files with 759707 additions and 286 deletions

View File

@@ -0,0 +1,81 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import nls = require('vs/nls');
import { TPromise } from 'vs/base/common/winjs.base';
import Severity from 'vs/base/common/severity';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { Action } from 'vs/base/common/actions';
export interface IMessageWithAction {
message: string;
actions: Action[];
source?: string;
}
export interface IConfirmation {
title?: string;
type?: 'none' | 'info' | 'error' | 'question' | 'warning';
message: string;
detail?: string;
primaryButton?: string;
secondaryButton?: string;
}
export const CloseAction = new Action('close.message', nls.localize('close', "Close"), null, true, () => TPromise.as(true));
export const LaterAction = new Action('later.message', nls.localize('later', "Later"), null, true, () => TPromise.as(true));
export const CancelAction = new Action('cancel.message', nls.localize('cancel', "Cancel"), null, true, () => TPromise.as(true));
export const IMessageService = createDecorator<IMessageService>('messageService');
export interface IMessageService {
_serviceBrand: any;
/**
* Tells the service to show a message with a given severity
* the returned function can be used to hide the message again
*/
show(sev: Severity, message: string): () => void;
show(sev: Severity, message: Error): () => void;
show(sev: Severity, message: string[]): () => void;
show(sev: Severity, message: Error[]): () => void;
show(sev: Severity, message: IMessageWithAction): () => void;
/**
* Hide any messages showing currently.
*/
hideAll(): void;
/**
* Ask the user for confirmation.
*/
confirm(confirmation: IConfirmation): boolean;
}
export const IChoiceService = createDecorator<IChoiceService>('choiceService');
export interface IChoiceService {
_serviceBrand: any;
/**
* Prompt the user for a choice between multiple options.
*
* @param when `modal` is true, this will block the user until chooses.
*
* @returns A promise with the selected choice index. The promise is cancellable
* which hides the message. The promise can return an error, meaning that
* the user refused to choose.
*
* When `modal` is true and user refused to choose, then promise with index of
* `Cancel` option is returned. If there is no such option then promise with
* `0` index is returned.
*/
choose(severity: Severity, message: string, options: string[], cancelId: number, modal?: boolean): TPromise<number>;
}
export import Severity = Severity;

View File

@@ -0,0 +1,39 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
import { IChoiceService, Severity } from 'vs/platform/message/common/message';
export interface IChoiceChannel extends IChannel {
call(command: 'choose'): TPromise<number>;
call(command: string, arg?: any): TPromise<any>;
}
export class ChoiceChannel implements IChoiceChannel {
constructor( @IChoiceService private choiceService: IChoiceService) {
}
call(command: string, args?: [Severity, string, string[], number, boolean]): TPromise<any> {
switch (command) {
case 'choose': return this.choiceService.choose(args[0], args[1], args[2], args[3], args[4]);
}
return TPromise.wrapError(new Error('invalid command'));
}
}
export class ChoiceChannelClient implements IChoiceService {
_serviceBrand: any;
constructor(private channel: IChoiceChannel) { }
choose(severity: Severity, message: string, options: string[], cancelId: number, modal?: boolean): TPromise<number> {
return this.channel.call('choose', [severity, message, options, cancelId, modal]);
}
}

View File

@@ -0,0 +1,57 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as readline from 'readline';
import { TPromise } from 'vs/base/common/winjs.base';
import { IChoiceService, Severity } from 'vs/platform/message/common/message';
export class ChoiceCliService implements IChoiceService {
_serviceBrand: any;
choose(severity: Severity, message: string, options: string[], cancelId: number): TPromise<number> {
const promise = new TPromise<number>((c, e) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: true
});
rl.prompt();
rl.write(this.toQuestion(message, options));
rl.prompt();
rl.once('line', (answer) => {
rl.close();
c(this.toOption(answer, options));
});
rl.once('SIGINT', () => {
rl.close();
promise.cancel();
});
});
return promise;
}
private toQuestion(message: string, options: string[]): string {
return options.reduce((previousValue: string, currentValue: string, currentIndex: number) => {
return previousValue + currentValue + '(' + currentIndex + ')' + (currentIndex < options.length - 1 ? ' | ' : '\n');
}, message + ' ');
}
private toOption(answer: string, options: string[]): number {
const value = parseInt(answer);
if (!isNaN(value)) {
return value;
}
answer = answer.toLocaleLowerCase();
for (let i = 0; i < options.length; i++) {
if (options[i].toLocaleLowerCase() === answer) {
return i;
}
}
return -1;
}
}