Breakpoint
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
#if Deprecated
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
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>>();
|
||||
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)
|
||||
{
|
||||
IDIS_Service.Singleton.Register(handle,x.Name, x.Format, x.Value,x.Category);
|
||||
}
|
||||
|
||||
foreach (var x in references)
|
||||
{
|
||||
IDIS_Service.Singleton.RegisterReference(handle,x);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -1,108 +0,0 @@
|
||||
#if Deprecated
|
||||
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;
|
||||
[Export] private NodePath addReferenceButtonPath;
|
||||
[Export] private NodePath referenceEditBuilderPath;
|
||||
[Export] private NodePath templateBuilderPath;
|
||||
|
||||
private LineEdit handleEdit=>formBuilder.GetNode<LineEdit>(handleEditPath);
|
||||
private Button generateButton=>formBuilder.GetNode<Button>(generateButtonPath);
|
||||
private Button addReferenceButton=>formBuilder.GetNode<Button>(addReferenceButtonPath);
|
||||
private NodeBuilder referenceEditBuilder=>formBuilder.GetNode<NodeBuilder>(referenceEditBuilderPath);
|
||||
private TemplateBuilder templateBuilder => formBuilder.GetNode<TemplateBuilder>(templateBuilderPath);
|
||||
|
||||
private readonly List<IDIS_Data> _values=new();
|
||||
private readonly List<string> _references=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;
|
||||
data.Name = field.Name;
|
||||
data.Value = field.DefaultValue;
|
||||
|
||||
//valueEdit.TextChanged += x => data.Value = x;
|
||||
valueEdit.TextChanged += newValue =>
|
||||
{
|
||||
data.Value = string.IsNullOrEmpty(newValue) ? field.DefaultValue : newValue;
|
||||
};
|
||||
}
|
||||
|
||||
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},
|
||||
{ "references",_references},
|
||||
{"createUser",templateBuilder.CurrentTemplate.Name}
|
||||
};
|
||||
|
||||
var json = JsonHelper.Get(value);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
public override void Clear()
|
||||
{
|
||||
_values.Clear();
|
||||
_references.Clear();
|
||||
referenceEditBuilder.Clear();
|
||||
}
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
generateButton.Pressed += () =>
|
||||
{
|
||||
handleEdit.Text = IDIS_Service.GenerateHandle();
|
||||
};
|
||||
addReferenceButton.Pressed += AddReference;
|
||||
}
|
||||
|
||||
private void AddReference()
|
||||
{
|
||||
var container = referenceEditBuilder.Build<UXContainer>();
|
||||
var myIndex = _references.Count;
|
||||
_references.Add("");
|
||||
container.lineEdit.Text = string.Empty;
|
||||
container.label.Text = "引用标识码:";
|
||||
container.lineEdit.PlaceholderText = "8.123.99/xxxxxxxx";
|
||||
container.lineEdit.TextChanged += x => _references[myIndex] = x;
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -1,37 +0,0 @@
|
||||
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; }
|
||||
}
|
@@ -1,96 +0,0 @@
|
||||
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 FormResource CreateTemplate()
|
||||
{
|
||||
var newResource =
|
||||
new IDIS_TemplateFormResource()
|
||||
{
|
||||
Name = "新的标识模板:"+Guid.NewGuid(),
|
||||
Fields = new IFormField[]
|
||||
{
|
||||
new IDIS_TemplateForm()
|
||||
{
|
||||
Name = "新的标识字段:",
|
||||
Type = "string",
|
||||
DefaultValue = "new",
|
||||
Category = "默认分类"
|
||||
}
|
||||
}
|
||||
};
|
||||
Templates.Add(newResource);
|
||||
return newResource;
|
||||
}
|
||||
|
||||
public override void DeleteTemplate(string name)
|
||||
{
|
||||
var index = Templates.FindIndex(x => x.Name == name);
|
||||
if (index == -1) return;
|
||||
Templates.RemoveAt(index);
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
}
|
@@ -1,155 +0,0 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BITKit;
|
||||
|
||||
namespace BITFactory;
|
||||
[GlobalClass]
|
||||
public partial class IDIS_TemplateWeaver : FormWeaverResource
|
||||
{
|
||||
[Export] private IDIS_TemplateResource templateResource;
|
||||
[ExportCategory(nameof(NodePath))]
|
||||
[Export] private NodePath addFieldsButtonPath;
|
||||
[Export] private NodePath templateBuilderPath;
|
||||
[Export] private NodePath templateNameEditPath;
|
||||
[Export] private NodePath saveTemplateNameButtonPath;
|
||||
[Export] private NodePath deleteTemplateButtonPath;
|
||||
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 Button deleteTemplateButton => formBuilder.GetNode<Button>(deleteTemplateButtonPath);
|
||||
|
||||
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.GetPopup().AddItem("url");
|
||||
typeButton.GetPopup().AddItem("dateTime");
|
||||
typeButton.GetPopup().AddItem("float");
|
||||
|
||||
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();
|
||||
|
||||
if (templateBuilder.CurrentTemplate is null) return;
|
||||
templateNameEdit.Text = templateBuilder.CurrentTemplate?.Name;
|
||||
}
|
||||
public override void OnStart()
|
||||
{
|
||||
addFieldsButton.Pressed+=AddFields;
|
||||
deleteTemplateButton.Pressed += DeleteCurrentTemplate;
|
||||
saveTemplateNameButton.Pressed+=()=>
|
||||
{
|
||||
ChangeCurrentTemplateName(templateNameEdit.Text);
|
||||
};
|
||||
templateNameEdit.TextSubmitted+=ChangeCurrentTemplateName;
|
||||
}
|
||||
private void AddFields()
|
||||
{
|
||||
var current = templateBuilder.CurrentTemplate.Fields.ToList();
|
||||
current.Add(new IDIS_TemplateForm()
|
||||
{
|
||||
Name = "新字段",
|
||||
Type = "string",
|
||||
DefaultValue = "",
|
||||
Category = ""
|
||||
});
|
||||
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();
|
||||
}
|
||||
private void DeleteCurrentTemplate()
|
||||
{
|
||||
if(templateBuilder.CurrentTemplate==null) return;
|
||||
templateResource.DeleteTemplate(templateBuilder.CurrentTemplate.Name);
|
||||
templateBuilder.Rebuild();
|
||||
}
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
#if Deprecated
|
||||
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;
|
||||
|
||||
}
|
||||
#endif
|
@@ -1,87 +0,0 @@
|
||||
#if deprecated
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -1,171 +0,0 @@
|
||||
#if Deprecated
|
||||
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BITKit;
|
||||
using Cysharp.Threading.Tasks;
|
||||
namespace BITFactory;
|
||||
public partial class IDIS_SearchService : Node
|
||||
{
|
||||
[ExportCategory("Service")]
|
||||
[Export] private IDIS_Service service;
|
||||
|
||||
[ExportCategory("UI 绑定 ")]
|
||||
[Export] private LineEdit searchEdit;
|
||||
[Export] private Control searchCandidateContainer;
|
||||
[Export] private StringResource searchButtonVariation;
|
||||
[Export] private Control searchEditPadding;
|
||||
[Export] private Button searchButton;
|
||||
[Export] private Button copyHandleButton;
|
||||
|
||||
[ExportCategory("Query 绑定")]
|
||||
[Export] private Label handleLabel;
|
||||
[Export] private Label nameLabel;
|
||||
[Export] private Label createTimeLabel;
|
||||
[Export] private Label updateTimeLabel;
|
||||
[Export] private Control valueContainer;
|
||||
[Export] private Control referenceContainer;
|
||||
|
||||
[ExportCategory("Template")]
|
||||
[Export] private PackedScene valueTemplate;
|
||||
[Export] private PackedScene referenceTemplate;
|
||||
[Export] private PackedScene categoryTemplate;
|
||||
|
||||
private string currentHandle;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
MathNode.ClearChild(searchCandidateContainer);
|
||||
MathNode.ClearChild(valueContainer);
|
||||
|
||||
searchEdit.TextChanged += Search;
|
||||
//searchEdit.FocusExited += Clear;
|
||||
searchButton.Pressed+=Search;
|
||||
copyHandleButton.Pressed += CopyCurrentHandle;
|
||||
}
|
||||
|
||||
private void Search()
|
||||
{
|
||||
Search(searchEdit.Text);
|
||||
}
|
||||
private void Search(string word)
|
||||
{
|
||||
var split = word.Split('?');
|
||||
var condition = string.Empty;
|
||||
switch (split)
|
||||
{
|
||||
case var x when x.Length is 1:
|
||||
break;
|
||||
case var x when x.Length is 2:
|
||||
condition = split[1];
|
||||
break;
|
||||
case var x when x.Length > 2:
|
||||
split = word.Split('?', 2);
|
||||
condition = split[1];
|
||||
break;
|
||||
}
|
||||
var rawHandle = split[0];
|
||||
|
||||
|
||||
MathNode.ClearChild(searchCandidateContainer);
|
||||
if (service.Query(word, out IDIS_Query[] queries) is false) return;
|
||||
if (queries.Length is 1 && queries.First().Handle == rawHandle)
|
||||
{
|
||||
QueryIDIS(queries.First());
|
||||
return;
|
||||
}
|
||||
foreach (var query in queries.Take(3))
|
||||
{
|
||||
var button = new Button();
|
||||
|
||||
button.Flat = true;
|
||||
|
||||
searchCandidateContainer.AddChild(button);
|
||||
|
||||
button.Text = $"{query.Handle}:{query.CreateUser}";
|
||||
|
||||
button.Pressed+=OnButtonOnPressed;
|
||||
|
||||
button.ThemeTypeVariation = searchButtonVariation.Value;
|
||||
|
||||
void OnButtonOnPressed()
|
||||
{
|
||||
searchEdit.Text =string.IsNullOrEmpty(condition) ? query.Handle :query.Handle + condition ;
|
||||
Search(query.Handle);
|
||||
QueryIDIS(query);
|
||||
}
|
||||
}
|
||||
}
|
||||
private async void Clear()
|
||||
{
|
||||
await Task.Delay(100);
|
||||
MathNode.ClearChild(searchCandidateContainer);
|
||||
}
|
||||
private void QueryIDIS(IDIS_Query query)
|
||||
{
|
||||
searchEditPadding.Hide();
|
||||
|
||||
handleLabel.Text = query.Handle;
|
||||
|
||||
currentHandle = query.Handle;
|
||||
|
||||
createTimeLabel.Text = query.CreateTime.ToString("yyyy-MM-dd HH:mm:ss",CultureInfo.InvariantCulture);
|
||||
updateTimeLabel.Text = query.UpdateTime.ToString("yyyy-MM-dd HH:mm:ss",CultureInfo.InvariantCulture);
|
||||
|
||||
MathNode.ClearChild(valueContainer);
|
||||
MathNode.ClearChild(referenceContainer);
|
||||
|
||||
foreach (var categoryGroup in query.Datas.GroupBy(x=>x.Category))
|
||||
{
|
||||
var categoryContainer = categoryTemplate.Instantiate<UXContainer>();
|
||||
categoryContainer.Text = categoryGroup.First().Category;
|
||||
foreach (var x in categoryGroup)
|
||||
{
|
||||
var container = valueTemplate.Instantiate<UXContainer>();
|
||||
|
||||
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);
|
||||
|
||||
categoryContainer.contextContainer.AddChild(container);
|
||||
}
|
||||
valueContainer.AddChild(categoryContainer);
|
||||
}
|
||||
|
||||
foreach (var x in query.References)
|
||||
{
|
||||
var container = referenceTemplate.Instantiate<UXContainer>();
|
||||
|
||||
container.Text = x.RelatedHandle;
|
||||
|
||||
container.button.Pressed += () =>
|
||||
{
|
||||
service.Query(x.RelatedHandle,out IDIS_Query _query);
|
||||
QueryIDIS(_query);
|
||||
};
|
||||
|
||||
referenceContainer.AddChild(container);
|
||||
}
|
||||
}
|
||||
|
||||
private void CopyCurrentHandle()
|
||||
{
|
||||
DisplayServer.ClipboardSet(currentHandle);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -1,128 +0,0 @@
|
||||
#if Deprecated
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Timers;
|
||||
using BITFactory;
|
||||
using BITKit;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SQLitePCL;
|
||||
using Timer = System.Timers.Timer;
|
||||
// ReSharper disable All
|
||||
|
||||
namespace BITFactory;
|
||||
public partial class IDIS_THService : Node
|
||||
{
|
||||
public enum UpdateMode
|
||||
{
|
||||
None,
|
||||
Update,
|
||||
Insert,
|
||||
UpdateAndInsert,
|
||||
}
|
||||
|
||||
[Export] private UpdateMode currentUpdateMode = UpdateMode.Insert;
|
||||
|
||||
[ExportCategory("Services")]
|
||||
[Export] private IDIS_Service service;
|
||||
|
||||
[Export] private 温湿度Reader thReader;
|
||||
|
||||
[ExportCategory("UI 绑定")]
|
||||
[Export] private Button submitButton;
|
||||
|
||||
[Export] private CheckButton autoUpdateButton;
|
||||
[Export] private OptionButton updateModeButton;
|
||||
[Export] private LineEdit handleEdit;
|
||||
[Export] private LineEdit temperatureEdit;
|
||||
[Export] private LineEdit humidityEdit;
|
||||
[Export] private RichTextLabel hintsLabel;
|
||||
[Export] private RichTextLabel autoUpdateLabel;
|
||||
|
||||
private Timer autoUpdateTimer;
|
||||
public override void _Ready()
|
||||
{
|
||||
submitButton.Pressed += Submit;
|
||||
autoUpdateButton.Toggled += toggle =>
|
||||
{
|
||||
submitButton.Disabled = toggle;
|
||||
handleEdit.Editable = !toggle;
|
||||
temperatureEdit.Editable = !toggle;
|
||||
humidityEdit.Editable = !toggle;
|
||||
autoUpdateTimer.Enabled = toggle;
|
||||
};
|
||||
|
||||
updateModeButton.GetPopup().Clear();
|
||||
updateModeButton.GetPopup().AddItem("不更新");
|
||||
updateModeButton.GetPopup().AddItem("更新记录");
|
||||
updateModeButton.GetPopup().AddItem("添加记录");
|
||||
updateModeButton.GetPopup().IndexPressed += index =>
|
||||
{
|
||||
currentUpdateMode = (UpdateMode)index;
|
||||
};
|
||||
|
||||
autoUpdateTimer = new Timer();
|
||||
autoUpdateTimer.AutoReset = true;
|
||||
autoUpdateTimer.Interval = 1000;
|
||||
autoUpdateTimer.Elapsed += AutoUpdate;
|
||||
}
|
||||
|
||||
private async void AutoUpdate(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
await UniTask.SwitchToSynchronizationContext(BITApp.SynchronizationContext);
|
||||
UpdateTH(handleEdit.Text,thReader.temperature.ToString(),thReader.humidity.ToString());
|
||||
}
|
||||
|
||||
private void Submit()
|
||||
{
|
||||
switch (handleEdit.Text, temperatureEdit.Text, humidityEdit.Text)
|
||||
{
|
||||
case ("", _, _):
|
||||
hintsLabel.Text = "请输入标识码";
|
||||
return;
|
||||
case (_, "", _):
|
||||
hintsLabel.Text = "请输入温度";
|
||||
return;
|
||||
case (_, _, ""):
|
||||
hintsLabel.Text = "请输入湿度";
|
||||
return;
|
||||
}
|
||||
UpdateTH(handleEdit.Text,temperatureEdit.Text,humidityEdit.Text);
|
||||
}
|
||||
|
||||
private void UpdateTH(string handle,string temperature,string humidity)
|
||||
{
|
||||
if (string.IsNullOrEmpty(handle))
|
||||
{
|
||||
autoUpdateLabel.SetTextAsync("空的标识码");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (currentUpdateMode)
|
||||
{
|
||||
case UpdateMode.Insert:
|
||||
service.Register(handle,"温度" ,"float", temperature, "环境");
|
||||
service.Register(handle, "湿度","float", humidity, "环境");
|
||||
break;
|
||||
case UpdateMode.Update:
|
||||
if (service.Update(handle, "当前温度",temperature) is false)
|
||||
{
|
||||
autoUpdateLabel.SetTextAsync("温度更新失败,未知异常");
|
||||
return;
|
||||
}
|
||||
if (service.Update(handle, "当前湿度",humidity) is false)
|
||||
{
|
||||
autoUpdateLabel.SetTextAsync("湿度更新失败,未知异常");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case UpdateMode.UpdateAndInsert:
|
||||
service.Register(handle,"温度" ,"float", temperature, "环境");
|
||||
service.Register(handle, "湿度","float", humidity, "环境");
|
||||
goto case UpdateMode.Update;
|
||||
}
|
||||
autoUpdateLabel.SetTextAsync($"温湿度已自动更新:{DateTime.Now}");
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -1,168 +0,0 @@
|
||||
#if Deprecated
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using BITKit;
|
||||
using BITKit.IO;
|
||||
using Godot;
|
||||
|
||||
namespace BITFactory;
|
||||
[Serializable]
|
||||
public class IDIS_Template
|
||||
{
|
||||
public string TemplateName="标识注册模板";
|
||||
public string TemplateDescription="该模板通常用于xxx用途";
|
||||
public string IconPath="Register";
|
||||
public DateTime CreateTime=DateTime.Now;
|
||||
public DateTime UpdateTime=DateTime.Now;
|
||||
public List<(string format,string hint,string category)> Formats=new();
|
||||
}
|
||||
public partial class IDIS_TemplateService : Node
|
||||
{
|
||||
private static string assetPath => PathHelper.GetPath("标识注册模板.zip");
|
||||
private const string templateName = $"{nameof(IDIS_Template)}.json";
|
||||
public readonly List<IDIS_Template> templates=new();
|
||||
|
||||
[ExportCategory("Quick Start")]
|
||||
[Export] private Button createButton;
|
||||
[Export] private Button newFormatButton;
|
||||
[Export] private NodeBuilder templateIndexBuilder;
|
||||
[Export] private NodeBuilder templateFormatBuilder;
|
||||
[Export] private LineEdit templateNameEdit;
|
||||
[Export] private LineEdit templateDescriptionEdit;
|
||||
[Export] private Label templateCreateTimeLabel;
|
||||
[Export] private Label templateUpdateTimeLabel;
|
||||
[ExportCategory("Template")]
|
||||
[Export] private PackedScene templateContainer;
|
||||
|
||||
private bool isDirty;
|
||||
|
||||
private IDIS_Template _selectedTemplate;
|
||||
public override void _Ready()
|
||||
{
|
||||
if (File.Exists(assetPath) is false)
|
||||
{
|
||||
BIT4Log.Log<IDIS_TemplateService>($"未找到配置文件:{assetPath}");
|
||||
Save();
|
||||
}
|
||||
var temp = BITAssets.Read<List<IDIS_Template>>(assetPath, templateName);
|
||||
|
||||
templates.AddRange(temp);
|
||||
BIT4Log.Log<IDIS_TemplateService>($"已加载配置文件:{assetPath}");
|
||||
|
||||
createButton.Pressed += CreateTemplate;
|
||||
newFormatButton.Pressed += CreateFormat;
|
||||
|
||||
templateNameEdit.TextChanged += OnTemplateNameChanged;
|
||||
templateDescriptionEdit.TextChanged += OnTemplateDescriptionChanged;
|
||||
|
||||
EnsureConfigure();
|
||||
}
|
||||
|
||||
private void CreateFormat()
|
||||
{
|
||||
if (_selectedTemplate is null) return;
|
||||
_selectedTemplate.Formats ??= new();
|
||||
_selectedTemplate.Formats.Add(("新的数据格式","格式类型","数据类型"));
|
||||
_selectedTemplate.UpdateTime= DateTime.Now;
|
||||
EnsureConfigure();
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
Save();
|
||||
}
|
||||
|
||||
private void CreateTemplate()
|
||||
{
|
||||
templates.Add(new IDIS_Template()
|
||||
{
|
||||
TemplateName = "新的标识注册模板"
|
||||
});
|
||||
EnsureConfigure();
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
BITAssets.Build(assetPath,new IAsset[]
|
||||
{
|
||||
new BITAsset(templateName,JsonHelper.Get(templates))
|
||||
});
|
||||
BIT4Log.Log<IDIS_TemplateService>($"已创建配置文件:{assetPath}");
|
||||
}
|
||||
private void OnTemplateNameChanged(string text)
|
||||
{
|
||||
if (_selectedTemplate is null) return;
|
||||
_selectedTemplate.TemplateName = text;
|
||||
_selectedTemplate.UpdateTime= DateTime.Now;
|
||||
}
|
||||
private void OnTemplateDescriptionChanged(string text)
|
||||
{
|
||||
if (_selectedTemplate is null) return;
|
||||
_selectedTemplate.TemplateDescription = text;
|
||||
_selectedTemplate.UpdateTime= DateTime.Now;
|
||||
}
|
||||
|
||||
private void EnsureConfigure()
|
||||
{
|
||||
templateIndexBuilder.Clear();
|
||||
templateFormatBuilder.Clear();
|
||||
|
||||
foreach (var x in templates)
|
||||
{
|
||||
var _container = templateIndexBuilder.Build<UXContainer>();
|
||||
_container.button.Text = x.TemplateName;
|
||||
_container.button.Pressed += () =>
|
||||
{
|
||||
_selectedTemplate = x;
|
||||
EnsureConfigure();
|
||||
};
|
||||
}
|
||||
|
||||
if (_selectedTemplate is null) return;
|
||||
|
||||
templateNameEdit.Text = _selectedTemplate.TemplateName;
|
||||
templateDescriptionEdit.Text = _selectedTemplate.TemplateDescription;
|
||||
templateCreateTimeLabel.Text = _selectedTemplate.CreateTime.ToString(CultureInfo.InvariantCulture);
|
||||
templateUpdateTimeLabel.Text = _selectedTemplate.UpdateTime.ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
for (var i = 0; i < _selectedTemplate.Formats.Count; i++)
|
||||
{
|
||||
var x = _selectedTemplate.Formats[i];
|
||||
var _container = templateFormatBuilder.Build<UXContainer>();
|
||||
|
||||
_container.lineEdits[0].Text = x.format;
|
||||
_container.lineEdits[1].Text = x.hint;
|
||||
_container.lineEdits[2].Text = x.category;
|
||||
|
||||
var index = i;
|
||||
|
||||
_container.lineEdits[0].TextChanged += (s) =>
|
||||
{
|
||||
var current = _selectedTemplate.Formats[index];
|
||||
current.format = s;
|
||||
_selectedTemplate.Formats[index] = current;
|
||||
_selectedTemplate.UpdateTime = DateTime.Now;
|
||||
};
|
||||
_container.lineEdits[1].TextChanged += s =>
|
||||
{
|
||||
var current = _selectedTemplate.Formats[index];
|
||||
current.hint = s;
|
||||
_selectedTemplate.Formats[index] = current;
|
||||
};
|
||||
_container.lineEdits[2].TextChanged += s =>
|
||||
{
|
||||
var current = _selectedTemplate.Formats[index];
|
||||
current.category = s;
|
||||
_selectedTemplate.Formats[index] = current;
|
||||
};
|
||||
_container.button.Pressed += () =>
|
||||
{
|
||||
_selectedTemplate.Formats.RemoveAt(index);
|
||||
EnsureConfigure();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -1,85 +0,0 @@
|
||||
#if Deprecated
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BITKit;
|
||||
|
||||
namespace BITFactory;
|
||||
public partial class IDIS_UpdateService : Node
|
||||
{
|
||||
[ExportCategory("Service")]
|
||||
[Export] private IDIS_Service service;
|
||||
[Export] private IDIS_TemplateService templateService;
|
||||
|
||||
[ExportCategory("UI 绑定")]
|
||||
[Export] private NodeBuilder indexBuilder;
|
||||
[Export] private NodeBuilder templateBuilder;
|
||||
[Export] private LineEdit handleEdit;
|
||||
[Export] private Button submitButton;
|
||||
[Export] private RichTextLabel hintsLabel;
|
||||
|
||||
private ButtonGroup _buttonGroup;
|
||||
|
||||
private readonly Dictionary<string,LineEdit> dataEdits = new();
|
||||
public override void _Ready()
|
||||
{
|
||||
_buttonGroup = new ButtonGroup();
|
||||
|
||||
submitButton.Pressed += Submit;
|
||||
|
||||
submitButton.Disabled = true;
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void Refresh()
|
||||
{
|
||||
templateBuilder.Clear();
|
||||
indexBuilder.Clear();
|
||||
foreach (var x in templateService.templates)
|
||||
{
|
||||
var container = indexBuilder.Build<UXContainer>();
|
||||
container.button.Text = x.TemplateName;
|
||||
container.button.ButtonPressed = true;
|
||||
container.button.ButtonGroup = _buttonGroup;
|
||||
container.button.Pressed +=()=> Entry(x);
|
||||
}
|
||||
}
|
||||
private void Entry(IDIS_Template template)
|
||||
{
|
||||
templateBuilder.Clear();
|
||||
dataEdits.Clear();
|
||||
foreach (var x in template.Formats)
|
||||
{
|
||||
var container = templateBuilder.Build<UXContainer>();
|
||||
container.Text = x.format;
|
||||
container.lineEdit.PlaceholderText = x.hint;
|
||||
|
||||
dataEdits.TryAdd(x.format, container.lineEdit);
|
||||
}
|
||||
|
||||
submitButton.Disabled = false;
|
||||
}
|
||||
|
||||
private void Submit()
|
||||
{
|
||||
if (string.IsNullOrEmpty(handleEdit.Text))
|
||||
{
|
||||
hintsLabel.Text="请填写标识码";
|
||||
return;
|
||||
}
|
||||
var handle = handleEdit.Text;
|
||||
var values = new Dictionary<string, string>(
|
||||
dataEdits
|
||||
.Where(x=>string.IsNullOrEmpty(x.Value.Text) is false)
|
||||
.Select(x => new KeyValuePair<string, string>(x.Key, x.Value.Text))
|
||||
);
|
||||
foreach (var x in values)
|
||||
{
|
||||
service.Update(handle, x.Key, x.Value);
|
||||
}
|
||||
hintsLabel.Text=$"更新成功,已更新{values.Count}个值"+DateTime.Now;
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -1,17 +0,0 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using BITKit;
|
||||
|
||||
namespace BITKit;
|
||||
public partial class TemplateCondition : ConditionComponent
|
||||
{
|
||||
public override Type BaseType => typeof(ConditionComponent);
|
||||
[Export] private TemplateResource templateResource;
|
||||
[Export] private string templateName;
|
||||
|
||||
public override bool OnCheck()
|
||||
{
|
||||
return templateResource.GetTemplates().Any(x => x.Name == templateName);
|
||||
}
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
#if Deprecated
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
namespace BITFactory;
|
||||
public partial class 生成温湿度 : Node
|
||||
{
|
||||
[Export] private string handle;
|
||||
[Export] private int count;
|
||||
[Export] private LineEdit _lineEdit;
|
||||
|
||||
private void Excute()
|
||||
{
|
||||
var myHandle = handle;
|
||||
if (_lineEdit is not null) myHandle = _lineEdit.Text;
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
IDIS_Service.Singleton.Register(myHandle, "温度", "float", $"{new Random().Next(10, 60)}", "环境");
|
||||
IDIS_Service.Singleton.Register(myHandle, "湿度", "float", $"{new Random().Next(0, 100)}", "环境");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -1,151 +0,0 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Net.Mime;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Timers;
|
||||
using BITKit;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SharpModbus;
|
||||
using Timer = System.Timers.Timer;
|
||||
|
||||
namespace BITFactory;
|
||||
public partial class 温湿度Reader : Node
|
||||
{
|
||||
[ExportCategory("参数")]
|
||||
[Export(PropertyHint.Range,"100,2000")] private int interval=500;
|
||||
|
||||
[ExportCategory("网络设置")]
|
||||
[Export] private string ip="192.168.3.7";
|
||||
[Export] private int port=502;
|
||||
|
||||
[ExportCategory("运行时")]
|
||||
[Export]public double humidity = 50.0;
|
||||
[Export]public double temperature = 26.0;
|
||||
|
||||
[ExportCategory("UI 绑定")]
|
||||
[Export] private Button connectToModbusButton;
|
||||
[Export] private UXContainer temperatureContainer;
|
||||
[Export] private UXContainer humidityContainer;
|
||||
[Export] private LineEdit ipEdit;
|
||||
[Export] private LineEdit portEdit;
|
||||
[Export] private RichTextLabel hintsLabel;
|
||||
|
||||
private ModbusMaster _modbus;
|
||||
private Timer timer;
|
||||
private CancellationTokenSource _CancellationTokenSource;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_CancellationTokenSource = new CancellationTokenSource();
|
||||
try
|
||||
{
|
||||
_modbus = ModbusMaster.TCP(ip, port);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
hintsLabel.Text = e.Message;
|
||||
}
|
||||
|
||||
ipEdit.TextChanged+=s=>ip=s;
|
||||
portEdit.TextChanged+=s=>
|
||||
{
|
||||
try
|
||||
{
|
||||
port = int.Parse(s);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
hintsLabel.SetTextAsync(e.Message);
|
||||
}
|
||||
};
|
||||
connectToModbusButton.Pressed += Connect;
|
||||
|
||||
Connect();
|
||||
|
||||
timer = new Timer();
|
||||
timer.Interval = interval;
|
||||
timer.Elapsed += OnTimerElapsed;
|
||||
timer.AutoReset = false;
|
||||
timer.Start();
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
_CancellationTokenSource.Cancel();
|
||||
timer.Stop();
|
||||
}
|
||||
/// <summary>
|
||||
/// 连接到Modbus
|
||||
/// </summary>
|
||||
private void Connect()
|
||||
{
|
||||
_modbus?.Dispose();
|
||||
try
|
||||
{
|
||||
_modbus = ModbusMaster.TCP(ip, port);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BIT4Log.Log<温湿度Reader>(e.Message);
|
||||
hintsLabel.SetTextAsync(e.Message);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 内部方法,定时器回调用于读取Modbus
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private async void OnTimerElapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
await UniTask.SwitchToTaskPool();
|
||||
try
|
||||
{
|
||||
if (_modbus is null)
|
||||
{
|
||||
hintsLabel.SetTextAsync("Modbus未初始化");
|
||||
timer.Start();
|
||||
return;
|
||||
}
|
||||
|
||||
_CancellationTokenSource.Token.ThrowIfCancellationRequested();
|
||||
hintsLabel.SetTextAsync( "正在读取温湿度数据..."+DateTime.Now);
|
||||
|
||||
var vs = _modbus.ReadInputRegisters(1, 0, 2);
|
||||
|
||||
_CancellationTokenSource.Token.ThrowIfCancellationRequested();
|
||||
|
||||
hintsLabel.SetTextAsync( "已采集到数据,正在解析..."+DateTime.Now);
|
||||
|
||||
if (vs is not { Length: 2 })
|
||||
{
|
||||
hintsLabel.SetTextAsync(hintsLabel.Text = $"获取温湿度数据失败:数据长度为:{vs.Length}"+DateTime.Now);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
temperature = vs[0] / 10.0;
|
||||
humidity = vs[1] / 10.0;
|
||||
|
||||
hintsLabel.SetTextAsync("已获取到温湿度数据:"+DateTime.Now);
|
||||
|
||||
temperatureContainer.label.SetTextAsync(temperature.ToString(CultureInfo.InvariantCulture)); ;
|
||||
humidityContainer.label.SetTextAsync(humidity.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
timer.Start();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
BIT4Log.Log<温湿度Reader>($"Modbus读取任务已取消");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
hintsLabel.SetTextAsync(ex.Message);
|
||||
timer.Start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user