Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
3fc1302
style: remove unused using
Grey-Wind Dec 21, 2024
e405fca
docs: change some comments
Grey-Wind Dec 21, 2024
f0f43e8
docs: add "How To Use" file
Grey-Wind Dec 22, 2024
9a0aa6c
写三个新方法用于读取不同大小的文件文件
Grey-Wind Dec 23, 2024
21800da
统一传参
Grey-Wind Dec 23, 2024
5cb8fe1
扩大缓存
Grey-Wind Dec 23, 2024
fa35dad
加入自动readfile判断
Grey-Wind Dec 23, 2024
9750411
删除无用代码
Grey-Wind Dec 24, 2024
ecc0291
移除对旧版本的支持
Grey-Wind Dec 24, 2024
c8e9a4d
优化读取代码
Grey-Wind Dec 24, 2024
692f409
优化测试代码
Grey-Wind Dec 24, 2024
41b856e
删除无法使用的测试代码
Grey-Wind Dec 24, 2024
097b1ef
优化读取代码
Grey-Wind Dec 24, 2024
364a659
优化测试代码
Grey-Wind Dec 24, 2024
d815c53
重命名文件
Grey-Wind Dec 24, 2024
a66e61e
快速缓存支持
Grey-Wind Dec 27, 2024
80eeca3
更新readme
Grey-Wind Dec 27, 2024
4920f4e
更新版本号
Grey-Wind Dec 27, 2024
9c48a8b
feat: 使用接口
Grey-Wind Dec 27, 2024
a218cc1
refactor: 代码略微优化
Grey-Wind Dec 27, 2024
870ca7f
docs: 更新版本号
Grey-Wind Dec 27, 2024
3449d16
docs: 调整打包设置
Grey-Wind Dec 27, 2024
54268c9
feat: 尝试使用更快的并发词典
Grey-Wind Dec 27, 2024
dd32742
Merge branch 'main' into v1.0.0
Grey-Wind Dec 27, 2024
510cbf4
refactor: 使用抽象类来过渡接口与实现
Grey-Wind Dec 28, 2024
d12e130
docs: 添加更新日志
Grey-Wind Dec 28, 2024
9b48b27
Merge branch 'v1.0.0' of https://github.com/Grey-Wind/TYLDDB-CSharp i…
Grey-Wind Dec 28, 2024
88c56c4
Merge branch 'main' into v1.0.0
Grey-Wind Dec 28, 2024
8a1047d
docs: 修改版权声明
Grey-Wind Dec 28, 2024
be42d7a
docs: 修正版权许可名称
Grey-Wind Dec 28, 2024
42cf92d
docs: 删除旧的发行日志
Grey-Wind Dec 28, 2024
91a965f
docs: 优化注释
Grey-Wind Dec 28, 2024
70213e7
docs: 更新版本号
Grey-Wind Dec 28, 2024
4cdb916
test: 设置单独的类来进行时间测试,而不是很多一样的代码
Grey-Wind Dec 28, 2024
ddbb9ba
feat: 添加写入文件的代码
Grey-Wind Dec 28, 2024
0a42304
test: 写入文件的测试代码
Grey-Wind Dec 28, 2024
c91cbf4
refactor: 简化using
Grey-Wind Dec 29, 2024
c04c3aa
feat: parser
Grey-Wind Dec 29, 2024
9f2c010
feat: rewrite parser
Grey-Wind Dec 29, 2024
47ab038
docs: update release notes
Grey-Wind Dec 29, 2024
104d9de
Merge branch 'main' into v1.0.0
Grey-Wind Dec 29, 2024
be97a20
feat: 优化文件路径输入验证
Grey-Wind Dec 30, 2024
c11689f
chore: 删除不需要的触发器
Grey-Wind Dec 30, 2024
4779471
style: 修改类名
Grey-Wind Dec 30, 2024
1cf749d
feat: 字符串缓存测试
Grey-Wind Dec 30, 2024
23167eb
delete test proj
Grey-Wind Dec 30, 2024
e66327d
refactor: 重构缓存代码结构
Grey-Wind Dec 30, 2024
e3147fd
refactor: 删除接口
Grey-Wind Dec 30, 2024
81ae0b6
feat: 添加int类型缓存
Grey-Wind Dec 30, 2024
c539e61
feat: 添加long类型缓存
Grey-Wind Dec 30, 2024
4b15912
feat: 信号线程锁缓存全部完成
Grey-Wind Dec 30, 2024
541b5be
feat: 并发词典缓存全部完成
Grey-Wind Dec 30, 2024
201e2c6
Merge https://github.com/TYLDDB/TYLDDB-CSharp into v1.0.0
Grey-Wind Dec 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions TYLDDB-CSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TYLDDB.Test", "TYLDDB.Test\TYLDDB.Test.csproj", "{FDFD566C-CB13-43EB-970E-0EC0A21E36C0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TYLDDB.Utils.FastCache.Test", "TYLDDB.Utils.FastCache.Test\TYLDDB.Utils.FastCache.Test.csproj", "{A58C0A6B-9BD4-4B29-9B5F-5FDFB849D23B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{95BC8FAF-AB03-44A3-A7E7-8E42FA7138E3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TYLDDB.Utils.Writer.Test", "TYLDDB.Utils.Writer.Test\TYLDDB.Utils.Writer.Test.csproj", "{1BA4CC53-078F-4943-B8EF-A522DA9E5060}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TimeRecord", "TimeRecord\TimeRecord.csproj", "{F95CF6BC-2255-47F8-AAB3-B7812BB2894D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TYLDDB.Parser.Test", "TYLDDB.Parser.Test\TYLDDB.Parser.Test.csproj", "{0B96CCF3-16C7-4B18-9D07-A19D5D8E9641}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -36,32 +30,17 @@ Global
{FDFD566C-CB13-43EB-970E-0EC0A21E36C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FDFD566C-CB13-43EB-970E-0EC0A21E36C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FDFD566C-CB13-43EB-970E-0EC0A21E36C0}.Release|Any CPU.Build.0 = Release|Any CPU
{A58C0A6B-9BD4-4B29-9B5F-5FDFB849D23B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A58C0A6B-9BD4-4B29-9B5F-5FDFB849D23B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A58C0A6B-9BD4-4B29-9B5F-5FDFB849D23B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A58C0A6B-9BD4-4B29-9B5F-5FDFB849D23B}.Release|Any CPU.Build.0 = Release|Any CPU
{1BA4CC53-078F-4943-B8EF-A522DA9E5060}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1BA4CC53-078F-4943-B8EF-A522DA9E5060}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1BA4CC53-078F-4943-B8EF-A522DA9E5060}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1BA4CC53-078F-4943-B8EF-A522DA9E5060}.Release|Any CPU.Build.0 = Release|Any CPU
{F95CF6BC-2255-47F8-AAB3-B7812BB2894D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F95CF6BC-2255-47F8-AAB3-B7812BB2894D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F95CF6BC-2255-47F8-AAB3-B7812BB2894D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F95CF6BC-2255-47F8-AAB3-B7812BB2894D}.Release|Any CPU.Build.0 = Release|Any CPU
{0B96CCF3-16C7-4B18-9D07-A19D5D8E9641}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0B96CCF3-16C7-4B18-9D07-A19D5D8E9641}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B96CCF3-16C7-4B18-9D07-A19D5D8E9641}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B96CCF3-16C7-4B18-9D07-A19D5D8E9641}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{FDFD566C-CB13-43EB-970E-0EC0A21E36C0} = {95BC8FAF-AB03-44A3-A7E7-8E42FA7138E3}
{A58C0A6B-9BD4-4B29-9B5F-5FDFB849D23B} = {95BC8FAF-AB03-44A3-A7E7-8E42FA7138E3}
{1BA4CC53-078F-4943-B8EF-A522DA9E5060} = {95BC8FAF-AB03-44A3-A7E7-8E42FA7138E3}
{F95CF6BC-2255-47F8-AAB3-B7812BB2894D} = {95BC8FAF-AB03-44A3-A7E7-8E42FA7138E3}
{0B96CCF3-16C7-4B18-9D07-A19D5D8E9641} = {95BC8FAF-AB03-44A3-A7E7-8E42FA7138E3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {19390089-354C-41AD-AF7D-9FB3998A88EA}
Expand Down
8 changes: 6 additions & 2 deletions TYLDDB.Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@
}
WriteTime("从发起读取数据库名称到成功返回读取内容的总时间为: ", readAllDbNameTimer.ElapsedMilliseconds());



///////////////////////////////////////////////////////////////////////////////////////////////////////// 数据库解析缓存
HighPrecisionTimer parseDbTimer = new(); // 从发起解析文件到成功解析并写入缓存的总时间
parseDbTimer.Start();
await lddb.ParseAsync();
parseDbTimer.Stop();
WriteTime("从发起解析文件到成功解析并写入缓存的总时间: ", parseDbTimer.ElapsedMilliseconds());



Expand Down
149 changes: 0 additions & 149 deletions TYLDDB.Utils.FastCache.Test/Program.cs

This file was deleted.

15 changes: 0 additions & 15 deletions TYLDDB.Utils.FastCache.Test/TYLDDB.Utils.FastCache.Test.csproj

This file was deleted.

2 changes: 1 addition & 1 deletion TYLDDB/Parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace TYLDDB.Parser
/// Data type parser.<br />
/// 数据类型解析器。
/// </summary>
public class Parser
public class DataParser
{
// 定义正则表达式来匹配键值对(类型::"key"="value")
private readonly static string pattern = @"(?<=^|\s)(\w+)\s*::\s*""([^""]+)""";
Expand Down
62 changes: 51 additions & 11 deletions TYLDDB/TYLDDB.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using TYLDDB.Basic;
using TYLDDB.Parser;
using TYLDDB.Utils;
using TYLDDB.Utils.FastCache;
using TYLDDB.Utils.FastCache.ConcurrentDictionary;
using TYLDDB.Utils.FastCache.SemaphoreThreadLock;

namespace TYLDDB
{
Expand All @@ -27,10 +29,9 @@ public LDDB()
private string _database; // 存储正在访问的数据库
private string _databaseContent; // 存储数据库内容
private bool _isRead = false; // 是否已调用读取文件
private event Action OnFileReadComplete;
private Database database = new Database();
private Cache cdCache = new ConcurrentDictionary();
private Cache stlCache = new SemaphoreThreadLock();
private CdStringDictionary cdStringDictionary = new CdStringDictionary();
private StlStringDictionary StlStringDictionary = new StlStringDictionary();

///////////////////////////////////////////////////// 公开字段
/// <summary>
Expand All @@ -39,11 +40,16 @@ public LDDB()
/// </summary>
public string FilePath
{
get => _filePath; // 获取文件路径
get
{
return _filePath; // 获取文件路径
}
set
{
ValidateFilePath(value); // 在设置值之前进行验证
_filePath = value; // 只有通过验证后才设置值
if (ValidateFilePath(value)) // 在设置值之前进行验证
{
_filePath = value;
}
}
}
/// <summary>
Expand All @@ -57,12 +63,15 @@ public string FilePath
/// </summary>
/// <param name="path">路径</param>
/// <exception cref="FilePathIsNullOrWhiteSpace"></exception>
private static void ValidateFilePath(string path)
/// <returns>If <c>true</c>, it can be used, if <c>false</c>, it cannot be used.<br />如果为<c>true</c>则可以使用,若为<c>false</c>则不可使用。</returns>
private static bool ValidateFilePath(string path)
{
if (string.IsNullOrWhiteSpace(path))
{
return false;
throw new FilePathIsNullOrWhiteSpace("文件路径不能为 null 或空白");
}
return true;
}

/// <summary>
Expand All @@ -80,7 +89,7 @@ public void ReadingFile()
/// 设置要加载的数据库
/// </summary>
/// <param name="db">name of the database<br/>数据库名称</param>
public void LoadDatabase(string db)
public async void LoadDatabase(string db)
{
switch (_isRead)
{
Expand All @@ -92,6 +101,7 @@ public void LoadDatabase(string db)
_databaseContent = database.GetDatabaseContent(_fileContent, db);
break;
}
await ParseAsync();
}

/// <summary>
Expand All @@ -105,5 +115,35 @@ public void LoadDatabase(string db)
/// 读取全部数据库的名称
/// </summary>
public void ReadAllDatabaseName() => AllDatabaseName = database.GetDatabaseList(_fileContent);

/// <summary>
/// Reparse the entire database.<br />
/// 重新解析整个数据库。
/// </summary>
public async Task ParseAsync()
{
// 创建多个任务,并使用 LongRunning 来确保每个任务在独立线程中运行
Task cdStringCacheTask = Task.Factory.StartNew(() => CdString(), TaskCreationOptions.LongRunning);
//Task cdIntCacheTask = Task.Factory.StartNew(() => CdInt(), TaskCreationOptions.LongRunning);
//Task cdShortCacheTask = Task.Factory.StartNew(() => CdShort(), TaskCreationOptions.LongRunning);

// 等待所有任务完成
await Task.WhenAll(cdStringCacheTask);

async void CdString()
{
var dict = DataParser.ParseString(_databaseContent);

// 遍历 dict 中的每一项
foreach (var kvp in dict)
{
var key = kvp.Key; // 获取第一个值 (key)
var value = kvp.Value; // 获取第二个值 (value)

// 将 key-value 对存储到缓存
await cdStringDictionary.SetAsync(key, value);
}
}
}
}
}
2 changes: 1 addition & 1 deletion TYLDDB/TYLDDB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.1;net6.0;net8.0;net9.0</TargetFrameworks>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>TYLDDB.NET</Title>
<Version>1.0.0-alpha.3</Version>
<Version>1.0.0-alpha.4</Version>
<Authors>TYLDDB-Project</Authors>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
Expand Down
Loading
Loading