Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
e7600b87
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e7600b87
编写于
11月 23, 2018
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
storage - add a main side storage service
上级
91d53ea7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
159 addition
and
0 deletion
+159
-0
src/vs/platform/storage/electron-main/storageMainService.ts
src/vs/platform/storage/electron-main/storageMainService.ts
+159
-0
未找到文件。
src/vs/platform/storage/electron-main/storageMainService.ts
0 → 100644
浏览文件 @
e7600b87
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
Event
,
Emitter
}
from
'
vs/base/common/event
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
ILogService
,
LogLevel
}
from
'
vs/platform/log/common/log
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
IStorage
,
Storage
,
IStorageLoggingOptions
}
from
'
vs/base/node/storage
'
;
import
{
join
}
from
'
path
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
export
const
IStorageMainService
=
createDecorator
<
IStorageMainService
>
(
'
storageMainService
'
);
export
interface
IStorageMainService
{
_serviceBrand
:
any
;
/**
* Emitted whenever data is updated or deleted.
*/
readonly
onDidChangeStorage
:
Event
<
IStorageChangeEvent
>
;
/**
* Emitted when the storage is about to persist. This is the right time
* to persist data to ensure it is stored before the application shuts
* down.
*/
readonly
onWillSaveState
:
Event
<
void
>
;
/**
* Retrieve an element stored with the given key from storage. Use
* the provided defaultValue if the element is null or undefined.
*/
get
(
key
:
string
,
fallbackValue
:
string
):
string
;
/**
* Retrieve an element stored with the given key from storage. Use
* the provided defaultValue if the element is null or undefined. The element
* will be converted to a boolean.
*/
getBoolean
(
key
:
string
,
fallbackValue
:
boolean
):
boolean
;
/**
* Retrieve an element stored with the given key from storage. Use
* the provided defaultValue if the element is null or undefined. The element
* will be converted to a number using parseInt with a base of 10.
*/
getInteger
(
key
:
string
,
fallbackValue
:
number
):
number
;
/**
* Store a string value under the given key to storage. The value will
* be converted to a string.
*/
store
(
key
:
string
,
value
:
any
):
void
;
/**
* Delete an element stored under the provided key from storage.
*/
remove
(
key
:
string
):
void
;
}
export
interface
IStorageChangeEvent
{
key
:
string
;
}
export
class
StorageMainService
extends
Disposable
implements
IStorageMainService
{
_serviceBrand
:
any
;
private
static
STORAGE_NAME
=
'
storage.db
'
;
private
_onDidChangeStorage
:
Emitter
<
IStorageChangeEvent
>
=
this
.
_register
(
new
Emitter
<
IStorageChangeEvent
>
());
get
onDidChangeStorage
():
Event
<
IStorageChangeEvent
>
{
return
this
.
_onDidChangeStorage
.
event
;
}
private
_onWillSaveState
:
Emitter
<
void
>
=
this
.
_register
(
new
Emitter
<
void
>
());
get
onWillSaveState
():
Event
<
void
>
{
return
this
.
_onWillSaveState
.
event
;
}
private
storage
:
IStorage
;
constructor
(
@
ILogService
private
logService
:
ILogService
,
@
IEnvironmentService
environmentService
:
IEnvironmentService
,
@
ITelemetryService
private
telemetryService
:
ITelemetryService
)
{
super
();
this
.
storage
=
new
Storage
({
path
:
join
(
environmentService
.
globalStorageHome
,
StorageMainService
.
STORAGE_NAME
),
logging
:
this
.
createLogginOptions
()
});
this
.
registerListeners
();
}
private
createLogginOptions
():
IStorageLoggingOptions
{
const
loggedStorageErrors
=
new
Set
<
string
>
();
return
{
logTrace
:
(
this
.
logService
.
getLevel
()
===
LogLevel
.
Trace
)
?
msg
=>
this
.
logService
.
trace
(
msg
)
:
void
0
,
logError
:
error
=>
{
this
.
logService
.
error
(
error
);
const
errorStr
=
`
${
error
}
`
;
if
(
!
loggedStorageErrors
.
has
(
errorStr
))
{
loggedStorageErrors
.
add
(
errorStr
);
/* __GDPR__
"sqliteMainStorageError" : {
"storageError": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
this
.
telemetryService
.
publicLog
(
'
sqliteMainStorageError
'
,
{
'
storageError
'
:
errorStr
});
}
}
}
as
IStorageLoggingOptions
;
}
private
registerListeners
():
void
{
this
.
_register
(
this
.
storage
.
onDidChangeStorage
(
key
=>
this
.
_onDidChangeStorage
.
fire
({
key
})));
}
initialize
():
Thenable
<
void
>
{
return
this
.
storage
.
init
();
}
get
(
key
:
string
,
fallbackValue
:
string
):
string
{
return
this
.
storage
.
get
(
key
,
fallbackValue
);
}
getBoolean
(
key
:
string
,
fallbackValue
:
boolean
):
boolean
{
return
this
.
storage
.
getBoolean
(
key
,
fallbackValue
);
}
getInteger
(
key
:
string
,
fallbackValue
:
number
):
number
{
return
this
.
storage
.
getInteger
(
key
,
fallbackValue
);
}
store
(
key
:
string
,
value
:
any
):
Thenable
<
void
>
{
return
this
.
storage
.
set
(
key
,
value
);
}
remove
(
key
:
string
):
Thenable
<
void
>
{
return
this
.
storage
.
delete
(
key
);
}
close
():
Thenable
<
void
>
{
// Signal as event so that clients can still store data
this
.
_onWillSaveState
.
fire
();
// Do it
return
this
.
storage
.
close
().
then
(()
=>
void
0
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录