ShopPlatform.Web 1.0.0.0
농산물, 소프트웨어 라이선스와 개발 용역을 직접 판매하는 CodeMaru 직영 쇼핑몰입니다.
로딩중...
검색중...
일치하는것 없음
JsonShopTenantStore.cs
이 파일의 문서화 페이지로 가기
1using System.Text.Json;
3
5
15{
24 private readonly string _root;
33 private static readonly JsonSerializerOptions _json = new() { WriteIndented = true };
34
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}
static readonly JsonSerializerOptions _json
async Task< ShopConfig?> GetAsync(string slug)
async Task< IReadOnlyList< ShopConfig > > GetAllAsync()