Browse Source

fixed doc and changed name EGObject to EGObjects

master
jkpete 3 weeks ago
parent
commit
21d0bd3051
  1. 27
      Example/SaveSystem/Script/ViewSaveSystem.cs
  2. 29
      Manual/ProtocolTools.md
  3. 98
      Manual/SaveTools.md
  4. 71
      ReadMe.md
  5. 12
      addons/EGFramework/Module/EGObjects.cs
  6. 3
      addons/EGFramework/Module/NodeExtension/EGGodotPath.cs
  7. 47
      addons/EGFramework/Module/SaveTools/Object/EGByteSave.cs
  8. 2
      addons/EGFramework/Module/SaveTools/Object/EGJsonSave.cs
  9. 2
      addons/EGFramework/Module/SaveTools/Object/EGRedisSave.cs
  10. 2
      addons/EGFramework/Module/SaveTools/SaveToolsInterface.cs

27
Example/SaveSystem/Script/ViewSaveSystem.cs

@ -18,6 +18,7 @@ namespace EGFramework.Examples.Test { @@ -18,6 +18,7 @@ namespace EGFramework.Examples.Test {
{
TestTree();
TestTable();
TestJson();
}
public override void _ExitTree()
@ -41,19 +42,21 @@ namespace EGFramework.Examples.Test { @@ -41,19 +42,21 @@ namespace EGFramework.Examples.Test {
'Date': new Date(123456789)
}
}";
EGJsonSave jsonManage = this.EGSave().Read<EGJsonSave>("Example", json);
GD.Print(jsonManage.GetObject<string>("CPU"));
JsonTextReader reader = new JsonTextReader(new StringReader(json));
while (reader.Read())
{
if (reader.Value != null)
{
GD.Print("Token: {"+reader.TokenType+"}, Value: {"+ reader.Value+"}");
}
else
{
GD.Print("Token: {"+ reader.TokenType+"}");
}
}
// JsonTextReader reader = new JsonTextReader(new StringReader(json));
// while (reader.Read())
// {
// if (reader.Value != null)
// {
// GD.Print("Token: {"+reader.TokenType+"}, Value: {"+ reader.Value+"}");
// }
// else
// {
// GD.Print("Token: {"+ reader.TokenType+"}");
// }
// }
}
public void TestTree()

29
Manual/ProtocolTools.md

@ -8,6 +8,8 @@ Protocol Tools允许您在任何通讯物理层发送信息、接受服务器返 @@ -8,6 +8,8 @@ Protocol Tools允许您在任何通讯物理层发送信息、接受服务器返
目前工具以发布+订阅的方式处理消息,后续会增加问答的方式处理消息。
本指南中,您将学到以下内容
- 如何在互联网&串口通讯&文件读写&进程吞吐中,发送您的请求,获取您的响应消息。
@ -15,6 +17,33 @@ Protocol Tools允许您在任何通讯物理层发送信息、接受服务器返 @@ -15,6 +17,33 @@ Protocol Tools允许您在任何通讯物理层发送信息、接受服务器返
- 自定义插拔式的开启或关闭消息处理功能。
- Protocol Tools的消息解耦原理
Protocol Tools 的结构如下
```mermaid
mindmap
root((ProtocolTools))
EGMessage
ProtocolSchedule
Internet
TCPClient
TCPServer
UDP
MQTT
SSH
WebsocketClient
WebsocketServer - Only Godot
SerialPort
Other
FileStream
Process
Soft
CommandLine
```
---
# 目录

98
Manual/SaveTools.md

@ -2,51 +2,103 @@ @@ -2,51 +2,103 @@
---
注:下述`数据`无特殊声明默认指代:对象的集合。
注:SaveTools 目前因为接口反复修改的关系,Load方法增加对象的返回值以提供更多的操作方法。下面Not Complete表示该部分功能并未开发完毕。
```mermaid
mindmap
root((SaveTools))
Data
CSV
LiteDB
Dapper
MySql
Sqlite
File
FTP
SFTP
LocalFileSystem
WebDav - Not Complete
Object
Json
Redis
Byte - Not Complete
```
## 支持的数据类型
- `Object` 对象类型的存储类型,通过key-value的方式获取对应的对象,常见的例子有Json,Redis等等。
- `Data` 数据类型的存储类型,同样通过key-Table的方式获取对应的数据表,通常为各种类型的数据库,比如MySql,Sqlite,LiteDB,CSV表格文件等等。
- `File` 文件类型的存储类型,提供对应的下载,上传接口以及各类文件系统管理接口,通常为各种文件共享服务,比如FTP,WebDav,本地文件系统等等。
SaveTools使用了两种数据格式,一种是表式存储,一种是对象存储,统一使用key-value方式存储数据,通过唯一key值锁定对应的数据。如果是只读数据,则需指定唯一标识key,读写数据,这个key值则为文件路径(唯一)。
在使用该库时,一定要保证该数据被加载。可以重复读取数据文件,如果外部进行了修改,新读取的数据会覆盖掉原来的数据。使用流程:加载数据->读写数据或者其他操作
需要在对应Godot的Node类下实现接口 `IEGFramework`
## 加载存储管理对象(可读可写)
下面演示一个打开Res文件夹的示例:
Load为可读写存储对象的加载,通常是用Path,或者数据库地址来进行实例化。
以SQLite数据库为例
```csharp
public partial class EGSaveTest : Node,IEGFramework{
public override void _Ready()
{
base._Ready();
this.EGSave().OpenResPath();
}
}
EGSqliteSave SqliteTest = this.EGSave().Load<EGSqliteSave>("SaveData/test.db");
```
数据工具类开发状态如下:
具体使用方法详见API - IEGSaveData部分。
## 读取存储管理对象(只读)
只读&非只读数据:
Read为只读存储对象的加载,通常以字符&字节流的方式来获取,由于是只读数据,仅包含相关数据的搜索,获取功能。
- [x] CSV
以Json为例
```csharp
string json = @"{
'CPU': 'Intel',
'PSU': '500W',
'Drives': [
'DVD read/writer'
/*(broken)*/,
'500 gigabyte hard drive',
'200 gigabyte hard drive'
],
'My' : {
'AA':'BB',
'Date': new Date(123456789)
}
}";
EGJsonSave jsonManage = this.EGSave().Read<EGJsonSave>("Example", json);
GD.Print(jsonManage.GetObject<string>("CPU"));
```
## 开发计划(随版本更新)
Object:
- [x] Json
- [ ] XML
- [x] Redis
- [ ] Byte
- [ ] etc...
非只读数据:
Data
- [x] LiteDB
- [x] Dapper
- [x] Sqlite
- [x] MySql
- [x] Csv
- [ ] etc...
- [x] Byte
- [ ] Sqlite
File:
- [ ] Other DataBase
- [x] LocalFile
- [x] Ftp
- [x] SFtp
- [ ] WebDav
- [ ] etc...
# API参考
---

71
ReadMe.md

@ -48,80 +48,9 @@ mindmap @@ -48,80 +48,9 @@ mindmap
EasyEvent
```
---
EGFramework - SaveTools
```mermaid
mindmap
root((SaveTools))
Data
CSV
LiteDB
Dapper
MySql
Sqlite
File
FTP
SFTP
LocalFileSystem
WebDav - Not Complete
Object
Json
Redis
Byte - Not Complete
```
---
EGFramework - ProtocolTools
```mermaid
mindmap
root((ProtocolTools))
EGMessage
ProtocolSchedule
Internet
TCPClient
TCPServer
UDP
MQTT
SSH
WebsocketClient
WebsocketServer - Only Godot
SerialPort
Other
FileStream
Process
Soft
CommandLine
```
EGFramework-GenerateTools
```mermaid
mindmap
root((Generate-Tools))
Dialog
Basic
Confirm
Edit
File
UI
EditParam
Table
Menu
Tree
Inteface
Variant
Tree
Range
Select
Path
ReadOnly
```

12
addons/EGFramework/Module/EGObjects.cs

@ -3,13 +3,13 @@ using System.Collections.Generic; @@ -3,13 +3,13 @@ using System.Collections.Generic;
namespace EGFramework
{
public interface IEGObject
public interface IEGObjects
{
void RegisterObject<T>(T object_);
T GetObject<T>() where T : class,new();
}
public class EGObject : EGModule,IEGObject
public class EGObjects : EGModule,IEGObjects
{
private IOCContainer ObjectContainer = new IOCContainer();
public override void Init()
@ -40,25 +40,25 @@ namespace EGFramework @@ -40,25 +40,25 @@ namespace EGFramework
{
public static T EGGetObject<T>(this IEGFramework self) where T : class,new()
{
return EGArchitectureImplement.Interface.GetModule<EGObject>().GetObject<T>();
return EGArchitectureImplement.Interface.GetModule<EGObjects>().GetObject<T>();
}
}
public static class CanRegisterObjectExtension
{
public static void EGRegisterObject<T>(this IArchitecture self,T object_) where T : class,new()
{
self.GetModule<EGObject>().RegisterObject(object_);
self.GetModule<EGObjects>().RegisterObject(object_);
}
public static void EGRegisterObject<T>(this IEGFramework self,T object_) where T : class,new()
{
EGArchitectureImplement.Interface.GetModule<EGObject>().RegisterObject(object_);
EGArchitectureImplement.Interface.GetModule<EGObjects>().RegisterObject(object_);
}
}
public static class CanContainsObjectExtension{
public static bool EGContainsObject<T>(this IEGFramework self)
{
return EGArchitectureImplement.Interface.GetModule<EGObject>().ContainsObject<T>();
return EGArchitectureImplement.Interface.GetModule<EGObjects>().ContainsObject<T>();
}
}

3
addons/EGFramework/Module/NodeExtension/EGGodotPath.cs

@ -18,10 +18,9 @@ namespace EGFramework{ @@ -18,10 +18,9 @@ namespace EGFramework{
}
public IArchitecture GetArchitecture()
{
throw new System.NotImplementedException();
return EGArchitectureImplement.Interface;
}
}
public static class GodotPathExtension{

47
addons/EGFramework/Module/SaveTools/Object/EGByteSave.cs

@ -17,20 +17,21 @@ namespace EGFramework @@ -17,20 +17,21 @@ namespace EGFramework
void SetBytes(byte[] byteData);
}
[Obsolete("This class is not comlpete, please not use it!")]
public class EGByteObjectSave : IEGSave,IEGSaveObject
public class EGByteObjectSave : IEGSave, IEGSaveObject
{
public Encoding StringEncoding { set; get; } = Encoding.ASCII;
private string DefaultPath { set; get; }
private uint PointerLength { get; set; }
private uint[] Pointer { get; set; }
private Dictionary<uint,byte[]> Data { get; set; }
private Dictionary<uint, byte[]> Data { get; set; }
private byte[] _Data;
public void ReadDataBlock(string path){
public void ReadDataBlock(string path)
{
DefaultPath = path;
try
{
FileStream fileStream = new FileStream(path,FileMode.OpenOrCreate);
FileStream fileStream = new FileStream(path, FileMode.OpenOrCreate);
byte[] buffer = new byte[fileStream.Length];
fileStream.Read(buffer, 0, (int)fileStream.Length);
fileStream.Close();
@ -43,11 +44,12 @@ namespace EGFramework @@ -43,11 +44,12 @@ namespace EGFramework
throw;
}
}
public void WriteDataBlock(string path){
public void WriteDataBlock(string path)
{
try
{
FileStream fileStream = File.Create(path);
fileStream.Write(_Data,0,_Data.Length);
fileStream.Write(_Data, 0, _Data.Length);
fileStream.Close();
fileStream.Dispose();
}
@ -69,26 +71,20 @@ namespace EGFramework @@ -69,26 +71,20 @@ namespace EGFramework
/// <param name="objectKey"></param>
/// <param name="obj"></param>
/// <typeparam name="TObject"></typeparam>
public void SetObject<TObject>(string objectKey , TObject obj)
public void SetObject<TObject>(string objectKey, TObject obj)
{
if(typeof(TObject).GetInterfaces().Contains(typeof(IEGByteObject))){
if (typeof(TObject).GetInterfaces().Contains(typeof(IEGByteObject)))
{
_Data = ((IEGByteObject)obj).GetBytes();
}else{
}
else
{
throw new Exception("This byte class cannot be serialized! you should implement IRequest first!");
}
WriteDataBlock(DefaultPath);
}
public TObject GetObject<TObject>(string objectKey) where TObject : new()
{
if(typeof(TObject).GetInterfaces().Contains(typeof(IEGByteObject))){
TObject result = new TObject();
((IEGByteObject)result).SetBytes(_Data);
return result;
}else{
throw new Exception("This byte class cannot be serialized! you should implement IRequest first!");
}
}
public void RemoveObject<TObject>(string objectKey)
{
@ -114,6 +110,19 @@ namespace EGFramework @@ -114,6 +110,19 @@ namespace EGFramework
{
throw new NotImplementedException();
}
public TObject GetObject<TObject>(string objectKey)
{
throw new NotImplementedException();
// if(typeof(TObject).GetInterfaces().Contains(typeof(IEGByteObject))){
// TObject result = new TObject();
// ((IEGByteObject)result).SetBytes(_Data);
// return result;
// }else{
// throw new Exception("This byte class cannot be serialized! you should implement IRequest first!");
// }
}
}
public interface IEGByteInit{

2
addons/EGFramework/Module/SaveTools/Object/EGJsonSave.cs

@ -71,7 +71,7 @@ namespace EGFramework @@ -71,7 +71,7 @@ namespace EGFramework
/// <summary>
/// Get data from file, if your data is not in file, then throw an exception.
/// </summary>
public TObject GetObject<TObject>(string objectKey) where TObject : new()
public TObject GetObject<TObject>(string objectKey)
{
if(!SaveObject.ContainsKey(objectKey)){
throw new Exception("Key not found!");

2
addons/EGFramework/Module/SaveTools/Object/EGRedisSave.cs

@ -61,7 +61,7 @@ namespace EGFramework{ @@ -61,7 +61,7 @@ namespace EGFramework{
Database.SetAdd(objectKey, JsonConvert.SerializeObject(obj));
}
public TObject GetObject<TObject>(string objectKey) where TObject : new()
public TObject GetObject<TObject>(string objectKey)
{
try
{

2
addons/EGFramework/Module/SaveTools/SaveToolsInterface.cs

@ -45,7 +45,7 @@ namespace EGFramework @@ -45,7 +45,7 @@ namespace EGFramework
#region Object
public interface IEGSaveObjectReadOnly
{
TObject GetObject<TObject>(string objectKey) where TObject : new();
TObject GetObject<TObject>(string objectKey);
IEnumerable<string> GetKeys();
bool ContainsKey(string objectKey);
}

Loading…
Cancel
Save