當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript storageLegacyService.IStorageLegacy類代碼示例

本文整理匯總了TypeScript中vs/platform/storage/common/storageLegacyService.IStorageLegacy的典型用法代碼示例。如果您正苦於以下問題:TypeScript IStorageLegacy類的具體用法?TypeScript IStorageLegacy怎麽用?TypeScript IStorageLegacy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了IStorageLegacy類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: parseMultiRootStorage

export function parseMultiRootStorage(storage: IStorageLegacy, targetWorkspaceId: string): StorageObject {
	const multiRootStoragePrefix = `${COMMON_WORKSPACE_PREFIX}${targetWorkspaceId}/`;

	const multiRootWorkspaceStorage: StorageObject = Object.create(null);
	for (let i = 0; i < storage.length; i++) {
		const key = storage.key(i);

		if (startsWith(key, multiRootStoragePrefix) && !endsWith(key, StorageLegacyService.WORKSPACE_IDENTIFIER)) {
			// storage://workspace/root:<id>/someKey => someKey
			multiRootWorkspaceStorage[key.substr(multiRootStoragePrefix.length)] = storage.getItem(key);
		}
	}

	return multiRootWorkspaceStorage;
}
開發者ID:,項目名稱:,代碼行數:15,代碼來源:

示例2: parseNoWorkspaceStorage

export function parseNoWorkspaceStorage(storage: IStorageLegacy) {
	const noWorkspacePrefix = `${StorageLegacyService.WORKSPACE_PREFIX}__$noWorkspace__`;

	const noWorkspaceStorage: StorageObject = Object.create(null);
	for (let i = 0; i < storage.length; i++) {
		const key = storage.key(i);

		// No Workspace key is for extension development windows
		if (startsWith(key, noWorkspacePrefix) && !endsWith(key, StorageLegacyService.WORKSPACE_IDENTIFIER)) {
			// storage://workspace/__$noWorkspace__someKey => someKey
			noWorkspaceStorage[key.substr(NO_WORKSPACE_PREFIX.length)] = storage.getItem(key);
		}
	}

	return noWorkspaceStorage;
}
開發者ID:,項目名稱:,代碼行數:16,代碼來源:

示例3: parseStorage

export function parseStorage(storage: IStorageLegacy): IParsedStorage {
	const globalStorage = new Map<string, string>();
	const folderWorkspacesStorage = new Map<string /* workspace file resource */, StorageObject>();
	const emptyWorkspacesStorage = new Map<string /* empty workspace id */, StorageObject>();
	const multiRootWorkspacesStorage = new Map<string /* multi root workspace id */, StorageObject>();

	const workspaces: { prefix: string; resource: string; }[] = [];
	for (let i = 0; i < storage.length; i++) {
		const key = storage.key(i);

		// Workspace Storage (storage://workspace/)
		if (startsWith(key, StorageLegacyService.WORKSPACE_PREFIX)) {

			// We are looking for key: storage://workspace/<folder>/workspaceIdentifier to be able to find all folder
			// paths that are known to the storage. is the only way how to parse all folder paths known in storage.
			if (endsWith(key, StorageLegacyService.WORKSPACE_IDENTIFIER)) {

				// storage://workspace/<folder>/workspaceIdentifier => <folder>/
				let workspace = key.substring(StorageLegacyService.WORKSPACE_PREFIX.length, key.length - StorageLegacyService.WORKSPACE_IDENTIFIER.length);

				// macOS/Unix: Users/name/folder/
				//    Windows: c%3A/Users/name/folder/
				if (!startsWith(workspace, 'file:')) {
					workspace = `file:///${rtrim(workspace, '/')}`;
				}

				// Windows UNC path: file://localhost/c%3A/Users/name/folder/
				else {
					workspace = rtrim(workspace, '/');
				}

				// storage://workspace/<folder>/workspaceIdentifier => storage://workspace/<folder>/
				const prefix = key.substr(0, key.length - StorageLegacyService.WORKSPACE_IDENTIFIER.length);
				workspaces.push({ prefix, resource: workspace });
			}

			// Empty workspace key: storage://workspace/empty:<id>/<key>
			else if (startsWith(key, EMPTY_WORKSPACE_PREFIX)) {

				// storage://workspace/empty:<id>/<key> => <id>
				const emptyWorkspaceId = key.substring(EMPTY_WORKSPACE_PREFIX.length, key.indexOf('/', EMPTY_WORKSPACE_PREFIX.length));
				const emptyWorkspaceResource = URI.from({ path: emptyWorkspaceId, scheme: 'empty' }).toString();

				let emptyWorkspaceStorage = emptyWorkspacesStorage.get(emptyWorkspaceResource);
				if (!emptyWorkspaceStorage) {
					emptyWorkspaceStorage = Object.create(null);
					emptyWorkspacesStorage.set(emptyWorkspaceResource, emptyWorkspaceStorage);
				}

				// storage://workspace/empty:<id>/someKey => someKey
				const storageKey = key.substr(EMPTY_WORKSPACE_PREFIX.length + emptyWorkspaceId.length + 1 /* trailing / */);

				emptyWorkspaceStorage[storageKey] = storage.getItem(key);
			}

			// Multi root workspace key: storage://workspace/root:<id>/<key>
			else if (startsWith(key, MULTI_ROOT_WORKSPACE_PREFIX)) {

				// storage://workspace/root:<id>/<key> => <id>
				const multiRootWorkspaceId = key.substring(MULTI_ROOT_WORKSPACE_PREFIX.length, key.indexOf('/', MULTI_ROOT_WORKSPACE_PREFIX.length));
				const multiRootWorkspaceResource = URI.from({ path: multiRootWorkspaceId, scheme: 'root' }).toString();

				let multiRootWorkspaceStorage = multiRootWorkspacesStorage.get(multiRootWorkspaceResource);
				if (!multiRootWorkspaceStorage) {
					multiRootWorkspaceStorage = Object.create(null);
					multiRootWorkspacesStorage.set(multiRootWorkspaceResource, multiRootWorkspaceStorage);
				}

				// storage://workspace/root:<id>/someKey => someKey
				const storageKey = key.substr(MULTI_ROOT_WORKSPACE_PREFIX.length + multiRootWorkspaceId.length + 1 /* trailing / */);

				multiRootWorkspaceStorage[storageKey] = storage.getItem(key);
			}
		}

		// Global Storage (storage://global)
		else if (startsWith(key, StorageLegacyService.GLOBAL_PREFIX)) {

			// storage://global/someKey => someKey
			const globalStorageKey = key.substr(StorageLegacyService.GLOBAL_PREFIX.length);
			if (startsWith(globalStorageKey, StorageLegacyService.COMMON_PREFIX)) {
				continue; // filter out faulty keys that have the form storage://something/storage://
			}

			globalStorage.set(globalStorageKey, storage.getItem(key));
		}
	}

	// With all the folder paths known we can now extract storage for each path. We have to go through all workspaces
	// from the longest path first to reliably extract the storage. The reason is that one folder path can be a parent
	// of another folder path and as such a simple indexOf check is not enough.
	const workspacesByLength = workspaces.sort((w1, w2) => w1.prefix.length >= w2.prefix.length ? -1 : 1);
	const handledKeys = new Map<string, boolean>();
	workspacesByLength.forEach(workspace => {
		for (let i = 0; i < storage.length; i++) {
			const key = storage.key(i);

			if (handledKeys.has(key) || !startsWith(key, workspace.prefix)) {
				continue; // not part of workspace prefix or already handled
			}
//.........這裏部分代碼省略.........
開發者ID:DonJayamanne,項目名稱:vscode,代碼行數:101,代碼來源:storageLegacyMigration.ts

示例4: parseFolderStorage

export function parseFolderStorage(storage: IStorageLegacy, folderId: string): StorageObject {

	const workspaces: { prefix: string; resource: string; }[] = [];
	const activeKeys = new Set<string>();

	for (let i = 0; i < storage.length; i++) {
		const key = storage.key(i);

		// Workspace Storage (storage://workspace/)
		if (!startsWith(key, StorageLegacyService.WORKSPACE_PREFIX)) {
			continue;
		}

		activeKeys.add(key);

		// We are looking for key: storage://workspace/<folder>/workspaceIdentifier to be able to find all folder
		// paths that are known to the storage. is the only way how to parse all folder paths known in storage.
		if (endsWith(key, StorageLegacyService.WORKSPACE_IDENTIFIER)) {

			// storage://workspace/<folder>/workspaceIdentifier => <folder>/
			let workspace = key.substring(StorageLegacyService.WORKSPACE_PREFIX.length, key.length - StorageLegacyService.WORKSPACE_IDENTIFIER.length);

			// macOS/Unix: Users/name/folder/
			//    Windows: c%3A/Users/name/folder/
			if (!startsWith(workspace, 'file:')) {
				workspace = `file:///${rtrim(workspace, '/')}`;
			}

			// Windows UNC path: file://localhost/c%3A/Users/name/folder/
			else {
				workspace = rtrim(workspace, '/');
			}

			// storage://workspace/<folder>/workspaceIdentifier => storage://workspace/<folder>/
			const prefix = key.substr(0, key.length - StorageLegacyService.WORKSPACE_IDENTIFIER.length);
			if (startsWith(workspace, folderId)) {
				workspaces.push({ prefix, resource: workspace });
			}
		}
	}

	// With all the folder paths known we can now extract storage for each path. We have to go through all workspaces
	// from the longest path first to reliably extract the storage. The reason is that one folder path can be a parent
	// of another folder path and as such a simple indexOf check is not enough.
	const workspacesByLength = workspaces.sort((w1, w2) => w1.prefix.length >= w2.prefix.length ? -1 : 1);

	const folderWorkspaceStorage: StorageObject = Object.create(null);

	workspacesByLength.forEach(workspace => {
		activeKeys.forEach(key => {
			if (!startsWith(key, workspace.prefix)) {
				return; // not part of workspace prefix or already handled
			}

			activeKeys.delete(key);

			if (workspace.resource === folderId) {
				// storage://workspace/<folder>/someKey => someKey
				const storageKey = key.substr(workspace.prefix.length);
				folderWorkspaceStorage[storageKey] = storage.getItem(key);
			}
		});
	});

	return folderWorkspaceStorage;
}
開發者ID:,項目名稱:,代碼行數:66,代碼來源:

示例5:

		Object.keys(storageForWorkspace).forEach(key => {
			if (key === StorageLegacyService.WORKSPACE_IDENTIFIER) {
				return; // make sure to never migrate the workspace identifier
			}

			storage.setItem(`${StorageLegacyService.WORKSPACE_PREFIX}${newWorkspaceId}/${key}`, storageForWorkspace[key]);
		});
開發者ID:DonJayamanne,項目名稱:vscode,代碼行數:7,代碼來源:storageLegacyMigration.ts

示例6:

		activeKeys.forEach(key => {
			if (!startsWith(key, workspace.prefix)) {
				return; // not part of workspace prefix or already handled
			}

			activeKeys.delete(key);

			if (workspace.resource === folderId) {
				// storage://workspace/<folder>/someKey => someKey
				const storageKey = key.substr(workspace.prefix.length);
				folderWorkspaceStorage[storageKey] = storage.getItem(key);
			}
		});
開發者ID:,項目名稱:,代碼行數:13,代碼來源:


注:本文中的vs/platform/storage/common/storageLegacyService.IStorageLegacy類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。