Portfolio.Web
1.0.0.0
.NET, Blazor, WPF와 서비스 운영 경험을 프로젝트·이력·기술 스택 단위로 보여주는 개발자 포트폴리오입니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
JsonContactStore.cs
이 파일의 문서화 페이지로 가기
1
using
System.IO;
2
using
System.Text.Json;
3
using
PortfolioApp.Models
;
4
5
namespace
PortfolioApp.Services
;
6
15
public
class
JsonContactStore
:
IContactStore
16
{
25
private
readonly
string
_root
;
34
private
static
readonly JsonSerializerOptions
_json
=
new
() { WriteIndented =
true
};
35
52
public
JsonContactStore
(
PortfolioOptions
opts) =>
_root
= opts.
ResolvedDataPath
;
53
78
private
string
Dir
(
string
slug) => Path.Combine(
_root
, slug,
"contacts"
);
111
private
string
Path_
(
string
slug,
string
id
) => Path.Combine(
Dir
(slug), $
"{id}.json"
);
112
137
public
async Task<List<ContactMessage>>
GetAllAsync
(
string
slug)
138
{
139
var dir =
Dir
(slug);
140
if
(!Directory.Exists(dir))
return
[];
141
var list =
new
List<ContactMessage>();
142
foreach
(var f
in
Directory.GetFiles(dir,
"*.json"
))
143
{
144
try
145
{
146
var json = await File.ReadAllTextAsync(f);
147
var msg = JsonSerializer.Deserialize<
ContactMessage
>(json);
148
if
(msg !=
null
) list.Add(msg);
149
}
150
catch
{ }
151
}
152
return
[.. list.OrderByDescending(m => m.SentAt)];
153
}
154
187
public
async Task
SaveAsync
(
string
slug,
ContactMessage
msg)
188
{
189
Directory.CreateDirectory(
Dir
(slug));
190
var json = JsonSerializer.Serialize(msg,
_json
);
191
await File.WriteAllTextAsync(
Path_
(slug, msg.
Id
), json);
192
}
193
226
public
Task
DeleteAsync
(
string
slug,
string
msgId)
227
{
228
var path =
Path_
(slug, msgId);
229
if
(File.Exists(path)) File.Delete(path);
230
return
Task.CompletedTask;
231
}
232
265
public
async Task
MarkReadAsync
(
string
slug,
string
msgId)
266
{
267
var path =
Path_
(slug, msgId);
268
if
(!File.Exists(path))
return
;
269
var json = await File.ReadAllTextAsync(path);
270
var msg = JsonSerializer.Deserialize<
ContactMessage
>(json);
271
if
(msg is
null
)
return
;
272
msg.IsRead =
true
;
273
await File.WriteAllTextAsync(path, JsonSerializer.Serialize(msg,
_json
));
274
}
275
}
PortfolioApp.Models
Definition
ContactMessage.cs:1
PortfolioApp.Services
Definition
GhostAccountCleanupService.cs:4
PortfolioApp.Models.ContactMessage
Definition
ContactMessage.cs:12
PortfolioApp.Models.ContactMessage.Id
string Id
Definition
ContactMessage.cs:21
PortfolioApp.Services.IContactStore
Definition
IContactStore.cs:14
PortfolioApp.Services.JsonContactStore.GetAllAsync
async Task< List< ContactMessage > > GetAllAsync(string slug)
Definition
JsonContactStore.cs:137
PortfolioApp.Services.JsonContactStore._json
static readonly JsonSerializerOptions _json
Definition
JsonContactStore.cs:34
PortfolioApp.Services.JsonContactStore._root
readonly string _root
Definition
JsonContactStore.cs:25
PortfolioApp.Services.JsonContactStore.DeleteAsync
Task DeleteAsync(string slug, string msgId)
Definition
JsonContactStore.cs:226
PortfolioApp.Services.JsonContactStore.Dir
string Dir(string slug)
Definition
JsonContactStore.cs:78
PortfolioApp.Services.JsonContactStore.SaveAsync
async Task SaveAsync(string slug, ContactMessage msg)
Definition
JsonContactStore.cs:187
PortfolioApp.Services.JsonContactStore.JsonContactStore
JsonContactStore(PortfolioOptions opts)
Definition
JsonContactStore.cs:52
PortfolioApp.Services.JsonContactStore.Path_
string Path_(string slug, string id)
Definition
JsonContactStore.cs:111
PortfolioApp.Services.JsonContactStore.MarkReadAsync
async Task MarkReadAsync(string slug, string msgId)
Definition
JsonContactStore.cs:265
PortfolioApp.Services.PortfolioOptions
Definition
PortfolioOptions.cs:15
PortfolioApp.Services.PortfolioOptions.ResolvedDataPath
string ResolvedDataPath
Definition
PortfolioOptions.cs:43
Services
JsonContactStore.cs
다음에 의해 생성됨 :
1.17.0