breakpoint

This commit is contained in:
CortexCore
2023-09-15 23:02:46 +08:00
parent f6bf8fffe3
commit eabf0c6188
43 changed files with 1701 additions and 1582 deletions

View File

@@ -1,6 +1,8 @@
#if Deprecated
using Godot;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using BITKit;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@@ -11,11 +13,18 @@ public partial class IDIS_RegisterDB : FormDBProvider
{
public override void Submit(string data)
{
var jObject = JsonConvert.DeserializeObject<JObject>(data);
var handle = jObject["handle"]!.ToObject<string>();
var values = jObject["values"]!.ToObject<List<IDIS_Data>>();
var references = jObject["references"]!.ToObject<List<string>>();
var createUser = jObject["createUser"]!.ToObject<string>();
if(Regex.IsMatch(handle,IDIS_Code.AddressRegex) is false)
{
throw new InvalidOperationException("标识格式不正确");
}
IDIS_Service.Singleton.Register(handle, createUser);
foreach (var x in values)
@@ -29,3 +38,4 @@ public partial class IDIS_RegisterDB : FormDBProvider
}
}
}
#endif

View File

@@ -1,3 +1,4 @@
#if Deprecated
using Godot;
using System;
using System.Collections.Generic;
@@ -104,3 +105,4 @@ public partial class IDIS_RegisterWeaver : FormWeaverResource
container.lineEdit.TextChanged += x => _references[myIndex] = x;
}
}
#endif

View File

@@ -1,3 +1,4 @@
#if Deprecated
using Godot;
using System;
@@ -17,3 +18,4 @@ public partial class IDIS_AutoRegResource : Resource
[Export] public string RefHandleSeed;
}
#endif

View File

@@ -1,3 +1,4 @@
#if deprecated
using Godot;
using System;
using System.Collections.Generic;
@@ -83,3 +84,4 @@ public partial class IDIS_AutoRegister : Node
}
}
}
#endif

View File

@@ -0,0 +1,26 @@
using System;
using BITKit;
using Cysharp.Threading.Tasks;
using Godot;
using IDIS.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace BITFactory;
/// <summary>
/// 标识码注册与查询服务
/// </summary>
public partial class IDIS_GodotBasedService:EntityComponent
{
public override void BuildService(IServiceCollection serviceCollection)
{
serviceCollection.AddTransient<IDIS_Service, IDIS_Service_SQLite>();
}
public override async void OnStart()
{
base.OnStart();
var service = Entity.ServiceProvider.GetRequiredService<IDIS_Service>();
await service.IsExistAsync("123");
}
}

View File

@@ -1,3 +1,5 @@
#if Deprecated
using Godot;
using System;
using System.Globalization;
@@ -156,8 +158,7 @@ public partial class IDIS_SearchService : Node
DisplayServer.ClipboardSet(currentHandle);
}
}
#endif

View File

@@ -1,310 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Net.Mime;
using System.Reflection.Metadata;
using BITKit;
using Cysharp.Threading.Tasks;
using Godot;
using Microsoft.EntityFrameworkCore;
using Constant = BITKit.Constant;
namespace BITFactory;
// ReSharper disable once IdentifierTypo
[Serializable]
public abstract class IDIS_Base
{
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreateTime { get; set; }=DateTime.Now;
/// <summary>
/// 更新时间
/// </summary>
public DateTime UpdateTime { get; set; }=DateTime.Now;
}
// ReSharper disable once IdentifierTypo
/// <summary>
/// 标识的值
/// </summary>
[Serializable]
public class IDIS_Value:IDIS_Base
{
/// <summary>
/// 标识码
/// </summary>
[Key]
public string Handle { get; set; }
/// <summary>
/// 创建用户,例如:模板名称,用户名称
/// </summary>
public string CreateUser { get; set; }
}
// ReSharper disable once IdentifierTypo
public class IDIS_Query : IDIS_Value
{
// ReSharper disable once IdentifierTypo
/// <summary>
/// 关联的数据
/// </summary>
public IDIS_Data[] Datas { get; internal set; }
// ReSharper disable once IdentifierTypo
/// <summary>
/// 关联的标识引用
/// </summary>
public IDIS_Reference[] References { get; internal set; }
}
/// <summary>
/// 标识的格式
/// </summary>
[Serializable]
// ReSharper disable once IdentifierTypo
public class IDIS_Data:IDIS_Base
{
/// <summary>
/// 不需要处理这个
/// </summary>
[Key]
public int Index { get; set; }
/// <summary>
/// 标识码
/// </summary>
public string Handle { get; set; }
/// <summary>
/// 记录的名称,通常为中文
/// </summary>
public string Name { get; set; }
/// <summary>
/// 值类型,例如string,url,site
/// </summary>
public string Format { get; set; }
/// <summary>
/// 值
/// </summary>
public string Value { get; set; }
/// <summary>
/// 类型,用于解析时对数据条目进行分类
/// </summary>
public string Category { get; set; }
}
/// <summary>
/// 标识的引用或关联
/// </summary>
[Serializable]
// ReSharper disable once IdentifierTypo
public class IDIS_Reference:IDIS_Base
{
/// <summary>
/// 不需要处理这个
/// </summary>
[Key]
public int Index{ get; set; }
/// <summary>
/// 标识码
/// </summary>
public string Handle { get; set; }
/// <summary>
/// 相关联的标识
/// </summary>
public string RelatedHandle { get; set; }
}
// ReSharper disable once IdentifierTypo
public class IDIS_DBContext:DbContext
{
/// <summary>
/// 标识表
/// </summary>
private DbSet<IDIS_Value> Values { get; set; }
/// <summary>
/// 标识数据表
/// </summary>
private DbSet<IDIS_Data> Datas{ get; set; }
/// <summary>
/// 标识引用表
/// </summary>
private DbSet<IDIS_Reference> References{ get; set; }
/// <summary>
/// 确保创建数据库
/// </summary>
/// <param name="optionsBuilder"></param>
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// ReSharper disable once StringLiteralTypo
//var sql = SQLiteContextHelper.GetConnectionString("IDIS");
SQLiteContextHelper.GetConnectionSqlAndPath("IDIS",out var sql,out var path);
optionsBuilder.UseSqlite(sql);
optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.TrackAll);
BIT4Log.Log<IDIS_DBContext>($"已创建标识数据库:{path}");
}
/// <summary>
/// 查询多个标识
/// </summary>
/// <param name="key">模糊标识码</param>
/// <param name="queries">查询列表</param>
/// <returns>是否查询到了内容</returns>
public bool Query(string key, out IDIS_Query[] queries)
{
ChangeTracker.DetectChanges();
ChangeTracker.Clear();
var _data = Datas.ToList();
var _values = Values.ToList();
var handleKey = key.Split('?').First();
var _queries=_values.Where(x => x.Handle.Contains(handleKey) || (string.IsNullOrEmpty(x.CreateUser) is false && x.CreateUser.Contains(handleKey))).ToArray();
var searchEnties =new List<KeyValuePair<string, string>>();
if (_queries.Any() is false)
{
queries = Array.Empty<IDIS_Query>();
return false;
}
if (key.Contains('?'))
{
var expression = key.Split("?", 2).Last();
foreach (var cmd in expression.Split("&").Where(x=>x.Contains('=')).Where(x=>x.Split('=').Length is 2)) {
var split = cmd.Split('=',2);
var name = split[0];
var value = split[1];
searchEnties.Add(new KeyValuePair<string, string>(name,value));
var validData = _data.Where(x => x.Name == name && x.Value == value);
if (_queries.Any())
{
validData = validData.Where(x=>_queries.Any(y=>y.Handle==x.Handle));
}
_queries=_values
.Select(x=>validData.Any(y=>x.Handle == y.Handle)?x:null)
.Where(x=>x!=null)
.ToArray();
}
}
queries = _queries.Select(x => new IDIS_Query()
{
Handle = x.Handle,
CreateTime = x.CreateTime,
UpdateTime = x.UpdateTime,
CreateUser = x.CreateUser,
Datas = Datas.Where(data => data.Handle == x.Handle).ToArray(),
References = References.Where(reference => reference.Handle == x.Handle).ToArray()
}).ToArray();
if (searchEnties.Any())
{
var newQueries = new List<IDIS_Query>();
foreach (var query in queries)
{
query.Datas = query.Datas.Where(x=>searchEnties.Any(y=>y.Key==x.Name&&y.Value==x.Value)).ToArray();
newQueries.Add(query);
}
queries=newQueries.ToArray();
}
return queries.Any();
}
/// <summary>
/// 查询单个标识
/// </summary>
/// <param name="key">模糊标识</param>
/// <param name="query">标识查询结果</param>
/// <returns>是否查询到了标识</returns>
public bool Query(string key, out IDIS_Query query)
{
Query(key, out IDIS_Query[] queries);
query = queries.FirstOrDefault();
return queries.Any();
}
public bool Register(string handle,string createUser = Constant.System.Internal)
{
var handleExists = Values.Any(x => x.Handle == handle);
if (handleExists)
{
return false;
}
var value = new IDIS_Value()
{
Handle = handle,
CreateUser = createUser,
};
Values.Add(value);
SaveChangesAsync();
return true;
}
public void Register(string handle,string name,string format, string value,string category)
{
var handleExists = Values.Any(x => x.Handle == handle);
if (!handleExists)
{
Register(handle);
}
var data = new IDIS_Data()
{
Name = name,
Handle = handle,
Format = format,
Value = value,
Category = category,
};
Datas.Add(data);
SaveChangesAsync();
}
public void RegisterReference(string handle, string refenceHandle)
{
References.Add(new IDIS_Reference()
{
Handle = handle,
RelatedHandle = refenceHandle,
});
SaveChangesAsync();
}
public bool Update(string handle, string name, string value)
{
var result = Datas.FirstOrDefault(x => x.Handle == handle && x.Name == name);
if (result is null) return false;
var handleValue = Values.FirstOrDefault(x=>x.Handle==handle);
if (handleValue != null) handleValue.UpdateTime = DateTime.Now;
result.UpdateTime=DateTime.Now;
result.Value = value;
SaveChangesAsync();
return true;
}
}
// ReSharper disable once IdentifierTypo
/// <summary>
/// 标识码注册与查询服务
/// </summary>
public partial class IDIS_Service:Node
{
public static IDIS_Service Singleton { get; private set; }
private static IDIS_DBContext Context;
public override void _Ready()
{
Context = new IDIS_DBContext();
BIT4Log.Log<IDIS_Service>("已创建标识数据库");
UniTask.Run(()=>Context.Database.EnsureCreatedAsync());
}
public override void _EnterTree()
{
Singleton = this;
}
public override void _ExitTree()
{
Context.Dispose();
Context = null;
}
public bool Query(string word,out IDIS_Query[] queries) => Context.Query(word, out queries);
public bool Register(string handle,string createUser=Constant.System.Internal) => Context.Register(handle,createUser);
public void Register(string handle,string name, string format, string value,string category) => Context.Register(handle,name, format, value,category);
public void RegisterReference(string handle,string refenceHandle) => Context.RegisterReference(handle,refenceHandle);
public static string GenerateHandle() => $"88.123.99/{Mathf.Abs(Guid.NewGuid().GetHashCode())}";
public bool Query(string key, out IDIS_Query query) => Context.Query(key, out query);
public bool Update(string handle, string name, string value) => Context.Update(handle, name, value);
}

View File

@@ -1,3 +1,4 @@
#if Deprecated
using Godot;
using System;
using System.Globalization;
@@ -124,3 +125,4 @@ public partial class IDIS_THService : Node
autoUpdateLabel.SetTextAsync($"温湿度已自动更新:{DateTime.Now}");
}
}
#endif

View File

@@ -1,3 +1,4 @@
#if Deprecated
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -164,3 +165,4 @@ public partial class IDIS_TemplateService : Node
}
}
}
#endif

View File

@@ -1,3 +1,4 @@
#if Deprecated
using Godot;
using System;
using System.Collections.Generic;
@@ -81,3 +82,4 @@ public partial class IDIS_UpdateService : Node
hintsLabel.Text=$"更新成功,已更新{values.Count}个值"+DateTime.Now;
}
}
#endif

View File

@@ -1,3 +1,4 @@
#if Deprecated
using Godot;
using System;
@@ -19,3 +20,4 @@ public partial class 生成温湿度 : Node
}
}
}
#endif