Codemaru 1.0.0.0
QR 코드, 모바일 랜딩 페이지, vCard 연락처 저장과 명함 디자인을 한 화면에서 제공하는 디지털 명함 서비스입니다.
로딩중...
검색중...
일치하는것 없음
Codemaru.Services.JsonCardProfileStore 클래스 참조sealed

더 자세히 ...

Codemaru.Services.JsonCardProfileStore에 대한 상속 다이어그램 :
Codemaru.Services.JsonCardProfileStore에 대한 협력 다이어그램:

Public 멤버 함수

 JsonCardProfileStore ()
async Task< CardHybridSnapshot?> LoadAsync (string userId, CancellationToken cancellationToken=default)
async Task SaveAsync (string userId, CardHybridSnapshot snapshot, CancellationToken cancellationToken=default)
async Task< CardHybridSnapshot?> LoadBySlugAsync (string slug, CancellationToken cancellationToken=default)
Task DeleteAsync (string userId, CancellationToken cancellationToken=default)

Private 멤버 함수

string GetSnapshotPath (string userId)

정적 Private 멤버 함수

static bool IsGuest (string userId)
static string SanitizeUserId (string userId)

Private 속성

readonly string _rootDirectory

정적 Private 속성

const string SnapshotFileName = "snapshot.json"
static readonly JsonSerializerOptions SerializerOptions

상세한 설명

CardHybrid 스냅샷을 프로젝트의 App_Data/Cards/{userId}/snapshot.json 에 저장합니다.

Guest 사용자의 데이터는 파일로 저장하지 않습니다 (서킷 메모리만 사용).

JsonCardProfileStore.cs 파일의 23 번째 라인에서 정의되었습니다.

생성자 & 소멸자 문서화

◆ JsonCardProfileStore()

Codemaru.Services.JsonCardProfileStore.JsonCardProfileStore ( )
inline

지정한 설정으로 JsonCardProfileStore 클래스의 새 인스턴스를 초기화합니다.

JsonCardProfileStore.cs 파일의 66 번째 라인에서 정의되었습니다.

67 {
68 _rootDirectory = Path.Combine(AppContext.BaseDirectory, "App_Data", "Cards");
69 Directory.CreateDirectory(_rootDirectory);
70 }

다음을 참조함 : _rootDirectory.

멤버 함수 문서화

◆ DeleteAsync()

Task Codemaru.Services.JsonCardProfileStore.DeleteAsync ( string userId,
CancellationToken cancellationToken = default )
inline

Delete Async 작업을 수행합니다.

매개변수
userIduser Id에 사용할 string 값입니다.
cancellationToken취소 요청을 감시하는 토큰입니다.
반환값
Delete Async 작업에서 생성한 Task 결과입니다.

Codemaru.Services.ICardProfileStore를 구현.

JsonCardProfileStore.cs 파일의 297 번째 라인에서 정의되었습니다.

298 {
299 if (IsGuest(userId))
300 {
301 return Task.CompletedTask;
302 }
303
304 var filePath = GetSnapshotPath(userId);
305 if (File.Exists(filePath))
306 {
307 File.Delete(filePath);
308 }
309
310 return Task.CompletedTask;
311 }

다음을 참조함 : GetSnapshotPath(), IsGuest().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ GetSnapshotPath()

string Codemaru.Services.JsonCardProfileStore.GetSnapshotPath ( string userId)
inlineprivate

Snapshot Path 값을 가져옵니다.

매개변수
userIduser Id에 사용할 string 값입니다.
반환값
Get Snapshot Path 작업에서 생성한 string 결과입니다.

JsonCardProfileStore.cs 파일의 337 번째 라인에서 정의되었습니다.

338 {
339 return Path.Combine(_rootDirectory, SanitizeUserId(userId), SnapshotFileName);
340 }

다음을 참조함 : _rootDirectory, SanitizeUserId(), SnapshotFileName.

다음에 의해서 참조됨 : DeleteAsync(), LoadAsync(), SaveAsync().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ IsGuest()

bool Codemaru.Services.JsonCardProfileStore.IsGuest ( string userId)
inlinestaticprivate

Is Guest 조건을 확인합니다.

매개변수
userIduser Id에 사용할 string 값입니다.
반환값
Is Guest 조건이 충족되면 true이고, 그렇지 않으면 false입니다.

JsonCardProfileStore.cs 파일의 366 번째 라인에서 정의되었습니다.

366 =>
367 string.IsNullOrWhiteSpace(userId) ||
368 string.Equals(userId, CardHybridUser.Guest.Id, StringComparison.OrdinalIgnoreCase);
record CardHybridUser(string Id, string Email, string DisplayName, DateTime SignedInAt)

다음을 참조함 : Codemaru.Models.CardHybridUser().

다음에 의해서 참조됨 : DeleteAsync(), LoadAsync(), SaveAsync().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ LoadAsync()

async Task< CardHybridSnapshot?> Codemaru.Services.JsonCardProfileStore.LoadAsync ( string userId,
CancellationToken cancellationToken = default )
inline

Async 데이터를 불러옵니다.

매개변수
userIduser Id에 사용할 string 값입니다.
cancellationToken취소 요청을 감시하는 토큰입니다.
반환값
Load Async 작업에서 생성한 Task<CardHybridSnapshot?> 결과입니다.

Codemaru.Services.ICardProfileStore를 구현.

JsonCardProfileStore.cs 파일의 104 번째 라인에서 정의되었습니다.

105 {
106 if (IsGuest(userId))
107 {
108 return null;
109 }
110
111 var filePath = GetSnapshotPath(userId);
112 if (!File.Exists(filePath))
113 {
114 return null;
115 }
116
117 await using var stream = File.OpenRead(filePath);
118 var snapshot = await JsonSerializer.DeserializeAsync<CardHybridSnapshot>(
119 stream, SerializerOptions, cancellationToken).ConfigureAwait(false);
120
121 return snapshot?.UserId == userId ? snapshot : snapshot;
122 }
record CardHybridSnapshot(string? UserId, CardProfile Profile, IReadOnlyList< CardHistoryEntry > History, DateTime SavedAt)

다음을 참조함 : Codemaru.Models.CardHybridSnapshot(), GetSnapshotPath(), IsGuest(), SerializerOptions.

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ LoadBySlugAsync()

async Task< CardHybridSnapshot?> Codemaru.Services.JsonCardProfileStore.LoadBySlugAsync ( string slug,
CancellationToken cancellationToken = default )
inline

By Slug Async 데이터를 불러옵니다.

매개변수
slugslug에 사용할 string 값입니다.
cancellationToken취소 요청을 감시하는 토큰입니다.
반환값
Load By Slug Async 작업에서 생성한 Task<CardHybridSnapshot?> 결과입니다.

Codemaru.Services.ICardProfileStore를 구현.

JsonCardProfileStore.cs 파일의 220 번째 라인에서 정의되었습니다.

221 {
222 if (string.IsNullOrWhiteSpace(slug))
223 {
224 return null;
225 }
226
227 var normalizedSlug = slug.Trim().Trim('/').ToLowerInvariant();
228
229 foreach (var userDirectory in Directory.EnumerateDirectories(_rootDirectory))
230 {
231 cancellationToken.ThrowIfCancellationRequested();
232
233 var filePath = Path.Combine(userDirectory, SnapshotFileName);
234 if (!File.Exists(filePath))
235 {
236 continue;
237 }
238
239 try
240 {
241 await using var stream = File.OpenRead(filePath);
242 var snapshot = await JsonSerializer.DeserializeAsync<CardHybridSnapshot>(
243 stream, SerializerOptions, cancellationToken).ConfigureAwait(false);
244
245 if (snapshot?.Profile is null)
246 {
247 continue;
248 }
249
250 var profileSlug = snapshot.Profile.LandingSlug.Trim().Trim('/').ToLowerInvariant();
251 if (profileSlug == $"card/{normalizedSlug}" || profileSlug == normalizedSlug)
252 {
253 return snapshot;
254 }
255 }
256 catch
257 {
258 // skip corrupt files
259 }
260 }
261
262 return null;
263 }

다음을 참조함 : _rootDirectory, Codemaru.Models.CardHybridSnapshot(), SerializerOptions, SnapshotFileName.

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ SanitizeUserId()

string Codemaru.Services.JsonCardProfileStore.SanitizeUserId ( string userId)
inlinestaticprivate

Sanitize User Id 작업을 수행합니다.

매개변수
userIduser Id에 사용할 string 값입니다.
반환값
Sanitize User Id 작업에서 생성한 string 결과입니다.

JsonCardProfileStore.cs 파일의 394 번째 라인에서 정의되었습니다.

395 {
396 var safe = new string((string.IsNullOrWhiteSpace(userId) ? "guest" : userId)
397 .Select(static c => char.IsLetterOrDigit(c) || c is '-' or '_' ? c : '_')
398 .ToArray());
399 return string.IsNullOrWhiteSpace(safe) ? "guest" : safe;
400 }

다음에 의해서 참조됨 : GetSnapshotPath().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ SaveAsync()

async Task Codemaru.Services.JsonCardProfileStore.SaveAsync ( string userId,
CardHybridSnapshot snapshot,
CancellationToken cancellationToken = default )
inline

Async 데이터를 저장합니다.

매개변수
userIduser Id에 사용할 string 값입니다.
snapshotsnapshot에 사용할 CardHybridSnapshot 값입니다.
cancellationToken취소 요청을 감시하는 토큰입니다.
반환값
Save Async 작업에서 생성한 Task 결과입니다.

Codemaru.Services.ICardProfileStore를 구현.

JsonCardProfileStore.cs 파일의 164 번째 라인에서 정의되었습니다.

165 {
166 ArgumentNullException.ThrowIfNull(snapshot);
167
168 if (IsGuest(userId))
169 {
170 return;
171 }
172
173 var filePath = GetSnapshotPath(userId);
174 var directory = Path.GetDirectoryName(filePath)!;
175 Directory.CreateDirectory(directory);
176
177 var tempPath = filePath + ".tmp";
178 await using (var stream = File.Create(tempPath))
179 {
180 await JsonSerializer.SerializeAsync(stream, snapshot, SerializerOptions, cancellationToken)
181 .ConfigureAwait(false);
182 }
183
184 File.Copy(tempPath, filePath, overwrite: true);
185 File.Delete(tempPath);
186 }

다음을 참조함 : Codemaru.Models.CardHybridSnapshot(), GetSnapshotPath(), IsGuest(), SerializerOptions.

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

멤버 데이터 문서화

◆ _rootDirectory

readonly string Codemaru.Services.JsonCardProfileStore._rootDirectory
private

root Directory 값을 보관합니다.

JsonCardProfileStore.cs 파일의 56 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : GetSnapshotPath(), JsonCardProfileStore(), LoadBySlugAsync().

◆ SerializerOptions

readonly JsonSerializerOptions Codemaru.Services.JsonCardProfileStore.SerializerOptions
staticprivate
초기값:
= new(JsonSerializerDefaults.Web)
{
WriteIndented = true
}

Serializer Options 값을 보관합니다.

JsonCardProfileStore.cs 파일의 43 번째 라인에서 정의되었습니다.

44 {
45 WriteIndented = true
46 };

다음에 의해서 참조됨 : LoadAsync(), LoadBySlugAsync(), SaveAsync().

◆ SnapshotFileName

const string Codemaru.Services.JsonCardProfileStore.SnapshotFileName = "snapshot.json"
staticprivate

Snapshot File Name 값을 보관합니다.

JsonCardProfileStore.cs 파일의 33 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : GetSnapshotPath(), LoadBySlugAsync().


이 클래스에 대한 문서화 페이지는 다음의 파일로부터 생성되었습니다.: