ShopPlatform.Web
1.0.0.0
농산물, 소프트웨어 라이선스와 개발 용역을 직접 판매하는 CodeMaru 직영 쇼핑몰입니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
JsonShopTenantStore.cs
이 파일의 문서화 페이지로 가기
1
using
System.Text.Json;
2
using
ShopPlatform.Models
;
3
4
namespace
ShopPlatform.Services
;
5
14
public
sealed
class
JsonShopTenantStore
:
IShopTenantStore
15
{
24
private
readonly
string
_root
;
33
private
static
readonly JsonSerializerOptions
_json
=
new
() { WriteIndented =
true
};
34
51
public
JsonShopTenantStore
(
ShopOptions
opts) =>
_root
= opts.
ResolvedDataPath
;
52
77
public
async Task<ShopConfig?>
GetAsync
(
string
slug)
78
{
79
var path =
ConfigPath
(slug);
80
if
(!File.Exists(path))
return
null
;
81
await
using
var stream = File.OpenRead(path);
82
return
await JsonSerializer.DeserializeAsync<
ShopConfig
>(stream,
_json
);
83
}
84
101
public
async Task<IReadOnlyList<ShopConfig>>
GetAllAsync
()
102
{
103
if
(!Directory.Exists(
_root
))
return
Array.Empty<
ShopConfig
>();
104
var list =
new
List<ShopConfig>();
105
foreach
(var dir
in
Directory.EnumerateDirectories(
_root
))
106
{
107
var path = Path.Combine(dir,
"config.json"
);
108
if
(!File.Exists(path))
continue
;
109
await
using
var stream = File.OpenRead(path);
110
var cfg = await JsonSerializer.DeserializeAsync<
ShopConfig
>(stream,
_json
);
111
if
(cfg !=
null
) list.Add(cfg);
112
}
113
return
list;
114
}
115
140
public
async Task
SaveAsync
(
ShopConfig
config)
141
{
142
var dir =
ShopDir
(config.
Slug
);
143
Directory.CreateDirectory(dir);
144
var json = JsonSerializer.Serialize(config,
_json
);
145
await File.WriteAllTextAsync(
ConfigPath
(config.
Slug
), json);
146
}
147
172
public
Task
DeleteAsync
(
string
slug)
173
{
174
var dir =
ShopDir
(slug);
175
if
(Directory.Exists(dir)) Directory.Delete(dir, recursive:
true
);
176
return
Task.CompletedTask;
177
}
178
203
public
Task<bool>
ExistsAsync
(
string
slug) =>
204
Task.FromResult(File.Exists(
ConfigPath
(slug)));
205
230
private
string
ShopDir
(
string
slug) => Path.Combine(
_root
, slug);
255
private
string
ConfigPath
(
string
slug) => Path.Combine(
ShopDir
(slug),
"config.json"
);
256
}
ShopPlatform.Models
Definition
CartItem.cs:1
ShopPlatform.Services
Definition
CartService.cs:3
ShopPlatform.Models.ShopConfig
Definition
ShopConfig.cs:12
ShopPlatform.Models.ShopConfig.Slug
string Slug
Definition
ShopConfig.cs:21
ShopPlatform.Models.ShopOptions
Definition
ShopOptions.cs:12
ShopPlatform.Models.ShopOptions.ResolvedDataPath
string ResolvedDataPath
Definition
ShopOptions.cs:61
ShopPlatform.Services.IShopTenantStore
Definition
IShopTenantStore.cs:14
ShopPlatform.Services.JsonShopTenantStore._root
readonly string _root
Definition
JsonShopTenantStore.cs:24
ShopPlatform.Services.JsonShopTenantStore.ShopDir
string ShopDir(string slug)
Definition
JsonShopTenantStore.cs:230
ShopPlatform.Services.JsonShopTenantStore._json
static readonly JsonSerializerOptions _json
Definition
JsonShopTenantStore.cs:33
ShopPlatform.Services.JsonShopTenantStore.GetAsync
async Task< ShopConfig?> GetAsync(string slug)
Definition
JsonShopTenantStore.cs:77
ShopPlatform.Services.JsonShopTenantStore.GetAllAsync
async Task< IReadOnlyList< ShopConfig > > GetAllAsync()
Definition
JsonShopTenantStore.cs:101
ShopPlatform.Services.JsonShopTenantStore.ExistsAsync
Task< bool > ExistsAsync(string slug)
Definition
JsonShopTenantStore.cs:203
ShopPlatform.Services.JsonShopTenantStore.DeleteAsync
Task DeleteAsync(string slug)
Definition
JsonShopTenantStore.cs:172
ShopPlatform.Services.JsonShopTenantStore.ConfigPath
string ConfigPath(string slug)
Definition
JsonShopTenantStore.cs:255
ShopPlatform.Services.JsonShopTenantStore.SaveAsync
async Task SaveAsync(ShopConfig config)
Definition
JsonShopTenantStore.cs:140
ShopPlatform.Services.JsonShopTenantStore.JsonShopTenantStore
JsonShopTenantStore(ShopOptions opts)
Definition
JsonShopTenantStore.cs:51
Services
JsonShopTenantStore.cs
다음에 의해 생성됨 :
1.17.0