调整了模板
This commit is contained in:
23
Mods/工业数据采集与分析应用分享/Scripts/Builder/IDIS_RegisterDB.cs
Normal file
23
Mods/工业数据采集与分析应用分享/Scripts/Builder/IDIS_RegisterDB.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BITKit;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace BITFactory;
|
||||
[GlobalClass]
|
||||
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>>();
|
||||
|
||||
foreach (var x in values)
|
||||
{
|
||||
IDIS_Service.Singleton.Register(handle,x.Name, x.Format, x.Value,x.Category);
|
||||
}
|
||||
}
|
||||
}
|
77
Mods/工业数据采集与分析应用分享/Scripts/Builder/IDIS_RegisterWeaver.cs
Normal file
77
Mods/工业数据采集与分析应用分享/Scripts/Builder/IDIS_RegisterWeaver.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BITKit;
|
||||
|
||||
namespace BITFactory;
|
||||
[GlobalClass]
|
||||
public partial class IDIS_RegisterWeaver : FormWeaverResource
|
||||
{
|
||||
[Export] private NodePath handleEditPath;
|
||||
[Export] private NodePath generateButtonPath;
|
||||
|
||||
private LineEdit handleEdit=>formBuilder.GetNode<LineEdit>(handleEditPath);
|
||||
private Button generateButton=>formBuilder.GetNode<Button>(generateButtonPath);
|
||||
|
||||
private readonly List<IDIS_Data> _values=new();
|
||||
public override void Weaver(Control container, IFormField formField)
|
||||
{
|
||||
var field = (IDIS_TemplateForm)formField;
|
||||
|
||||
var data = new IDIS_Data();
|
||||
|
||||
var vBox = container.Create<HBoxContainer>();
|
||||
|
||||
var label = vBox.Create<Label>();
|
||||
var typeLabel = vBox.Create<Label>();
|
||||
var valueEdit = vBox.Create<LineEdit>();
|
||||
|
||||
var myIndex = _values.Count;
|
||||
_values.Add(data);
|
||||
|
||||
label.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
typeLabel.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
valueEdit.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
|
||||
label.Text = field.Name;
|
||||
typeLabel.Text = field.Type;
|
||||
valueEdit.PlaceholderText = field.DefaultValue;
|
||||
|
||||
data.Category = field.Category;
|
||||
data.Handle = handleEdit.Text;
|
||||
data.Format = field.Type;
|
||||
|
||||
valueEdit.TextChanged += x => data.Value = x;
|
||||
}
|
||||
|
||||
public override string GetContent()
|
||||
{
|
||||
if (string.IsNullOrEmpty(handleEdit.Text))
|
||||
{
|
||||
throw new InvalidOperationException("[color=red]输入的标识码为空[/color]");
|
||||
}
|
||||
|
||||
var value = new Dictionary<object, object>
|
||||
{
|
||||
{ "handle", handleEdit.Text },
|
||||
{ "values",_values},
|
||||
};
|
||||
|
||||
var json = JsonHelper.Get(value);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
public override void Clear()
|
||||
{
|
||||
_values.Clear();
|
||||
}
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
generateButton.Pressed += () =>
|
||||
{
|
||||
handleEdit.Text = IDIS_Service.GenerateHandle();
|
||||
};
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using BITKit;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BITFactory;
|
||||
|
||||
[Serializable]
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class IDIS_TemplateForm:IFormField
|
||||
{
|
||||
[JsonProperty]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty]
|
||||
public string Type { get; set; }
|
||||
[JsonProperty]
|
||||
public string DefaultValue { get; set; }
|
||||
[JsonProperty]
|
||||
public string Category { get; set; }
|
||||
public int FieldCount => 4;
|
||||
public string[] FieldNames => new string[]
|
||||
{
|
||||
nameof(Name),
|
||||
nameof(Type),
|
||||
nameof(DefaultValue),
|
||||
nameof(Category),
|
||||
};
|
||||
public string[] FieldTypes => FieldNames;
|
||||
public string[] DefaultValues => FieldNames;
|
||||
}
|
||||
|
||||
[GlobalClass]
|
||||
public partial class IDIS_TemplateFormResource : FormResource
|
||||
{
|
||||
public override string Name { get; set; }
|
||||
public override IFormField[] Fields { get; set; }
|
||||
}
|
79
Mods/工业数据采集与分析应用分享/Scripts/Builder/IDIS_TemplateResource.cs
Normal file
79
Mods/工业数据采集与分析应用分享/Scripts/Builder/IDIS_TemplateResource.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using BITKit;
|
||||
using BITKit.IO;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace BITFactory;
|
||||
[GlobalClass]
|
||||
public partial class IDIS_TemplateResource : TemplateResource
|
||||
{
|
||||
private static readonly List<FormResource> Templates=new();
|
||||
private static InitializationState state = InitializationState.None;
|
||||
private static string assetPath => PathHelper.GetPath("标识模板资源包.zip");
|
||||
private static string entryPath => "Templates.json";
|
||||
public override FormResource[] GetTemplates()
|
||||
{
|
||||
EnsureCreated();
|
||||
return Templates.ToArray();
|
||||
}
|
||||
public override string[] GetTemplateNames()
|
||||
{
|
||||
EnsureCreated();
|
||||
return Templates.Select(x => x.Name).ToArray();
|
||||
}
|
||||
public override FormResource GetTemplate(string name)
|
||||
{
|
||||
EnsureCreated();
|
||||
return Templates.Single(x => x.Name == name);
|
||||
}
|
||||
public override bool IsSupportCreateTemplate => true;
|
||||
public override void CreateTemplate()
|
||||
{
|
||||
Templates.Add(new IDIS_TemplateFormResource()
|
||||
{
|
||||
Name = "新的标识模板:"+Guid.NewGuid(),
|
||||
Fields = new IFormField[]
|
||||
{
|
||||
new IDIS_TemplateForm()
|
||||
}
|
||||
});
|
||||
}
|
||||
private void EnsureCreated()
|
||||
{
|
||||
if (state != InitializationState.None) return;
|
||||
if (File.Exists(assetPath))
|
||||
{
|
||||
foreach (var x in BITAssets.Read<KeyValuePair<string,IDIS_TemplateForm[]>[]>(assetPath, entryPath))
|
||||
{
|
||||
Templates.Add(new IDIS_TemplateFormResource()
|
||||
{
|
||||
Name = x.Key,
|
||||
Fields = x.Value.Select(_=>_ as IFormField).ToArray()
|
||||
});
|
||||
}
|
||||
}
|
||||
state = InitializationState.Initialized;
|
||||
}
|
||||
|
||||
public override void OnStop()
|
||||
{
|
||||
ManualSave();
|
||||
}
|
||||
|
||||
public override void ManualSave()
|
||||
{
|
||||
// var values = new System.Collections.Generic.Dictionary<string, List<IFormField>>(
|
||||
// Templates.Select(x=>new KeyValuePair<string, List<IFormField>>(
|
||||
// x.Key,x.Value.Fields.ToList()
|
||||
// ))
|
||||
// );
|
||||
var values = Templates.Select(x => new KeyValuePair<string, object>(
|
||||
x.Name, x.Fields
|
||||
));
|
||||
BITAssets.Build(assetPath,new BITAsset(entryPath,JsonHelper.Get(values)));
|
||||
}
|
||||
}
|
143
Mods/工业数据采集与分析应用分享/Scripts/Builder/IDIS_TemplateWeaver.cs
Normal file
143
Mods/工业数据采集与分析应用分享/Scripts/Builder/IDIS_TemplateWeaver.cs
Normal file
@@ -0,0 +1,143 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BITKit;
|
||||
|
||||
namespace BITFactory;
|
||||
[GlobalClass]
|
||||
public partial class IDIS_TemplateWeaver : FormWeaverResource
|
||||
{
|
||||
[Export] private NodePath addFieldsButtonPath;
|
||||
[Export] private NodePath templateBuilderPath;
|
||||
[Export] private NodePath templateNameEditPath;
|
||||
[Export] private NodePath saveTemplateNameButtonPath;
|
||||
private Button addFieldsButton => formBuilder.GetNode<Button>(addFieldsButtonPath);
|
||||
private TemplateBuilder templateBuilder => formBuilder.GetNode<TemplateBuilder>(templateBuilderPath);
|
||||
private LineEdit templateNameEdit => formBuilder.GetNode<LineEdit>(templateNameEditPath);
|
||||
private Button saveTemplateNameButton => formBuilder.GetNode<Button>(saveTemplateNameButtonPath);
|
||||
|
||||
private readonly List<IDIS_TemplateForm> fields = new();
|
||||
public override void Weaver(Control container, IFormField formField)
|
||||
{
|
||||
var field = formField as IDIS_TemplateForm;
|
||||
|
||||
fields.Add(field);
|
||||
|
||||
var hBox = container.Create<HBoxContainer>();
|
||||
var nameEdit = hBox.Create<LineEdit>();
|
||||
var typeButton = hBox.Create<OptionButton>();
|
||||
var defaultValueEdit = hBox.Create<LineEdit>();
|
||||
var categoryEdit = hBox.Create<LineEdit>();
|
||||
var removeButton = hBox.Create<Button>();
|
||||
|
||||
nameEdit.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
typeButton.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
defaultValueEdit.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
categoryEdit.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
|
||||
nameEdit.PlaceholderText="名称";
|
||||
typeButton.Text = "类型";
|
||||
defaultValueEdit.PlaceholderText="默认值";
|
||||
categoryEdit.PlaceholderText="分类";
|
||||
|
||||
typeButton.GetPopup().AddItem("string");
|
||||
typeButton.GetPopup().AddItem("int");
|
||||
typeButton.GetPopup().AddItem("ulong");
|
||||
typeButton.GetPopup().AddItem("double");
|
||||
typeButton.GetPopup().AddItem("h_site");
|
||||
typeButton.GetPopup().AddItem("base64");
|
||||
typeButton.GetPopup().AddItem("guid");
|
||||
|
||||
typeButton.Selected = 0;
|
||||
|
||||
nameEdit.Text = field!.Name;
|
||||
typeButton.Text = field!.Type;
|
||||
defaultValueEdit.Text = field!.DefaultValue;
|
||||
categoryEdit.Text = field!.Category;
|
||||
removeButton.Text= "删除";
|
||||
|
||||
nameEdit.TextChanged+=x=>field!.Name=x;
|
||||
typeButton.ItemSelected+=x=>field!.Type=typeButton.GetPopup().GetItemText((int)x);
|
||||
defaultValueEdit.TextChanged+=x=>field!.DefaultValue=x;
|
||||
categoryEdit.TextChanged+=x=>field!.Category=x;
|
||||
|
||||
removeButton.Pressed+=()=>
|
||||
{
|
||||
fields.Remove(field!);
|
||||
container.QueueFree();
|
||||
|
||||
var current = templateBuilder.CurrentTemplate.Fields.ToList();
|
||||
current.Remove(formField);
|
||||
templateBuilder.CurrentTemplate.Fields = current.ToArray();
|
||||
};
|
||||
}
|
||||
|
||||
public override string GetContent()
|
||||
{
|
||||
if (fields.Any(x =>
|
||||
{
|
||||
switch (x.Name, x.Type, x.DefaultValue, x.Category)
|
||||
{
|
||||
case ("", _, _, _):
|
||||
case (_, "", _, _):
|
||||
case (_, _, "", _):
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}))
|
||||
{
|
||||
throw new InvalidOperationException("请填写完整");
|
||||
}
|
||||
var value = JsonHelper.Get(fields);
|
||||
return value;
|
||||
}
|
||||
public override void Clear()
|
||||
{
|
||||
fields.Clear();
|
||||
templateNameEdit.Text = templateBuilder.CurrentTemplate?.Name;
|
||||
}
|
||||
public override void OnStart()
|
||||
{
|
||||
addFieldsButton.Pressed+=AddFields;
|
||||
|
||||
templateNameEdit.TextSubmitted+=ChangeCurrentTemplateName;
|
||||
saveTemplateNameButton.Pressed+=()=>
|
||||
{
|
||||
ChangeCurrentTemplateName(templateNameEdit.Text);
|
||||
};
|
||||
}
|
||||
private void AddFields()
|
||||
{
|
||||
var current = templateBuilder.CurrentTemplate.Fields.ToList();
|
||||
current.Add(new IDIS_TemplateForm()
|
||||
{
|
||||
|
||||
});
|
||||
templateBuilder.CurrentTemplate.Fields = current.ToArray();
|
||||
|
||||
templateBuilder.Rebuild();
|
||||
}
|
||||
|
||||
private void ChangeCurrentTemplateName(string newName)
|
||||
{
|
||||
if(templateBuilder.CurrentTemplate==null) return;
|
||||
|
||||
if (templateBuilder.template.GetTemplates().Any(x => x.Name == newName))
|
||||
// ReSharper disable once StringLiteralTypo
|
||||
newName+=DateTime.Now.ToString("mmss");
|
||||
|
||||
templateBuilder.CurrentTemplate.Name = newName;
|
||||
|
||||
templateBuilder.template.ManualSave();
|
||||
|
||||
templateBuilder.Rebuild();
|
||||
|
||||
UXContextMenu
|
||||
.Create()
|
||||
.AddAction("New PopopMenu",null)
|
||||
.Build();
|
||||
|
||||
}
|
||||
}
|
19
Mods/工业数据采集与分析应用分享/Scripts/IDIS_AutoRegResource.cs
Normal file
19
Mods/工业数据采集与分析应用分享/Scripts/IDIS_AutoRegResource.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
namespace BITFactory;
|
||||
[GlobalClass]
|
||||
public partial class IDIS_AutoRegResource : Resource
|
||||
{
|
||||
[Export] public string HandleSeed;
|
||||
|
||||
[ExportCategory("IDIS")]
|
||||
[Export] public string Format;
|
||||
[Export] public string Category;
|
||||
[Export] public string Name;
|
||||
[Export] public string Value;
|
||||
|
||||
[ExportCategory("标识引用")]
|
||||
[Export] public string RefHandleSeed;
|
||||
|
||||
}
|
85
Mods/工业数据采集与分析应用分享/Scripts/IDIS_AutoRegister.cs
Normal file
85
Mods/工业数据采集与分析应用分享/Scripts/IDIS_AutoRegister.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using BITFactory;
|
||||
using BITKit;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace BITFactory;
|
||||
public partial class IDIS_AutoRegister : Node
|
||||
{
|
||||
[Export] private Array<IDIS_AutoRegResource> regResources;
|
||||
|
||||
[ExportCategory("UI 绑定")]
|
||||
[Export] private Array<ProgressBar> progressBars;
|
||||
[Export] private RichTextLabel logLabel;
|
||||
|
||||
private readonly Queue<ProgressBar> _progressQueue = new();
|
||||
private ProgressBar _currentProgressBar;
|
||||
|
||||
private void Register()
|
||||
{
|
||||
BIT4Log.Log<IDIS_AutoRegister>("开始自动注册中...");
|
||||
var seeds = new List<string>();
|
||||
foreach (var x in regResources)
|
||||
{
|
||||
seeds.Add(x.HandleSeed);
|
||||
if (string.IsNullOrEmpty(x.RefHandleSeed) is false)
|
||||
{
|
||||
seeds.Add(x.RefHandleSeed);
|
||||
}
|
||||
}
|
||||
|
||||
seeds = seeds.Distinct().ToList();
|
||||
|
||||
var handles =
|
||||
new System.Collections.Generic.Dictionary<string, string>(seeds.Select(x =>
|
||||
new KeyValuePair<string, string>(x, IDIS_Service.GenerateHandle())));
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var x in regResources)
|
||||
{
|
||||
var handle = handles[x.HandleSeed];
|
||||
IDIS_Service.Singleton.Register(handle, x.Name, x.Format, x.Value, x.Category);
|
||||
if (string.IsNullOrEmpty(x.RefHandleSeed) is false && handles.TryGetValue(x.RefHandleSeed, out var refHandle))
|
||||
{
|
||||
IDIS_Service.Singleton.RegisterReference(handle, refHandle);
|
||||
}
|
||||
logLabel.Text+=$"\n[{DateTime.Now}]{x.Name} 已注册,使用标识: {handle}";
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logLabel.Text += $"\n[color=red]错误:\n{e.Message}[/color]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
foreach (var x in progressBars)
|
||||
{
|
||||
x.Value = x.MinValue;
|
||||
_progressQueue.Enqueue(x);
|
||||
}
|
||||
}
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
switch (_currentProgressBar)
|
||||
{
|
||||
case null when _progressQueue.Count == 0:
|
||||
return;
|
||||
case null:
|
||||
_progressQueue.TryDequeue(out _currentProgressBar);
|
||||
return;
|
||||
case (var x) when x.Value >= x.MaxValue:
|
||||
_progressQueue.TryDequeue(out _currentProgressBar);
|
||||
return;
|
||||
default:
|
||||
_currentProgressBar.Value +=
|
||||
Mathf.Lerp(_currentProgressBar.MinValue, _currentProgressBar.MaxValue, delta);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,155 +0,0 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using BITKit;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
|
||||
|
||||
namespace BITFactory;
|
||||
|
||||
public partial class IDIS_RegisterService : Node
|
||||
{
|
||||
[ExportCategory("Services")]
|
||||
[Export] private IDIS_Service service;
|
||||
[Export] private IDIS_TemplateService templateService;
|
||||
|
||||
[ExportCategory("UI 绑定")]
|
||||
[Export] private NodeBuilder templateIndexBuilder;
|
||||
[Export] private LineEdit handleEdit;
|
||||
[Export] private Button generateHandleButton;
|
||||
[Export] private NodeBuilder templateFormatBuilder;
|
||||
[Export] private Button registerButton;
|
||||
[Export] private ProgressBar registerProgress;
|
||||
|
||||
[ExportCategory("Register Reference")]
|
||||
[Export] private Control referenceContainer;
|
||||
[Export] private Button addReferenceButton;
|
||||
|
||||
[ExportCategory("Hints")]
|
||||
[Export] private Label hints;
|
||||
|
||||
private readonly List<(string format,string value,string category)> _currentValues = new();
|
||||
private readonly List<string> _currentReferences = new();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
registerButton.Pressed += Register;
|
||||
|
||||
generateHandleButton.Pressed += ()=>handleEdit.Text = IDIS_Service.GenerateHandle();
|
||||
|
||||
addReferenceButton.Pressed += AddReferenceEdit;
|
||||
|
||||
handleEdit.Editable = false;
|
||||
registerButton.Disabled = true;
|
||||
|
||||
Rebuild();
|
||||
}
|
||||
|
||||
private void Rebuild()
|
||||
{
|
||||
if (Engine.IsEditorHint()) return;
|
||||
templateIndexBuilder.Clear();
|
||||
templateFormatBuilder.Clear();
|
||||
foreach (var x in templateService.templates)
|
||||
{
|
||||
var container = templateIndexBuilder.Build<UXContainer>();
|
||||
container.button.Text = x.TemplateName;
|
||||
container.button.Pressed += () =>
|
||||
{
|
||||
Entry(x);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private void Entry(IDIS_Template template)
|
||||
{
|
||||
_currentValues.Clear();
|
||||
templateFormatBuilder.Clear();
|
||||
var currentIndex = 0;
|
||||
foreach (var x in template.Formats)
|
||||
{
|
||||
var myIndex = currentIndex++;
|
||||
|
||||
_currentValues.Add((x.format, string.Empty, x.category));
|
||||
|
||||
var formatContainer = templateFormatBuilder.Build<UXContainer>();
|
||||
|
||||
formatContainer.labels[0].Text = x.format;
|
||||
formatContainer.lineEdits[0].PlaceholderText = x.hint;
|
||||
|
||||
formatContainer.lineEdits[0].TextChanged += s =>
|
||||
{
|
||||
var value = _currentValues[myIndex];
|
||||
value.value = s;
|
||||
_currentValues[myIndex] = value;
|
||||
};
|
||||
}
|
||||
|
||||
handleEdit.Editable = true;
|
||||
registerButton.Disabled = false;
|
||||
}
|
||||
|
||||
private void AddReferenceEdit()
|
||||
{
|
||||
var lineEdit = new LineEdit();
|
||||
|
||||
var currentIndex = referenceContainer.GetChildCount();
|
||||
|
||||
_currentReferences.Add(string.Empty);
|
||||
lineEdit.TextChanged += s =>
|
||||
{
|
||||
_currentReferences[currentIndex] = s;
|
||||
};
|
||||
|
||||
lineEdit.Text = "88.123.99/";
|
||||
|
||||
referenceContainer.AddChild(lineEdit);
|
||||
}
|
||||
private void Register()
|
||||
{
|
||||
if (_currentValues.Any(x =>
|
||||
string.IsNullOrEmpty(x.format) || string.IsNullOrEmpty(x.value) || string.IsNullOrEmpty(x.category)))
|
||||
{
|
||||
hints.SetTextAsync("请填写完整的数据格式");
|
||||
return;
|
||||
}
|
||||
|
||||
var handle = string.IsNullOrEmpty(handleEdit.Text) ? IDIS_Service.GenerateHandle() : handleEdit.Text;
|
||||
var dataJson = JsonHelper.Get(_currentValues);
|
||||
var referenceJson = JsonHelper.Get(_currentReferences);
|
||||
|
||||
BIT4Log.Log<IDIS_RegisterService>($"注册标识:{handle}");
|
||||
BIT4Log.Log<IDIS_RegisterService>($"\n{dataJson}");
|
||||
BIT4Log.Log<IDIS_RegisterService>("注册引用:");
|
||||
BIT4Log.Log<IDIS_RegisterService>($"\n{referenceJson}");
|
||||
|
||||
hints.Text="正在注册...";
|
||||
|
||||
service.Register(handle);
|
||||
foreach (var x in _currentValues)
|
||||
{
|
||||
service.Register(handle, x.format, x.value,x.category);
|
||||
}
|
||||
foreach (var x in _currentReferences)
|
||||
{
|
||||
service.RegisterReference(handle, x);
|
||||
}
|
||||
|
||||
var tween = CreateTween();
|
||||
registerButton.Disabled = true;
|
||||
registerProgress.Value = 0;
|
||||
tween.TweenProperty(registerProgress, "value", registerProgress.MaxValue, 0.5f);
|
||||
tween.Finished+= () =>
|
||||
{
|
||||
registerProgress.Value = 0;
|
||||
registerProgress.Visible = false;
|
||||
registerButton.Disabled = false;
|
||||
hints.Text = "注册成功";
|
||||
tween.Stop();
|
||||
};
|
||||
tween.Play();
|
||||
|
||||
handleEdit.Text = string.Empty;
|
||||
}
|
||||
}
|
@@ -95,7 +95,7 @@ public partial class IDIS_SearchService : Node
|
||||
{
|
||||
var container = valueTemplate.Instantiate<UXContainer>();
|
||||
|
||||
container.labels[0].Text = x.Format;
|
||||
container.labels[0].Text = x.Name;
|
||||
container.labels[1].Text = x.Value;
|
||||
container.labels[2].Text = x.UpdateTime.ToString(CultureInfo.InvariantCulture);
|
||||
container.labels[3].Text = x.CreateTime.ToString(CultureInfo.InvariantCulture);
|
||||
|
@@ -72,6 +72,10 @@ public class IDIS_Data:IDIS_Base
|
||||
/// </summary>
|
||||
public string Handle { get; set; }
|
||||
/// <summary>
|
||||
/// 记录的名称,通常为中文
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// 值类型,例如string,url,site
|
||||
/// </summary>
|
||||
public string Format { get; set; }
|
||||
@@ -184,7 +188,7 @@ public class IDIS_DBContext:DbContext
|
||||
SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
public void Register(string handle,string format, string value,string category)
|
||||
public void Register(string handle,string name,string format, string value,string category)
|
||||
{
|
||||
var handleExists = Values.Any(x => x.Handle == handle);
|
||||
if (!handleExists)
|
||||
@@ -193,6 +197,7 @@ public class IDIS_DBContext:DbContext
|
||||
}
|
||||
var data = new IDIS_Data()
|
||||
{
|
||||
Name = name,
|
||||
Handle = handle,
|
||||
Format = format,
|
||||
Value = value,
|
||||
@@ -228,6 +233,7 @@ public class IDIS_DBContext:DbContext
|
||||
/// </summary>
|
||||
public partial class IDIS_Service:Node
|
||||
{
|
||||
public static IDIS_Service Singleton { get; private set; }
|
||||
private static IDIS_DBContext Context;
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -236,6 +242,11 @@ public partial class IDIS_Service:Node
|
||||
UniTask.Run(()=>Context.Database.EnsureCreatedAsync());
|
||||
}
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
Singleton = this;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
Context.Dispose();
|
||||
@@ -244,7 +255,7 @@ public partial class IDIS_Service:Node
|
||||
|
||||
public bool Query(string word,out IDIS_Query[] queries) => Context.Query(word, out queries);
|
||||
public bool Register(string handle) => Context.Register(handle);
|
||||
public void Register(string handle, string format, string value,string category) => Context.Register(handle, format, value,category);
|
||||
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);
|
||||
|
@@ -99,8 +99,8 @@ public partial class IDIS_THService : Node
|
||||
switch (currentUpdateMode)
|
||||
{
|
||||
case UpdateMode.Insert:
|
||||
service.Register(handle ,"温度", temperature, "环境");
|
||||
service.Register(handle, "湿度", humidity, "环境");
|
||||
service.Register(handle,"温度" ,"float", temperature, "环境");
|
||||
service.Register(handle, "湿度","float", humidity, "环境");
|
||||
break;
|
||||
case UpdateMode.Update:
|
||||
if (service.Update(handle, "温度",temperature) is false)
|
||||
|
Reference in New Issue
Block a user