mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-14 01:25:37 -05:00
* Add limit on the file size that can be opened with Open XEL feature * Add limit on the file size that can be opened and post a notification for large files * Update wording * Use FileService interface instead of fs to fix layering rules
This commit is contained in:
@@ -19,6 +19,7 @@ import { IConnectionDialogService } from 'sql/workbench/services/connection/comm
|
||||
import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/browser/objectExplorerService';
|
||||
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
|
||||
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
|
||||
import { IFileService } from 'vs/platform/files/common/files';
|
||||
|
||||
CommandsRegistry.registerCommand({
|
||||
id: 'profiler.newProfiler',
|
||||
@@ -107,9 +108,10 @@ CommandsRegistry.registerCommand({
|
||||
const editorService: IEditorService = accessor.get(IEditorService);
|
||||
const fileDialogService: IFileDialogService = accessor.get(IFileDialogService);
|
||||
const profilerService: IProfilerService = accessor.get(IProfilerService);
|
||||
const instantiationService: IInstantiationService = accessor.get(IInstantiationService)
|
||||
const instantiationService: IInstantiationService = accessor.get(IInstantiationService);
|
||||
const fileService: IFileService = accessor.get(IFileService);
|
||||
|
||||
const result = await profilerService.openFile(fileDialogService, editorService, instantiationService);
|
||||
const result = await profilerService.openFile(fileDialogService, editorService, instantiationService, fileService);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import * as azdata from 'azdata';
|
||||
import { INewProfilerState } from 'sql/workbench/common/editor/profiler/profilerState';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
|
||||
import { IFileService } from 'vs/platform/files/common/files';
|
||||
|
||||
const PROFILER_SERVICE_ID = 'profilerService';
|
||||
export const IProfilerService = createDecorator<IProfilerService>(PROFILER_SERVICE_ID);
|
||||
@@ -148,7 +149,7 @@ export interface IProfilerService {
|
||||
* @param editorService service to open profiler editor
|
||||
* @param instantiationService service to create profiler instance
|
||||
*/
|
||||
openFile(fileDialogService: IFileDialogService, editorService: IEditorService, instantiationService: IInstantiationService): Promise<boolean>;
|
||||
openFile(fileDialogService: IFileDialogService, editorService: IEditorService, instantiationService: IInstantiationService, fileService: IFileService): Promise<boolean>;
|
||||
}
|
||||
|
||||
export enum ProfilingSessionType {
|
||||
|
||||
@@ -22,6 +22,7 @@ import { ProfilerFilterDialog } from 'sql/workbench/services/profiler/browser/pr
|
||||
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
|
||||
import { ACTIVE_GROUP, IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
|
||||
import { ByteSize, IFileService } from 'vs/platform/files/common/files';
|
||||
|
||||
class TwoWayMap<T, K> {
|
||||
private forwardMap: Map<T, K>;
|
||||
@@ -303,7 +304,7 @@ export class ProfilerService implements IProfilerService {
|
||||
await this._configurationService.updateValue(PROFILER_FILTER_SETTINGS, config, ConfigurationTarget.USER);
|
||||
}
|
||||
|
||||
public async openFile(fileDialogService: IFileDialogService, editorService: IEditorService, instantiationService: IInstantiationService): Promise<boolean> {
|
||||
public async openFile(fileDialogService: IFileDialogService, editorService: IEditorService, instantiationService: IInstantiationService, fileService: IFileService): Promise<boolean> {
|
||||
const fileURIs = await fileDialogService.showOpenDialog({
|
||||
filters: [
|
||||
{
|
||||
@@ -317,6 +318,21 @@ export class ProfilerService implements IProfilerService {
|
||||
if (fileURIs?.length === 1) {
|
||||
const fileURI = fileURIs[0];
|
||||
|
||||
try {
|
||||
const fileSize = (await fileService.stat(fileURI)).size;
|
||||
const fileLimitSize = 1 * ByteSize.GB;
|
||||
const fileOpenWarningSize = 100 * ByteSize.MB;
|
||||
|
||||
if (fileSize > fileLimitSize) {
|
||||
this._notificationService.error(nls.localize('FileTooLarge', "The file is too large to open in profiler. The profiler can open files that are less than 1GB."));
|
||||
return false;
|
||||
} else if (fileSize > fileOpenWarningSize) {
|
||||
this._notificationService.info(nls.localize('LargeFileWait', "Loading the file might take a moment due to the file size."));
|
||||
}
|
||||
} catch (err) {
|
||||
this._notificationService.error(err.message);
|
||||
}
|
||||
|
||||
let profilerInput: ProfilerInput = instantiationService.createInstance(ProfilerInput, undefined, fileURI);
|
||||
await editorService.openEditor(profilerInput, { pinned: true }, ACTIVE_GROUP);
|
||||
profilerInput.setConnectionState(false); // Reset connection to be not connected for File session, so that "Start" is not enabled.
|
||||
|
||||
Reference in New Issue
Block a user