Families.AutoWriter
1.0.0.0
Families 콘텐츠를 반복 작업 없이 작성·등록하도록 돕는 자동화 작성 도구입니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
PromptHistoryService.cs
이 파일의 문서화 페이지로 가기
1
using
System.IO;
2
using
System.Security.Cryptography;
3
using
System.Text;
4
using
System.Text.Json;
5
6
namespace
FamiliesAutoWriter.Services
;
7
16
public
sealed
class
PromptHistoryService
17
{
26
private
static
readonly
object
_fileGate
=
new
();
35
private
readonly
string
_historyFile
;
44
private
readonly HashSet<string>
_sentHashes
;
45
54
public
PromptHistoryService
()
55
{
56
var dir = Path.Combine(
57
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
58
"FamiliesAutoWriter"
);
59
Directory.CreateDirectory(dir);
60
_historyFile
= Path.Combine(dir,
"prompt_history.json"
);
61
_sentHashes
=
Load
();
62
}
63
88
public
bool
IsDuplicate
(
string
prompt)
89
{
90
lock (
_fileGate
)
91
{
92
foreach
(var hash
in
Load
())
93
_sentHashes
.Add(hash);
94
return
_sentHashes
.Contains(
Hash
(prompt));
95
}
96
}
97
114
public
void
MarkSent
(
string
prompt)
115
{
116
lock (
_fileGate
)
117
{
118
foreach
(var hash
in
Load
())
119
_sentHashes
.Add(hash);
120
_sentHashes
.Add(
Hash
(prompt));
121
Save
();
122
}
123
}
124
133
public
void
Clear
()
134
{
135
lock (
_fileGate
)
136
{
137
_sentHashes
.Clear();
138
Save
();
139
}
140
}
141
158
private
HashSet<string>
Load
()
159
{
160
if
(!File.Exists(
_historyFile
))
return
[];
161
try
162
{
163
var json = File.ReadAllText(
_historyFile
);
164
return
JsonSerializer.Deserialize<HashSet<string>>(json) ?? [];
165
}
166
catch
{
return
[]; }
167
}
168
177
private
void
Save
() =>
178
File.WriteAllText(
_historyFile
, JsonSerializer.Serialize(
_sentHashes
));
179
204
private
static
string
Hash
(
string
s) =>
205
Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(s.Trim()))).ToLower()[..16];
206
}
FamiliesAutoWriter.Services
Definition
PostWriterService.cs:7
FamiliesAutoWriter.Services.PromptHistoryService.Clear
void Clear()
Definition
PromptHistoryService.cs:133
FamiliesAutoWriter.Services.PromptHistoryService._sentHashes
readonly HashSet< string > _sentHashes
Definition
PromptHistoryService.cs:44
FamiliesAutoWriter.Services.PromptHistoryService.Load
HashSet< string > Load()
Definition
PromptHistoryService.cs:158
FamiliesAutoWriter.Services.PromptHistoryService._historyFile
readonly string _historyFile
Definition
PromptHistoryService.cs:35
FamiliesAutoWriter.Services.PromptHistoryService.MarkSent
void MarkSent(string prompt)
Definition
PromptHistoryService.cs:114
FamiliesAutoWriter.Services.PromptHistoryService.Save
void Save()
Definition
PromptHistoryService.cs:177
FamiliesAutoWriter.Services.PromptHistoryService.PromptHistoryService
PromptHistoryService()
Definition
PromptHistoryService.cs:54
FamiliesAutoWriter.Services.PromptHistoryService._fileGate
static readonly object _fileGate
Definition
PromptHistoryService.cs:26
FamiliesAutoWriter.Services.PromptHistoryService.Hash
static string Hash(string s)
Definition
PromptHistoryService.cs:204
FamiliesAutoWriter.Services.PromptHistoryService.IsDuplicate
bool IsDuplicate(string prompt)
Definition
PromptHistoryService.cs:88
Services
PromptHistoryService.cs
다음에 의해 생성됨 :
1.17.0