WeddingPlatform.Web
1.0.0.0
지도, 갤러리, 방명록, 계좌 안내와 배경음악을 링크 하나에 담는 무료 모바일 청첩장 서비스입니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
JsonGlobalSettingsStore.cs
이 파일의 문서화 페이지로 가기
1
using
System;
2
using
System.IO;
3
using
System.Text.Json;
4
using
System.Threading;
5
using
System.Threading.Tasks;
6
using
WeddingPlatform.Models
;
7
8
namespace
WeddingPlatform.Services
9
{
18
public
sealed
class
JsonGlobalSettingsStore
:
IGlobalSettingsStore
19
{
28
private
readonly
string
_path
;
37
private
static
readonly SemaphoreSlim
_gate
=
new
(1, 1);
46
private
GlobalSettings
?
_cache
;
47
56
private
static
readonly JsonSerializerOptions
_jsonOpts
=
new
() { WriteIndented =
true
};
57
74
public
JsonGlobalSettingsStore
(
WeddingOptions
opts)
75
{
76
var dataRoot = Path.GetDirectoryName(opts.
ResolvedDataPath
.TrimEnd(Path.DirectorySeparatorChar))
77
?? Path.Combine(AppContext.BaseDirectory,
"App_Data"
);
78
Directory.CreateDirectory(dataRoot);
79
_path
= Path.Combine(dataRoot,
"global-settings.json"
);
80
}
81
106
public
async Task<GlobalSettings>
GetAsync
(CancellationToken ct =
default
)
107
{
108
if
(
_cache
is not
null
)
return
_cache
;
109
110
await
_gate
.WaitAsync(ct).ConfigureAwait(
false
);
111
try
112
{
113
if
(
_cache
is not
null
)
return
_cache
;
114
115
if
(!File.Exists(
_path
))
116
{
117
_cache
=
new
GlobalSettings
();
118
return
_cache
;
119
}
120
121
await
using
var fs = File.OpenRead(
_path
);
122
_cache
= await JsonSerializer.DeserializeAsync<
GlobalSettings
>(fs,
_jsonOpts
, ct).ConfigureAwait(
false
)
123
??
new
GlobalSettings
();
124
_cache
.Normalize();
125
return
_cache
;
126
}
127
finally
{
_gate
.Release(); }
128
}
129
162
public
async Task
SaveAsync
(
GlobalSettings
settings, CancellationToken ct =
default
)
163
{
164
settings.
Normalize
();
165
await
_gate
.WaitAsync(ct).ConfigureAwait(
false
);
166
try
167
{
168
var tmp =
_path
+
".tmp"
;
169
await
using
(var fs = File.Create(tmp))
170
await JsonSerializer.SerializeAsync(fs, settings,
_jsonOpts
, ct).ConfigureAwait(
false
);
171
172
File.Copy(tmp,
_path
, overwrite:
true
);
173
File.Delete(tmp);
174
_cache
= settings;
175
}
176
finally
{
_gate
.Release(); }
177
}
178
}
179
}
WeddingPlatform.Models
Definition
AccountInfo.cs:1
WeddingPlatform.Services
Definition
CsvGuestbookStorage.cs:6
WeddingPlatform.Models.GlobalSettings
Definition
GlobalSettings.cs:12
WeddingPlatform.Models.GlobalSettings.Normalize
void Normalize()
Definition
GlobalSettings.cs:51
WeddingPlatform.Services.IGlobalSettingsStore
Definition
IGlobalSettingsStore.cs:16
WeddingPlatform.Services.JsonGlobalSettingsStore._path
readonly string _path
Definition
JsonGlobalSettingsStore.cs:28
WeddingPlatform.Services.JsonGlobalSettingsStore._cache
GlobalSettings? _cache
Definition
JsonGlobalSettingsStore.cs:46
WeddingPlatform.Services.JsonGlobalSettingsStore.SaveAsync
async Task SaveAsync(GlobalSettings settings, CancellationToken ct=default)
Definition
JsonGlobalSettingsStore.cs:162
WeddingPlatform.Services.JsonGlobalSettingsStore._gate
static readonly SemaphoreSlim _gate
Definition
JsonGlobalSettingsStore.cs:37
WeddingPlatform.Services.JsonGlobalSettingsStore._jsonOpts
static readonly JsonSerializerOptions _jsonOpts
Definition
JsonGlobalSettingsStore.cs:56
WeddingPlatform.Services.JsonGlobalSettingsStore.JsonGlobalSettingsStore
JsonGlobalSettingsStore(WeddingOptions opts)
Definition
JsonGlobalSettingsStore.cs:74
WeddingPlatform.Services.JsonGlobalSettingsStore.GetAsync
async Task< GlobalSettings > GetAsync(CancellationToken ct=default)
Definition
JsonGlobalSettingsStore.cs:106
WeddingPlatform.Services.WeddingOptions
Definition
WeddingOptions.cs:15
WeddingPlatform.Services.WeddingOptions.ResolvedDataPath
string ResolvedDataPath
Definition
WeddingOptions.cs:62
Services
JsonGlobalSettingsStore.cs
다음에 의해 생성됨 :
1.17.0