diff --git a/XCoder/Engine/XConfig.cs b/XCoder/Engine/XConfig.cs index fdff6acc..8555bc8e 100644 --- a/XCoder/Engine/XConfig.cs +++ b/XCoder/Engine/XConfig.cs @@ -2,87 +2,85 @@ using NewLife; using NewLife.Configuration; -namespace XCoder +namespace XCoder; + +[Config("XCoder")] +public class XConfig : Config { - //[XmlConfigFile("Config\\XCoder.config")] - [Config("XCoder")] - public class XConfig : Config + #region 属性 + /// 标题 + [Description("标题")] + public String Title { get; set; } = ""; + + /// 宽度 + [Description("宽度")] + public Int32 Width { get; set; } + + /// 高度 + [Description("高度")] + public Int32 Height { get; set; } + + /// 顶部 + [Description("顶部")] + public Int32 Top { get; set; } + + /// 左边 + [Description("左边")] + public Int32 Left { get; set; } + + /// 扩展数据 + [Description("扩展数据")] + public String Extend { get; set; } = ""; + + /// 日志着色 + [Description("日志着色")] + public Boolean ColorLog { get; set; } = true; + + /// 语音提示。默认true + [Description("语音提示。默认true")] + public Boolean SpeechTip { get; set; } = true; + + /// 证书 + [Description("证书")] + public String Code { get; set; } + + /// 密钥 + [Description("密钥")] + public String Secret { get; set; } + + /// 服务地址端口。默认为空,子网内自动发现 + [Description("服务地址端口。默认为空,子网内自动发现")] + public String Server { get; set; } = ""; + + /// 更新通道。默认Release + [Description("更新通道。默认Release")] + public String Channel { get; set; } = "Release"; + + /// 更新服务器 + [Description("更新服务器")] + public String UpdateServer { get; set; } = ""; + + /// 最后更新时间 + [DisplayName("最后更新时间")] + public DateTime LastUpdate { get; set; } + + /// 最后一个使用的工具 + [DisplayName("最后一个使用的工具")] + public String LastTool { get; set; } = ""; + #endregion + + #region 加载/保存 + public XConfig() + { + } + + protected override void OnLoaded() { - #region 属性 - /// 标题 - [Description("标题")] - public String Title { get; set; } = ""; - - /// 宽度 - [Description("宽度")] - public Int32 Width { get; set; } - - /// 高度 - [Description("高度")] - public Int32 Height { get; set; } - - /// 顶部 - [Description("顶部")] - public Int32 Top { get; set; } - - /// 左边 - [Description("左边")] - public Int32 Left { get; set; } - - /// 扩展数据 - [Description("扩展数据")] - public String Extend { get; set; } = ""; - - /// 日志着色 - [Description("日志着色")] - public Boolean ColorLog { get; set; } = true; - - /// 语音提示。默认true - [Description("语音提示。默认true")] - public Boolean SpeechTip { get; set; } = true; - - /// 证书 - [Description("证书")] - public String Code { get; set; } - - /// 密钥 - [Description("密钥")] - public String Secret { get; set; } - - /// 服务地址端口。默认为空,子网内自动发现 - [Description("服务地址端口。默认为空,子网内自动发现")] - public String Server { get; set; } = ""; - - /// 更新通道。默认Release - [Description("更新通道。默认Release")] - public String Channel { get; set; } = "Release"; - - /// 更新服务器 - [Description("更新服务器")] - public String UpdateServer { get; set; } = ""; - - /// 最后更新时间 - [DisplayName("最后更新时间")] - public DateTime LastUpdate { get; set; } - - /// 最后一个使用的工具 - [DisplayName("最后一个使用的工具")] - public String LastTool { get; set; } = ""; - #endregion - - #region 加载/保存 - public XConfig() - { - } - - protected override void OnLoaded() - { - if (UpdateServer.IsNullOrEmpty() || UpdateServer.EqualIgnoreCase("http://x.newlifex.com/")) UpdateServer = NewLife.Setting.Current.PluginServer; - - if (Server.IsNullOrEmpty()) Server = "http://s.newlifex.com:6600"; - - base.OnLoaded(); - } - #endregion + if (UpdateServer.IsNullOrEmpty() || UpdateServer.EqualIgnoreCase("http://x.newlifex.com/")) UpdateServer = NewLife.Setting.Current.PluginServer; + + if (Server.IsNullOrEmpty()) Server = "http://s.newlifex.com:6600"; + + base.OnLoaded(); } + #endregion } \ No newline at end of file diff --git a/XCoderLinux/Log/XTrace.cs b/XCoderLinux/Log/XTrace.cs index 104d8499..f3e16ec4 100644 --- a/XCoderLinux/Log/XTrace.cs +++ b/XCoderLinux/Log/XTrace.cs @@ -15,7 +15,7 @@ namespace NewLife.Log /// /// 该静态类包括写日志、写调用栈和Dump进程内存等调试功能。 /// - /// 默认写日志到文本文件,可通过修改属性来增加日志输出方式。 + /// 默认写日志到文本文件,可通过修改属性来增加日志输出方式。 /// 对于控制台工程,可以直接通过UseConsole方法,把日志输出重定向为控制台输出,并且可以为不同线程使用不同颜色。 /// public static partial class XTrace2 diff --git a/XCoderLinux/SharpApp.cs b/XCoderLinux/SharpApp.cs index bbddba55..40df1e73 100644 --- a/XCoderLinux/SharpApp.cs +++ b/XCoderLinux/SharpApp.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections; -using System.Linq; -using System.Reflection; -using System.Threading.Tasks; -using Gdk; +using System.Reflection; using Gtk; using NewLife; using NewLife.Reflection; @@ -12,228 +7,227 @@ using XCom; using Window = Gtk.Window; -namespace XCoder -{ - class SharpApp : Window - { - #region 窗口初始化 - Task _load; +namespace XCoder; - private readonly VBox _windowBox = new VBox(false, 1); - private readonly Menu _menuTool = new Menu(); - private String _title = "新生命码神工具"; +class SharpApp : Window +{ + #region 窗口初始化 + Task _load; + private readonly VBox _windowBox = new(false, 1); + private readonly Menu _menuTool = []; + private String _title = "新生命码神工具"; + public SharpApp() : base("新生命码神工具") + { + _load = Task.Factory.StartNew(() => typeof(IXForm).GetAllSubclasses().ToArray()); - public SharpApp() : base("新生命码神工具") + DeleteEvent += delegate { - _load = Task.Factory.StartNew(() => typeof(IXForm).GetAllSubclasses().ToArray()); + SharpApp_Closing(); + Application.Quit(); + }; - DeleteEvent += delegate - { - SharpApp_Closing(); - Application.Quit(); - }; + Shown += SharpApp_Shown; - Shown += SharpApp_Shown; - ShowAll();// 触发Shown事件、递归显示所有控件,容器ShowAll后才能显示容器内所有控件 - } + // 触发Shown事件、递归显示所有控件,容器ShowAll后才能显示容器内所有控件 + //ShowAll(); + } - private void SharpApp_Shown(System.Object sender, System.EventArgs e) + private void SharpApp_Shown(Object sender, EventArgs e) + { + var set = XConfig.Current; + if (set.Width > 0 || set.Height > 0) { - var set = XConfig.Current; - if (set.Width > 0 || set.Height > 0) - { - DefaultWidth = set.Width; - DefaultHeight = set.Height; - //SetDefaultSize(set.Width, set.Height); - } + DefaultWidth = set.Width; + DefaultHeight = set.Height; + //SetDefaultSize(set.Width, set.Height); + } - SetPosition(WindowPosition.Center); + SetPosition(WindowPosition.Center); - AddMenuButton(); + AddMenuButton(); - //AddMenu(); + //AddMenu(); - var frm = new FrmMain(); + var frm = new FrmMain(); - _windowBox.PackStart(frm, true, true, 0); + _windowBox.PackStart(frm, true, true, 0); - Add(_windowBox); + Add(_windowBox); - var asm = AssemblyX.Create(Assembly.GetExecutingAssembly()); - if (set.Title.IsNullOrEmpty()) set.Title = asm.Title; - _title = Title = String.Format("{2} v{0} {1:HH:mm:ss}", asm.FileVersion, asm.Compile, set.Title); + var asm = AssemblyX.Create(Assembly.GetExecutingAssembly()); + if (set.Title.IsNullOrEmpty()) set.Title = asm.Title; + _title = Title = String.Format("{2} v{0} {1:HH:mm:ss}", asm.FileVersion, asm.Compile, set.Title); - _load.ContinueWith(t => LoadForms(t.Result)); + _load.ContinueWith(t => LoadForms(t.Result)); - ShowAll(); - } + ShowAll(); + } - void LoadForms(Type[] ts) + void LoadForms(Type[] ts) + { + var name = XConfig.Current.LastTool + ""; + foreach (var item in ts) { - var name = XConfig.Current.LastTool + ""; - foreach (var item in ts) + if (item.FullName.EqualIgnoreCase(name)) { - if (item.FullName.EqualIgnoreCase(name)) + Application.Invoke((sender, args) => { - Application.Invoke((sender, args) => - { - CreateForm(item.CreateInstance() as Box); - Title = _title + $"[{item.GetDisplayName() ?? item.FullName}]"; - }); - - break; - } - } + CreateForm(item.CreateInstance() as Box); + Title = _title + $"[{item.GetDisplayName() ?? item.FullName}]"; + }); - Application.Invoke((sender, args) => - { - foreach (var item in ts) - { - var menuItem = new MenuItem { Label = item.GetDisplayName() ?? item.FullName }; - - menuItem.Activated += (s, e) => - { - var set = XConfig.Current; - - if (set.LastTool == item.FullName) return; - var frm = item.CreateInstance() as Box; - CreateForm(frm); - Title = _title + $"[{menuItem.Label}]"; - }; - - _menuTool.Append(menuItem); - } - _menuTool.ShowAll(); - }); + break; + } } - private void SharpApp_Closing() + Application.Invoke((sender, args) => { - var set = XConfig.Current; - //var area = Screen.PrimaryScreen.WorkingArea; - //if (Left >= 0 && Top >= 0 && Width < area.Width - 60 && Height < area.Height - 60) + foreach (var item in ts) { - set.Width = AllocatedWidth; - set.Height = AllocatedHeight; - //set.Top = Top; - //set.Left = Left; - set.Save(); + var menuItem = new MenuItem { Label = item.GetDisplayName() ?? item.FullName }; + + menuItem.Activated += (s, e) => + { + var set = XConfig.Current; + + if (set.LastTool == item.FullName) return; + var frm = item.CreateInstance() as Box; + CreateForm(frm); + Title = _title + $"[{menuItem.Label}]"; + }; + + _menuTool.Append(menuItem); } - } - #endregion + _menuTool.ShowAll(); + }); + } - #region 应用窗口 - void CreateForm(Box frm) + private void SharpApp_Closing() + { + var set = XConfig.Current; + //var area = Screen.PrimaryScreen.WorkingArea; + //if (Left >= 0 && Top >= 0 && Width < area.Width - 60 && Height < area.Height - 60) { - var name = frm.GetType().FullName; - var cfg = XConfig.Current; - if (name != cfg.LastTool) - { - cfg.LastTool = name; - cfg.Save(); - } + set.Width = AllocatedWidth; + set.Height = AllocatedHeight; + //set.Top = Top; + //set.Left = Left; + set.Save(); + } + } + #endregion - //frm.MdiParent = this; - //frm.WindowState = FormWindowState.Maximized; - if (_windowBox.Children.Length > 1) - { - _windowBox.Remove(_windowBox.Children[1]); - } - _windowBox.Add(frm); - _windowBox.ShowAll(); - //frm.ShowAll(); + #region 应用窗口 + void CreateForm(Box frm) + { + var name = frm.GetType().FullName; + var cfg = XConfig.Current; + if (name != cfg.LastTool) + { + cfg.LastTool = name; + cfg.Save(); } - #endregion - #region 菜单 - void AddMenu() + //frm.MdiParent = this; + //frm.WindowState = FormWindowState.Maximized; + if (_windowBox.Children.Length > 1) { - var mb = new MenuBar(); + _windowBox.Remove(_windowBox.Children[1]); + } + _windowBox.Add(frm); + _windowBox.ShowAll(); + //frm.ShowAll(); + } + #endregion - var filemenu = new Menu(); - var file = new MenuItem("文件") - { - Submenu = filemenu - }; + #region 菜单 + void AddMenu() + { + var mb = new MenuBar(); - var agr = new AccelGroup(); - AddAccelGroup(agr); + var filemenu = new Menu(); + var file = new MenuItem("文件") + { + Submenu = filemenu + }; - var newi = new ImageMenuItem(Stock.New, agr); - newi.AddAccelerator("activate", agr, new AccelKey(Gdk.Key.n, Gdk.ModifierType.ControlMask, AccelFlags.Visible)); - filemenu.Append(newi); + var agr = new AccelGroup(); + AddAccelGroup(agr); - var open = new ImageMenuItem(Stock.Open, agr); - open.AddAccelerator("activate", agr, new AccelKey(Gdk.Key.n, Gdk.ModifierType.ControlMask, AccelFlags.Visible)); - filemenu.Append(open); + var newi = new ImageMenuItem(Stock.New, agr); + newi.AddAccelerator("activate", agr, new AccelKey(Gdk.Key.n, Gdk.ModifierType.ControlMask, AccelFlags.Visible)); + filemenu.Append(newi); - var sep = new SeparatorMenuItem(); - filemenu.Append(sep); + var open = new ImageMenuItem(Stock.Open, agr); + open.AddAccelerator("activate", agr, new AccelKey(Gdk.Key.n, Gdk.ModifierType.ControlMask, AccelFlags.Visible)); + filemenu.Append(open); - var exit = new ImageMenuItem(Stock.Quit, agr); - exit.AddAccelerator("activate", agr, new AccelKey(Gdk.Key.q, Gdk.ModifierType.ControlMask, AccelFlags.Visible)); + var sep = new SeparatorMenuItem(); + filemenu.Append(sep); - //var exit = new MenuItem("退出"); - exit.Activated += (sender, args) => - { - Application.Quit(); - }; - filemenu.Append(exit); + var exit = new ImageMenuItem(Stock.Quit, agr); + exit.AddAccelerator("activate", agr, new AccelKey(Gdk.Key.q, Gdk.ModifierType.ControlMask, AccelFlags.Visible)); - mb.Append(file); + //var exit = new MenuItem("退出"); + exit.Activated += (sender, args) => + { + Application.Quit(); + }; + filemenu.Append(exit); - //var _windowBox = new VBox(false, 2); - _windowBox.PackStart(mb, false, false, 0); - //_windowBox.PackStart(new Label("2333"), false, false, 0); + mb.Append(file); - //Add(_windowBox); - } + //var _windowBox = new VBox(false, 2); + _windowBox.PackStart(mb, false, false, 0); + //_windowBox.PackStart(new Label("2333"), false, false, 0); - void AddMenuButton() - { - var mb = new MenuBar(); + //Add(_windowBox); + } - mb.Append(GetMenuTool()); - mb.Append(GetMenuHelp()); + void AddMenuButton() + { + var mb = new MenuBar(); - _windowBox.PackStart(mb, false, false, 0); - } + mb.Append(GetMenuTool()); + mb.Append(GetMenuHelp()); - /// - /// 添加帮助菜单 - /// - /// - MenuItem GetMenuHelp() + _windowBox.PackStart(mb, false, false, 0); + } + + /// + /// 添加帮助菜单 + /// + /// + MenuItem GetMenuHelp() + { + var menu = new Menu(); + var menuItem = new MenuItem("帮助") { - var menu = new Menu(); - var menuItem = new MenuItem("帮助") - { - Submenu = menu - }; + Submenu = menu + }; - var inspector = new MenuItem("切换开发工具"); - inspector.Activated += (s, e) => InteractiveDebugging = true; - menu.Append(inspector); + var inspector = new MenuItem("切换开发工具"); + inspector.Activated += (s, e) => InteractiveDebugging = true; + menu.Append(inspector); - return menuItem; - } + return menuItem; + } - /// - /// 添加工具菜单 - /// - /// - MenuItem GetMenuTool() + /// + /// 添加工具菜单 + /// + /// + MenuItem GetMenuTool() + { + var menu = _menuTool; + var menuItem = new MenuItem("工具") { - var menu = _menuTool; - var menuItem = new MenuItem("工具") - { - Submenu = menu - }; - - return menuItem; - } - #endregion + Submenu = menu + }; + + return menuItem; } + #endregion } diff --git a/XCoderLinux/XNet/FrmMain.cs b/XCoderLinux/XNet/FrmMain.cs index 77b69f34..90a320bd 100644 --- a/XCoderLinux/XNet/FrmMain.cs +++ b/XCoderLinux/XNet/FrmMain.cs @@ -35,7 +35,7 @@ public partial class FrmMain : Box, IXForm #region 窗体 static FrmMain() { - _task = Task.Factory.StartNew(() => GetNetServers()); + _task = TaskEx.Factory.StartNew(() => GetNetServers()); } public FrmMain() : base(Orientation.Horizontal, 2) @@ -355,7 +355,7 @@ void OnReceived(Object sender, ReceivedEventArgs e) // } //} - private Task _Send; + private TaskEx _Send; private void btnSend_Click(Object sender, EventArgs e) { var str = txtSend.Buffer.Text; @@ -407,7 +407,7 @@ private void btnSend_Click(Object sender, EventArgs e) list.Add(client); } - var ts = new List(); + var ts = new List(); for (var i = 0; i < ths; i++) { var task = list[i].SendConcurrency(pk, count, sleep);