mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-28 09:35:38 -05:00
No browser from common (#7178)
* no browser from common * clean up some imports
This commit is contained in:
197
src/sql/workbench/services/profiler/browser/interfaces.ts
Normal file
197
src/sql/workbench/services/profiler/browser/interfaces.ts
Normal file
@@ -0,0 +1,197 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { ProfilerInput } from 'sql/workbench/parts/profiler/browser/profilerInput';
|
||||
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import * as azdata from 'azdata';
|
||||
import { INewProfilerState } from 'sql/workbench/parts/profiler/common/profilerState';
|
||||
|
||||
const PROFILER_SERVICE_ID = 'profilerService';
|
||||
export const IProfilerService = createDecorator<IProfilerService>(PROFILER_SERVICE_ID);
|
||||
|
||||
export type ProfilerSessionID = string;
|
||||
|
||||
export const PROFILER_VIEW_TEMPLATE_SETTINGS = 'profiler.viewTemplates';
|
||||
export const PROFILER_SESSION_TEMPLATE_SETTINGS = 'profiler.sessionTemplates';
|
||||
export const PROFILER_FILTER_SETTINGS = 'profiler.filters';
|
||||
export const PROFILER_SETTINGS = 'profiler';
|
||||
|
||||
/**
|
||||
* A front end provider for a profiler session
|
||||
*/
|
||||
export interface IProfilerSession {
|
||||
/**
|
||||
* Called by the service when more rows are available to render
|
||||
*/
|
||||
onMoreRows(events: azdata.ProfilerSessionEvents);
|
||||
/**
|
||||
* Called by the service when the session is closed unexpectedly
|
||||
*/
|
||||
onSessionStopped(events: azdata.ProfilerSessionStoppedParams);
|
||||
/**
|
||||
* Called by the service when a new profiler session is created by the dialog
|
||||
*/
|
||||
onProfilerSessionCreated(events: azdata.ProfilerSessionCreatedParams);
|
||||
/**
|
||||
* Called by the service when the session state is changed
|
||||
*/
|
||||
onSessionStateChanged(newState: INewProfilerState);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Profiler Service that handles session communication between the backends and frontends
|
||||
*/
|
||||
export interface IProfilerService {
|
||||
_serviceBrand: any;
|
||||
/**
|
||||
* Registers a backend provider for profiler session. ex: mssql
|
||||
*/
|
||||
registerProvider(providerId: string, provider: azdata.ProfilerProvider): void;
|
||||
/**
|
||||
* Registers a session with the service that acts as the UI for a profiler session
|
||||
* @returns An unique id that should be used to make subsequent calls to this service
|
||||
*/
|
||||
registerSession(uri: string, connectionProfile: IConnectionProfile, session: IProfilerSession): Promise<ProfilerSessionID>;
|
||||
/**
|
||||
* Connects the session specified by the id
|
||||
*/
|
||||
connectSession(sessionId: ProfilerSessionID): Thenable<boolean>;
|
||||
/**
|
||||
* Disconnected the session specified by the id
|
||||
*/
|
||||
disconnectSession(sessionId: ProfilerSessionID): Thenable<boolean>;
|
||||
/**
|
||||
* Creates a new session using the given create statement and session name
|
||||
*/
|
||||
createSession(id: string, createStatement: string, template: azdata.ProfilerSessionTemplate): Thenable<boolean>;
|
||||
/**
|
||||
* Starts the session specified by the id
|
||||
*/
|
||||
startSession(sessionId: ProfilerSessionID, sessionName: string): Thenable<boolean>;
|
||||
/**
|
||||
* Pauses the session specified by the id
|
||||
*/
|
||||
pauseSession(sessionId: ProfilerSessionID): Thenable<boolean>;
|
||||
/**
|
||||
* Stops the session specified by the id
|
||||
*/
|
||||
stopSession(sessionId: ProfilerSessionID): Thenable<boolean>;
|
||||
/**
|
||||
* Gets a list of running XEvent sessions on the Profiler Session's target
|
||||
*/
|
||||
getXEventSessions(sessionId: ProfilerSessionID): Thenable<string[]>;
|
||||
/**
|
||||
* The method called by the service provider for when more rows are available to render
|
||||
*/
|
||||
onMoreRows(params: azdata.ProfilerSessionEvents): void;
|
||||
/**
|
||||
* The method called by the service provider for when more rows are available to render
|
||||
*/
|
||||
onSessionStopped(params: azdata.ProfilerSessionStoppedParams): void;
|
||||
/**
|
||||
* Called by the service when a new profiler session is created by the dialog
|
||||
*/
|
||||
onProfilerSessionCreated(events: azdata.ProfilerSessionCreatedParams);
|
||||
/**
|
||||
* Gets a list of the view templates that are specified in the settings
|
||||
* @param provider An optional string to limit the view templates to a specific provider
|
||||
* @returns An array of view templates that match the provider passed, if passed, and generic ones (no provider specified),
|
||||
* otherwise returns all view templates
|
||||
*/
|
||||
getViewTemplates(providerId?: string): Array<IProfilerViewTemplate>;
|
||||
/**
|
||||
* Gets a list of the session templates that are specified in the settings
|
||||
* @param provider An optional string to limit the session template to a specific
|
||||
* @returns An array of session templates that match the provider passed, if passed, and generic ones (no provider specified),
|
||||
* otherwise returns all session templates
|
||||
*/
|
||||
getSessionTemplates(providerId?: string): Array<IProfilerSessionTemplate>;
|
||||
/**
|
||||
* Gets the session view state
|
||||
* @param sessionId The session ID to get the view state for
|
||||
* @returns Sessions view state
|
||||
*/
|
||||
getSessionViewState(sessionId: string): any;
|
||||
/**
|
||||
* Launches the dialog for editing the view columns of a profiler session template for the given input
|
||||
* @param input input object that contains the necessary information which will be modified based on used input
|
||||
*/
|
||||
launchColumnEditor(input: ProfilerInput): Thenable<void>;
|
||||
/**
|
||||
* Launches the dialog for creating a new XEvent session from a template
|
||||
* @param input input object that contains the necessary information which will be modified based on used input
|
||||
*/
|
||||
launchCreateSessionDialog(input: ProfilerInput): Thenable<void>;
|
||||
/**
|
||||
* Launches the dialog for collecting the filter object
|
||||
* @param input input object
|
||||
*/
|
||||
launchFilterSessionDialog(input: ProfilerInput): void;
|
||||
/**
|
||||
* Gets the filters
|
||||
*/
|
||||
getFilters(): Array<ProfilerFilter>;
|
||||
/**
|
||||
* Saves the filter
|
||||
* @param filter filter object
|
||||
*/
|
||||
saveFilter(filter: ProfilerFilter): void;
|
||||
}
|
||||
|
||||
export interface IProfilerSettings {
|
||||
viewTemplates: Array<IProfilerViewTemplate>;
|
||||
sessionTemplates: Array<IProfilerSessionTemplate>;
|
||||
filters: Array<ProfilerFilter>;
|
||||
}
|
||||
|
||||
export interface IColumnViewTemplate {
|
||||
name: string;
|
||||
eventsMapped: Array<string>;
|
||||
}
|
||||
|
||||
export interface IProfilerViewTemplate {
|
||||
name: string;
|
||||
columns: Array<IColumnViewTemplate>;
|
||||
}
|
||||
|
||||
export enum EngineType {
|
||||
AzureSQLDB = 'AzureSQLDB',
|
||||
Standalone = 'Standalone'
|
||||
}
|
||||
|
||||
export interface IProfilerSessionTemplate {
|
||||
name: string;
|
||||
engineTypes?: EngineType[];
|
||||
defaultView: string;
|
||||
createStatement: string;
|
||||
}
|
||||
|
||||
export interface ProfilerFilter {
|
||||
name?: string;
|
||||
clauses: ProfilerFilterClause[];
|
||||
}
|
||||
|
||||
export interface ProfilerFilterClause {
|
||||
field: string;
|
||||
operator: ProfilerFilterClauseOperator;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export enum ProfilerFilterClauseOperator {
|
||||
Equals,
|
||||
NotEquals,
|
||||
LessThan,
|
||||
LessThanOrEquals,
|
||||
GreaterThan,
|
||||
GreaterThanOrEquals,
|
||||
IsNull,
|
||||
IsNotNull,
|
||||
Contains,
|
||||
NotContains,
|
||||
StartsWith,
|
||||
NotStartsWith
|
||||
}
|
||||
103
src/sql/workbench/services/profiler/browser/profilerFilter.ts
Normal file
103
src/sql/workbench/services/profiler/browser/profilerFilter.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ProfilerFilterClause, ProfilerFilter, ProfilerFilterClauseOperator } from 'sql/workbench/services/profiler/browser/interfaces';
|
||||
|
||||
|
||||
export function FilterData(filter: ProfilerFilter, data: any[]): any[] {
|
||||
if (!data || !filter) {
|
||||
return data;
|
||||
}
|
||||
return data.filter(item => matches(item, filter.clauses));
|
||||
}
|
||||
|
||||
function matches(item: any, clauses: ProfilerFilterClause[]): boolean {
|
||||
let match = true;
|
||||
if (!item) {
|
||||
match = false;
|
||||
} else if (clauses) {
|
||||
for (let i = 0; i < clauses.length; i++) {
|
||||
let clause = clauses[i];
|
||||
if (!!clause && !!clause.field) {
|
||||
let actualValue: any = item[clause.field];
|
||||
let expectedValue: any = clause.value;
|
||||
let actualValueString: string = actualValue === undefined ? undefined : actualValue.toLocaleLowerCase();
|
||||
let expectedValueString: string = expectedValue === undefined ? undefined : expectedValue.toLocaleLowerCase();
|
||||
let actualValueDate = new Date(actualValue).valueOf();
|
||||
let expectedValueDate = new Date(expectedValue).valueOf();
|
||||
let actualValueNumber = Number(actualValue).valueOf();
|
||||
let expectedValueNumber = Number(expectedValue).valueOf();
|
||||
|
||||
if (isValidNumber(actualValue) && isValidNumber(expectedValue)) {
|
||||
actualValue = actualValueNumber;
|
||||
expectedValue = expectedValueNumber;
|
||||
} else if (isValidDate(actualValue) && isValidDate(expectedValue)) {
|
||||
actualValue = actualValueDate;
|
||||
expectedValue = expectedValueDate;
|
||||
} else {
|
||||
actualValue = actualValueString;
|
||||
expectedValue = expectedValueString;
|
||||
}
|
||||
|
||||
switch (clause.operator) {
|
||||
case ProfilerFilterClauseOperator.Equals:
|
||||
match = actualValue === expectedValue;
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.NotEquals:
|
||||
match = actualValue !== expectedValue;
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.LessThan:
|
||||
match = actualValue < expectedValue;
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.LessThanOrEquals:
|
||||
match = actualValue <= expectedValue;
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.GreaterThan:
|
||||
match = actualValue > expectedValue;
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.GreaterThanOrEquals:
|
||||
match = actualValue >= expectedValue;
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.IsNull:
|
||||
match = actualValue === undefined || actualValue === null || actualValue === '';
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.IsNotNull:
|
||||
match = actualValue !== undefined && actualValue !== null && actualValue !== '';
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.Contains:
|
||||
match = actualValueString && actualValueString.includes(expectedValueString);
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.NotContains:
|
||||
match = !actualValueString || !actualValueString.includes(expectedValueString);
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.StartsWith:
|
||||
match = actualValueString.startsWith(expectedValueString);
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.NotStartsWith:
|
||||
match = !actualValueString || !actualValueString.startsWith(expectedValueString);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Not a valid operator: ${clause.operator}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (!match) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
function isValidNumber(value: string): boolean {
|
||||
let num = Number(value);
|
||||
return value !== undefined && !isNaN(num.valueOf()) && value.replace(' ', '') !== '';
|
||||
}
|
||||
|
||||
function isValidDate(value: string): boolean {
|
||||
let date = new Date(value);
|
||||
return value !== undefined && !isNaN(date.valueOf());
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IConnectionManagementService, IConnectionCompletionOptions, ConnectionType, RunQueryOnConnectionMode } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { ProfilerSessionID, IProfilerSession, IProfilerService, IProfilerViewTemplate, IProfilerSessionTemplate, PROFILER_SETTINGS, IProfilerSettings, EngineType, ProfilerFilter, PROFILER_FILTER_SETTINGS } from '../common/interfaces';
|
||||
import { ProfilerSessionID, IProfilerSession, IProfilerService, IProfilerViewTemplate, IProfilerSessionTemplate, PROFILER_SETTINGS, IProfilerSettings, EngineType, ProfilerFilter, PROFILER_FILTER_SETTINGS } from './interfaces';
|
||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { ProfilerInput } from 'sql/workbench/parts/profiler/browser/profilerInput';
|
||||
import { ProfilerColumnEditorDialog } from 'sql/workbench/parts/profiler/browser/profilerColumnEditorDialog';
|
||||
|
||||
Reference in New Issue
Block a user