Refresh master with initial release/0.24 snapshot (#332)

* Initial port of release/0.24 source code

* Fix additional headers

* Fix a typo in launch.json
This commit is contained in:
Karl Burtram
2017-12-15 15:38:57 -08:00
committed by GitHub
parent 271b3a0b82
commit 6ad0df0e3e
7118 changed files with 107999 additions and 56466 deletions

View File

@@ -9,17 +9,19 @@ import * as data from 'data';
import * as nls from 'vs/nls';
import * as platform from 'vs/platform/registry/common/platform';
import * as statusbar from 'vs/workbench/browser/parts/statusbar/statusbar';
import AccountStore from 'sql/services/accountManagement/accountStore';
import Event, { Emitter } from 'vs/base/common/event';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { Memento, Scope as MementoScope } from 'vs/workbench/common/memento';
import { ISqlOAuthService } from 'sql/common/sqlOAuthService';
import AccountStore from 'sql/services/accountManagement/accountStore';
import { AccountDialogController } from 'sql/parts/accountManagement/accountDialog/accountDialogController';
import { AutoOAuthDialogController } from 'sql/parts/accountManagement/autoOAuthDialog/autoOAuthDialogController';
import { AccountListStatusbarItem } from 'sql/parts/accountManagement/accountListStatusbar/accountListStatusbarItem';
import { AccountProviderAddedEventParams, UpdateAccountListEventParams } from 'sql/services/accountManagement/eventTypes';
import { IAccountManagementService } from 'sql/services/accountManagement/interfaces';
import { warn } from 'sql/base/common/log';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
export class AccountManagementService implements IAccountManagementService {
// CONSTANTS ///////////////////////////////////////////////////////////
@@ -30,9 +32,8 @@ export class AccountManagementService implements IAccountManagementService {
public _serviceBrand: any;
private _accountStore: AccountStore;
private _accountDialogController: AccountDialogController;
private _autoOAuthDialogController: AutoOAuthDialogController;
private _mementoContext: Memento;
private _oAuthCallbacks: { [eventId: string]: { resolve, reject } } = {};
private _oAuthEventId: number = 0;
// EVENT EMITTERS //////////////////////////////////////////////////////
private _addAccountProviderEmitter: Emitter<AccountProviderAddedEventParams>;
@@ -49,10 +50,8 @@ export class AccountManagementService implements IAccountManagementService {
private _mementoObj: object,
@IInstantiationService private _instantiationService: IInstantiationService,
@IStorageService private _storageService: IStorageService,
@ISqlOAuthService private _oAuthService: ISqlOAuthService
@IClipboardService private _clipboardService: IClipboardService,
) {
let self = this;
// Create the account store
if (!this._mementoObj) {
this._mementoContext = new Memento(AccountManagementService.ACCOUNT_MEMENTO);
@@ -66,33 +65,101 @@ export class AccountManagementService implements IAccountManagementService {
this._updateAccountListEmitter = new Emitter<UpdateAccountListEventParams>();
// Register status bar item
// FEATURE FLAG TOGGLE
if (process.env['VSCODE_DEV']) {
let statusbarDescriptor = new statusbar.StatusbarItemDescriptor(
AccountListStatusbarItem,
statusbar.StatusbarAlignment.LEFT,
15000 /* Highest Priority */
);
(<statusbar.IStatusbarRegistry>platform.Registry.as(statusbar.Extensions.Statusbar)).registerStatusbarItem(statusbarDescriptor);
}
let statusbarDescriptor = new statusbar.StatusbarItemDescriptor(
AccountListStatusbarItem,
statusbar.StatusbarAlignment.LEFT,
15000 /* Highest Priority */
);
(<statusbar.IStatusbarRegistry>platform.Registry.as(statusbar.Extensions.Statusbar)).registerStatusbarItem(statusbarDescriptor);
}
// Register event handler for OAuth completion
this._oAuthService.registerOAuthCallback((event, args) => {
self.onOAuthResponse(args);
});
private get autoOAuthDialogController(): AutoOAuthDialogController {
// If the add account dialog hasn't been defined, create a new one
if (!this._autoOAuthDialogController) {
this._autoOAuthDialogController = this._instantiationService.createInstance(AutoOAuthDialogController);
}
return this._autoOAuthDialogController;
}
// PUBLIC METHODS //////////////////////////////////////////////////////
/**
* Called from an account provider (via extension host -> main thread interop) when an
* account's properties have been updated (usually when the account goes stale).
* @param {Account} updatedAccount Account with the updated properties
*/
public accountUpdated(updatedAccount: data.Account): Thenable<void> {
let self = this;
// 1) Update the account in the store
// 2a) If the account was added, then the account provider incorrectly called this method.
// Remove the account
// 2b) If the account was modified, then update it in the local cache and notify any
// listeners that the account provider's list changed
// 3) Handle any errors
return this.doWithProvider(updatedAccount.key.providerId, provider => {
return self._accountStore.addOrUpdate(updatedAccount)
.then(result => {
if (result.accountAdded) {
self._accountStore.remove(updatedAccount.key);
return Promise.reject('Called with a new account!');
}
if (result.accountModified) {
self.spliceModifiedAccount(provider, result.changedAccount);
self.fireAccountListUpdate(provider, false);
}
return Promise.resolve();
});
}).then(
() => { },
reason => {
console.warn(`Account update handler encountered error: ${reason}`);
}
);
}
/**
* Asks the requested provider to prompt for an account
* @param {string} providerId ID of the provider to ask to prompt for an account
* @return {Thenable<Account>} Promise to return an account
*/
public addAccount(providerId: string): Thenable<data.Account> {
public addAccount(providerId: string): Thenable<void> {
let self = this;
return this.doWithProvider(providerId, (provider) => {
return provider.provider.prompt()
.then(account => self._accountStore.addOrUpdate(account))
.then(result => {
if (result.accountAdded) {
// Add the account to the list
provider.accounts.push(result.changedAccount);
}
if (result.accountModified) {
self.spliceModifiedAccount(provider, result.changedAccount);
}
self.fireAccountListUpdate(provider, result.accountAdded);
})
.then(null, err => {
// On error, check to see if the error is because the user cancelled. If so, just ignore
if ('userCancelledSignIn' in err) {
return Promise.resolve();
}
return Promise.reject(err);
});
});
}
/**
* Asks the requested provider to refresh an account
* @param {Account} account account to refresh
* @return {Thenable<Account>} Promise to return an account
*/
public refreshAccount(account: data.Account): Thenable<data.Account> {
let self = this;
return this.doWithProvider(account.key.providerId, (provider) => {
return provider.provider.refresh(account)
.then(account => self._accountStore.addOrUpdate(account))
.then(result => {
if (result.accountAdded) {
@@ -211,32 +278,51 @@ export class AccountManagementService implements IAccountManagementService {
self._accountDialogController.openAccountDialog();
resolve();
} catch(e) {
} catch (e) {
reject(e);
}
});
}
/**
* Opens a browser window to perform the OAuth authentication
* @param {string} url URL to visit that will perform the OAuth authentication
* @param {boolean} silent Whether or not to perform authentication silently using browser's cookies
* @return {Thenable<string>} Promise to return a authentication token on successful authentication
* Begin auto OAuth device code open add account dialog
* @return {TPromise<any>} Promise that finishes when the account list dialog opens
*/
public performOAuthAuthorization(url: string, silent: boolean): Thenable<string> {
public beginAutoOAuthDeviceCode(providerId: string, title: string, message: string, userCode: string, uri: string): Thenable<void> {
let self = this;
return new Promise<string>((resolve, reject) => {
// TODO: replace with uniqid
let eventId: string = `oauthEvent${self._oAuthEventId++}`;
self._oAuthCallbacks[eventId] = {
resolve: resolve,
reject: reject
};
self._oAuthService.performOAuthAuthorization(eventId, url, silent);
return this.doWithProvider(providerId, provider => {
return self.autoOAuthDialogController.openAutoOAuthDialog(providerId, title, message, userCode, uri);
});
}
/**
* End auto OAuth Devide code closes add account dialog
*/
public endAutoOAuthDeviceCode(): void {
this.autoOAuthDialogController.closeAutoOAuthDialog();
}
/**
* Called from the UI when a user cancels the auto OAuth dialog
*/
public cancelAutoOAuthDeviceCode(providerId: string): void {
this.doWithProvider(providerId, provider => provider.provider.autoOAuthCancelled())
.then( // Swallow errors
null,
err => { console.warn(`Error when cancelling auto OAuth: ${err}`); }
)
.then(() => this.autoOAuthDialogController.closeAutoOAuthDialog());
}
/**
* Copy the user code to the clipboard and open a browser to the verification URI
*/
public copyUserCodeAndOpenBrowser(userCode: string, uri: string): void {
this._clipboardService.writeText(userCode);
window.open(uri);
}
// SERVICE MANAGEMENT METHODS //////////////////////////////////////////
/**
* Called by main thread to register an account provider from extension
@@ -333,28 +419,13 @@ export class AccountManagementService implements IAccountManagementService {
this._updateAccountListEmitter.fire(eventArg);
}
private onOAuthResponse(args: object): void {
// Verify the arguments are correct
if (!args || args['eventId'] === undefined) {
warn('Received invalid OAuth event response args');
return;
}
// Find the event
let eventId: string = args['eventId'];
let eventCallbacks = this._oAuthCallbacks[eventId];
if (!eventCallbacks) {
warn('Received OAuth event response for non-existent eventId');
return;
}
// Parse the args
let error: string = args['error'];
let code: string = args['code'];
if (error) {
eventCallbacks.reject(error);
} else {
eventCallbacks.resolve(code);
private spliceModifiedAccount(provider: AccountProviderWithMetadata, modifiedAccount: data.Account) {
// Find the updated account and splice the updated one in
let indexToRemove: number = provider.accounts.findIndex(account => {
return account.key.accountId === modifiedAccount.key.accountId;
});
if (indexToRemove >= 0) {
provider.accounts.splice(indexToRemove, 1, modifiedAccount);
}
}
}

View File

@@ -7,7 +7,7 @@
import * as data from 'data';
import Event from 'vs/base/common/event';
import { AccountAdditionResult, AccountProviderAddedEventParams, UpdateAccountListEventParams } from 'sql/services/accountManagement/eventTypes';
import { AccountAdditionResult, AccountProviderAddedEventParams, UpdateAccountListEventParams } from 'sql/services/accountManagement/eventTypes';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
export const SERVICE_ID = 'accountManagementService';
@@ -18,15 +18,20 @@ export interface IAccountManagementService {
_serviceBrand: any;
// ACCOUNT MANAGEMENT METHODS //////////////////////////////////////////
addAccount(providerId: string): Thenable<data.Account>;
accountUpdated(account: data.Account): Thenable<void>;
addAccount(providerId: string): Thenable<void>;
getAccountProviderMetadata(): Thenable<data.AccountProviderMetadata[]>;
getAccountsForProvider(providerId: string): Thenable<data.Account[]>;
getSecurityToken(account: data.Account): Thenable<{}>;
removeAccount(accountKey: data.AccountKey): Thenable<boolean>;
refreshAccount(account: data.Account): Thenable<data.Account>;
// UI METHODS //////////////////////////////////////////////////////////
openAccountListDialog(): Thenable<void>;
performOAuthAuthorization(url: string, silent: boolean): Thenable<string>;
beginAutoOAuthDeviceCode(providerId: string, title: string, message: string, userCode: string, uri: string): Thenable<void>;
endAutoOAuthDeviceCode(): void;
cancelAutoOAuthDeviceCode(providerId: string): void;
copyUserCodeAndOpenBrowser(userCode: string, uri: string): void;
// SERVICE MANAGEMENT METHODS /////////////////////////////////////////
registerProvider(providerMetadata: data.AccountProviderMetadata, provider: data.AccountProvider): void;

View File

@@ -13,7 +13,17 @@ export const IAngularEventingService = createDecorator<IAngularEventingService>(
export enum AngularEventType {
NAV_DATABASE,
NAV_SERVER
NAV_SERVER,
DELETE_WIDGET
}
export interface IDeleteWidgetPayload {
id: string;
}
export interface IAngularEvent {
event: AngularEventType;
payload: any;
}
export interface IAngularEventingService {
@@ -24,24 +34,24 @@ export interface IAngularEventingService {
* @param cb Listening function
* @returns
*/
onAngularEvent(uri: string, cb: (event: AngularEventType) => void): Subscription;
onAngularEvent(uri: string, cb: (event: IAngularEvent) => void): Subscription;
/**
* Send an event to the dashboard; no op if the dashboard has not started listening yet
* @param uri Uri of the dashboard to send the event to
* @param event event to send
*/
sendAngularEvent(uri: string, event: AngularEventType): void;
sendAngularEvent(uri: string, event: AngularEventType, payload?: any): void;
}
export class AngularEventingService implements IAngularEventingService {
public _serviceBrand: any;
private _angularMap = new Map<string, Subject<AngularEventType>>();
private _angularMap = new Map<string, Subject<IAngularEvent>>();
public onAngularEvent(uri: string, cb: (event: AngularEventType) => void): Subscription {
let subject: Subject<AngularEventType>;
public onAngularEvent(uri: string, cb: (event: IAngularEvent) => void): Subscription {
let subject: Subject<IAngularEvent>;
if (!this._angularMap.has(uri)) {
subject = new Subject<AngularEventType>();
subject = new Subject<IAngularEvent>();
this._angularMap.set(uri, subject);
} else {
subject = this._angularMap.get(uri);
@@ -50,11 +60,11 @@ export class AngularEventingService implements IAngularEventingService {
return sub;
}
public sendAngularEvent(uri: string, event: AngularEventType): void {
public sendAngularEvent(uri: string, event: AngularEventType, payload?: any): void {
if (!this._angularMap.has(uri)) {
warn('Got request to send an event to a dashboard that has not started listening');
} else {
this._angularMap.get(uri).next(event);
this._angularMap.get(uri).next({ event, payload });
}
}
}

View File

@@ -37,6 +37,7 @@ import { IAccountManagementService } from 'sql/services/accountManagement/interf
import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { ConfigurationEditingService } from 'vs/workbench/services/configuration/node/configurationEditingService';
export const BOOTSTRAP_SERVICE_ID = 'bootstrapService';
export const IBootstrapService = createDecorator<IBootstrapService>(BOOTSTRAP_SERVICE_ID);
@@ -84,6 +85,7 @@ export interface IBootstrapService {
storageService: IStorageService;
clipboardService: IClipboardService;
capabilitiesService: ICapabilitiesService;
configurationEditorService: ConfigurationEditingService;
/*
* Bootstraps the Angular module described. Components that need singleton services should inject the

View File

@@ -41,6 +41,7 @@ import { IAccountManagementService } from 'sql/services/accountManagement/interf
import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { ConfigurationEditingService } from 'vs/workbench/services/configuration/node/configurationEditingService';
export class BootstrapService implements IBootstrapService {
@@ -55,6 +56,8 @@ export class BootstrapService implements IBootstrapService {
// Maps selectors (as opposed to uniqueSelectors) to the next available uniqueSelector ID number
private _selectorCountMap: Map<string, number>;
public configurationEditorService: ConfigurationEditingService;
constructor(
@IConnectionManagementService public connectionManagementService: IConnectionManagementService,
@IMetadataService public metadataService: IMetadataService,
@@ -93,6 +96,7 @@ export class BootstrapService implements IBootstrapService {
@IClipboardService public clipboardService: IClipboardService,
@ICapabilitiesService public capabilitiesService: ICapabilitiesService
) {
this.configurationEditorService = this.instantiationService.createInstance(ConfigurationEditingService);
this._bootstrapParameterMap = new Map<string, BootstrapParams>();
this._selectorQueueMap = new Map<string, string[]>();
this._selectorCountMap = new Map<string, number>();

View File

@@ -11,8 +11,10 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import data = require('data');
import Event, { Emitter } from 'vs/base/common/event';
import { Action } from 'vs/base/common/actions';
import { IAction } from 'vs/base/common/actions';
import { Deferred } from 'sql/base/common/promise';
import { getGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { IExtensionManagementService, ILocalExtension, IExtensionEnablementService, LocalExtensionType } from 'vs/platform/extensionManagement/common/extensionManagement';
export const SERVICE_ID = 'capabilitiesService';
export const HOST_NAME = 'sqlops';
@@ -39,7 +41,7 @@ export interface ICapabilitiesService {
/**
* Returns true if the feature is available for given connection
*/
isFeatureAvailable(action: Action, connectionManagementInfo: ConnectionManagementInfo): boolean;
isFeatureAvailable(action: IAction, connectionManagementInfo: ConnectionManagementInfo): boolean;
/**
* Event raised when a provider is registered
@@ -61,6 +63,8 @@ export class CapabilitiesService implements ICapabilitiesService {
public _serviceBrand: any;
private static DATA_PROVIDER_CATEGORY: string = 'Data Provider'
private _providers: data.CapabilitiesProvider[] = [];
private _capabilities: data.DataProtocolServerCapabilities[] = [];
@@ -77,16 +81,36 @@ export class CapabilitiesService implements ICapabilitiesService {
private _onCapabilitiesReady: Deferred<void>;
// Due to absence of a way to infer the number of expected data tools extensions from the package.json, this is being hard-coded
// TODO: a better mechanism to populate the expected number of capabilities
// Setting this to 1 by default as we have MS SQL provider by default and then we increament
// this number based on extensions installed.
// TODO once we have a complete extension story this might change and will have to be looked into
private _expectedCapabilitiesCount: number = 1;
private _registeredCapabilities: number = 0;
constructor() {
constructor(@IExtensionManagementService private extensionManagementService: IExtensionManagementService,
@IExtensionEnablementService private extensionEnablementService: IExtensionEnablementService) {
this._onProviderRegistered = new Emitter<data.DataProtocolServerCapabilities>();
this.disposables.push(this._onProviderRegistered);
this._onCapabilitiesReady = new Deferred();
// Get extensions and filter where the category has 'Data Provider' in it
this.extensionManagementService.getInstalled(LocalExtensionType.User).then((extensions: ILocalExtension[]) => {
let dataProviderExtensions = extensions.filter(extension =>
extension.manifest.categories.indexOf(CapabilitiesService.DATA_PROVIDER_CATEGORY) > -1)
if(dataProviderExtensions.length > 0) {
// Scrape out disabled extensions
const disabledExtensions = this.extensionEnablementService.getGloballyDisabledExtensions()
.map(disabledExtension => disabledExtension.id);
dataProviderExtensions = dataProviderExtensions.filter(extension =>
disabledExtensions.indexOf(getGalleryExtensionId(extension.manifest.publisher, extension.manifest.name)) < 0)
}
this._expectedCapabilitiesCount += dataProviderExtensions.length;
});
}
public onCapabilitiesReady(): Promise<void> {
@@ -127,7 +151,7 @@ export class CapabilitiesService implements ICapabilitiesService {
* @param featureComponent a component which should have the feature name
* @param connectionManagementInfo connectionManagementInfo
*/
public isFeatureAvailable(action: Action, connectionManagementInfo: ConnectionManagementInfo): boolean {
public isFeatureAvailable(action: IAction, connectionManagementInfo: ConnectionManagementInfo): boolean {
let isCloud = connectionManagementInfo && connectionManagementInfo.serverInfo && connectionManagementInfo.serverInfo.isCloud;
let isMssql = connectionManagementInfo.connectionProfile.providerName === 'MSSQL';
// TODO: The logic should from capabilities service.

View File

@@ -60,16 +60,7 @@ export class ScriptingService implements IScriptingService {
if (providerId) {
let provider = this._providers[providerId];
if (provider) {
switch (operation) {
case (ScriptOperation.Select):
return provider.scriptAsSelect(connectionUri, metadata, paramDetails);
case (ScriptOperation.Create):
return provider.scriptAsCreate(connectionUri, metadata, paramDetails);
case (ScriptOperation.Delete):
return provider.scriptAsDelete(connectionUri, metadata, paramDetails);
default:
return Promise.resolve(undefined);
}
return provider.scriptAsOperation(connectionUri, operation, metadata, paramDetails)
}
}
return Promise.resolve(undefined);