Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit 6ae4ede

Browse files
committed
format code
1 parent cc773c2 commit 6ae4ede

File tree

16 files changed

+218
-131
lines changed

16 files changed

+218
-131
lines changed

build/Program.cs

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,20 @@ public override void Run(BuildContext context)
113113
// context.CopyDirectory(srcDir, midDir);
114114

115115
var ptn =
116-
@"Clipboar.+\.dll|" +
117-
@".+\.png|" +
118-
@"Dapper\.dll|" +
119-
@"plugin\.json|H\.InputSimulator\.dll|" +
120-
@"SQLitePCLRaw.+\.dll|Microsoft.+(S|s)qlite\.dll";
116+
@"Clipboar.+\.dll|"
117+
+ @".+\.png|"
118+
+ @"Dapper\.dll|"
119+
+ @"plugin\.json|H\.InputSimulator\.dll|"
120+
+ @"SQLitePCLRaw.+\.dll|Microsoft.+(S|s)qlite\.dll";
121121
var files = context.GetFiles($"{srcDir}/**/*");
122122
FilePath? versionFile = null;
123123
foreach (var f in files)
124124
{
125125
var fStr = f.ToString();
126126
var fName = f.GetFilename().ToString();
127-
if (fStr == null || fName == null) continue;
128-
if (fStr.EndsWith("e_sqlite3.dll") && ! fStr.EndsWith(".e_sqlite3.dll"))
127+
if (fStr == null || fName == null)
128+
continue;
129+
if (fStr.EndsWith("e_sqlite3.dll") && !fStr.EndsWith(".e_sqlite3.dll"))
129130
{
130131
files.Remove(f);
131132
continue;
@@ -146,11 +147,12 @@ public override void Run(BuildContext context)
146147
.Combine($"{context.BuildFor}")
147148
.Combine("native")
148149
.CombineWithFilePath(new FilePath("e_sqlite3.dll"));
149-
context.CopyFile(
150-
eSqlite3Path,
151-
srcDir.CombineWithFilePath("e_sqlite3.dll"));
150+
context.CopyFile(eSqlite3Path, srcDir.CombineWithFilePath("e_sqlite3.dll"));
152151
files.Add(srcDir.CombineWithFilePath("e_sqlite3.dll"));
153-
context.DeleteDirectory(srcDir.Combine("runtimes"), new DeleteDirectorySettings() { Recursive = true });
152+
context.DeleteDirectory(
153+
srcDir.Combine("runtimes"),
154+
new DeleteDirectorySettings() { Recursive = true }
155+
);
154156

155157
if (versionFile != null)
156158
{
@@ -191,30 +193,36 @@ public override void Run(BuildContext context)
191193
[IsDependentOn(typeof(CleanTask))]
192194
[IsDependentOn(typeof(BuildTask))]
193195
[IsDependentOn(typeof(PublishTask))]
194-
public class DefaultTask : FrostingTask
195-
{
196-
}
196+
public class DefaultTask : FrostingTask { }
197197

198198
[TaskName("Deploy")]
199199
public class DeployTask : FrostingTask<BuildContext>
200200
{
201201
public override void Run(BuildContext context)
202202
{
203203
var builder = context.DefaultSln.Value.Projects.First(p => p.Name.EndsWith("Build"));
204-
var distDir = builder.Path.GetDirectory().GetParent().Combine(new DirectoryPath(context.PublishDir));
204+
var distDir = builder.Path
205+
.GetDirectory()
206+
.GetParent()
207+
.Combine(new DirectoryPath(context.PublishDir));
205208
var files = context.GetFiles($"{distDir}/ClipboardR*.zip");
206209

207210
DateTime t = DateTime.FromFileTime(0);
208211
FilePath mostRecentFile = files.First();
209212
foreach (var f in files)
210213
{
211-
if (File.GetCreationTime(f.FullPath) <= t) continue;
214+
if (File.GetCreationTime(f.FullPath) <= t)
215+
continue;
212216
t = File.GetCreationTime(f.FullPath);
213217
mostRecentFile = f;
214218
}
215219

216-
context.Unzip(mostRecentFile,
217-
new DirectoryPath(@"%APPDATA%/FlowLauncher/Plugins" + mostRecentFile.GetFilenameWithoutExtension()));
220+
context.Unzip(
221+
mostRecentFile,
222+
new DirectoryPath(
223+
@"%APPDATA%/FlowLauncher/Plugins" + mostRecentFile.GetFilenameWithoutExtension()
224+
)
225+
);
218226
}
219227
}
220228

@@ -230,4 +238,4 @@ public class VersionInfo
230238
public string? Website { get; set; }
231239
public string? IcoPath { get; set; }
232240
public string? ExecuteFileName { get; set; }
233-
}
241+
}

src/ClipboardR.Core.Test/DbHelperTest.cs

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,38 +44,42 @@ public DbHelperTest(ITestOutputHelper testOutputHelper)
4444
public ClipboardData GetRandomClipboardData()
4545
{
4646
var rand = new Random();
47-
var data =
48-
new ClipboardData()
49-
{
50-
HashId = Utils.GetGuid(),
51-
Text = Utils.RandomString(10),
52-
Type = (CbContentType)rand.Next(3),
53-
Data = Utils.RandomString(10),
54-
SenderApp = Utils.RandomString(5)+".exe",
55-
DisplayTitle = Utils.RandomString(10),
56-
IconPath = _defaultIconPath,
57-
Icon = new BitmapImage(new Uri(_defaultIconPath, UriKind.RelativeOrAbsolute)),
58-
PreviewImagePath = _defaultIconPath,
59-
Score = rand.Next(1000),
60-
InitScore = rand.Next(1000),
61-
Time = DateTime.Now,
62-
Pined = false,
63-
CreateTime = DateTime.Now,
64-
};
47+
var data = new ClipboardData()
48+
{
49+
HashId = Utils.GetGuid(),
50+
Text = Utils.RandomString(10),
51+
Type = (CbContentType)rand.Next(3),
52+
Data = Utils.RandomString(10),
53+
SenderApp = Utils.RandomString(5) + ".exe",
54+
DisplayTitle = Utils.RandomString(10),
55+
IconPath = _defaultIconPath,
56+
Icon = new BitmapImage(new Uri(_defaultIconPath, UriKind.RelativeOrAbsolute)),
57+
PreviewImagePath = _defaultIconPath,
58+
Score = rand.Next(1000),
59+
InitScore = rand.Next(1000),
60+
Time = DateTime.Now,
61+
Pined = false,
62+
CreateTime = DateTime.Now,
63+
};
6564
if (data.Type == CbContentType.Image)
6665
data.Data = _defaultImage;
6766
else if (data.Type == CbContentType.Files)
68-
data.Data = new string[] { Utils.RandomString(10), Utils.RandomString(10)};
67+
data.Data = new string[] { Utils.RandomString(10), Utils.RandomString(10) };
6968
return data;
7069
}
7170

7271
[Fact]
7372
public void TestCreateDb()
7473
{
75-
var helper = new DbHelper("TestDb", mode: SqliteOpenMode.Memory, cache: SqliteCacheMode.Shared);
74+
var helper = new DbHelper(
75+
"TestDb",
76+
mode: SqliteOpenMode.Memory,
77+
cache: SqliteCacheMode.Shared
78+
);
7679
_testOutputHelper.WriteLine(helper.Connection.ConnectionString);
7780
helper.CreateDb();
78-
var sql = @"SELECT name from sqlite_master WHERE name IN ('record', 'assets') ORDER BY name ASC;";
81+
var sql =
82+
@"SELECT name from sqlite_master WHERE name IN ('record', 'assets') ORDER BY name ASC;";
7983
var r = helper.Connection.Query(sql).AsList();
8084
Assert.True(r.Count == 2 && r[0].name == "assets" && r[1].name == "record");
8185
helper.Close();
@@ -86,7 +90,11 @@ public async void TestInsertRecord()
8690
{
8791
// test text
8892
var exampleTextRecord = GetRandomClipboardData();
89-
var helper = new DbHelper("TestDb", mode: SqliteOpenMode.Memory, cache: SqliteCacheMode.Shared);
93+
var helper = new DbHelper(
94+
"TestDb",
95+
mode: SqliteOpenMode.Memory,
96+
cache: SqliteCacheMode.Shared
97+
);
9098
helper.CreateDb();
9199
helper.AddOneRecord(exampleTextRecord);
92100
var c = (await helper.GetAllRecord()).First();
@@ -102,11 +110,18 @@ public async void TestInsertRecord()
102110
[InlineData(2, "2023-05-28 11:35:00.1+08:00", 72)]
103111
public async void TestDeleteRecordBefore(int type, string creatTime, int keepTime)
104112
{
105-
var helper = new DbHelper("TestDb", mode: SqliteOpenMode.Memory, cache: SqliteCacheMode.Shared);
113+
var helper = new DbHelper(
114+
"TestDb",
115+
mode: SqliteOpenMode.Memory,
116+
cache: SqliteCacheMode.Shared
117+
);
106118
helper.CreateDb();
107119
var now = DateTime.Now;
108120
var ctime = DateTime.ParseExact(
109-
creatTime, "yyyy-MM-dd HH:mm:ss.fzzz", CultureInfo.CurrentCulture);
121+
creatTime,
122+
"yyyy-MM-dd HH:mm:ss.fzzz",
123+
CultureInfo.CurrentCulture
124+
);
110125
var spans = Enumerable.Range(0, 5000).Skip(12).Select(i => TimeSpan.FromHours(i));
111126
foreach (var s in spans)
112127
{
@@ -117,9 +132,9 @@ public async void TestDeleteRecordBefore(int type, string creatTime, int keepTim
117132
// helper.Connection.BackupDatabase(new SqliteConnection("Data Source=a.db"));
118133

119134
helper.DeleteRecordByKeepTime(type, keepTime);
120-
135+
121136
var recordsAfterDelete = await helper.GetAllRecord();
122-
foreach (var record in recordsAfterDelete.Where(r=>r.Type==(CbContentType)type))
137+
foreach (var record in recordsAfterDelete.Where(r => r.Type == (CbContentType)type))
123138
{
124139
var expTime = record.CreateTime + TimeSpan.FromHours(keepTime);
125140
if (expTime < now)
@@ -128,4 +143,4 @@ public async void TestDeleteRecordBefore(int type, string creatTime, int keepTim
128143
}
129144
helper.Close();
130145
}
131-
}
146+
}

src/ClipboardR.Core.Test/ExtensionTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ public void TestStringToMd5(string s, string md5)
5555
_testOutputHelper.WriteLine(s.GetMd5());
5656
Assert.True(s.GetMd5() == md5);
5757
}
58-
}
58+
}

src/ClipboardR.Core.Test/Usings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
global using Xunit;
1+
global using Xunit;

src/ClipboardR.Core/DbHelper.cs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,23 @@ public async void DeleteOneRecord(ClipboardData clipboardData)
113113
{
114114
var dataMd5 = clipboardData.DataToString().GetMd5();
115115
var sql = "SELECT COUNT() FROM record WHERE data_md5=@DataMd5;";
116-
var count = await Connection.QueryFirstAsync<int>(sql, new {DataMd5=dataMd5});
116+
var count = await Connection.QueryFirstAsync<int>(sql, new { DataMd5 = dataMd5 });
117117
// count > 1 means there are more than one record in table `record`
118118
// depends on corresponding record in table `assets`, in this condition,
119119
// we only delete record in table `record`
120120
sql = "DELETE FROM record WHERE hash_id=@HashId OR data_md5=@DataMd5;";
121121
if (count > 1)
122-
await Connection.ExecuteAsync(sql,new { HashId=clipboardData.HashId, DataMd5=dataMd5 });
122+
await Connection.ExecuteAsync(
123+
sql,
124+
new { HashId = clipboardData.HashId, DataMd5 = dataMd5 }
125+
);
123126
// otherwise, no record depends on assets, directly delete records
124127
// **both** in `record` and `assets` using foreign key constraint,
125128
// i.e., ON DELETE CASCADE
126129
else
127130
{
128131
sql = "PRAGMA foreign_keys = ON; DELETE FROM assets WHERE md5=@DataMd5;";
129-
await Connection.ExecuteAsync(sql, new {DataMd5=dataMd5});
132+
await Connection.ExecuteAsync(sql, new { DataMd5 = dataMd5 });
130133
}
131134
CloseIfNotKeep();
132135
}
@@ -137,18 +140,20 @@ public async void DeleteAllRecords()
137140
await Connection.ExecuteAsync(sql);
138141
CreateDb();
139142
}
140-
143+
141144
public async void PinOneRecord(ClipboardData clipboardData)
142145
{
143146
var sql = "UPDATE record SET pined=@Pin WHERE hash_id=@HashId";
144-
await Connection.ExecuteAsync(sql, new { Pin=clipboardData.Pined, HashId=clipboardData.HashId });
147+
await Connection.ExecuteAsync(
148+
sql,
149+
new { Pin = clipboardData.Pined, HashId = clipboardData.HashId }
150+
);
145151
CloseIfNotKeep();
146152
}
147153

148154
public async Task<LinkedList<ClipboardData>> GetAllRecord()
149155
{
150-
var sql =
151-
"""
156+
var sql = """
152157
SELECT r.id as Id, a.data_b64 as DataMd5, r.text as Text, r.display_title as DisplayTitle,
153158
r.senderapp as SenderApp, r.icon_path as IconPath, b.data_b64 as IconMd5,
154159
r.preview_image_path as PreviewImagePath, r.content_type as ContentType,
@@ -166,13 +171,15 @@ FROM record r
166171

167172
public async void DeleteRecordByKeepTime(int contentType, int keepTime)
168173
{
169-
var sql =
170-
"""
174+
var sql = """
171175
DELETE FROM record
172176
WHERE strftime('%s', 'now') - strftime('%s', create_time) > @KeepTime*3600
173177
AND content_type=@ContentType;
174178
""";
175-
var r = await Connection.ExecuteAsync(sql, new { KeepTime=keepTime, ContentType=contentType});
179+
var r = await Connection.ExecuteAsync(
180+
sql,
181+
new { KeepTime = keepTime, ContentType = contentType }
182+
);
176183
CloseIfNotKeep();
177184
}
178185

@@ -220,9 +227,17 @@ public class Record
220227
public int Score { get; set; }
221228
public int InitScore { get; set; }
222229
public DateTime _time;
223-
public string Time { get=>_time.ToString("O"); set=>_time=DateTime.Parse(value); }
230+
public string Time
231+
{
232+
get => _time.ToString("O");
233+
set => _time = DateTime.Parse(value);
234+
}
224235
public DateTime _create_time;
225-
public string CreateTime { get=>_create_time.ToString("O"); set=>_create_time=DateTime.Parse(value); }
236+
public string CreateTime
237+
{
238+
get => _create_time.ToString("O");
239+
set => _create_time = DateTime.Parse(value);
240+
}
226241
public bool Pined { get; set; }
227242

228243
public static Record FromClipboardData(ClipboardData data)
@@ -287,6 +302,5 @@ public static ClipboardData ToClipboardData(Record record)
287302
}
288303

289304
return clipboardData;
290-
291305
}
292306
}

src/ClipboardR.Core/Enums.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ public enum CbResultType
2020
{
2121
Record,
2222
Clear,
23-
}
23+
}

src/ClipboardR.Core/Extension.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static string GetMd5(this string s)
5757
var hex = hash.Select(i => i.ToString("X2"));
5858
return string.Join("", hex);
5959
}
60-
60+
6161
public static string GetSha256(this string s)
6262
{
6363
byte[] inputBytes = Encoding.UTF8.GetBytes(s);
@@ -73,4 +73,4 @@ public static string GetSha256(this string s)
7373
// bf.Serialize();
7474
// return Convert.ToBase64String(m.ToArray());
7575
// }
76-
}
76+
}

src/ClipboardR.Core/Struct.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public override int GetHashCode()
3434
return hashcode;
3535
}
3636

37-
public static bool operator == (ClipboardData a, ClipboardData b) => a.HashId == b.HashId;
37+
public static bool operator ==(ClipboardData a, ClipboardData b) => a.HashId == b.HashId;
3838

3939
public static bool operator !=(ClipboardData a, ClipboardData b) => a.HashId != b.HashId;
4040

@@ -71,4 +71,4 @@ public override string ToString()
7171
{
7272
return $"ClipboardDate(type: {Type}, text: {Text}, ctime: {CreateTime})";
7373
}
74-
}
74+
}

0 commit comments

Comments
 (0)