From 9f534a87d66aac0aa5e6218906b1bbb55613c82d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=BA=E8=83=BD=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Sat, 11 Dec 2021 16:49:18 +0800 Subject: [PATCH 01/12] =?UTF-8?q?v7.5.2021.1211=20=20=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?ModbusMaster/ModbusSlave?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XCoder/Properties/AssemblyInfo.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/XCoder/Properties/AssemblyInfo.cs b/XCoder/Properties/AssemblyInfo.cs index bfe24e2d..92dcea10 100644 --- a/XCoder/Properties/AssemblyInfo.cs +++ b/XCoder/Properties/AssemblyInfo.cs @@ -28,10 +28,12 @@ // 内部版本号 // 修订号 // -[assembly: AssemblyVersion("7.4.*")] -[assembly: AssemblyFileVersion("7.4.2021.1001")] +[assembly: AssemblyVersion("7.5.*")] +[assembly: AssemblyFileVersion("7.5.2021.1211")] /* + * v7.5.2021.1211 新增ModbusMaster/ModbusSlave + * * v7.4.2021.1001 新增MQTT客户端工具 * * v7.3.2021.0321 支持星尘升级码神工具 From b024459842c0b2f2328a9983d4c417315c770c1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=BA=E8=83=BD=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Sat, 11 Dec 2021 22:09:19 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E5=80=9F=E5=8A=A9=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=EF=BC=8C=E6=8E=A7=E5=88=B6Modbus=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=9A=84=E6=97=A5=E5=BF=97=E6=98=BE=E7=A4=BA=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E5=8D=A1=E6=AD=BB=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XCoder/XNet/FrmModbusMaster.cs | 17 ++- XCoder/XNet/FrmModbusMaster.designer.cs | 186 +++++++++++++++++------- XCoder/XNet/FrmModbusMaster.resx | 3 + XCoder/XNet/FrmModbusSlave.cs | 25 +++- XCoder/XNet/RegisterUnit.cs | 3 +- 5 files changed, 175 insertions(+), 59 deletions(-) diff --git a/XCoder/XNet/FrmModbusMaster.cs b/XCoder/XNet/FrmModbusMaster.cs index 93da8649..4f84b5d8 100644 --- a/XCoder/XNet/FrmModbusMaster.cs +++ b/XCoder/XNet/FrmModbusMaster.cs @@ -129,7 +129,7 @@ private void btnSend_Click(Object sender, EventArgs e) unit.Value = data.ToUInt16(i, true); } - this.Invoke(() => + Invoke(() => { if (len != _data.Count) { @@ -157,6 +157,16 @@ private void btnSend_Click(Object sender, EventArgs e) } #endregion + #region 右键菜单 + private void mi清空_Click(Object sender, EventArgs e) => txtReceive.Clear(); + + private void Menu_Click(Object sender, EventArgs e) + { + var mi = sender as ToolStripMenuItem; + mi.Checked = !mi.Checked; + } + #endregion + private void cbFunctionCode_SelectedIndexChanged(Object sender, EventArgs e) { var code = (FunctionCodes)Enum.ToObject(typeof(FunctionCodes), cbFunctionCode.SelectedValue); @@ -188,10 +198,7 @@ private void cbFunctionCode_SelectedIndexChanged(Object sender, EventArgs e) } } - private void dataGridView1_CellValueChanged(Object sender, DataGridViewCellEventArgs e) - { - dgv.Refresh(); - } + private void dataGridView1_CellValueChanged(Object sender, DataGridViewCellEventArgs e) => dgv.Refresh(); private void btnAdd_Click(Object sender, EventArgs e) { diff --git a/XCoder/XNet/FrmModbusMaster.designer.cs b/XCoder/XNet/FrmModbusMaster.designer.cs index cd8a213e..e7645d53 100644 --- a/XCoder/XNet/FrmModbusMaster.designer.cs +++ b/XCoder/XNet/FrmModbusMaster.designer.cs @@ -45,6 +45,15 @@ private void InitializeComponent() this.label2 = new System.Windows.Forms.Label(); this.label7 = new System.Windows.Forms.Label(); this.txtReceive = new System.Windows.Forms.RichTextBox(); + this.menuReceive = new System.Windows.Forms.ContextMenuStrip(this.components); + this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.mi日志着色 = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripSeparator(); + this.mi显示应用日志 = new System.Windows.Forms.ToolStripMenuItem(); + this.mi显示网络日志 = new System.Windows.Forms.ToolStripMenuItem(); + this.mi显示接收字符串 = new System.Windows.Forms.ToolStripMenuItem(); + this.mi显示发送数据 = new System.Windows.Forms.ToolStripMenuItem(); + this.mi显示接收数据 = new System.Windows.Forms.ToolStripMenuItem(); this.dgv = new System.Windows.Forms.DataGridView(); this.btnAdd = new System.Windows.Forms.Button(); this.pnlSetting.SuspendLayout(); @@ -52,15 +61,16 @@ private void InitializeComponent() this.gbSend.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numCount)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numAddress)).BeginInit(); + this.menuReceive.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dgv)).BeginInit(); this.SuspendLayout(); // // btnConnect // - this.btnConnect.Location = new System.Drawing.Point(881, 13); - this.btnConnect.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.btnConnect.Location = new System.Drawing.Point(783, 11); + this.btnConnect.Margin = new System.Windows.Forms.Padding(4); this.btnConnect.Name = "btnConnect"; - this.btnConnect.Size = new System.Drawing.Size(100, 43); + this.btnConnect.Size = new System.Drawing.Size(89, 36); this.btnConnect.TabIndex = 3; this.btnConnect.Text = "打开"; this.btnConnect.UseVisualStyleBackColor = true; @@ -78,45 +88,44 @@ private void InitializeComponent() this.pnlSetting.Controls.Add(this.label3); this.pnlSetting.Controls.Add(this.label4); this.pnlSetting.Controls.Add(this.numHost); - this.pnlSetting.Location = new System.Drawing.Point(14, 12); - this.pnlSetting.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.pnlSetting.Location = new System.Drawing.Point(12, 10); + this.pnlSetting.Margin = new System.Windows.Forms.Padding(4); this.pnlSetting.Name = "pnlSetting"; - this.pnlSetting.Size = new System.Drawing.Size(858, 47); + this.pnlSetting.Size = new System.Drawing.Size(763, 39); this.pnlSetting.TabIndex = 13; // // txtAddress // - this.txtAddress.Location = new System.Drawing.Point(81, 8); - this.txtAddress.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.txtAddress.Location = new System.Drawing.Point(72, 7); this.txtAddress.Name = "txtAddress"; - this.txtAddress.Size = new System.Drawing.Size(234, 28); + this.txtAddress.Size = new System.Drawing.Size(208, 25); this.txtAddress.TabIndex = 19; this.txtAddress.Text = "tcp://127.0.0.1:502"; // // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(344, 14); + this.label3.Location = new System.Drawing.Point(306, 12); this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(62, 18); + this.label3.Size = new System.Drawing.Size(52, 15); this.label3.TabIndex = 18; this.label3.Text = "站号:"; // // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(14, 14); + this.label4.Location = new System.Drawing.Point(12, 12); this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(44, 18); + this.label4.Size = new System.Drawing.Size(37, 15); this.label4.TabIndex = 16; this.label4.Text = "远程"; // // numHost // - this.numHost.Location = new System.Drawing.Point(407, 8); - this.numHost.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.numHost.Location = new System.Drawing.Point(362, 7); + this.numHost.Margin = new System.Windows.Forms.Padding(4); this.numHost.Maximum = new decimal(new int[] { 65535, 0, @@ -128,7 +137,7 @@ private void InitializeComponent() 0, 0}); this.numHost.Name = "numHost"; - this.numHost.Size = new System.Drawing.Size(76, 28); + this.numHost.Size = new System.Drawing.Size(68, 25); this.numHost.TabIndex = 11; this.numHost.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; this.numHost.Value = new decimal(new int[] { @@ -149,11 +158,11 @@ private void InitializeComponent() this.gbSend.Controls.Add(this.label2); this.gbSend.Controls.Add(this.label7); this.gbSend.Enabled = false; - this.gbSend.Location = new System.Drawing.Point(14, 425); - this.gbSend.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.gbSend.Location = new System.Drawing.Point(12, 354); + this.gbSend.Margin = new System.Windows.Forms.Padding(4); this.gbSend.Name = "gbSend"; - this.gbSend.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); - this.gbSend.Size = new System.Drawing.Size(978, 126); + this.gbSend.Padding = new System.Windows.Forms.Padding(4); + this.gbSend.Size = new System.Drawing.Size(869, 105); this.gbSend.TabIndex = 15; this.gbSend.TabStop = false; this.gbSend.Text = "发送区:"; @@ -161,10 +170,10 @@ private void InitializeComponent() // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(507, 50); + this.label1.Location = new System.Drawing.Point(451, 42); this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(62, 18); + this.label1.Size = new System.Drawing.Size(52, 15); this.label1.TabIndex = 20; this.label1.Text = "个数:"; // @@ -181,17 +190,16 @@ private void InitializeComponent() "06 写单个保存寄存器", "15 写多个线圈", "16 写多个保持寄存器"}); - this.cbFunctionCode.Location = new System.Drawing.Point(94, 44); - this.cbFunctionCode.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.cbFunctionCode.Location = new System.Drawing.Point(84, 37); this.cbFunctionCode.Name = "cbFunctionCode"; - this.cbFunctionCode.Size = new System.Drawing.Size(192, 26); + this.cbFunctionCode.Size = new System.Drawing.Size(171, 23); this.cbFunctionCode.TabIndex = 19; this.cbFunctionCode.SelectedIndexChanged += new System.EventHandler(this.cbFunctionCode_SelectedIndexChanged); // // numCount // - this.numCount.Location = new System.Drawing.Point(575, 44); - this.numCount.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.numCount.Location = new System.Drawing.Point(511, 37); + this.numCount.Margin = new System.Windows.Forms.Padding(4); this.numCount.Maximum = new decimal(new int[] { 100000, 0, @@ -203,7 +211,7 @@ private void InitializeComponent() 0, 0}); this.numCount.Name = "numCount"; - this.numCount.Size = new System.Drawing.Size(78, 28); + this.numCount.Size = new System.Drawing.Size(69, 25); this.numCount.TabIndex = 18; this.numCount.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; this.numCount.Value = new decimal(new int[] { @@ -214,10 +222,10 @@ private void InitializeComponent() // // btnSend // - this.btnSend.Location = new System.Drawing.Point(698, 36); - this.btnSend.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.btnSend.Location = new System.Drawing.Point(620, 30); + this.btnSend.Margin = new System.Windows.Forms.Padding(4); this.btnSend.Name = "btnSend"; - this.btnSend.Size = new System.Drawing.Size(75, 46); + this.btnSend.Size = new System.Drawing.Size(67, 38); this.btnSend.TabIndex = 1; this.btnSend.Text = "发送"; this.btnSend.UseVisualStyleBackColor = true; @@ -225,8 +233,8 @@ private void InitializeComponent() // // numAddress // - this.numAddress.Location = new System.Drawing.Point(389, 44); - this.numAddress.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.numAddress.Location = new System.Drawing.Point(346, 37); + this.numAddress.Margin = new System.Windows.Forms.Padding(4); this.numAddress.Maximum = new decimal(new int[] { 65535, 0, @@ -238,7 +246,7 @@ private void InitializeComponent() 0, 0}); this.numAddress.Name = "numAddress"; - this.numAddress.Size = new System.Drawing.Size(87, 28); + this.numAddress.Size = new System.Drawing.Size(77, 25); this.numAddress.TabIndex = 14; this.numAddress.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; this.numAddress.Value = new decimal(new int[] { @@ -250,20 +258,20 @@ private void InitializeComponent() // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(18, 49); + this.label2.Location = new System.Drawing.Point(16, 41); this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(80, 18); + this.label2.Size = new System.Drawing.Size(67, 15); this.label2.TabIndex = 17; this.label2.Text = "操作码:"; // // label7 // this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(338, 50); + this.label7.Location = new System.Drawing.Point(300, 42); this.label7.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(62, 18); + this.label7.Size = new System.Drawing.Size(52, 15); this.label7.TabIndex = 15; this.label7.Text = "地址:"; // @@ -272,34 +280,104 @@ private void InitializeComponent() this.txtReceive.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.txtReceive.ContextMenuStrip = this.menuReceive; this.txtReceive.HideSelection = false; - this.txtReceive.Location = new System.Drawing.Point(401, 68); - this.txtReceive.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.txtReceive.Location = new System.Drawing.Point(356, 57); + this.txtReceive.Margin = new System.Windows.Forms.Padding(4); this.txtReceive.Name = "txtReceive"; - this.txtReceive.Size = new System.Drawing.Size(590, 347); + this.txtReceive.Size = new System.Drawing.Size(525, 290); this.txtReceive.TabIndex = 1; this.txtReceive.Text = ""; // + // menuReceive + // + this.menuReceive.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuReceive.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripMenuItem1, + this.mi日志着色, + this.toolStripMenuItem3, + this.mi显示应用日志, + this.mi显示网络日志, + this.mi显示接收字符串, + this.mi显示发送数据, + this.mi显示接收数据}); + this.menuReceive.Name = "menuSend"; + this.menuReceive.Size = new System.Drawing.Size(184, 178); + // + // toolStripMenuItem1 + // + this.toolStripMenuItem1.Name = "toolStripMenuItem1"; + this.toolStripMenuItem1.Size = new System.Drawing.Size(183, 24); + this.toolStripMenuItem1.Text = "清空"; + this.toolStripMenuItem1.Click += new System.EventHandler(this.mi清空_Click); + // + // mi日志着色 + // + this.mi日志着色.Name = "mi日志着色"; + this.mi日志着色.Size = new System.Drawing.Size(183, 24); + this.mi日志着色.Text = "日志着色"; + this.mi日志着色.Click += new System.EventHandler(this.Menu_Click); + // + // toolStripMenuItem3 + // + this.toolStripMenuItem3.Name = "toolStripMenuItem3"; + this.toolStripMenuItem3.Size = new System.Drawing.Size(180, 6); + // + // mi显示应用日志 + // + this.mi显示应用日志.Name = "mi显示应用日志"; + this.mi显示应用日志.Size = new System.Drawing.Size(183, 24); + this.mi显示应用日志.Text = "显示应用日志"; + this.mi显示应用日志.Click += new System.EventHandler(this.Menu_Click); + // + // mi显示网络日志 + // + this.mi显示网络日志.Name = "mi显示网络日志"; + this.mi显示网络日志.Size = new System.Drawing.Size(183, 24); + this.mi显示网络日志.Text = "显示网络日志"; + this.mi显示网络日志.Click += new System.EventHandler(this.Menu_Click); + // + // mi显示接收字符串 + // + this.mi显示接收字符串.Name = "mi显示接收字符串"; + this.mi显示接收字符串.Size = new System.Drawing.Size(183, 24); + this.mi显示接收字符串.Text = "显示接收字符串"; + this.mi显示接收字符串.Click += new System.EventHandler(this.Menu_Click); + // + // mi显示发送数据 + // + this.mi显示发送数据.Name = "mi显示发送数据"; + this.mi显示发送数据.Size = new System.Drawing.Size(183, 24); + this.mi显示发送数据.Text = "显示发送数据"; + this.mi显示发送数据.Click += new System.EventHandler(this.Menu_Click); + // + // mi显示接收数据 + // + this.mi显示接收数据.Name = "mi显示接收数据"; + this.mi显示接收数据.Size = new System.Drawing.Size(183, 24); + this.mi显示接收数据.Text = "显示接收数据"; + this.mi显示接收数据.Click += new System.EventHandler(this.Menu_Click); + // // dgv // this.dgv.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.dgv.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dgv.Location = new System.Drawing.Point(14, 67); - this.dgv.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.dgv.Location = new System.Drawing.Point(12, 56); this.dgv.Name = "dgv"; this.dgv.RowHeadersWidth = 51; this.dgv.RowTemplate.Height = 27; - this.dgv.Size = new System.Drawing.Size(380, 304); + this.dgv.Size = new System.Drawing.Size(338, 253); this.dgv.TabIndex = 16; this.dgv.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellValueChanged); // // btnAdd // this.btnAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.btnAdd.Location = new System.Drawing.Point(14, 378); + this.btnAdd.Location = new System.Drawing.Point(12, 315); + this.btnAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.btnAdd.Name = "btnAdd"; - this.btnAdd.Size = new System.Drawing.Size(87, 37); + this.btnAdd.Size = new System.Drawing.Size(77, 31); this.btnAdd.TabIndex = 17; this.btnAdd.Text = "添加"; this.btnAdd.UseVisualStyleBackColor = true; @@ -307,16 +385,16 @@ private void InitializeComponent() // // FrmModbusMaster // - this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1000, 569); + this.ClientSize = new System.Drawing.Size(889, 474); this.Controls.Add(this.btnAdd); this.Controls.Add(this.dgv); this.Controls.Add(this.txtReceive); this.Controls.Add(this.gbSend); this.Controls.Add(this.pnlSetting); this.Controls.Add(this.btnConnect); - this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.Margin = new System.Windows.Forms.Padding(4); this.Name = "FrmModbusMaster"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "ModbusMaster"; @@ -328,6 +406,7 @@ private void InitializeComponent() this.gbSend.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numCount)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numAddress)).EndInit(); + this.menuReceive.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dgv)).EndInit(); this.ResumeLayout(false); @@ -352,6 +431,15 @@ private void InitializeComponent() private System.Windows.Forms.RichTextBox txtReceive; private System.Windows.Forms.DataGridView dgv; private System.Windows.Forms.Button btnAdd; + private System.Windows.Forms.ContextMenuStrip menuReceive; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem mi日志着色; + private System.Windows.Forms.ToolStripSeparator toolStripMenuItem3; + private System.Windows.Forms.ToolStripMenuItem mi显示应用日志; + private System.Windows.Forms.ToolStripMenuItem mi显示网络日志; + private System.Windows.Forms.ToolStripMenuItem mi显示接收字符串; + private System.Windows.Forms.ToolStripMenuItem mi显示发送数据; + private System.Windows.Forms.ToolStripMenuItem mi显示接收数据; } } diff --git a/XCoder/XNet/FrmModbusMaster.resx b/XCoder/XNet/FrmModbusMaster.resx index 1f666f26..232f94b0 100644 --- a/XCoder/XNet/FrmModbusMaster.resx +++ b/XCoder/XNet/FrmModbusMaster.resx @@ -120,4 +120,7 @@ 17, 17 + + 259, 13 + \ No newline at end of file diff --git a/XCoder/XNet/FrmModbusSlave.cs b/XCoder/XNet/FrmModbusSlave.cs index 3d359217..7a013793 100644 --- a/XCoder/XNet/FrmModbusSlave.cs +++ b/XCoder/XNet/FrmModbusSlave.cs @@ -61,11 +61,18 @@ private void btnConnect_Click(Object sender, EventArgs e) var svr = new NetServer((Int32)numPort.Value) { Log = _log, - SessionLog = _log, + //SessionLog = _log, //SocketLog = _log, //LogReceive = true, //LogSend = true, }; + + var set = NetConfig.Current; + if (set.ShowLog) svr.SessionLog = _log; + if (set.ShowSocketLog) svr.SocketLog = _log; + if (set.ShowSend) svr.LogSend = true; + if (set.ShowReceive) svr.LogReceive = true; + // 加入定长编码器,处理Tcp粘包 svr.Add(new LengthFieldCodec { Offset = 4, Size = -2 }); svr.Received += OnReceived; @@ -161,13 +168,13 @@ private void DoRefreshData(Object state) private void OnReceived(Object sender, ReceivedEventArgs e) { - var session = sender as INetSession; + var session = sender as NetSession; if (session == null) return; var msg = ModbusMessage.Read(e.Packet); if (msg == null) return; - _log.Info("<= {0}", msg); + session.Log?.Info("<= {0}", msg); var rs = msg.CreateReply(); switch (msg.Code) @@ -207,7 +214,7 @@ private void OnReceived(Object sender, ReceivedEventArgs e) break; } - _log.Info("=> {0}", rs); + session.Log?.Info("=> {0}", rs); session.Send(rs.ToPacket()); } @@ -221,6 +228,16 @@ private void timer1_Tick(Object sender, EventArgs e) } #endregion + #region 右键菜单 + private void mi清空_Click(Object sender, EventArgs e) => txtReceive.Clear(); + + private void Menu_Click(Object sender, EventArgs e) + { + var mi = sender as ToolStripMenuItem; + mi.Checked = !mi.Checked; + } + #endregion + private void dataGridView1_CellValueChanged(Object sender, DataGridViewCellEventArgs e) { dgv.Refresh(); diff --git a/XCoder/XNet/RegisterUnit.cs b/XCoder/XNet/RegisterUnit.cs index b931c77d..b9c808af 100644 --- a/XCoder/XNet/RegisterUnit.cs +++ b/XCoder/XNet/RegisterUnit.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using NewLife; namespace XCoder.XNet { @@ -14,6 +15,6 @@ internal class RegisterUnit public UInt16 Value { get; set; } - public String ValueHex => Value.ToString("X4"); + public String ValueHex => Value.GetBytes(false).ToHex(); } } From aa60265a11048cce93ae8c091931ad6c3e995378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Sat, 11 Dec 2021 22:38:15 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E7=B2=BE=E7=BB=86=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E7=BD=91=E7=BB=9C=E6=97=A5=E5=BF=97=EF=BC=8C=E4=BF=9D=E9=9A=9C?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=90=9E=E5=90=90=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XCoder/XNet/FrmModbusMaster.cs | 35 +++++++++- XCoder/XNet/FrmModbusSlave.cs | 34 ++++++++- XCoder/XNet/FrmModbusSlave.designer.cs | 96 ++++++++++++++++++++++++-- XCoder/XNet/FrmModbusSlave.resx | 11 ++- 4 files changed, 159 insertions(+), 17 deletions(-) diff --git a/XCoder/XNet/FrmModbusMaster.cs b/XCoder/XNet/FrmModbusMaster.cs index 4f84b5d8..d9fe4626 100644 --- a/XCoder/XNet/FrmModbusMaster.cs +++ b/XCoder/XNet/FrmModbusMaster.cs @@ -55,6 +55,33 @@ private void FrmMain_Load(Object sender, EventArgs e) _config = new ControlConfig { Control = this, FileName = "ModbusMaster.json" }; _config.Load(); + LoadConfig(); + } + #endregion + + #region 加载/保存 配置 + void LoadConfig() + { + var cfg = NetConfig.Current; + mi显示应用日志.Checked = cfg.ShowLog; + mi显示网络日志.Checked = cfg.ShowSocketLog; + mi显示接收字符串.Checked = cfg.ShowReceiveString; + mi显示发送数据.Checked = cfg.ShowSend; + mi显示接收数据.Checked = cfg.ShowReceive; + mi日志着色.Checked = cfg.ColorLog; + } + + void SaveConfig() + { + var cfg = NetConfig.Current; + cfg.ShowLog = mi显示应用日志.Checked; + cfg.ShowSocketLog = mi显示网络日志.Checked; + cfg.ShowReceiveString = mi显示接收字符串.Checked; + cfg.ShowSend = mi显示发送数据.Checked; + cfg.ShowReceive = mi显示接收数据.Checked; + cfg.ColorLog = mi日志着色.Checked; + + cfg.Save(); } #endregion @@ -62,17 +89,22 @@ private void FrmMain_Load(Object sender, EventArgs e) private void btnConnect_Click(Object sender, EventArgs e) { _config.Save(); + SaveConfig(); var btn = sender as Button; if (btn.Text == "打开") { var address = txtAddress.Text; + var set = NetConfig.Current; var mb = new ModbusTcp { Server = address, - Log = _log + //Log = _log }; + + if (set.ShowLog) mb.Log = _log; + mb.Open(); _modbus = mb; @@ -111,6 +143,7 @@ private void btnSend_Click(Object sender, EventArgs e) var count = (UInt16)numCount.Value; _config.Save(); + SaveConfig(); // 读取 if (code <= FunctionCodes.ReadInput) diff --git a/XCoder/XNet/FrmModbusSlave.cs b/XCoder/XNet/FrmModbusSlave.cs index 7a013793..cfd04d90 100644 --- a/XCoder/XNet/FrmModbusSlave.cs +++ b/XCoder/XNet/FrmModbusSlave.cs @@ -38,15 +38,42 @@ private void FrmMain_Load(Object sender, EventArgs e) { _log = new TextControlLog { Control = txtReceive }; - _config = new ControlConfig { Control = this, FileName = "ModbusSlave.json" }; - _config.Load(); - if (cbMode.SelectedIndex < 0) cbMode.SelectedIndex = 0; txtReceive.SetDefaultStyle(12); // 加载保存的颜色 UIConfig.Apply(txtReceive); + + _config = new ControlConfig { Control = this, FileName = "ModbusSlave.json" }; + _config.Load(); + LoadConfig(); + } + #endregion + + #region 加载/保存 配置 + void LoadConfig() + { + var cfg = NetConfig.Current; + mi显示应用日志.Checked = cfg.ShowLog; + mi显示网络日志.Checked = cfg.ShowSocketLog; + mi显示接收字符串.Checked = cfg.ShowReceiveString; + mi显示发送数据.Checked = cfg.ShowSend; + mi显示接收数据.Checked = cfg.ShowReceive; + mi日志着色.Checked = cfg.ColorLog; + } + + void SaveConfig() + { + var cfg = NetConfig.Current; + cfg.ShowLog = mi显示应用日志.Checked; + cfg.ShowSocketLog = mi显示网络日志.Checked; + cfg.ShowReceiveString = mi显示接收字符串.Checked; + cfg.ShowSend = mi显示发送数据.Checked; + cfg.ShowReceive = mi显示接收数据.Checked; + cfg.ColorLog = mi日志着色.Checked; + + cfg.Save(); } #endregion @@ -54,6 +81,7 @@ private void FrmMain_Load(Object sender, EventArgs e) private void btnConnect_Click(Object sender, EventArgs e) { _config.Save(); + SaveConfig(); var btn = sender as Button; if (btn.Text == "开始") diff --git a/XCoder/XNet/FrmModbusSlave.designer.cs b/XCoder/XNet/FrmModbusSlave.designer.cs index d5c8011b..96dde2a0 100644 --- a/XCoder/XNet/FrmModbusSlave.designer.cs +++ b/XCoder/XNet/FrmModbusSlave.designer.cs @@ -43,7 +43,15 @@ private void InitializeComponent() this.numCount = new System.Windows.Forms.NumericUpDown(); this.numAddress = new System.Windows.Forms.NumericUpDown(); this.label2 = new System.Windows.Forms.Label(); - this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); + this.menuReceive = new System.Windows.Forms.ContextMenuStrip(this.components); + this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.mi日志着色 = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripSeparator(); + this.mi显示应用日志 = new System.Windows.Forms.ToolStripMenuItem(); + this.mi显示网络日志 = new System.Windows.Forms.ToolStripMenuItem(); + this.mi显示接收字符串 = new System.Windows.Forms.ToolStripMenuItem(); + this.mi显示发送数据 = new System.Windows.Forms.ToolStripMenuItem(); + this.mi显示接收数据 = new System.Windows.Forms.ToolStripMenuItem(); this.dgv = new System.Windows.Forms.DataGridView(); this.btnAdd = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.numPort)).BeginInit(); @@ -51,6 +59,7 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.numHost)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numCount)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numAddress)).BeginInit(); + this.menuReceive.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dgv)).BeginInit(); this.SuspendLayout(); // @@ -59,6 +68,7 @@ private void InitializeComponent() this.txtReceive.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.txtReceive.ContextMenuStrip = this.menuReceive; this.txtReceive.HideSelection = false; this.txtReceive.Location = new System.Drawing.Point(401, 66); this.txtReceive.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); @@ -139,7 +149,6 @@ private void InitializeComponent() this.numPort.Size = new System.Drawing.Size(76, 28); this.numPort.TabIndex = 11; this.numPort.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; - this.toolTip1.SetToolTip(this.numPort, "端口"); this.numPort.Value = new decimal(new int[] { 502, 0, @@ -182,7 +191,6 @@ private void InitializeComponent() this.numHost.Size = new System.Drawing.Size(76, 28); this.numHost.TabIndex = 21; this.numHost.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; - this.toolTip1.SetToolTip(this.numHost, "端口"); this.numHost.Value = new decimal(new int[] { 1, 0, @@ -227,7 +235,6 @@ private void InitializeComponent() this.numCount.Size = new System.Drawing.Size(76, 28); this.numCount.TabIndex = 18; this.numCount.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; - this.toolTip1.SetToolTip(this.numCount, "端口"); this.numCount.Value = new decimal(new int[] { 32, 0, @@ -252,7 +259,6 @@ private void InitializeComponent() this.numAddress.Size = new System.Drawing.Size(96, 28); this.numAddress.TabIndex = 17; this.numAddress.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; - this.toolTip1.SetToolTip(this.numAddress, "端口"); this.numAddress.Value = new decimal(new int[] { 40000, 0, @@ -269,6 +275,75 @@ private void InitializeComponent() this.label2.TabIndex = 19; this.label2.Text = "端口:"; // + // menuReceive + // + this.menuReceive.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuReceive.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripMenuItem1, + this.mi日志着色, + this.toolStripMenuItem3, + this.mi显示应用日志, + this.mi显示网络日志, + this.mi显示接收字符串, + this.mi显示发送数据, + this.mi显示接收数据}); + this.menuReceive.Name = "menuSend"; + this.menuReceive.Size = new System.Drawing.Size(184, 178); + // + // toolStripMenuItem1 + // + this.toolStripMenuItem1.Name = "toolStripMenuItem1"; + this.toolStripMenuItem1.Size = new System.Drawing.Size(183, 24); + this.toolStripMenuItem1.Text = "清空"; + this.toolStripMenuItem1.Click += new System.EventHandler(this.mi清空_Click); + // + // mi日志着色 + // + this.mi日志着色.Name = "mi日志着色"; + this.mi日志着色.Size = new System.Drawing.Size(183, 24); + this.mi日志着色.Text = "日志着色"; + this.mi日志着色.Click += new System.EventHandler(this.Menu_Click); + // + // toolStripMenuItem3 + // + this.toolStripMenuItem3.Name = "toolStripMenuItem3"; + this.toolStripMenuItem3.Size = new System.Drawing.Size(180, 6); + // + // mi显示应用日志 + // + this.mi显示应用日志.Name = "mi显示应用日志"; + this.mi显示应用日志.Size = new System.Drawing.Size(183, 24); + this.mi显示应用日志.Text = "显示应用日志"; + this.mi显示应用日志.Click += new System.EventHandler(this.Menu_Click); + // + // mi显示网络日志 + // + this.mi显示网络日志.Name = "mi显示网络日志"; + this.mi显示网络日志.Size = new System.Drawing.Size(183, 24); + this.mi显示网络日志.Text = "显示网络日志"; + this.mi显示网络日志.Click += new System.EventHandler(this.Menu_Click); + // + // mi显示接收字符串 + // + this.mi显示接收字符串.Name = "mi显示接收字符串"; + this.mi显示接收字符串.Size = new System.Drawing.Size(183, 24); + this.mi显示接收字符串.Text = "显示接收字符串"; + this.mi显示接收字符串.Click += new System.EventHandler(this.Menu_Click); + // + // mi显示发送数据 + // + this.mi显示发送数据.Name = "mi显示发送数据"; + this.mi显示发送数据.Size = new System.Drawing.Size(183, 24); + this.mi显示发送数据.Text = "显示发送数据"; + this.mi显示发送数据.Click += new System.EventHandler(this.Menu_Click); + // + // mi显示接收数据 + // + this.mi显示接收数据.Name = "mi显示接收数据"; + this.mi显示接收数据.Size = new System.Drawing.Size(183, 24); + this.mi显示接收数据.Text = "显示接收数据"; + this.mi显示接收数据.Click += new System.EventHandler(this.Menu_Click); + // // dgv // this.dgv.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -315,6 +390,7 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.numHost)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numCount)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numAddress)).EndInit(); + this.menuReceive.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dgv)).EndInit(); this.ResumeLayout(false); @@ -329,7 +405,6 @@ private void InitializeComponent() private System.Windows.Forms.ComboBox cbMode; private System.Windows.Forms.NumericUpDown numPort; private System.Windows.Forms.Panel pnlSetting; - private System.Windows.Forms.ToolTip toolTip1; private System.Windows.Forms.NumericUpDown numCount; private System.Windows.Forms.NumericUpDown numAddress; private System.Windows.Forms.DataGridView dgv; @@ -338,6 +413,15 @@ private void InitializeComponent() private System.Windows.Forms.Label label4; private System.Windows.Forms.NumericUpDown numHost; private System.Windows.Forms.Button btnAdd; + private System.Windows.Forms.ContextMenuStrip menuReceive; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem mi日志着色; + private System.Windows.Forms.ToolStripSeparator toolStripMenuItem3; + private System.Windows.Forms.ToolStripMenuItem mi显示应用日志; + private System.Windows.Forms.ToolStripMenuItem mi显示网络日志; + private System.Windows.Forms.ToolStripMenuItem mi显示接收字符串; + private System.Windows.Forms.ToolStripMenuItem mi显示发送数据; + private System.Windows.Forms.ToolStripMenuItem mi显示接收数据; } } diff --git a/XCoder/XNet/FrmModbusSlave.resx b/XCoder/XNet/FrmModbusSlave.resx index 57fa2ec7..8a2a8a60 100644 --- a/XCoder/XNet/FrmModbusSlave.resx +++ b/XCoder/XNet/FrmModbusSlave.resx @@ -117,13 +117,10 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 17, 17 - - - 601, 17 + + 439, 13 - - 601, 17 + + 152, 17 \ No newline at end of file From 7728e416d9c41aa2baeeeaddc59dc59ad3a96927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Sun, 12 Dec 2021 13:04:36 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E7=A0=81=E7=A5=9E=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E4=BB=8ENET4.6=E9=80=80=E5=9B=9E=E9=83=BDNET4.5=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=EF=BC=8C=E8=AE=A9=E5=85=B6=E8=83=BD=E5=A4=9F=E5=9C=A8?= =?UTF-8?q?win7sp1=E4=B8=8A=E7=9B=B4=E6=8E=A5=E8=BF=90=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XCoder/App.config | 4 ++-- XCoder/Program.cs | 5 ----- XCoder/XCoder.csproj | 3 ++- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/XCoder/App.config b/XCoder/App.config index 42c09bc9..4d80070d 100644 --- a/XCoder/App.config +++ b/XCoder/App.config @@ -21,7 +21,7 @@ - + diff --git a/XCoder/Program.cs b/XCoder/Program.cs index fdc34adc..974c97ca 100644 --- a/XCoder/Program.cs +++ b/XCoder/Program.cs @@ -1,15 +1,10 @@ using System; -using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Reflection; using System.Windows.Forms; using NewLife; using NewLife.Log; -using NewLife.Net; using NewLife.Threading; -using NewLife.Xml; -using XCode.DataAccessLayer; using System.Threading.Tasks; #if !NET4 using Stardust; diff --git a/XCoder/XCoder.csproj b/XCoder/XCoder.csproj index d20e8531..a43b1bb1 100644 --- a/XCoder/XCoder.csproj +++ b/XCoder/XCoder.csproj @@ -12,6 +12,7 @@ XCoder leaf.ico latest + v4.6 @@ -23,7 +24,7 @@ false - v4.6 + v4.5 ..\..\XCoder\ TRACE true From 465bcb51095b2d53875e4b8f46318375365fcb58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Sun, 6 Aug 2023 20:51:27 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=88=B0=E6=9C=80=E6=96=B0=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XCoder/Engine/ModelConfig.cs | 6 +- XCoder/FrmMDI.cs | 2 +- XCoder/Program.cs | 237 ++++++++++++++++++++++------------- XCoder/Protocols/Modbus.cs | 2 +- XCoder/Windows/FrmMain.cs | 20 +++ XCoder/XApi/FrmMain.cs | 26 ++-- XCoder/XCoder.csproj | 39 ++---- XCoder/XICO/FileSource.cs | 142 +++++++++++++++++++++ XCoder/XICO/IconFile.cs | 2 +- XCoder/XNet/FrmMain.cs | 26 ++-- XCoder/XNet/FrmMqtt.cs | 1 - XCoder/Yun/FrmMap.cs | 3 +- 12 files changed, 359 insertions(+), 147 deletions(-) create mode 100644 XCoder/XICO/FileSource.cs diff --git a/XCoder/Engine/ModelConfig.cs b/XCoder/Engine/ModelConfig.cs index c490f1e9..a12f7c44 100644 --- a/XCoder/Engine/ModelConfig.cs +++ b/XCoder/Engine/ModelConfig.cs @@ -121,9 +121,9 @@ public String BaseClass [DisplayName("调试")] public Boolean Debug { get; set; } - /// 字典属性 - [DisplayName("数据字典")] - public SerializableDictionary Items { get; set; } = new SerializableDictionary(); + ///// 字典属性 + //[DisplayName("数据字典")] + //public SerializableDictionary Items { get; set; } = new SerializableDictionary(); #endregion #region 加载/保存 diff --git a/XCoder/FrmMDI.cs b/XCoder/FrmMDI.cs index 3636f076..1c6922c4 100644 --- a/XCoder/FrmMDI.cs +++ b/XCoder/FrmMDI.cs @@ -45,7 +45,7 @@ private void FrmMDI_Shown(Object sender, EventArgs e) var asm = AssemblyX.Create(Assembly.GetExecutingAssembly()); if (set.Title.IsNullOrEmpty()) set.Title = asm.Title; - Text = String.Format("{2} v{0} {1:HH:mm:ss}", asm.CompileVersion, asm.Compile, set.Title); + Text = String.Format("{2} v{0} {1:HH:mm:ss}", asm.Version, asm.Compile, set.Title); _load.ContinueWith(t => LoadForms(t.Result)); diff --git a/XCoder/Program.cs b/XCoder/Program.cs index 974c97ca..9e2907de 100644 --- a/XCoder/Program.cs +++ b/XCoder/Program.cs @@ -6,134 +6,199 @@ using NewLife.Log; using NewLife.Threading; using System.Threading.Tasks; +using NewLife.Model; +using Stardust.Services; +using Stardust.Models; +using System.Net.NetworkInformation; #if !NET4 using Stardust; #endif -namespace XCoder +namespace XCoder; + +static class Program { - static class Program + /// 应用程序的主入口点。 + [STAThread] + static void Main() { - /// 应用程序的主入口点。 - [STAThread] - static void Main() - { #if NC30 - XTrace2.UseWinForm(); - Application.SetHighDpiMode(HighDpiMode.SystemAware); + XTrace2.UseWinForm(); + Application.SetHighDpiMode(HighDpiMode.SystemAware); #else - XTrace.UseWinForm(); + XTrace.UseWinForm(); #endif - MachineInfo.RegisterAsync(); + MachineInfo.RegisterAsync(); #if !NET4 - StartClient(); + StartClient(); #endif - StringHelper.EnableSpeechTip = XConfig.Current.SpeechTip; + StringHelper.EnableSpeechTip = XConfig.Current.SpeechTip; - if (XConfig.Current.IsNew) "学无先后达者为师,欢迎使用新生命码神工具!".SpeechTip(); + if (XConfig.Current.IsNew) "学无先后达者为师,欢迎使用新生命码神工具!".SpeechTip(); - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new FrmMDI()); - } + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new FrmMDI()); + } #if !NET4 - static TimerX _timer; - static StarClient _Client; - //static ServiceManager _Manager; - private static void StartClient() - { - var set = XConfig.Current; - var server = set.Server; - if (server.IsNullOrEmpty()) return; + static TimerX _timer; + static StarClient _Client; + //static ServiceManager _Manager; + private static void StartClient() + { + var set = XConfig.Current; + var server = set.Server; + if (server.IsNullOrEmpty()) return; - XTrace.WriteLine("初始化服务端地址:{0}", server); + XTrace.WriteLine("初始化服务端地址:{0}", server); - var client = new StarClient(server) + var client = new StarClient(server) + { + Code = set.Code, + Secret = set.Secret, + ProductCode = "XCoder", + Log = XTrace.Log, + }; + + // 登录后保存证书 + client.OnLogined += (s, e) => + { + var inf = client.Info; + if (inf != null && !inf.Code.IsNullOrEmpty()) { - Code = set.Code, - Secret = set.Secret, - Log = XTrace.Log, - }; + set.Code = inf.Code; + set.Secret = inf.Secret; + set.Save(); + } + }; - // 登录后保存证书 - client.OnLogined += (s, e) => - { - var inf = client.Info; - if (inf != null && !inf.Code.IsNullOrEmpty()) - { - set.Code = inf.Code; - set.Secret = inf.Secret; - set.Save(); - } - }; + // 使用跟踪 + client.UseTrace(); - client.UseTrace(); + Application.ApplicationExit += (s, e) => client.Logout("ApplicationExit"); - Application.ApplicationExit += (s, e) => client.Logout("ApplicationExit"); + // 可能需要多次尝试 + _timer = new TimerX(TryConnectServer, client, 0, 5_000) { Async = true }; - // 可能需要多次尝试 - _timer = new TimerX(TryConnectServer, client, 0, 5_000) { Async = true }; + _Client = client; + } - _Client = client; + private static async Task TryConnectServer(Object state) + { + if (!NetworkInterface.GetIsNetworkAvailable() || AgentInfo.GetIps().IsNullOrEmpty()) + { + return; } - private static async Task TryConnectServer(Object state) + var client = state as StarClient; + + try { - var client = state as StarClient; - var set = XConfig.Current; await client.Login(); - await CheckUpgrade(client, set.Channel); + //await CheckUpgrade(client); + } + catch (Exception ex) + { + // 登录报错后,加大定时间隔,输出简单日志 + //_timer.Period = 30_000; + if (_timer.Period < 30_000) _timer.Period += 5_000; - // 登录成功,销毁定时器 - //TimerX.Current.Period = 0; - _timer.TryDispose(); - _timer = null; + XTrace.Log?.Error(ex.Message); + + return; } - private static String _lastVersion; - private static async Task CheckUpgrade(StarClient client, String channel) - { - var ug = new Stardust.Web.Upgrade { Log = XTrace.Log }; + _timer.TryDispose(); + _timer = new TimerX(CheckUpgrade, null, 5_000, 600_000) { Async = true }; - // 检查更新 - var ur = await client.Upgrade(channel); - if (ur != null && ur.Version != _lastVersion) + client.RegisterCommand("node/upgrade", s => _timer.SetNext(-1)); + } + + private static String _lastVersion; + private static async Task CheckUpgrade(Object data) + { + var client = _Client; + using var span = client.Tracer?.NewSpan("CheckUpgrade", new { _lastVersion }); + + // 运行过程中可能改变配置文件的通道 + var set = XConfig.Current; + var ug = new Stardust.Web.Upgrade { Log = XTrace.Log }; + + // 去除多余入口文件 + ug.Trim("XCoder"); + + // 检查更新 + var ur = await client.Upgrade(set.Channel); + if (ur != null && ur.Version != _lastVersion) + { + client.WriteInfoEvent("Upgrade", $"准备从[{_lastVersion}]更新到[{ur.Version}],开始下载 {ur.Source}"); + try { - ug.Url = ur.Source; + ug.Url = client.BuildUrl(ur.Source); await ug.Download(); // 检查文件完整性 - if (ur.FileHash.IsNullOrEmpty() || ug.CheckFileHash(ur.FileHash)) + var checkHash = ug.CheckFileHash(ur.FileHash); + if (!ur.FileHash.IsNullOrEmpty() && !checkHash) { - // 执行更新,解压缩覆盖文件 - var rs = ug.Update(); - if (rs && !ur.Executor.IsNullOrEmpty()) ug.Run(ur.Executor); - _lastVersion = ur.Version; - - // 去除多余入口文件 - ug.Trim("StarAgent"); - - // 强制更新时,马上重启 - if (rs && ur.Force) + client.WriteInfoEvent("Upgrade", "下载完成,哈希校验失败"); + } + else + { + client.WriteInfoEvent("Upgrade", "下载完成,准备解压文件"); + if (!ug.Extract()) { - //StopWork("Upgrade"); - - // 重新拉起进程 - var star = "XCoder.exe"; - XTrace.WriteLine("强制升级,拉起进程 {0} -upgrade", star.GetFullPath()); - Process.Start(star.GetFullPath(), "-upgrade"); - - //var p = Process.GetCurrentProcess(); - //p.Close(); - //p.Kill(); - Application.Exit(); + client.WriteInfoEvent("Upgrade", "解压失败"); + } + else + { + if (!ur.Preinstall.IsNullOrEmpty()) + { + client.WriteInfoEvent("Upgrade", "执行预安装脚本"); + + ug.Run(ur.Preinstall); + } + + client.WriteInfoEvent("Upgrade", "解压完成,准备覆盖文件"); + + // 执行更新,解压缩覆盖文件 + var rs = ug.Update(); + if (rs && !ur.Executor.IsNullOrEmpty()) ug.Run(ur.Executor); + _lastVersion = ur.Version; + + // 去除多余入口文件 + ug.Trim("XCoder"); + + // 强制更新时,马上重启 + if (rs && ur.Force) + { + // 重新拉起进程 + rs = ug.Run("XCoder.exe", "-run -upgrade"); + + if (rs) + { + var pid = Process.GetCurrentProcess().Id; + client.WriteInfoEvent("Upgrade", "强制更新完成,新进程已拉起,准备退出当前进程!PID=" + pid); + + ug.KillSelf(); + } + else + { + client.WriteInfoEvent("Upgrade", "强制更新完成,但拉起新进程失败"); + } + } } } } + catch (Exception ex) + { + XTrace.WriteException(ex); + client.WriteErrorEvent("Upgrade", ex.ToString()); + } } -#endif } +#endif } \ No newline at end of file diff --git a/XCoder/Protocols/Modbus.cs b/XCoder/Protocols/Modbus.cs index b112f83d..4086b37b 100644 --- a/XCoder/Protocols/Modbus.cs +++ b/XCoder/Protocols/Modbus.cs @@ -149,7 +149,7 @@ public Byte[] WriteCoil(Byte host, UInt16 address, UInt16 value) if (rs == null || rs.Length <= 0) return null; // 去掉2字节地址 - return rs.ReadBytes(2); + return rs.ReadBytes(2, -1); } /// 写入保持寄存器,0x06 diff --git a/XCoder/Windows/FrmMain.cs b/XCoder/Windows/FrmMain.cs index 73110889..0edac97c 100644 --- a/XCoder/Windows/FrmMain.cs +++ b/XCoder/Windows/FrmMain.cs @@ -539,6 +539,7 @@ private void bt_GenTable_Click(Object sender, EventArgs e) //var builder = new EntityBuilder(); var cfg = Config; +#if NET4 var option = new BuilderOption { BaseClass = cfg.BaseClass, @@ -546,6 +547,15 @@ private void bt_GenTable_Click(Object sender, EventArgs e) Namespace = cfg.NameSpace, Output = cfg.OutputPath, }; +#else + var option = new EntityBuilderOption + { + BaseClass = cfg.BaseClass, + ConnName = cfg.EntityConnName, + Namespace = cfg.NameSpace, + Output = cfg.OutputPath, + }; +#endif var rs = EntityBuilder.BuildTables(new[] { table }, option); MessageBox.Show("生成" + table + "成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); @@ -581,6 +591,7 @@ private void bt_GenAll_Click(Object sender, EventArgs e) //} var cfg = Config; +#if NET4 var option = new BuilderOption { BaseClass = cfg.BaseClass, @@ -588,6 +599,15 @@ private void bt_GenAll_Click(Object sender, EventArgs e) Namespace = cfg.NameSpace, Output = cfg.OutputPath, }; +#else + var option = new EntityBuilderOption + { + BaseClass = cfg.BaseClass, + ConnName = cfg.EntityConnName, + Namespace = cfg.NameSpace, + Output = cfg.OutputPath, + }; +#endif var rs = EntityBuilder.BuildTables(tables, option); sw.Stop(); diff --git a/XCoder/XApi/FrmMain.cs b/XCoder/XApi/FrmMain.cs index 23bd9e5b..7eef74ca 100644 --- a/XCoder/XApi/FrmMain.cs +++ b/XCoder/XApi/FrmMain.cs @@ -70,19 +70,19 @@ private void FrmMain_Load(Object sender, EventArgs e) LoadConfig(); - // 语音识别 - ThreadPoolX.QueueUserWorkItem(() => - { - var sp = SpeechRecognition.Current; - if (!sp.Enable) return; - - sp.Register("打开", () => this.Invoke(Connect)) - .Register("关闭", () => this.Invoke(Disconnect)) - .Register("退出", () => Application.Exit()) - .Register("发送", () => this.Invoke(() => btnSend_Click(null, null))); - - BizLog.Info("语音识别前缀:{0} 可用命令:{1}", sp.Name, sp.GetAllKeys().Join()); - }); + //// 语音识别 + //ThreadPoolX.QueueUserWorkItem(() => + //{ + // var sp = SpeechRecognition.Current; + // if (!sp.Enable) return; + + // sp.Register("打开", () => this.Invoke(Connect)) + // .Register("关闭", () => this.Invoke(Disconnect)) + // .Register("退出", () => Application.Exit()) + // .Register("发送", () => this.Invoke(() => btnSend_Click(null, null))); + + // BizLog.Info("语音识别前缀:{0} 可用命令:{1}", sp.Name, sp.GetAllKeys().Join()); + //}); } #endregion diff --git a/XCoder/XCoder.csproj b/XCoder/XCoder.csproj index a43b1bb1..4e1ec577 100644 --- a/XCoder/XCoder.csproj +++ b/XCoder/XCoder.csproj @@ -15,7 +15,7 @@ - v4.6 + v4.5 true ..\..\XCoder\ TRACE;DEBUG @@ -73,12 +73,6 @@ - - Form - - - FrmMain.cs - Form @@ -147,6 +141,7 @@ SerialPortList.cs + Form @@ -186,12 +181,6 @@ - - Form - - - FrmMap.cs - @@ -241,16 +230,12 @@ FrmMain.cs - FrmRedis.cs FrmRedisConfig.cs - - FrmMain.cs - FrmMain.cs @@ -293,9 +278,6 @@ FrmSsh.cs - - FrmMap.cs - Form @@ -402,25 +384,28 @@ - 8.11.2021.1204 + 10.5.2023.801 + + + 2.3.2023.806 - 1.0.2021.1204 + 1.4.2023.806 - 3.6.2021.1204 + 4.3.2023.806 - 3.9.2021.1204 + 5.5.2023.803 - 1.5.2021.1204 + 2.9.2023.801 - 10.3.2021.1204 + 11.9.2023.801 - 2020.0.1 + 2020.0.2 diff --git a/XCoder/XICO/FileSource.cs b/XCoder/XICO/FileSource.cs new file mode 100644 index 00000000..95673c13 --- /dev/null +++ b/XCoder/XICO/FileSource.cs @@ -0,0 +1,142 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Web; + +namespace NewLife.IO +{ + /// 文件资源 + public static class FileSource + { + /// 释放文件 + /// + /// + /// + /// + public static void ReleaseFile(this Assembly asm, String fileName, String destFile = null, Boolean overWrite = false) + { + if (fileName.IsNullOrEmpty()) return; + + if (asm == null) asm = Assembly.GetCallingAssembly(); + var stream = GetFileResource(asm, fileName); + if (stream == null) throw new ArgumentException("filename", $"在程序集{asm.GetName().Name}中无法找到名为{fileName}的资源!"); + + if (destFile.IsNullOrEmpty()) destFile = fileName; + destFile = destFile.GetFullPath(); + + if (File.Exists(destFile) && !overWrite) return; + + //var path = Path.GetDirectoryName(dest); + //if (!path.IsNullOrWhiteSpace() && !Directory.Exists(path)) Directory.CreateDirectory(path); + destFile.EnsureDirectory(true); + try + { + if (File.Exists(destFile)) File.Delete(destFile); + + using var fs = File.Create(destFile); + //IOHelper.CopyTo(stream, fs); + stream.CopyTo(fs); + } + catch { } + finally { stream.Dispose(); } + } + + /// 释放文件夹 + /// + /// + /// + /// + public static void ReleaseFolder(this Assembly asm, String prefix, String dest, Boolean overWrite = false) + { + if (asm == null) asm = Assembly.GetCallingAssembly(); + ReleaseFolder(asm, prefix, dest, overWrite, null); + } + + /// 释放文件夹 + /// + /// + /// + /// + /// + public static void ReleaseFolder(this Assembly asm, String prefix, String dest, Boolean overWrite = false, Func filenameResolver = null) + { + if (asm == null) asm = Assembly.GetCallingAssembly(); + + // 找到符合条件的资源 + var names = asm.GetManifestResourceNames(); + if (names == null || names.Length <= 0) return; + IEnumerable ns = null; + if (prefix.IsNullOrWhiteSpace()) + ns = names.AsEnumerable(); + else + ns = names.Where(e => e.StartsWithIgnoreCase(prefix)); + + if (String.IsNullOrEmpty(dest)) dest = ".".GetFullPath(); + dest = dest.GetFullPath(); + + // 开始处理 + foreach (var item in ns) + { + var stream = asm.GetManifestResourceStream(item); + + // 计算filename + String filename = null; + // 去掉前缀 + if (filenameResolver != null) filename = filenameResolver(item); + + if (String.IsNullOrEmpty(filename)) + { + filename = item; + if (!String.IsNullOrEmpty(prefix)) filename = filename[prefix.Length..]; + if (filename[0] == '.') filename = filename[1..]; + + var ext = Path.GetExtension(item); + filename = filename[..^ext.Length]; + filename = filename.Replace(".", @"\") + ext; + filename = Path.Combine(dest, filename); + } + + if (File.Exists(filename) && !overWrite) return; + + //var path = Path.GetDirectoryName(filename); + //if (!path.IsNullOrWhiteSpace() && !Directory.Exists(path)) Directory.CreateDirectory(path); + filename.EnsureDirectory(true); + try + { + if (File.Exists(filename)) File.Delete(filename); + + using var fs = File.Create(filename); + //IOHelper.CopyTo(stream, fs); + stream.CopyTo(fs); + } + catch { } + finally { stream.Dispose(); } + } + } + + /// 获取文件资源 + /// + /// + /// + public static Stream GetFileResource(this Assembly asm, String filename) + { + if (String.IsNullOrEmpty(filename)) return null; + + var name = String.Empty; + if (asm == null) asm = Assembly.GetCallingAssembly(); + var ss = asm.GetManifestResourceNames(); + if (ss != null && ss.Length > 0) + { + //找到资源名 + name = ss.FirstOrDefault(e => e == filename); + if (String.IsNullOrEmpty(name)) name = ss.FirstOrDefault(e => e.EqualIgnoreCase(filename)); + if (String.IsNullOrEmpty(name)) name = ss.FirstOrDefault(e => e.EndsWith(filename)); + + if (!String.IsNullOrEmpty(name)) return asm.GetManifestResourceStream(name); + } + return null; + } + } +} \ No newline at end of file diff --git a/XCoder/XICO/IconFile.cs b/XCoder/XICO/IconFile.cs index 3a6bca64..8e35d80f 100644 --- a/XCoder/XICO/IconFile.cs +++ b/XCoder/XICO/IconFile.cs @@ -141,7 +141,7 @@ public void AddBmp(Image bmp, Int32 size, Int32 bit) var item = new IconItem(); // bmp要跳过14字节,还要修改高度,png不用 ms.Position = 14; - item.Data = ms.ReadBytes(); + item.Data = ms.ReadBytes(-1); item.Size = (UInt32)item.Data.Length; item.BitCount = (UInt16)bit; diff --git a/XCoder/XNet/FrmMain.cs b/XCoder/XNet/FrmMain.cs index 71d3795b..8987b246 100644 --- a/XCoder/XNet/FrmMain.cs +++ b/XCoder/XNet/FrmMain.cs @@ -87,19 +87,19 @@ private void FrmMain_Load(Object sender, EventArgs e) LoadConfig(); - // 语音识别 - ThreadPoolX.QueueUserWorkItem(() => - { - var sp = SpeechRecognition.Current; - if (!sp.Enable) return; - - sp.Register("打开", () => this.Invoke(Connect)) - .Register("关闭", () => this.Invoke(Disconnect)) - .Register("退出", () => Application.Exit()) - .Register("发送", () => this.Invoke(() => btnSend_Click(null, null))); - - BizLog.Info("语音识别前缀:{0} 可用命令:{1}", sp.Name, sp.GetAllKeys().Join()); - }); + //// 语音识别 + //ThreadPoolX.QueueUserWorkItem(() => + //{ + // var sp = SpeechRecognition.Current; + // if (!sp.Enable) return; + + // sp.Register("打开", () => this.Invoke(Connect)) + // .Register("关闭", () => this.Invoke(Disconnect)) + // .Register("退出", () => Application.Exit()) + // .Register("发送", () => this.Invoke(() => btnSend_Click(null, null))); + + // BizLog.Info("语音识别前缀:{0} 可用命令:{1}", sp.Name, sp.GetAllKeys().Join()); + //}); } #endregion diff --git a/XCoder/XNet/FrmMqtt.cs b/XCoder/XNet/FrmMqtt.cs index e9c5919f..bdf2038c 100644 --- a/XCoder/XNet/FrmMqtt.cs +++ b/XCoder/XNet/FrmMqtt.cs @@ -68,7 +68,6 @@ private async Task Connect() Password = txtPass.Text, Log = _log, - LogMessage = true, }; client.Received += Client_Received; client.Connected += (s, e) => XTrace.WriteLine("连接成功"); diff --git a/XCoder/Yun/FrmMap.cs b/XCoder/Yun/FrmMap.cs index 4946505e..dc7db2d7 100644 --- a/XCoder/Yun/FrmMap.cs +++ b/XCoder/Yun/FrmMap.cs @@ -8,6 +8,7 @@ using NewLife; using NewLife.Data; using NewLife.Log; +using NewLife.Map; using NewLife.Reflection; using NewLife.Serialization; using NewLife.Yun; @@ -114,7 +115,7 @@ private void btnInvoke_Click(Object sender, EventArgs e) SaveConfig(); var cfg = Setting; - var map = type.CreateInstance() as NewLife.Yun.Map; + var map = type.CreateInstance() as Map; map.Log = XTrace.Log; map.CoordType = cfg.Coordtype; From bcf9db2cb2e37c28b0436d206a0b878e3f851721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Mon, 7 Aug 2023 21:15:34 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XCoder/Program.cs | 3 +-- XCoder/Properties/AssemblyInfo.cs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/XCoder/Program.cs b/XCoder/Program.cs index 9e2907de..bf733e0e 100644 --- a/XCoder/Program.cs +++ b/XCoder/Program.cs @@ -46,7 +46,6 @@ static void Main() #if !NET4 static TimerX _timer; static StarClient _Client; - //static ServiceManager _Manager; private static void StartClient() { var set = XConfig.Current; @@ -176,7 +175,7 @@ private static async Task CheckUpgrade(Object data) if (rs && ur.Force) { // 重新拉起进程 - rs = ug.Run("XCoder.exe", "-run -upgrade"); + rs = ug.Run("XCoder", "-run -upgrade"); if (rs) { diff --git a/XCoder/Properties/AssemblyInfo.cs b/XCoder/Properties/AssemblyInfo.cs index 92dcea10..ccbfed9d 100644 --- a/XCoder/Properties/AssemblyInfo.cs +++ b/XCoder/Properties/AssemblyInfo.cs @@ -29,7 +29,7 @@ // 修订号 // [assembly: AssemblyVersion("7.5.*")] -[assembly: AssemblyFileVersion("7.5.2021.1211")] +[assembly: AssemblyFileVersion("7.5.2023.0807")] /* * v7.5.2021.1211 新增ModbusMaster/ModbusSlave From 2c7436fe66950db6a683274e6785e435c49a64e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Thu, 22 Aug 2024 11:17:54 +0800 Subject: [PATCH 07/12] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E6=98=9F=E5=B0=98?= =?UTF-8?q?=E5=88=B0=E6=9C=80=E6=96=B0=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XCoder/Program.cs | 163 +++----------------------- XCoder/XCoder.csproj | 16 +-- XCoder40/Program.cs | 203 +++++++++++++++++++++++++++++++++ XCoder40/XCoder40.csproj | 4 +- XCoderLinux/XCoderLinux.csproj | 4 +- XCoderWpf/XCoderWpf.csproj | 2 +- 6 files changed, 233 insertions(+), 159 deletions(-) create mode 100644 XCoder40/Program.cs diff --git a/XCoder/Program.cs b/XCoder/Program.cs index bf733e0e..cf22908c 100644 --- a/XCoder/Program.cs +++ b/XCoder/Program.cs @@ -1,18 +1,12 @@ using System; -using System.Diagnostics; -using System.IO; +using System.Net.NetworkInformation; +using System.Threading.Tasks; using System.Windows.Forms; using NewLife; using NewLife.Log; using NewLife.Threading; -using System.Threading.Tasks; -using NewLife.Model; -using Stardust.Services; -using Stardust.Models; -using System.Net.NetworkInformation; -#if !NET4 using Stardust; -#endif +using Stardust.Models; namespace XCoder; @@ -22,29 +16,22 @@ static class Program [STAThread] static void Main() { -#if NC30 - XTrace2.UseWinForm(); - Application.SetHighDpiMode(HighDpiMode.SystemAware); -#else XTrace.UseWinForm(); -#endif MachineInfo.RegisterAsync(); -#if !NET4 StartClient(); -#endif - StringHelper.EnableSpeechTip = XConfig.Current.SpeechTip; + var set = XConfig.Current; + StringHelper.EnableSpeechTip = set.SpeechTip; - if (XConfig.Current.IsNew) "学无先后达者为师,欢迎使用新生命码神工具!".SpeechTip(); + if (set.IsNew) "学无先后达者为师,欢迎使用新生命码神工具!".SpeechTip(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new FrmMDI()); } -#if !NET4 - static TimerX _timer; + static StarFactory _factory; static StarClient _Client; private static void StartClient() { @@ -54,150 +41,36 @@ private static void StartClient() XTrace.WriteLine("初始化服务端地址:{0}", server); + _factory = new StarFactory(server, "XCoder", null) + { + Log = XTrace.Log, + }; + var client = new StarClient(server) { Code = set.Code, Secret = set.Secret, ProductCode = "XCoder", + + Tracer = _factory.Tracer, Log = XTrace.Log, }; // 登录后保存证书 client.OnLogined += (s, e) => { - var inf = client.Info; - if (inf != null && !inf.Code.IsNullOrEmpty()) + if (client.Logined && !client.Code.IsNullOrEmpty()) { - set.Code = inf.Code; - set.Secret = inf.Secret; + set.Code = client.Code; + set.Secret = client.Secret; set.Save(); } }; - // 使用跟踪 - client.UseTrace(); + client.Open(); Application.ApplicationExit += (s, e) => client.Logout("ApplicationExit"); - // 可能需要多次尝试 - _timer = new TimerX(TryConnectServer, client, 0, 5_000) { Async = true }; - _Client = client; } - - private static async Task TryConnectServer(Object state) - { - if (!NetworkInterface.GetIsNetworkAvailable() || AgentInfo.GetIps().IsNullOrEmpty()) - { - return; - } - - var client = state as StarClient; - - try - { - await client.Login(); - //await CheckUpgrade(client); - } - catch (Exception ex) - { - // 登录报错后,加大定时间隔,输出简单日志 - //_timer.Period = 30_000; - if (_timer.Period < 30_000) _timer.Period += 5_000; - - XTrace.Log?.Error(ex.Message); - - return; - } - - _timer.TryDispose(); - _timer = new TimerX(CheckUpgrade, null, 5_000, 600_000) { Async = true }; - - client.RegisterCommand("node/upgrade", s => _timer.SetNext(-1)); - } - - private static String _lastVersion; - private static async Task CheckUpgrade(Object data) - { - var client = _Client; - using var span = client.Tracer?.NewSpan("CheckUpgrade", new { _lastVersion }); - - // 运行过程中可能改变配置文件的通道 - var set = XConfig.Current; - var ug = new Stardust.Web.Upgrade { Log = XTrace.Log }; - - // 去除多余入口文件 - ug.Trim("XCoder"); - - // 检查更新 - var ur = await client.Upgrade(set.Channel); - if (ur != null && ur.Version != _lastVersion) - { - client.WriteInfoEvent("Upgrade", $"准备从[{_lastVersion}]更新到[{ur.Version}],开始下载 {ur.Source}"); - try - { - ug.Url = client.BuildUrl(ur.Source); - await ug.Download(); - - // 检查文件完整性 - var checkHash = ug.CheckFileHash(ur.FileHash); - if (!ur.FileHash.IsNullOrEmpty() && !checkHash) - { - client.WriteInfoEvent("Upgrade", "下载完成,哈希校验失败"); - } - else - { - client.WriteInfoEvent("Upgrade", "下载完成,准备解压文件"); - if (!ug.Extract()) - { - client.WriteInfoEvent("Upgrade", "解压失败"); - } - else - { - if (!ur.Preinstall.IsNullOrEmpty()) - { - client.WriteInfoEvent("Upgrade", "执行预安装脚本"); - - ug.Run(ur.Preinstall); - } - - client.WriteInfoEvent("Upgrade", "解压完成,准备覆盖文件"); - - // 执行更新,解压缩覆盖文件 - var rs = ug.Update(); - if (rs && !ur.Executor.IsNullOrEmpty()) ug.Run(ur.Executor); - _lastVersion = ur.Version; - - // 去除多余入口文件 - ug.Trim("XCoder"); - - // 强制更新时,马上重启 - if (rs && ur.Force) - { - // 重新拉起进程 - rs = ug.Run("XCoder", "-run -upgrade"); - - if (rs) - { - var pid = Process.GetCurrentProcess().Id; - client.WriteInfoEvent("Upgrade", "强制更新完成,新进程已拉起,准备退出当前进程!PID=" + pid); - - ug.KillSelf(); - } - else - { - client.WriteInfoEvent("Upgrade", "强制更新完成,但拉起新进程失败"); - } - } - } - } - } - catch (Exception ex) - { - XTrace.WriteException(ex); - client.WriteErrorEvent("Upgrade", ex.ToString()); - } - } - } -#endif } \ No newline at end of file diff --git a/XCoder/XCoder.csproj b/XCoder/XCoder.csproj index 4e1ec577..9443a793 100644 --- a/XCoder/XCoder.csproj +++ b/XCoder/XCoder.csproj @@ -17,7 +17,7 @@ v4.5 true - ..\..\XCoder\ + ..\Bin\XCoder\ TRACE;DEBUG full AnyCPU @@ -25,7 +25,7 @@ v4.5 - ..\..\XCoder\ + ..\Bin\XCoder\ TRACE true pdbonly @@ -384,25 +384,25 @@ - 10.5.2023.801 + 10.10.2024.803 - 2.3.2023.806 + 2.6.2024.801 - 1.4.2023.806 + 2.0.2024.708 4.3.2023.806 - 5.5.2023.803 + 5.7.2024.801 - 2.9.2023.801 + 3.0.2024.806 - 11.9.2023.801 + 11.15.2024.806 2020.0.2 diff --git a/XCoder40/Program.cs b/XCoder40/Program.cs new file mode 100644 index 00000000..c6194de4 --- /dev/null +++ b/XCoder40/Program.cs @@ -0,0 +1,203 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Windows.Forms; +using NewLife; +using NewLife.Log; +using NewLife.Threading; +using System.Threading.Tasks; +using NewLife.Model; +using Stardust.Services; +using Stardust.Models; +using System.Net.NetworkInformation; +#if !NET4 +using Stardust; +#endif + +namespace XCoder; + +static class Program +{ + /// 应用程序的主入口点。 + [STAThread] + static void Main() + { +#if NC30 + XTrace2.UseWinForm(); + Application.SetHighDpiMode(HighDpiMode.SystemAware); +#else + XTrace.UseWinForm(); +#endif + MachineInfo.RegisterAsync(); + +#if !NET4 + StartClient(); +#endif + + StringHelper.EnableSpeechTip = XConfig.Current.SpeechTip; + + if (XConfig.Current.IsNew) "学无先后达者为师,欢迎使用新生命码神工具!".SpeechTip(); + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new FrmMDI()); + } + +#if !NET4 + static TimerX _timer; + static StarClient _Client; + private static void StartClient() + { + var set = XConfig.Current; + var server = set.Server; + if (server.IsNullOrEmpty()) return; + + XTrace.WriteLine("初始化服务端地址:{0}", server); + + var client = new StarClient(server) + { + Code = set.Code, + Secret = set.Secret, + ProductCode = "XCoder", + Log = XTrace.Log, + }; + + // 登录后保存证书 + client.OnLogined += (s, e) => + { + var inf = client.Info; + if (inf != null && !inf.Code.IsNullOrEmpty()) + { + set.Code = inf.Code; + set.Secret = inf.Secret; + set.Save(); + } + }; + + // 使用跟踪 + client.UseTrace(); + + Application.ApplicationExit += (s, e) => client.Logout("ApplicationExit"); + + // 可能需要多次尝试 + _timer = new TimerX(TryConnectServer, client, 0, 5_000) { Async = true }; + + _Client = client; + } + + private static async Task TryConnectServer(Object state) + { + if (!NetworkInterface.GetIsNetworkAvailable() || AgentInfo.GetIps().IsNullOrEmpty()) + { + return; + } + + var client = state as StarClient; + + try + { + await client.Login(); + //await CheckUpgrade(client); + } + catch (Exception ex) + { + // 登录报错后,加大定时间隔,输出简单日志 + //_timer.Period = 30_000; + if (_timer.Period < 30_000) _timer.Period += 5_000; + + XTrace.Log?.Error(ex.Message); + + return; + } + + _timer.TryDispose(); + _timer = new TimerX(CheckUpgrade, null, 5_000, 600_000) { Async = true }; + + client.RegisterCommand("node/upgrade", s => _timer.SetNext(-1)); + } + + private static String _lastVersion; + private static async Task CheckUpgrade(Object data) + { + var client = _Client; + using var span = client.Tracer?.NewSpan("CheckUpgrade", new { _lastVersion }); + + // 运行过程中可能改变配置文件的通道 + var set = XConfig.Current; + var ug = new Stardust.Web.Upgrade { Log = XTrace.Log }; + + // 去除多余入口文件 + ug.Trim("XCoder"); + + // 检查更新 + var ur = await client.Upgrade(set.Channel); + if (ur != null && ur.Version != _lastVersion) + { + client.WriteInfoEvent("Upgrade", $"准备从[{_lastVersion}]更新到[{ur.Version}],开始下载 {ur.Source}"); + try + { + ug.Url = client.BuildUrl(ur.Source); + await ug.Download(); + + // 检查文件完整性 + var checkHash = ug.CheckFileHash(ur.FileHash); + if (!ur.FileHash.IsNullOrEmpty() && !checkHash) + { + client.WriteInfoEvent("Upgrade", "下载完成,哈希校验失败"); + } + else + { + client.WriteInfoEvent("Upgrade", "下载完成,准备解压文件"); + if (!ug.Extract()) + { + client.WriteInfoEvent("Upgrade", "解压失败"); + } + else + { + if (!ur.Preinstall.IsNullOrEmpty()) + { + client.WriteInfoEvent("Upgrade", "执行预安装脚本"); + + ug.Run(ur.Preinstall); + } + + client.WriteInfoEvent("Upgrade", "解压完成,准备覆盖文件"); + + // 执行更新,解压缩覆盖文件 + var rs = ug.Update(); + if (rs && !ur.Executor.IsNullOrEmpty()) ug.Run(ur.Executor); + _lastVersion = ur.Version; + + // 去除多余入口文件 + ug.Trim("XCoder"); + + // 强制更新时,马上重启 + if (rs && ur.Force) + { + // 重新拉起进程 + rs = ug.Run("XCoder", "-run -upgrade"); + + if (rs) + { + var pid = Process.GetCurrentProcess().Id; + client.WriteInfoEvent("Upgrade", "强制更新完成,新进程已拉起,准备退出当前进程!PID=" + pid); + + ug.KillSelf(); + } + else + { + client.WriteInfoEvent("Upgrade", "强制更新完成,但拉起新进程失败"); + } + } + } + } + } + catch (Exception ex) + { + XTrace.WriteException(ex); + client.WriteErrorEvent("Upgrade", ex.ToString()); + } + } + } +#endif +} \ No newline at end of file diff --git a/XCoder40/XCoder40.csproj b/XCoder40/XCoder40.csproj index 692e4724..1098ffdc 100644 --- a/XCoder40/XCoder40.csproj +++ b/XCoder40/XCoder40.csproj @@ -100,9 +100,6 @@ IXForm.cs - - Program.cs - Properties\AssemblyInfo.cs @@ -270,6 +267,7 @@ Yun\MapSetting.cs + FileEncoding\FrmMain.resx diff --git a/XCoderLinux/XCoderLinux.csproj b/XCoderLinux/XCoderLinux.csproj index 3815414d..88931590 100644 --- a/XCoderLinux/XCoderLinux.csproj +++ b/XCoderLinux/XCoderLinux.csproj @@ -48,8 +48,8 @@ - - + + diff --git a/XCoderWpf/XCoderWpf.csproj b/XCoderWpf/XCoderWpf.csproj index 02c07fde..bf963b47 100644 --- a/XCoderWpf/XCoderWpf.csproj +++ b/XCoderWpf/XCoderWpf.csproj @@ -31,7 +31,7 @@ - + From 14b890f1468bbd73c1772eed0dc0b2dab1395fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Thu, 22 Aug 2024 22:13:47 +0800 Subject: [PATCH 08/12] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=BC=95=E7=94=A8=EF=BC=8C=E4=BF=AE=E6=AD=A3MQTT=E5=92=8CNET?= =?UTF-8?q?=E5=BC=95=E7=94=A8Core=E7=89=88=E6=9C=AC=E4=B8=8D=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E5=AF=BC=E8=87=B4=E5=90=84=E4=B8=AA=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=8F=8D=E5=B0=84=E5=8A=A0=E8=BD=BD=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XCoder/FrmMDI.cs | 2 ++ XCoder/XCoder.csproj | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/XCoder/FrmMDI.cs b/XCoder/FrmMDI.cs index 1c6922c4..5f4b79d8 100644 --- a/XCoder/FrmMDI.cs +++ b/XCoder/FrmMDI.cs @@ -54,6 +54,8 @@ private void FrmMDI_Shown(Object sender, EventArgs e) void LoadForms(Type[] ts) { + if (ts.Length == 0) ts = typeof(IXForm).GetAllSubclasses().ToArray(); + var name = XConfig.Current.LastTool + ""; foreach (var item in ts) { diff --git a/XCoder/XCoder.csproj b/XCoder/XCoder.csproj index 9443a793..285e330e 100644 --- a/XCoder/XCoder.csproj +++ b/XCoder/XCoder.csproj @@ -390,10 +390,10 @@ 2.6.2024.801 - 2.0.2024.708 + 2.0.2024.822-beta1012 - 4.3.2023.806 + 4.3.2024.822-beta1011 5.7.2024.801 From 98352d5920461d0057b32a4f1e40be38a9dc110d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=BA=E8=83=BD=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Wed, 14 May 2025 18:18:23 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XCoder/Protocols/ModbusMessage.cs | 271 +++--- XCoder/Protocols/ModbusTcp.cs | 2 +- XCoder/XCoder.csproj | 16 +- XCoder/XCom/SerialPortList.cs | 5 +- XCoder/XCom/SerialTransport.cs | 802 +++++++++--------- XCoder/XNet/BenchHelper.cs | 35 +- XCoder/XNet/FrmMain.cs | 4 +- XCoder/XNet/FrmMqtt.cs | 1 + XCoderLinux/SharpApp.cs | 2 +- XCoderLinux/Util/ControlHelper.cs | 1 + XCoderLinux/XCoderLinux.csproj | 11 +- XCoderLinux/XCom/SerialPortList.cs | 3 +- XCoderLinux/XNet/FrmMain.cs | 2 +- XCoderWpf/XCoderWpf.csproj | 2 +- ...1\347\245\236\345\267\245\345\205\267.sln" | 30 +- 15 files changed, 589 insertions(+), 598 deletions(-) diff --git a/XCoder/Protocols/ModbusMessage.cs b/XCoder/Protocols/ModbusMessage.cs index 38bf932b..69d29285 100644 --- a/XCoder/Protocols/ModbusMessage.cs +++ b/XCoder/Protocols/ModbusMessage.cs @@ -4,166 +4,165 @@ using NewLife.Data; using NewLife.Serialization; -namespace NewLife.IoT.Protocols +namespace NewLife.IoT.Protocols; + +public class ModbusMessage : IAccessor { - public class ModbusMessage : IAccessor - { - #region 属性 - /// 是否响应 - [IgnoreDataMember] - public Boolean Reply { get; set; } + #region 属性 + /// 是否响应 + [IgnoreDataMember] + public Boolean Reply { get; set; } - /// 事务编号 - public UInt16 TransactionId { get; set; } + /// 事务编号 + public UInt16 TransactionId { get; set; } - /// 协议 - public UInt16 ProtocolId { get; set; } + /// 协议 + public UInt16 ProtocolId { get; set; } - /// 站号 - public Byte Host { get; set; } + /// 站号 + public Byte Host { get; set; } - /// 操作码 - public FunctionCodes Code { get; set; } + /// 操作码 + public FunctionCodes Code { get; set; } - /// 地址。请求中使用 - public UInt16 Address { get; set; } + /// 地址。请求中使用 + public UInt16 Address { get; set; } - /// 个数 - public UInt16 Count { get; set; } + /// 个数 + public UInt16 Count { get; set; } - /// 负载数据。响应中使用 - [IgnoreDataMember] - public Packet Payload { get; set; } - #endregion + /// 负载数据。响应中使用 + [IgnoreDataMember] + public Packet Payload { get; set; } + #endregion - #region 构造 - public override String ToString() + #region 构造 + public override String ToString() + { + if (!Reply) { - if (!Reply) - { - if (Payload == null) - return $"{Code} ({Address}, {Count})"; - else - return $"{Code} ({Address}={Payload.ToHex()})"; - } + if (Payload == null) + return $"{Code} ({Address}, {Count})"; else - return $"{Code} {Payload.ToHex()}"; + return $"{Code} ({Address}={Payload.ToHex()})"; } - #endregion - - #region 方法 - /// 读取 - /// - /// - /// - public Boolean Read(Stream stream, Object context) + else + return $"{Code} {Payload.ToHex()}"; + } + #endregion + + #region 方法 + /// 读取 + /// + /// + /// + public Boolean Read(Stream stream, Object context) + { + var binary = context as Binary ?? new Binary { Stream = stream, IsLittleEndian = false }; + + TransactionId = binary.Read(); + ProtocolId = binary.Read(); + var len = binary.Read(); + if (len < 1 + 1 + 1) return false; + + Host = binary.ReadByte(); + Code = (FunctionCodes)binary.ReadByte(); + + len -= 2; + if (!Reply) { - var binary = context as Binary ?? new Binary { Stream = stream, IsLittleEndian = false }; - - TransactionId = binary.Read(); - ProtocolId = binary.Read(); - var len = binary.Read(); - if (len < 1 + 1 + 1) return false; - - Host = binary.ReadByte(); - Code = (FunctionCodes)binary.ReadByte(); - - len -= 2; - if (!Reply) - { - Address = binary.Read(); - if (len == 4) - Count = binary.Read(); - else - Payload = binary.ReadBytes(len - 2); - } - else if (len >= 1) - { - var len2 = binary.ReadByte(); - if (len2 <= len - 1) Payload = binary.ReadBytes(len2); - } - - return true; + Address = binary.Read(); + if (len == 4) + Count = binary.Read(); + else + Payload = binary.ReadBytes(len - 2); } - - /// 解析消息 - /// - /// - public static ModbusMessage Read(Packet pk, Boolean reply = false) + else if (len >= 1) { - var msg = new ModbusMessage { Reply = reply }; - if (msg.Read(pk.GetStream(), null)) return msg; - - return null; + var len2 = binary.ReadByte(); + if (len2 <= len - 1) Payload = binary.ReadBytes(len2); } - /// 写入消息到数据流 - /// - /// - /// - public Boolean Write(Stream stream, Object context) - { - var binary = context as Binary ?? new Binary { Stream = stream, IsLittleEndian = false }; + return true; + } - binary.Write(TransactionId); - binary.Write(ProtocolId); + /// 解析消息 + /// + /// + public static ModbusMessage Read(IPacket pk, Boolean reply = false) + { + var msg = new ModbusMessage { Reply = reply }; + if (msg.Read(pk.GetStream(), null)) return msg; - var pk = Payload; - var len = 1 + 1; - if (!Reply) - len += 2 + (pk?.Total ?? 2); - else - len += 1 + (pk?.Total ?? 0); - binary.Write((UInt16)len); - - binary.Write(Host); - binary.Write((Byte)Code); - - if (!Reply) - { - binary.Write(Address); - if (pk != null) - binary.Write(pk.Data, pk.Offset, pk.Count); - else - binary.Write(Count); - } + return null; + } + + /// 写入消息到数据流 + /// + /// + /// + public Boolean Write(Stream stream, Object context) + { + var binary = context as Binary ?? new Binary { Stream = stream, IsLittleEndian = false }; + + binary.Write(TransactionId); + binary.Write(ProtocolId); + + var pk = Payload; + var len = 1 + 1; + if (!Reply) + len += 2 + (pk?.Total ?? 2); + else + len += 1 + (pk?.Total ?? 0); + binary.Write((UInt16)len); + + binary.Write(Host); + binary.Write((Byte)Code); + + if (!Reply) + { + binary.Write(Address); + if (pk != null) + binary.Write(pk.Data, pk.Offset, pk.Count); else - { - var len2 = (pk?.Total ?? 0); - binary.Write((Byte)len2); - if (pk != null) - binary.Write(pk.Data, pk.Offset, pk.Count); - } - - return true; + binary.Write(Count); } - - /// 消息转数据包 - /// - public Packet ToPacket() + else { - var ms = new MemoryStream(); - Write(ms, null); - - ms.Position = 0; - return new Packet(ms); + var len2 = (pk?.Total ?? 0); + binary.Write((Byte)len2); + if (pk != null) + binary.Write(pk.Data, pk.Offset, pk.Count); } - public ModbusMessage CreateReply() + return true; + } + + /// 消息转数据包 + /// + public Packet ToPacket() + { + var ms = new MemoryStream(); + Write(ms, null); + + ms.Position = 0; + return new Packet(ms); + } + + public ModbusMessage CreateReply() + { + if (Reply) throw new InvalidOperationException(); + + var msg = new ModbusMessage { - if (Reply) throw new InvalidOperationException(); - - var msg = new ModbusMessage - { - Reply = true, - TransactionId = TransactionId, - ProtocolId = ProtocolId, - Host = Host, - Code = Code, - }; - - return msg; - } - #endregion + Reply = true, + TransactionId = TransactionId, + ProtocolId = ProtocolId, + Host = Host, + Code = Code, + }; + + return msg; } + #endregion } \ No newline at end of file diff --git a/XCoder/Protocols/ModbusTcp.cs b/XCoder/Protocols/ModbusTcp.cs index 9953451f..2455d591 100644 --- a/XCoder/Protocols/ModbusTcp.cs +++ b/XCoder/Protocols/ModbusTcp.cs @@ -108,7 +108,7 @@ public override Byte[] SendCommand(Byte host, FunctionCodes code, UInt16 address if (span2 != null) span2.Tag = buf.ToHex(); - var rs = ModbusMessage.Read(buf, true); + var rs = ModbusMessage.Read((ArrayPacket)buf, true); if (rs == null) return null; WriteLog("<= {0}", rs); diff --git a/XCoder/XCoder.csproj b/XCoder/XCoder.csproj index 285e330e..193b798f 100644 --- a/XCoder/XCoder.csproj +++ b/XCoder/XCoder.csproj @@ -13,6 +13,8 @@ leaf.ico latest + enable + latest v4.5 @@ -384,25 +386,25 @@ - 10.10.2024.803 + 11.5.2025.501 - 2.6.2024.801 + 2.6.2025.305 - 2.0.2024.822-beta1012 + 2.0.2025.415 - 4.3.2024.822-beta1011 + 4.4.2025.305 - 5.7.2024.801 + 6.2.2025.503 - 3.0.2024.806 + 3.3.2025.506 - 11.15.2024.806 + 11.19.2025.501 2020.0.2 diff --git a/XCoder/XCom/SerialPortList.cs b/XCoder/XCom/SerialPortList.cs index 7a4e5ff6..5007c27c 100644 --- a/XCoder/XCom/SerialPortList.cs +++ b/XCoder/XCom/SerialPortList.cs @@ -6,6 +6,7 @@ using System.IO.Ports; using System.Text; using System.Windows.Forms; +using NewLife.Data; using NewLife.Log; using NewLife.Net; using NewLife.Threading; @@ -87,7 +88,7 @@ public void LoadInfo() //cbEncoding.DataSource = new String[] { Encoding.UTF8.WebName, Encoding.ASCII.WebName, Encoding.UTF8.WebName }; // 添加编码子菜单 - var encs = new Encoding[] { Encoding.UTF8, Encoding.ASCII, Encoding.UTF7, Encoding.Unicode, Encoding.BigEndianUnicode, Encoding.UTF32,Encoding.GetEncoding("GB2312") }; + var encs = new Encoding[] { Encoding.UTF8, Encoding.ASCII, Encoding.UTF7, Encoding.Unicode, Encoding.BigEndianUnicode, Encoding.UTF32, Encoding.GetEncoding("GB2312") }; var list = new List(encs); // 暂时不用这么多编码 //list.AddRange(Encoding.GetEncodings().Select(e => e.GetEncoding()).Where(e => !encs.Contains(e))); @@ -449,7 +450,7 @@ public Int32 Send(String str) StreamReader _reader; void OnReceived(Object sender, ReceivedEventArgs e) { - var data = e.Packet.ReadBytes(); + var data = e.Packet.ReadBytes(0, -1); if (data == null || data.Length < 1) return; BytesOfReceived += data.Length; diff --git a/XCoder/XCom/SerialTransport.cs b/XCoder/XCom/SerialTransport.cs index c3d432ab..206b5d35 100644 --- a/XCoder/XCom/SerialTransport.cs +++ b/XCoder/XCom/SerialTransport.cs @@ -9,522 +9,532 @@ using NewLife.Log; using NewLife.Threading; -namespace NewLife.Net +namespace NewLife.Net; + +/// 串口传输 +/// +/// 标准例程: +/// +/// var st = new SerialTransport(); +/// st.PortName = "COM65"; // 通讯口 +/// st.FrameSize = 16; // 数据帧大小 +/// +/// st.Received += (s, e) => +/// { +/// Console.WriteLine("收到 {0}", e.ToHex()); +/// }; +/// // 开始异步操作 +/// st.Open(); +/// +/// //var buf = "01080000801A".ToHex(); +/// var buf = "0111C02C".ToHex(); +/// for (int i = 0; i < 100; i++) +/// { +/// Console.WriteLine("发送 {0}", buf.ToHex()); +/// st.Send(buf); +/// +/// Thread.Sleep(1000); +/// } +/// +/// +public class SerialTransport : DisposeBase, ITransport { - /// 串口传输 - /// - /// 标准例程: - /// - /// var st = new SerialTransport(); - /// st.PortName = "COM65"; // 通讯口 - /// st.FrameSize = 16; // 数据帧大小 - /// - /// st.Received += (s, e) => - /// { - /// Console.WriteLine("收到 {0}", e.ToHex()); - /// }; - /// // 开始异步操作 - /// st.Open(); - /// - /// //var buf = "01080000801A".ToHex(); - /// var buf = "0111C02C".ToHex(); - /// for (int i = 0; i < 100; i++) - /// { - /// Console.WriteLine("发送 {0}", buf.ToHex()); - /// st.Send(buf); - /// - /// Thread.Sleep(1000); - /// } - /// - /// - public class SerialTransport : DisposeBase, ITransport + #region 属性 + private SerialPort _Serial; + /// 串口对象 + public SerialPort Serial { - #region 属性 - private SerialPort _Serial; - /// 串口对象 - public SerialPort Serial + get { return _Serial; } + set { - get { return _Serial; } - set + _Serial = value; + if (_Serial != null) { - _Serial = value; - if (_Serial != null) - { - PortName = _Serial.PortName; - BaudRate = _Serial.BaudRate; - Parity = _Serial.Parity; - DataBits = _Serial.DataBits; - StopBits = _Serial.StopBits; - } + PortName = _Serial.PortName; + BaudRate = _Serial.BaudRate; + Parity = _Serial.Parity; + DataBits = _Serial.DataBits; + StopBits = _Serial.StopBits; } } + } - /// 端口名称。默认COM1 - public String PortName { get; set; } = "COM1"; + /// 端口名称。默认COM1 + public String PortName { get; set; } = "COM1"; - /// 波特率。默认115200 - public Int32 BaudRate { get; set; } = 115200; + /// 波特率。默认115200 + public Int32 BaudRate { get; set; } = 115200; - /// 奇偶校验位。默认None - public Parity Parity { get; set; } = Parity.None; + /// 奇偶校验位。默认None + public Parity Parity { get; set; } = Parity.None; - /// 数据位。默认8 - public Int32 DataBits { get; set; } = 8; + /// 数据位。默认8 + public Int32 DataBits { get; set; } = 8; - /// 停止位。默认One - public StopBits StopBits { get; set; } = StopBits.One; + /// 停止位。默认One + public StopBits StopBits { get; set; } = StopBits.One; - /// 超时时间。超过该大小未收到数据,说明是另一帧。默认10ms - public Int32 Timeout { get; set; } = 10; + /// 超时时间。超过该大小未收到数据,说明是另一帧。默认10ms + public Int32 Timeout { get; set; } = 10; - private String _Description; - /// 描述信息 - public String Description + private String _Description; + /// 描述信息 + public String Description + { + get { - get + if (_Description == null) { - if (_Description == null) - { - var dic = GetNames(); - if (!dic.TryGetValue(PortName, out _Description)) - _Description = ""; - } - return _Description; + var dic = GetNames(); + if (!dic.TryGetValue(PortName, out _Description)) + _Description = ""; } + return _Description; } + } - ///// 粘包处理接口 - //public IPacket Packet { get; set; } + ///// 粘包处理接口 + //public IPacket Packet { get; set; } - /// 字节超时。数据包间隔,默认20ms - public Int32 ByteTimeout { get; set; } = 20; - #endregion + /// 字节超时。数据包间隔,默认20ms + public Int32 ByteTimeout { get; set; } = 20; + #endregion - #region 构造 - /// 串口传输 - public SerialTransport() - { - // 每隔一段时间检查一次串口是否已经关闭,如果串口已经不存在,则关闭该传输口 - timer = new TimerX(CheckDisconnect, null, 3000, 3000) { Async = true }; - } + #region 构造 + /// 串口传输 + public SerialTransport() + { + // 每隔一段时间检查一次串口是否已经关闭,如果串口已经不存在,则关闭该传输口 + timer = new TimerX(CheckDisconnect, null, 3000, 3000) { Async = true }; + } - /// 销毁 - /// - //protected override void Dispose(Boolean disposing) - //{ - // base.Dispose(disposing); - - // try - // { - // if (Serial != null) Close(); - // if (timer != null) timer.Dispose(); - // } - // catch { } - //} - #endregion - - #region 方法 - /// 确保创建 - public virtual void EnsureCreate() + /// 销毁 + /// + //protected override void Dispose(Boolean disposing) + //{ + // base.Dispose(disposing); + + // try + // { + // if (Serial != null) Close(); + // if (timer != null) timer.Dispose(); + // } + // catch { } + //} + #endregion + + #region 方法 + /// 确保创建 + public virtual void EnsureCreate() + { + if (Serial == null) { - if (Serial == null) - { - Serial = new SerialPort(PortName, BaudRate, Parity, DataBits, StopBits); + Serial = new SerialPort(PortName, BaudRate, Parity, DataBits, StopBits); - _Description = null; - } + _Description = null; } + } + + /// 打开 + public virtual Boolean Open() + { + EnsureCreate(); - /// 打开 - public virtual Boolean Open() + if (!Serial.IsOpen) { - EnsureCreate(); + Serial.Open(); + if (Received != null) Serial.DataReceived += DataReceived; + } - if (!Serial.IsOpen) - { - Serial.Open(); - if (Received != null) Serial.DataReceived += DataReceived; - } + return true; + } + + /// 关闭 + public virtual Boolean Close() + { + // 关闭时必须清空,否则更换属性后再次打开也无法改变属性 + var sp = Serial; + if (sp != null) + { + Serial = null; + if (Received != null) sp.DataReceived -= DataReceived; + if (sp.IsOpen) sp.Close(); - return true; + OnDisconnect(); } - /// 关闭 - public virtual Boolean Close() - { - // 关闭时必须清空,否则更换属性后再次打开也无法改变属性 - var sp = Serial; - if (sp != null) - { - Serial = null; - if (Received != null) sp.DataReceived -= DataReceived; - if (sp.IsOpen) sp.Close(); + return true; + } + #endregion - OnDisconnect(); - } + #region 发送 + /// 写入数据 + /// 数据包 + public virtual Int32 Send(IPacket pk) + { + if (!Open()) return -1; - return true; - } - #endregion + WriteLog("Send:{0}", pk.ToHex()); - #region 发送 - /// 写入数据 - /// 数据包 - public virtual Int32 Send(Packet pk) + var sp = Serial; + lock (sp) { - if (!Open()) return -1; + if (pk.TryGetArray(out var arr)) + sp.Write(arr.Array, arr.Offset, arr.Count); + else + sp.Write(pk.ToArray(), 0, pk.Total); + } - WriteLog("Send:{0}", pk.ToHex()); + return pk.Total; + } - var sp = Serial; - lock (sp) - { - sp.Write(pk.Data, pk.Offset, pk.Count); - } + public Int32 Send(Byte[] buffer) => Send(new ArrayPacket(buffer)); - return pk.Total; - } + /// 异步发送数据并等待响应 + /// + /// + public virtual async Task SendAsync(IPacket pk) + { + if (!Open()) return null; - /// 异步发送数据并等待响应 - /// - /// - public virtual async Task SendAsync(Packet pk) - { - if (!Open()) return null; + //if (Packet == null) Packet = new PacketProvider(); - //if (Packet == null) Packet = new PacketProvider(); + //var task = Packet.Add(pk, null, Timeout); - //var task = Packet.Add(pk, null, Timeout); + _Source = new TaskCompletionSource(); - _Source = new TaskCompletionSource(); + if (pk != null) + { + WriteLog("SendAsync:{0}", pk.ToHex()); - if (pk != null) + // 发送数据 + var sp = Serial; + lock (sp) { - WriteLog("SendAsync:{0}", pk.ToHex()); - - // 发送数据 - Serial.Write(pk.Data, pk.Offset, pk.Count); + if (pk.TryGetArray(out var arr)) + sp.Write(arr.Array, arr.Offset, arr.Count); + else + sp.Write(pk.ToArray(), 0, pk.Total); } - - return await _Source.Task; } - /// 接收数据 - /// - public virtual Packet Receive() - { - if (!Open()) return null; + return await _Source.Task; + } - var task = SendAsync(null); - if (Timeout > 0 && !task.Wait(Timeout)) return null; + /// 接收数据 + /// + public virtual IOwnerPacket Receive() + { + if (!Open()) return null; - return task.Result; - } - #endregion + var task = SendAsync(null); + if (Timeout > 0 && !task.Wait(Timeout)) return null; - #region 异步接收 - void DataReceived(Object sender, SerialDataReceivedEventArgs e) + return task.Result; + } + #endregion + + #region 异步接收 + void DataReceived(Object sender, SerialDataReceivedEventArgs e) + { + // 发送者必须保持一定间隔,每个报文不能太大,否则会因为粘包拆包而出错 + try { - // 发送者必须保持一定间隔,每个报文不能太大,否则会因为粘包拆包而出错 - try + var sp = sender as SerialPort; + WaitMore(); + if (sp.BytesToRead > 0) { - var sp = sender as SerialPort; - WaitMore(); - if (sp.BytesToRead > 0) - { - var buf = new Byte[sp.BytesToRead]; + //var buf = new Byte[sp.BytesToRead]; - var count = sp.Read(buf, 0, buf.Length); - //if (count != buf.Length) buf = buf.ReadBytes(0, count); - //var ms = new MemoryStream(buf, 0, count, false); - var pk = new Packet(buf, 0, count); + var pk = new OwnerPacket(sp.BytesToRead); + var count = sp.Read(pk.Buffer, pk.Offset, pk.Length); + pk.Resize(count); - ProcessReceive(pk); - } - } - catch (Exception ex) - { - //WriteLog("Error " + ex.Message); - if (Log != null) Log.Error("DataReceived Error {0}", ex.Message); + ProcessReceive(pk); } } - - void WaitMore() + catch (Exception ex) { - var sp = Serial; - - var ms = ByteTimeout; - var end = DateTime.Now.AddMilliseconds(ms); - var count = sp.BytesToRead; - while (sp.IsOpen && end > DateTime.Now) - { - //Thread.SpinWait(1); - Thread.Sleep(ms); - if (count != sp.BytesToRead) - { - end = DateTime.Now.AddMilliseconds(ms); - count = sp.BytesToRead; - } - } + //WriteLog("Error " + ex.Message); + if (Log != null) Log.Error("DataReceived Error {0}", ex.Message); } + } + + void WaitMore() + { + var sp = Serial; - void ProcessReceive(Packet pk) + var ms = ByteTimeout; + var end = DateTime.Now.AddMilliseconds(ms); + var count = sp.BytesToRead; + while (sp.IsOpen && end > DateTime.Now) { - try - { - //if (Packet == null) - OnReceive(pk); - //else - //{ - // // 拆包,多个包多次调用处理程序 - // foreach (var msg in Packet.Parse(pk)) - // { - // OnReceive(msg); - // } - //} - } - catch (Exception ex) + //Thread.SpinWait(1); + Thread.Sleep(ms); + if (count != sp.BytesToRead) { - if (!ex.IsDisposed()) Log.Error("{0}.OnReceive {1}", PortName, ex.Message); + end = DateTime.Now.AddMilliseconds(ms); + count = sp.BytesToRead; } } + } - private TaskCompletionSource _Source; - /// 处理收到的数据。默认匹配同步接收委托 - /// - internal virtual void OnReceive(Packet pk) + void ProcessReceive(IOwnerPacket pk) + { + try + { + //if (Packet == null) + OnReceive(pk); + //else + //{ + // // 拆包,多个包多次调用处理程序 + // foreach (var msg in Packet.Parse(pk)) + // { + // OnReceive(msg); + // } + //} + } + catch (Exception ex) { - //// 同步匹配 - //if (Packet != null && Packet.Match(pk, null)) return; + if (!ex.IsDisposed()) Log.Error("{0}.OnReceive {1}", PortName, ex.Message); + } + } - if (_Source != null) - { - _Source.SetResult(pk); - _Source = null; - return; - } + private TaskCompletionSource _Source; + /// 处理收到的数据。默认匹配同步接收委托 + /// + internal virtual void OnReceive(IOwnerPacket pk) + { + //// 同步匹配 + //if (Packet != null && Packet.Match(pk, null)) return; - // 触发事件 - Received?.Invoke(this, new ReceivedEventArgs { Packet = pk }); + if (_Source != null) + { + _Source.SetResult(pk); + _Source = null; + return; } - /// 数据到达事件 - public event EventHandler Received; - #endregion + // 触发事件 + Received?.Invoke(this, new ReceivedEventArgs { Packet = pk }); + } + + /// 数据到达事件 + public event EventHandler Received; + #endregion - #region 自动检测串口断开 - /// 断开时触发,可能是人为断开,也可能是串口链路断开 - public event EventHandler Disconnected; + #region 自动检测串口断开 + /// 断开时触发,可能是人为断开,也可能是串口链路断开 + public event EventHandler Disconnected; - Boolean isInEvent; - void OnDisconnect() + Boolean isInEvent; + void OnDisconnect() + { + if (Disconnected != null) { - if (Disconnected != null) + // 判断是否在事件中,避免外部在断开时间中调用Close造成死循环 + if (!isInEvent) { - // 判断是否在事件中,避免外部在断开时间中调用Close造成死循环 - if (!isInEvent) - { - isInEvent = true; + isInEvent = true; - Disconnected(this, EventArgs.Empty); + Disconnected(this, EventArgs.Empty); - isInEvent = false; - } + isInEvent = false; } } + } - TimerX timer; - /// 检查串口是否已经断开 - /// - /// FX串口异步操作有严重的泄漏缺陷,如果外部硬件长时间断开, - /// SerialPort.IsOpen检测不到,并且会无限大占用内存。 - /// - /// - void CheckDisconnect(Object state) - { - if (String.IsNullOrEmpty(PortName) || Serial == null || !Serial.IsOpen) return; + TimerX timer; + /// 检查串口是否已经断开 + /// + /// FX串口异步操作有严重的泄漏缺陷,如果外部硬件长时间断开, + /// SerialPort.IsOpen检测不到,并且会无限大占用内存。 + /// + /// + void CheckDisconnect(Object state) + { + if (String.IsNullOrEmpty(PortName) || Serial == null || !Serial.IsOpen) return; - // 如果端口已经不存在,则断开吧 - if (!SerialPort.GetPortNames().Contains(PortName)) - { - WriteLog("串口{0}已经不存在,准备关闭!", PortName); + // 如果端口已经不存在,则断开吧 + if (!SerialPort.GetPortNames().Contains(PortName)) + { + WriteLog("串口{0}已经不存在,准备关闭!", PortName); - //OnDisconnect(); - Close(); - } + //OnDisconnect(); + Close(); } - #endregion + } + #endregion - #region 辅助 - /// 获取带有描述的串口名,没有时返回空数组 - /// - public static String[] GetPortNames() + #region 辅助 + /// 获取带有描述的串口名,没有时返回空数组 + /// + public static String[] GetPortNames() + { + var list = new List(); + foreach (var item in GetNames()) { - var list = new List(); - foreach (var item in GetNames()) - { - list.Add(String.Format("{0}({1})", item.Key, item.Value)); - } - return list.ToArray(); + list.Add(String.Format("{0}({1})", item.Key, item.Value)); } + return list.ToArray(); + } - /// 获取串口列表,名称和描述 - /// - public static Dictionary GetNames() - { - var dic = new Dictionary(StringComparer.OrdinalIgnoreCase); + /// 获取串口列表,名称和描述 + /// + public static Dictionary GetNames() + { + var dic = new Dictionary(StringComparer.OrdinalIgnoreCase); #if NC30 - foreach (var item in SerialPort.GetPortNames()) - { - dic.Add(item, ""); - } + foreach (var item in SerialPort.GetPortNames()) + { + dic.Add(item, ""); + } #else - using (var key = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DEVICEMAP\SERIALCOMM", false)) - using (var usb = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Enum\USB", false)) + using (var key = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DEVICEMAP\SERIALCOMM", false)) + using (var usb = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Enum\USB", false)) + { + if (key != null) { - if (key != null) + foreach (var item in key.GetValueNames()) { - foreach (var item in key.GetValueNames()) - { - var name = key.GetValue(item) + ""; - var des = ""; + var name = key.GetValue(item) + ""; + var des = ""; - // 尝试枚举USB串口 - foreach (var vid in usb.GetSubKeyNames()) + // 尝试枚举USB串口 + foreach (var vid in usb.GetSubKeyNames()) + { + var usbvid = usb.OpenSubKey(vid); + foreach (var elm in usbvid.GetSubKeyNames()) { - var usbvid = usb.OpenSubKey(vid); - foreach (var elm in usbvid.GetSubKeyNames()) + var sub = usbvid.OpenSubKey(elm); + //if (sub.GetValue("Class") + "" == "Ports") { - var sub = usbvid.OpenSubKey(elm); - //if (sub.GetValue("Class") + "" == "Ports") + var FriendlyName = sub.GetValue("FriendlyName") + ""; + if (FriendlyName.Contains("({0})".F(name))) { - var FriendlyName = sub.GetValue("FriendlyName") + ""; - if (FriendlyName.Contains("({0})".F(name))) - { - des = FriendlyName.TrimEnd("({0})".F(name)).Trim(); - break; - } + des = FriendlyName.TrimEnd("({0})".F(name)).Trim(); + break; } } - if (!des.IsNullOrEmpty()) break; - } - - // 最后选择设备映射的串口名 - if (des.IsNullOrEmpty()) - { - des = item; - var p = item.LastIndexOf('\\'); - if (p >= 0) des = des.Substring(p + 1); } + if (!des.IsNullOrEmpty()) break; + } - //dic.Add(name, des); - // 某台机器上发现,串口有重复 - dic[name] = des; + // 最后选择设备映射的串口名 + if (des.IsNullOrEmpty()) + { + des = item; + var p = item.LastIndexOf('\\'); + if (p >= 0) des = des.Substring(p + 1); } + + //dic.Add(name, des); + // 某台机器上发现,串口有重复 + dic[name] = des; } } + } #endif - return dic; - } + return dic; + } - /// 从串口列表选择串口,支持自动选择关键字 - /// 串口名称或者描述符的关键字 - /// - public static SerialTransport Choose(String keyWord = null) + /// 从串口列表选择串口,支持自动选择关键字 + /// 串口名称或者描述符的关键字 + /// + public static SerialTransport Choose(String keyWord = null) + { + var ns = GetNames(); + if (ns.Count == 0) { - var ns = GetNames(); - if (ns.Count == 0) - { - Console.WriteLine("没有可用串口!"); - return null; - } - - var name = ""; - var des = ""; + Console.WriteLine("没有可用串口!"); + return null; + } - Console.WriteLine("可用串口:"); - Console.ForegroundColor = ConsoleColor.Green; - foreach (var item in ns) - { - if (item.Value == "Serial0") continue; + var name = ""; + var des = ""; - if (keyWord != null && (item.Key.EqualIgnoreCase(keyWord) || item.Value.Contains(keyWord))) - { - name = item.Key; - des = item.Value; - } + Console.WriteLine("可用串口:"); + Console.ForegroundColor = ConsoleColor.Green; + foreach (var item in ns) + { + if (item.Value == "Serial0") continue; - //Console.WriteLine(item); - Console.WriteLine("{0,5}({1})", item.Key, item.Value); - } - // 没有自动选择,则默认最后一个 - if (name.IsNullOrEmpty()) + if (keyWord != null && (item.Key.EqualIgnoreCase(keyWord) || item.Value.Contains(keyWord))) { - var item = ns.Last(); name = item.Key; des = item.Value; } - while (true) - { - Console.ResetColor(); - Console.Write("请输入串口名称(默认 "); - Console.ForegroundColor = ConsoleColor.Red; - Console.Write("{0}", name); - Console.ResetColor(); - Console.Write("):"); - - var str = Console.ReadLine(); - if (str.IsNullOrEmpty()) break; - - // 只有输入有效串口名称才行 - if (ns.ContainsKey(str)) - { - name = str; - des = ns[str]; - break; - } - } - - Console.WriteLine(); - Console.Write("正在打开串口 "); - Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine("{0}({1})", name, des); + //Console.WriteLine(item); + Console.WriteLine("{0,5}({1})", item.Key, item.Value); + } + // 没有自动选择,则默认最后一个 + if (name.IsNullOrEmpty()) + { + var item = ns.Last(); + name = item.Key; + des = item.Value; + } + while (true) + { + Console.ResetColor(); + Console.Write("请输入串口名称(默认 "); + Console.ForegroundColor = ConsoleColor.Red; + Console.Write("{0}", name); Console.ResetColor(); + Console.Write("):"); - var sp = new SerialTransport - { - PortName = name - }; + var str = Console.ReadLine(); + if (str.IsNullOrEmpty()) break; - return sp; + // 只有输入有效串口名称才行 + if (ns.ContainsKey(str)) + { + name = str; + des = ns[str]; + break; + } } - #endregion - #region 日志 - /// 日志对象 - public ILog Log { get; set; } = Logger.Null; + Console.WriteLine(); + Console.Write("正在打开串口 "); + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("{0}({1})", name, des); - /// 输出日志 - /// - /// - public void WriteLog(String format, params Object[] args) - { - if (Log != null && Log.Enable) Log.Info(format, args); - } + Console.ResetColor(); - /// 已重载 - /// - public override String ToString() + var sp = new SerialTransport { - if (!String.IsNullOrEmpty(PortName)) - return PortName; - else - return "(SerialPort)"; - } + PortName = name + }; + + return sp; + } + #endregion + #region 日志 + /// 日志对象 + public ILog Log { get; set; } = Logger.Null; - #endregion + /// 输出日志 + /// + /// + public void WriteLog(String format, params Object[] args) + { + if (Log != null && Log.Enable) Log.Info(format, args); } + + /// 已重载 + /// + public override String ToString() + { + if (!String.IsNullOrEmpty(PortName)) + return PortName; + else + return "(SerialPort)"; + } + + + #endregion } \ No newline at end of file diff --git a/XCoder/XNet/BenchHelper.cs b/XCoder/XNet/BenchHelper.cs index 51bbda40..0ede2cbb 100644 --- a/XCoder/XNet/BenchHelper.cs +++ b/XCoder/XNet/BenchHelper.cs @@ -10,29 +10,28 @@ using TaskEx = System.Threading.Tasks.Task; #endif -namespace XCoder.XNet +namespace XCoder.XNet; + +static class BenchHelper { - static class BenchHelper + /// 异步多次发送数据 + /// 会话 + /// 数据包 + /// 次数 + /// 间隔 + /// + public static Task SendConcurrency(this ISocketRemote session, IPacket pk, Int32 times, Int32 msInterval) { - /// 异步多次发送数据 - /// 会话 - /// 数据包 - /// 次数 - /// 间隔 - /// - public static Task SendConcurrency(this ISocketRemote session, Packet pk, Int32 times, Int32 msInterval) + var task = TaskEx.Run(async () => { - var task = TaskEx.Run(async () => + for (var i = 0; i < times; i++) { - for (var i = 0; i < times; i++) - { - session.Send(pk); + session.Send(pk); - await TaskEx.Delay(msInterval); - } - }); + await TaskEx.Delay(msInterval); + } + }); - return task; - } + return task; } } \ No newline at end of file diff --git a/XCoder/XNet/FrmMain.cs b/XCoder/XNet/FrmMain.cs index 8987b246..28718bbb 100644 --- a/XCoder/XNet/FrmMain.cs +++ b/XCoder/XNet/FrmMain.cs @@ -377,7 +377,7 @@ private void btnSend_Click(Object sender, EventArgs e) // 处理换行 str = str.Replace("\n", "\r\n"); var buf = cfg.HexSend ? str.ToHex() : str.GetBytes(); - var pk = new Packet(buf); + var pk = new ArrayPacket(buf); if (_Client != null) { @@ -418,7 +418,7 @@ private void btnSend_Click(Object sender, EventArgs e) for (var i = 0; i < count && _Server != null; i++) { var sw = Stopwatch.StartNew(); - var cs = await _Server.SendAllAsync(buf); + var cs = await _Server.SendAllAsync(pk); sw.Stop(); BizLog.Info("{3}/{4} 已向[{0}]个客户端发送[{1}]数据 {2:n0}ms", cs, buf.Length, sw.ElapsedMilliseconds, i + 1, count); if (sleep > 0) await TaskEx.Delay(sleep); diff --git a/XCoder/XNet/FrmMqtt.cs b/XCoder/XNet/FrmMqtt.cs index bdf2038c..7cbc9c1a 100644 --- a/XCoder/XNet/FrmMqtt.cs +++ b/XCoder/XNet/FrmMqtt.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using NewLife; +using NewLife.Data; using NewLife.Log; using NewLife.MQTT; using NewLife.MQTT.Messaging; diff --git a/XCoderLinux/SharpApp.cs b/XCoderLinux/SharpApp.cs index 27c240be..bbddba55 100644 --- a/XCoderLinux/SharpApp.cs +++ b/XCoderLinux/SharpApp.cs @@ -63,7 +63,7 @@ private void SharpApp_Shown(System.Object sender, System.EventArgs e) 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.CompileVersion, asm.Compile, set.Title); + _title = Title = String.Format("{2} v{0} {1:HH:mm:ss}", asm.FileVersion, asm.Compile, set.Title); _load.ContinueWith(t => LoadForms(t.Result)); diff --git a/XCoderLinux/Util/ControlHelper.cs b/XCoderLinux/Util/ControlHelper.cs index 75668cd3..508ae016 100644 --- a/XCoderLinux/Util/ControlHelper.cs +++ b/XCoderLinux/Util/ControlHelper.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using Gtk; +using NewLife; namespace XCoder.Util { diff --git a/XCoderLinux/XCoderLinux.csproj b/XCoderLinux/XCoderLinux.csproj index 88931590..e3ebb46e 100644 --- a/XCoderLinux/XCoderLinux.csproj +++ b/XCoderLinux/XCoderLinux.csproj @@ -2,7 +2,7 @@ Exe - net5.0;netcoreapp3.1 + net8.0 XCoder XCoder 新生命码神工具 @@ -14,7 +14,9 @@ 8.0.* false ..\XCoder\leaf.ico - ..\..\XCoderLinux\ + ..\Bin\XCoderLinux\ + enable + latest pdbonly true TRACE;NC30;__CORE__ @@ -48,8 +50,9 @@ - - + + + diff --git a/XCoderLinux/XCom/SerialPortList.cs b/XCoderLinux/XCom/SerialPortList.cs index c24b0749..e742e150 100644 --- a/XCoderLinux/XCom/SerialPortList.cs +++ b/XCoderLinux/XCom/SerialPortList.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Text; using Gtk; +using NewLife.Data; using NewLife.Log; using NewLife.Net; using NewLife.Threading; @@ -451,7 +452,7 @@ public Int32 Send(String str) StreamReader _reader; void OnReceived(Object sender, ReceivedEventArgs e) { - var data = e.Packet.ReadBytes(); + var data = e.Packet.ReadBytes(0, -1); if (data == null || data.Length < 1) return; BytesOfReceived += data.Length; diff --git a/XCoderLinux/XNet/FrmMain.cs b/XCoderLinux/XNet/FrmMain.cs index 77b69f34..9c879dc0 100644 --- a/XCoderLinux/XNet/FrmMain.cs +++ b/XCoderLinux/XNet/FrmMain.cs @@ -426,7 +426,7 @@ private void btnSend_Click(Object sender, EventArgs e) for (var i = 0; i < count && _Server != null; i++) { var sw = Stopwatch.StartNew(); - var cs = await _Server.SendAllAsync(buf); + var cs = await _Server.SendAllAsync(pk); sw.Stop(); BizLog.Info("{3}/{4} 已向[{0}]个客户端发送[{1}]数据 {2:n0}ms", cs, buf.Length, sw.ElapsedMilliseconds, i + 1, count); if (sleep > 0) await TaskEx.Delay(sleep); diff --git a/XCoderWpf/XCoderWpf.csproj b/XCoderWpf/XCoderWpf.csproj index bf963b47..be04b100 100644 --- a/XCoderWpf/XCoderWpf.csproj +++ b/XCoderWpf/XCoderWpf.csproj @@ -31,7 +31,7 @@ - + diff --git "a/\347\240\201\347\245\236\345\267\245\345\205\267.sln" "b/\347\240\201\347\245\236\345\267\245\345\205\267.sln" index 2ef2e56d..b65083c3 100644 --- "a/\347\240\201\347\245\236\345\267\245\345\205\267.sln" +++ "b/\347\240\201\347\245\236\345\267\245\345\205\267.sln" @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29318.209 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36109.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Others", "Others", "{32891F65-FBA1-42B2-918E-61F3A9623F2A}" ProjectSection(SolutionItems) = preProject @@ -18,8 +18,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CrazyCoder", "CrazyCoder\Cr EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XCoderWpf", "XCoderWpf\XCoderWpf.csproj", "{405D4D22-FF61-4796-A3F2-222CFDA326D2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XCoder40", "XCoder40\XCoder40.csproj", "{A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -132,30 +130,6 @@ Global {405D4D22-FF61-4796-A3F2-222CFDA326D2}.Release|x64.Build.0 = Release|Any CPU {405D4D22-FF61-4796-A3F2-222CFDA326D2}.Release|x86.ActiveCfg = Release|Any CPU {405D4D22-FF61-4796-A3F2-222CFDA326D2}.Release|x86.Build.0 = Release|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Debug|ARM.ActiveCfg = Debug|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Debug|ARM.Build.0 = Debug|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Debug|iPhone.Build.0 = Debug|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Debug|x64.ActiveCfg = Debug|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Debug|x64.Build.0 = Debug|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Debug|x86.ActiveCfg = Debug|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Debug|x86.Build.0 = Debug|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Release|Any CPU.Build.0 = Release|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Release|ARM.ActiveCfg = Release|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Release|ARM.Build.0 = Release|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Release|iPhone.ActiveCfg = Release|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Release|iPhone.Build.0 = Release|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Release|x64.ActiveCfg = Release|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Release|x64.Build.0 = Release|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Release|x86.ActiveCfg = Release|Any CPU - {A4A7E1BD-9E53-4D60-A0E0-122E5441DDBF}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From e1bd36651e2a6aafa04fa0dc6ba43895a9146f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=BA=E8=83=BD=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Wed, 14 May 2025 18:28:18 +0800 Subject: [PATCH 10/12] =?UTF-8?q?v8.0=20=E5=8D=87=E7=BA=A7=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E7=BB=93=E6=9E=84=EF=BC=8Cnet45=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XCoder/FileEncoding/FrmMain.Designer.cs | 200 ---------- XCoder/FileEncoding/FrmMain.cs | 272 ------------- XCoder/FileEncoding/FrmMain.resx | 141 ------- XCoder/NewModelForm/AddField.Designer.cs | 257 ------------ XCoder/NewModelForm/AddField.cs | 141 ------- XCoder/NewModelForm/AddField.resx | 120 ------ XCoder/NewModelForm/AddTable.Designer.cs | 258 ------------ XCoder/NewModelForm/AddTable.cs | 120 ------ XCoder/NewModelForm/AddTable.resx | 229 ----------- XCoder/NewModelForm/BaseForm.cs | 18 - XCoder/NewModelForm/BaseForm.designer.cs | 49 --- XCoder/NewModelForm/BaseForm.resx | 120 ------ XCoder/NewModelForm/NewModel.Designer.cs | 161 -------- XCoder/NewModelForm/NewModel.cs | 100 ----- XCoder/NewModelForm/NewModel.resx | 217 ---------- XCoder/NewModelForm/WinFormHelper.cs | 125 ------ XCoder/XCoder.csproj | 363 +---------------- XCoder/XMessage/FrmMain.cs | 439 --------------------- XCoder/XMessage/FrmMain.designer.cs | 480 ----------------------- XCoder/XMessage/FrmMain.resx | 141 ------- XCoder/XMessage/MessageConfig.cs | 81 ---- XCoder/Yun/FrmMap.Designer.cs | 307 --------------- XCoder/Yun/FrmMap.cs | 251 ------------ XCoder/Yun/FrmMap.resx | 126 ------ XCoder/Yun/MapSetting.cs | 48 --- 25 files changed, 19 insertions(+), 4745 deletions(-) delete mode 100644 XCoder/FileEncoding/FrmMain.Designer.cs delete mode 100644 XCoder/FileEncoding/FrmMain.cs delete mode 100644 XCoder/FileEncoding/FrmMain.resx delete mode 100644 XCoder/NewModelForm/AddField.Designer.cs delete mode 100644 XCoder/NewModelForm/AddField.cs delete mode 100644 XCoder/NewModelForm/AddField.resx delete mode 100644 XCoder/NewModelForm/AddTable.Designer.cs delete mode 100644 XCoder/NewModelForm/AddTable.cs delete mode 100644 XCoder/NewModelForm/AddTable.resx delete mode 100644 XCoder/NewModelForm/BaseForm.cs delete mode 100644 XCoder/NewModelForm/BaseForm.designer.cs delete mode 100644 XCoder/NewModelForm/BaseForm.resx delete mode 100644 XCoder/NewModelForm/NewModel.Designer.cs delete mode 100644 XCoder/NewModelForm/NewModel.cs delete mode 100644 XCoder/NewModelForm/NewModel.resx delete mode 100644 XCoder/NewModelForm/WinFormHelper.cs delete mode 100644 XCoder/XMessage/FrmMain.cs delete mode 100644 XCoder/XMessage/FrmMain.designer.cs delete mode 100644 XCoder/XMessage/FrmMain.resx delete mode 100644 XCoder/XMessage/MessageConfig.cs delete mode 100644 XCoder/Yun/FrmMap.Designer.cs delete mode 100644 XCoder/Yun/FrmMap.cs delete mode 100644 XCoder/Yun/FrmMap.resx delete mode 100644 XCoder/Yun/MapSetting.cs diff --git a/XCoder/FileEncoding/FrmMain.Designer.cs b/XCoder/FileEncoding/FrmMain.Designer.cs deleted file mode 100644 index 95f446c6..00000000 --- a/XCoder/FileEncoding/FrmMain.Designer.cs +++ /dev/null @@ -1,200 +0,0 @@ -namespace XCoder.FileEncoding -{ - partial class FrmMain - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.lbl_file_suffix_name = new System.Windows.Forms.Label(); - this.txtSuffix = new System.Windows.Forms.TextBox(); - this.lbl_file_encode_name = new System.Windows.Forms.Label(); - this.ddlEncodes = new System.Windows.Forms.ComboBox(); - this.btnChoice = new System.Windows.Forms.Button(); - this.txtPath = new System.Windows.Forms.TextBox(); - this.btnReplace = new System.Windows.Forms.Button(); - this.gv_data = new System.Windows.Forms.DataGridView(); - this.序号 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.编码 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.名称 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.fbd_choice_folder = new System.Windows.Forms.FolderBrowserDialog(); - this.label1 = new System.Windows.Forms.Label(); - this.btnFind = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.gv_data)).BeginInit(); - this.SuspendLayout(); - // - // lbl_file_suffix_name - // - this.lbl_file_suffix_name.AutoSize = true; - this.lbl_file_suffix_name.Location = new System.Drawing.Point(12, 20); - this.lbl_file_suffix_name.Name = "lbl_file_suffix_name"; - this.lbl_file_suffix_name.Size = new System.Drawing.Size(29, 12); - this.lbl_file_suffix_name.TabIndex = 0; - this.lbl_file_suffix_name.Text = "后缀"; - // - // txtSuffix - // - this.txtSuffix.Location = new System.Drawing.Point(47, 16); - this.txtSuffix.Name = "txtSuffix"; - this.txtSuffix.Size = new System.Drawing.Size(85, 21); - this.txtSuffix.TabIndex = 1; - // - // lbl_file_encode_name - // - this.lbl_file_encode_name.AutoSize = true; - this.lbl_file_encode_name.Location = new System.Drawing.Point(480, 20); - this.lbl_file_encode_name.Name = "lbl_file_encode_name"; - this.lbl_file_encode_name.Size = new System.Drawing.Size(53, 12); - this.lbl_file_encode_name.TabIndex = 2; - this.lbl_file_encode_name.Text = "目标编码"; - // - // ddlEncodes - // - this.ddlEncodes.FormattingEnabled = true; - this.ddlEncodes.Location = new System.Drawing.Point(539, 16); - this.ddlEncodes.Name = "ddlEncodes"; - this.ddlEncodes.Size = new System.Drawing.Size(154, 20); - this.ddlEncodes.TabIndex = 3; - // - // btnChoice - // - this.btnChoice.Location = new System.Drawing.Point(361, 15); - this.btnChoice.Name = "btnChoice"; - this.btnChoice.Size = new System.Drawing.Size(31, 23); - this.btnChoice.TabIndex = 4; - this.btnChoice.Text = "..."; - this.btnChoice.UseVisualStyleBackColor = true; - this.btnChoice.Click += new System.EventHandler(this.btn_choice_file_Click); - // - // txtPath - // - this.txtPath.Location = new System.Drawing.Point(198, 16); - this.txtPath.Name = "txtPath"; - this.txtPath.Size = new System.Drawing.Size(157, 21); - this.txtPath.TabIndex = 5; - // - // btnReplace - // - this.btnReplace.Location = new System.Drawing.Point(699, 15); - this.btnReplace.Name = "btnReplace"; - this.btnReplace.Size = new System.Drawing.Size(66, 23); - this.btnReplace.TabIndex = 6; - this.btnReplace.Text = "批量转换"; - this.btnReplace.UseVisualStyleBackColor = true; - this.btnReplace.Click += new System.EventHandler(this.btn_replace_Click); - // - // gv_data - // - this.gv_data.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.gv_data.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.gv_data.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.序号, - this.编码, - this.名称}); - this.gv_data.Location = new System.Drawing.Point(3, 57); - this.gv_data.Name = "gv_data"; - this.gv_data.RowTemplate.Height = 23; - this.gv_data.Size = new System.Drawing.Size(784, 623); - this.gv_data.TabIndex = 7; - // - // 序号 - // - this.序号.HeaderText = "序号"; - this.序号.Name = "序号"; - // - // 编码 - // - this.编码.HeaderText = "编码"; - this.编码.Name = "编码"; - // - // 名称 - // - this.名称.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.名称.HeaderText = "名称"; - this.名称.Name = "名称"; - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(152, 20); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(29, 12); - this.label1.TabIndex = 8; - this.label1.Text = "路径"; - // - // btnFind - // - this.btnFind.Location = new System.Drawing.Point(398, 15); - this.btnFind.Name = "btnFind"; - this.btnFind.Size = new System.Drawing.Size(61, 23); - this.btnFind.TabIndex = 9; - this.btnFind.Text = "查找"; - this.btnFind.UseVisualStyleBackColor = true; - this.btnFind.Click += new System.EventHandler(this.btnFind_Click); - // - // FrmMain - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(789, 681); - this.Controls.Add(this.btnFind); - this.Controls.Add(this.label1); - this.Controls.Add(this.gv_data); - this.Controls.Add(this.btnReplace); - this.Controls.Add(this.txtPath); - this.Controls.Add(this.btnChoice); - this.Controls.Add(this.ddlEncodes); - this.Controls.Add(this.lbl_file_encode_name); - this.Controls.Add(this.txtSuffix); - this.Controls.Add(this.lbl_file_suffix_name); - this.Name = "FrmMain"; - this.Text = "文件编码名"; - this.Load += new System.EventHandler(this.FrmEncodeReplace_Load); - ((System.ComponentModel.ISupportInitialize)(this.gv_data)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.Label lbl_file_suffix_name; - private System.Windows.Forms.TextBox txtSuffix; - private System.Windows.Forms.Label lbl_file_encode_name; - private System.Windows.Forms.ComboBox ddlEncodes; - private System.Windows.Forms.Button btnChoice; - private System.Windows.Forms.TextBox txtPath; - private System.Windows.Forms.Button btnReplace; - private System.Windows.Forms.DataGridView gv_data; - private System.Windows.Forms.DataGridViewTextBoxColumn 序号; - private System.Windows.Forms.DataGridViewTextBoxColumn 编码; - private System.Windows.Forms.DataGridViewTextBoxColumn 名称; - private System.Windows.Forms.FolderBrowserDialog fbd_choice_folder; - private System.Windows.Forms.Label label1; - private System.Windows.Forms.Button btnFind; - } -} \ No newline at end of file diff --git a/XCoder/FileEncoding/FrmMain.cs b/XCoder/FileEncoding/FrmMain.cs deleted file mode 100644 index cbbb7806..00000000 --- a/XCoder/FileEncoding/FrmMain.cs +++ /dev/null @@ -1,272 +0,0 @@ -using System; -using System.ComponentModel; -using System.IO; -using System.Text; -using System.Windows.Forms; -using NewLife; -using NewLife.IO; - -namespace XCoder.FileEncoding -{ - [DisplayName("文件编码工具")] - public partial class FrmMain : Form, IXForm - { - public FrmMain() - { - InitializeComponent(); - - // 动态调节宽度高度,兼容高DPI - this.FixDpi(); - } - - private void FrmEncodeReplace_Load(Object sender, EventArgs e) - { - txtSuffix.Text = "*.cs;*.aspx"; - var encs = new String[] { "UTF-8", "UTF-8 NoBOM", "ASNI", "Unicode", "Default" }; - //var encs = new Encoding[] { Encoding.UTF8, new UTF8Encoding(false), Encoding.ASCII, Encoding.UTF8 }; - ddlEncodes.DataSource = encs; - ddlEncodes.Text = "UTF-8"; - //cmb_tag.Text = "UTF-8"; - btnReplace.Enabled = false; - } - - - private void btn_choice_file_Click(Object sender, EventArgs e) - { - if (!txtPath.Text.IsNullOrEmpty()) fbd_choice_folder.SelectedPath = txtPath.Text; - if (fbd_choice_folder.ShowDialog() != DialogResult.OK) return; - - txtPath.Text = fbd_choice_folder.SelectedPath; - } - - private void btn_replace_Click(Object sender, EventArgs e) - { - if (String.IsNullOrEmpty(txtPath.Text)) - { - MessageBox.Show("请选择文件夹"); - return; - } - - if (gv_data.Rows[0].Cells["序号"].Value == null) - { - MessageBox.Show("当前没有需要替换的文件"); - return; - } - - if (MessageBox.Show("是否确定要批量修改列表中的编码", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) - return; - - - var enc = Encoding.UTF8; - switch (ddlEncodes.Text) - { - case "UTF-8": enc = Encoding.UTF8; break; - case "UTF-8 NoBOM": enc = new UTF8Encoding(false); break; - case "ASNI": enc = Encoding.ASCII; break; - case "Unicode": enc = Encoding.Unicode; break; - } - - var count = 0; - foreach (DataGridViewRow item in gv_data.Rows) - { - if (item.Cells["序号"].Value == null) continue; - var fileCharset = item.Cells["编码"].Value.ToString(); - if (fileCharset.EqualIgnoreCase(ddlEncodes.Text)) continue; - - try - { - //ReplaceEncoding(txtPath.Text + item.Cells["名称"].Value.ToString(), fileCharset, enc); - var file = txtPath.Text + item.Cells["名称"].Value; - var txt = File.ReadAllText(file); - File.WriteAllText(file, txt, enc); - - count++; - } - catch (Exception ex) - { - MessageBox.Show("文件[" + txtPath.Text + item.Cells["名称"].Value.ToString() + "]" + "转换时出错,请手动转换" + ex.Message); - } - } - - MessageBox.Show("转换{0}个文件完成".F(count)); - gv_data.Rows.Clear(); - } - - /// - /// 替换文件编码 - /// - /// - private void ReplaceEncoding(String file, String charset, Encoding targetEncoding) - { - var fileInfo = ""; - using (var sr = new StreamReader(file, Encoding.GetEncoding(charset), false)) - { - fileInfo = sr.ReadToEnd(); - } - - using (var sw = new StreamWriter(file, false, targetEncoding)) - { - sw.Write(fileInfo); - } - } - - Encoding GetEncode() - { - // "UTF-8", "ASNI", "Unicode", "Default" - var e = ddlEncodes.Text; - - var result = Encoding.UTF8; - switch (e) - { - case "UTF-8": result = Encoding.UTF8; break; - case "ASNI": result = Encoding.ASCII; break; - case "Unicode": result = Encoding.Unicode; break; - } - return result; - } - - /// - /// 文件过滤 - /// - /// - public void FileFilter(String path) - { - var di = path.AsDirectory(); - if (!di.Exists) return; - - var Count = 1; - foreach (var file in di.GetAllFiles(txtSuffix.Text, true)) - { - var enc = EncodePelaceHelper.GetEncoding(file.FullName); - if (enc != null && !enc.WebName.EqualIgnoreCase(ddlEncodes.Text)) - { - gv_data.Rows.Add(Count++, enc.WebName, file.FullName.Substring(path.Length)); - } - } - } - - private void btnFind_Click(Object sender, EventArgs e) - { - gv_data.Rows.Clear(); - FileFilter(txtPath.Text); - btnReplace.Enabled = true; - } - } - - /// - /// 文件替换辅助类 - /// - public class EncodePelaceHelper - { - /// - /// 取得一个文本文件的编码方式。如果无法在文件头部找到有效的前导符,Encoding.UTF8将被返回。 - /// - /// 文件名 - /// - public static Encoding GetEncoding(String fileName) - { - return GetEncoding(fileName, Encoding.UTF8); - } - - /// 取得一个文本文件的编码方式。 - /// 文件名。 - /// 默认编码方式。当该方法无法从文件的头部取得有效的前导符时,将返回该编码方式。 - /// - /// - public static Encoding GetEncoding(String fileName, Encoding defaultEncoding) - { - using (var fs = File.OpenRead(fileName)) - { - return fs.Detect() ?? defaultEncoding; - } - } - - ///// - ///// 取得一个文本文件流的编码方式。 - ///// - ///// 文本文件流 - ///// - ///// - //public static Encoding GetEncoding(FileStream stream) - //{ - // return GetEncoding(stream, Encoding.UTF8); - //} - - ///// - ///// 取得一个文本文件的编码方式。 - ///// - ///// 文件名。 - ///// 默认编码方式。当该方法无法从文件的头部取得有效的前导符时,将返回该编码方式。 - ///// - ///// - //public static Encoding GetEncoding(string fileName, Encoding defaultEncoding) - //{ - // FileStream fs = new FileStream(fileName, FileMode.Open); - // Encoding targetEncoding = GetEncoding(fs, defaultEncoding); - // fs.Close(); - // return targetEncoding; - //} - - /// - /// 取得一个文本文件流的编码方式。 - - /// - /// 文本文件流。 - - /// 默认编码方式。当该方法无法从文件的头部取得有效的前导符时,将返回该编码方式。 - /// - /// - public static Encoding GetEncoding(FileStream stream, Encoding defaultEncoding) - { - var targetEncoding = defaultEncoding; - if (stream != null && stream.Length >= 2) - { - //保存文件流的前4个字节 - Byte byte1 = 0; - Byte byte2 = 0; - Byte byte3 = 0; - Byte byte4 = 0; - - //保存当前Seek位置 - var origPos = stream.Seek(0, SeekOrigin.Begin); - stream.Seek(0, SeekOrigin.Begin); - var nByte = stream.ReadByte(); - byte1 = Convert.ToByte(nByte); - byte2 = Convert.ToByte(stream.ReadByte()); - - if (stream.Length >= 3) - { - byte3 = Convert.ToByte(stream.ReadByte()); - } - - if (stream.Length >= 4) - { - byte4 = Convert.ToByte(stream.ReadByte()); - } - //根据文件流的前4个字节判断Encoding - //Unicode {0xFF, 0xFE}; - //BE-Unicode {0xFE, 0xFF}; - //UTF8 = {0xEF, 0xBB, 0xBF}; - - if (byte1 == 0xFE && byte2 == 0xFF)//UnicodeBe - { - targetEncoding = Encoding.BigEndianUnicode; - } - - if (byte1 == 0xFF && byte2 == 0xFE && byte3 != 0xFF)//Unicode - { - targetEncoding = Encoding.Unicode; - } - - if (byte1 == 0xEF && byte2 == 0xBB && byte3 == 0xBF)//UTF8 - { - targetEncoding = Encoding.UTF8; - } - - //恢复Seek位置 - stream.Seek(origPos, SeekOrigin.Begin); - } - return targetEncoding; - } - } -} diff --git a/XCoder/FileEncoding/FrmMain.resx b/XCoder/FileEncoding/FrmMain.resx deleted file mode 100644 index 44949346..00000000 --- a/XCoder/FileEncoding/FrmMain.resx +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - True - - - True - - - True - - - True - - - True - - - True - - - 17, 17 - - \ No newline at end of file diff --git a/XCoder/NewModelForm/AddField.Designer.cs b/XCoder/NewModelForm/AddField.Designer.cs deleted file mode 100644 index 74d716f0..00000000 --- a/XCoder/NewModelForm/AddField.Designer.cs +++ /dev/null @@ -1,257 +0,0 @@ -namespace XCoder -{ - partial class AddField - { - /// - /// 必需的设计器变量。 - /// - private System.ComponentModel.IContainer components = null; - - /// - /// 清理所有正在使用的资源。 - /// - /// 如果应释放托管资源,为 true;否则为 false。 - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region 组件设计器生成的代码 - - /// - /// 设计器支持所需的方法 - 不要 - /// 使用代码编辑器修改此方法的内容。 - /// - private void InitializeComponent() - { - this.gbInfo = new System.Windows.Forms.GroupBox(); - this.btnCancle = new System.Windows.Forms.Button(); - this.btnSave = new System.Windows.Forms.Button(); - this.txtDataType = new System.Windows.Forms.TextBox(); - this.txtDescription = new System.Windows.Forms.TextBox(); - this.label2 = new System.Windows.Forms.Label(); - this.ckbNullable = new System.Windows.Forms.CheckBox(); - this.txtLength = new System.Windows.Forms.TextBox(); - this.ckbPrimarykey = new System.Windows.Forms.CheckBox(); - this.ckbIdentity = new System.Windows.Forms.CheckBox(); - this.combRawType = new System.Windows.Forms.ComboBox(); - this.txtName = new System.Windows.Forms.TextBox(); - this.label13 = new System.Windows.Forms.Label(); - this.label10 = new System.Windows.Forms.Label(); - this.label6 = new System.Windows.Forms.Label(); - this.label3 = new System.Windows.Forms.Label(); - this.label1 = new System.Windows.Forms.Label(); - this.gbInfo.SuspendLayout(); - this.SuspendLayout(); - // - // gbInfo - // - this.gbInfo.Controls.Add(this.btnCancle); - this.gbInfo.Controls.Add(this.btnSave); - this.gbInfo.Controls.Add(this.txtDataType); - this.gbInfo.Controls.Add(this.txtDescription); - this.gbInfo.Controls.Add(this.label2); - this.gbInfo.Controls.Add(this.ckbNullable); - this.gbInfo.Controls.Add(this.txtLength); - this.gbInfo.Controls.Add(this.ckbPrimarykey); - this.gbInfo.Controls.Add(this.ckbIdentity); - this.gbInfo.Controls.Add(this.combRawType); - this.gbInfo.Controls.Add(this.txtName); - this.gbInfo.Controls.Add(this.label13); - this.gbInfo.Controls.Add(this.label10); - this.gbInfo.Controls.Add(this.label6); - this.gbInfo.Controls.Add(this.label3); - this.gbInfo.Controls.Add(this.label1); - this.gbInfo.Dock = System.Windows.Forms.DockStyle.Fill; - this.gbInfo.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.gbInfo.Location = new System.Drawing.Point(0, 0); - this.gbInfo.Name = "gbInfo"; - this.gbInfo.Size = new System.Drawing.Size(468, 267); - this.gbInfo.TabIndex = 0; - this.gbInfo.TabStop = false; - // - // btnCancle - // - this.btnCancle.Location = new System.Drawing.Point(368, 228); - this.btnCancle.Name = "btnCancle"; - this.btnCancle.Size = new System.Drawing.Size(88, 29); - this.btnCancle.TabIndex = 28; - this.btnCancle.Text = "取消"; - this.btnCancle.UseVisualStyleBackColor = true; - this.btnCancle.Click += new System.EventHandler(this.btnCancle_Click); - // - // btnSave - // - this.btnSave.Location = new System.Drawing.Point(277, 228); - this.btnSave.Name = "btnSave"; - this.btnSave.Size = new System.Drawing.Size(85, 29); - this.btnSave.TabIndex = 27; - this.btnSave.Text = "保存"; - this.btnSave.UseVisualStyleBackColor = true; - this.btnSave.Click += new System.EventHandler(this.btnSave_Click); - // - // txtDataType - // - this.txtDataType.Enabled = false; - this.txtDataType.Location = new System.Drawing.Point(101, 116); - this.txtDataType.Name = "txtDataType"; - this.txtDataType.Size = new System.Drawing.Size(155, 29); - this.txtDataType.TabIndex = 26; - // - // txtDescription - // - this.txtDescription.Location = new System.Drawing.Point(326, 116); - this.txtDescription.Name = "txtDescription"; - this.txtDescription.Size = new System.Drawing.Size(130, 29); - this.txtDescription.TabIndex = 25; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(24, 120); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(74, 21); - this.label2.TabIndex = 1; - this.label2.Text = "数据类型"; - // - // ckbNullable - // - this.ckbNullable.AutoSize = true; - this.ckbNullable.Location = new System.Drawing.Point(253, 197); - this.ckbNullable.Name = "ckbNullable"; - this.ckbNullable.Size = new System.Drawing.Size(109, 25); - this.ckbNullable.TabIndex = 21; - this.ckbNullable.Text = "是否允许空"; - this.ckbNullable.UseVisualStyleBackColor = true; - // - // txtLength - // - this.txtLength.Enabled = false; - this.txtLength.Location = new System.Drawing.Point(326, 36); - this.txtLength.Name = "txtLength"; - this.txtLength.Size = new System.Drawing.Size(130, 29); - this.txtLength.TabIndex = 19; - this.txtLength.TextChanged += new System.EventHandler(this.txtLength_TextChanged); - this.txtLength.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtLength_KeyPress); - // - // ckbPrimarykey - // - this.ckbPrimarykey.AutoSize = true; - this.ckbPrimarykey.Location = new System.Drawing.Point(143, 197); - this.ckbPrimarykey.Name = "ckbPrimarykey"; - this.ckbPrimarykey.Size = new System.Drawing.Size(93, 25); - this.ckbPrimarykey.TabIndex = 17; - this.ckbPrimarykey.Text = "是否主键"; - this.ckbPrimarykey.UseVisualStyleBackColor = true; - // - // ckbIdentity - // - this.ckbIdentity.AutoSize = true; - this.ckbIdentity.Location = new System.Drawing.Point(28, 197); - this.ckbIdentity.Name = "ckbIdentity"; - this.ckbIdentity.Size = new System.Drawing.Size(109, 25); - this.ckbIdentity.TabIndex = 16; - this.ckbIdentity.Text = "是否标识列"; - this.ckbIdentity.UseVisualStyleBackColor = true; - // - // combRawType - // - this.combRawType.DisplayMember = "Name"; - this.combRawType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.combRawType.FormattingEnabled = true; - this.combRawType.Location = new System.Drawing.Point(101, 78); - this.combRawType.Name = "combRawType"; - this.combRawType.Size = new System.Drawing.Size(155, 29); - this.combRawType.TabIndex = 15; - this.combRawType.ValueMember = "DataType"; - this.combRawType.SelectedIndexChanged += new System.EventHandler(this.combRawType_SelectedIndexChanged); - // - // txtName - // - this.txtName.Location = new System.Drawing.Point(101, 36); - this.txtName.Name = "txtName"; - this.txtName.Size = new System.Drawing.Size(155, 29); - this.txtName.TabIndex = 13; - // - // label13 - // - this.label13.AutoSize = true; - this.label13.Location = new System.Drawing.Point(281, 120); - this.label13.Name = "label13"; - this.label13.Size = new System.Drawing.Size(42, 21); - this.label13.TabIndex = 12; - this.label13.Text = "说明"; - // - // label10 - // - this.label10.AutoSize = true; - this.label10.Location = new System.Drawing.Point(302, 70); - this.label10.Name = "label10"; - this.label10.Size = new System.Drawing.Size(0, 21); - this.label10.TabIndex = 9; - // - // label6 - // - this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(281, 39); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(42, 21); - this.label6.TabIndex = 5; - this.label6.Text = "长度"; - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(24, 81); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(74, 21); - this.label3.TabIndex = 2; - this.label3.Text = "原始类型"; - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(24, 39); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(74, 21); - this.label1.TabIndex = 0; - this.label1.Text = "字段名称"; - // - // AddField - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.gbInfo); - this.Name = "AddField"; - this.Size = new System.Drawing.Size(468, 267); - this.gbInfo.ResumeLayout(false); - this.gbInfo.PerformLayout(); - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.GroupBox gbInfo; - private System.Windows.Forms.Label label1; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.Label label3; - private System.Windows.Forms.Label label6; - private System.Windows.Forms.Label label10; - private System.Windows.Forms.Label label13; - private System.Windows.Forms.TextBox txtName; - private System.Windows.Forms.ComboBox combRawType; - private System.Windows.Forms.CheckBox ckbIdentity; - private System.Windows.Forms.CheckBox ckbPrimarykey; - private System.Windows.Forms.TextBox txtLength; - private System.Windows.Forms.CheckBox ckbNullable; - private System.Windows.Forms.TextBox txtDescription; - private System.Windows.Forms.TextBox txtDataType; - private System.Windows.Forms.Button btnSave; - private System.Windows.Forms.Button btnCancle; - } -} diff --git a/XCoder/NewModelForm/AddField.cs b/XCoder/NewModelForm/AddField.cs deleted file mode 100644 index 18fa8aef..00000000 --- a/XCoder/NewModelForm/AddField.cs +++ /dev/null @@ -1,141 +0,0 @@ -using System; -using System.Windows.Forms; -using XCode.DataAccessLayer; - -namespace XCoder -{ - public partial class AddField : UserControl - { - public AddField() - { - InitializeComponent(); - } - - private IDataColumn DataColumn; - //是否添加,默认是添加数据 - private Boolean IsNew = true; - - public AddField(IDataColumn dc, Boolean isNew) - { - InitializeComponent(); - IsNew = isNew; - - - combRawType.DataSource = PrimitiveType.TypeList; - //combRawType.DisplayMember = "Name"; - //combRawType.ValueMember = "DataType"; - - DataColumn = dc; - - //修改的话,直接绑定数据到文本框 - if (!IsNew) BandText(); - } - - //绑定数据 - void BandText() - { - txtName.Text = DataColumn.Name; - //txtDefault.Text = DataColumn.Default; - txtDescription.Text = DataColumn.Description; - txtLength.Text = DataColumn.Length.ToString(); - //txtNumOfByte.Text = DataColumn.NumOfByte.ToString(); - //txtPrecision.Text = DataColumn.Precision.ToString(); - if (DataColumn.DataType != null) - { - txtDataType.Text = DataColumn.DataType.Name; - } - if (DataColumn.RawType.Contains("nvarchar")) combRawType.SelectedIndex = 3; - else combRawType.SelectedIndex = PrimitiveType.TypeList.FindIndex(n => n.Name.Contains(DataColumn.RawType)); - - combRawType.Text = DataColumn.RawType; - - ckbIdentity.Checked = DataColumn.Identity; - - ckbNullable.Checked = DataColumn.Nullable; - ckbPrimarykey.Checked = DataColumn.PrimaryKey; - } - - //保存数据 - void SaveValue() - { - DataColumn.Name = txtName.Text.Trim(); - //DataColumn.Default = txtDefault.Text.Trim(); - DataColumn.Description = txtDescription.Text.Trim(); - DataColumn.Length = Convert.ToInt32(txtLength.Text.Trim()); - //DataColumn.NumOfByte = Convert.ToInt32(txtNumOfByte.Text.Trim()); - //DataColumn.Precision = Convert.ToInt32(txtPrecision.Text.Trim()); - DataColumn.DataType = Type.GetType(txtDataType.Text.Trim()); - - if (combRawType.SelectedIndex != 3) - { - DataColumn.RawType = combRawType.Text.Trim(); - } - else - { - DataColumn.RawType = String.Format(combRawType.Text.Trim() + "({0})", DataColumn.Length); - } - - DataColumn.Identity = ckbIdentity.Checked; - DataColumn.Nullable = ckbNullable.Checked; - DataColumn.PrimaryKey = ckbPrimarykey.Checked; - DataColumn.ColumnName = DataColumn.Name; - } - - public static BaseForm CreateForm(IDataColumn column, Boolean isNew) - { - var frm = new AddField(column, isNew); - frm.Dock = DockStyle.Fill; - return WinFormHelper.CreateForm(frm, "编辑字段信息"); - } - - private void combRawType_SelectedIndexChanged(Object sender, EventArgs e) - { - if (combRawType.SelectedIndex == 3) - { - txtLength.Enabled = true; - if (!IsNew) txtLength.Text = DataColumn.Length.ToString(); - else - { - txtDataType.Text = PrimitiveType.TypeList[combRawType.SelectedIndex].DataType; - txtLength.Text = PrimitiveType.TypeList[combRawType.SelectedIndex].Length.ToString(); - //txtNumOfByte.Text = PrimitiveType.TypeList[combRawType.SelectedIndex].NumOfByte.ToString(); - //txtPrecision.Text = PrimitiveType.TypeList[combRawType.SelectedIndex].Precision.ToString(); - } - } - else - { - txtLength.Enabled = false; - txtDataType.Text = PrimitiveType.TypeList[combRawType.SelectedIndex].DataType; - txtLength.Text = PrimitiveType.TypeList[combRawType.SelectedIndex].Length.ToString(); - //txtNumOfByte.Text = PrimitiveType.TypeList[combRawType.SelectedIndex].NumOfByte.ToString(); - //txtPrecision.Text = PrimitiveType.TypeList[combRawType.SelectedIndex].Precision.ToString(); - } - } - - private void btnSave_Click(Object sender, EventArgs e) - { - SaveValue(); - ParentForm.DialogResult = DialogResult.OK; - ParentForm.Close(); - } - - private void btnCancle_Click(Object sender, EventArgs e) - { - ParentForm.DialogResult = DialogResult.Cancel; - ParentForm.Close(); - } - - private void txtLength_TextChanged(Object sender, EventArgs e) - { - //if (combRawType.SelectedIndex == 3) - //{ - // txtPrecision.Text = txtLength.Text; - //} - } - - private void txtLength_KeyPress(Object sender, KeyPressEventArgs e) - { - WinFormHelper.SetControlOnlyZS(sender, e); - } - } -} \ No newline at end of file diff --git a/XCoder/NewModelForm/AddField.resx b/XCoder/NewModelForm/AddField.resx deleted file mode 100644 index 29dcb1b3..00000000 --- a/XCoder/NewModelForm/AddField.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/XCoder/NewModelForm/AddTable.Designer.cs b/XCoder/NewModelForm/AddTable.Designer.cs deleted file mode 100644 index c6ba4d87..00000000 --- a/XCoder/NewModelForm/AddTable.Designer.cs +++ /dev/null @@ -1,258 +0,0 @@ -namespace XCoder -{ - partial class AddTable - { - /// - /// 必需的设计器变量。 - /// - private System.ComponentModel.IContainer components = null; - - /// - /// 清理所有正在使用的资源。 - /// - /// 如果应释放托管资源,为 true;否则为 false。 - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region 组件设计器生成的代码 - - /// - /// 设计器支持所需的方法 - 不要 - /// 使用代码编辑器修改此方法的内容。 - /// - private void InitializeComponent() - { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AddTable)); - this.dgvColumns = new System.Windows.Forms.DataGridView(); - this.toolAddColumns = new System.Windows.Forms.ToolStripButton(); - this.toolEidtColumn = new System.Windows.Forms.ToolStripButton(); - this.toolAddIndex = new System.Windows.Forms.ToolStripButton(); - this.toolAddRelation = new System.Windows.Forms.ToolStripButton(); - this.toolStrip1 = new System.Windows.Forms.ToolStrip(); - this.toolDelete = new System.Windows.Forms.ToolStripButton(); - this.toolSave = new System.Windows.Forms.ToolStripButton(); - this.toolStripButton1 = new System.Windows.Forms.ToolStripButton(); - this.gbTable = new System.Windows.Forms.GroupBox(); - this.combDbType = new System.Windows.Forms.ComboBox(); - this.txtTableRemark = new System.Windows.Forms.TextBox(); - this.txtTableName = new System.Windows.Forms.TextBox(); - this.label3 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.label1 = new System.Windows.Forms.Label(); - ((System.ComponentModel.ISupportInitialize)(this.dgvColumns)).BeginInit(); - this.toolStrip1.SuspendLayout(); - this.gbTable.SuspendLayout(); - this.SuspendLayout(); - // - // dgvColumns - // - this.dgvColumns.AllowUserToAddRows = false; - this.dgvColumns.AllowUserToDeleteRows = false; - this.dgvColumns.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dgvColumns.Dock = System.Windows.Forms.DockStyle.Bottom; - this.dgvColumns.Location = new System.Drawing.Point(0, 120); - this.dgvColumns.Name = "dgvColumns"; - this.dgvColumns.ReadOnly = true; - this.dgvColumns.RowTemplate.Height = 23; - this.dgvColumns.Size = new System.Drawing.Size(934, 240); - this.dgvColumns.TabIndex = 2; - // - // toolAddColumns - // - this.toolAddColumns.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.toolAddColumns.Image = ((System.Drawing.Image)(resources.GetObject("toolAddColumns.Image"))); - this.toolAddColumns.ImageTransparentColor = System.Drawing.Color.Magenta; - this.toolAddColumns.Name = "toolAddColumns"; - this.toolAddColumns.Size = new System.Drawing.Size(76, 22); - this.toolAddColumns.Text = "添加字段"; - this.toolAddColumns.Click += new System.EventHandler(this.toolAddColumns_Click); - // - // toolEidtColumn - // - this.toolEidtColumn.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.toolEidtColumn.Image = ((System.Drawing.Image)(resources.GetObject("toolEidtColumn.Image"))); - this.toolEidtColumn.ImageTransparentColor = System.Drawing.Color.Magenta; - this.toolEidtColumn.Name = "toolEidtColumn"; - this.toolEidtColumn.Size = new System.Drawing.Size(108, 22); - this.toolEidtColumn.Text = "编辑当前字段"; - this.toolEidtColumn.Click += new System.EventHandler(this.toolEidtColumn_Click); - // - // toolAddIndex - // - this.toolAddIndex.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.toolAddIndex.Image = ((System.Drawing.Image)(resources.GetObject("toolAddIndex.Image"))); - this.toolAddIndex.ImageTransparentColor = System.Drawing.Color.Magenta; - this.toolAddIndex.Name = "toolAddIndex"; - this.toolAddIndex.Size = new System.Drawing.Size(76, 22); - this.toolAddIndex.Text = "添加索引"; - // - // toolAddRelation - // - this.toolAddRelation.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.toolAddRelation.Image = ((System.Drawing.Image)(resources.GetObject("toolAddRelation.Image"))); - this.toolAddRelation.ImageTransparentColor = System.Drawing.Color.Magenta; - this.toolAddRelation.Name = "toolAddRelation"; - this.toolAddRelation.Size = new System.Drawing.Size(76, 22); - this.toolAddRelation.Text = "添加关系"; - // - // toolStrip1 - // - this.toolStrip1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolAddColumns, - this.toolEidtColumn, - this.toolDelete, - this.toolAddIndex, - this.toolAddRelation, - this.toolSave, - this.toolStripButton1}); - this.toolStrip1.Location = new System.Drawing.Point(0, 0); - this.toolStrip1.Name = "toolStrip1"; - this.toolStrip1.Size = new System.Drawing.Size(934, 25); - this.toolStrip1.TabIndex = 1; - this.toolStrip1.Text = "toolStrip1"; - // - // toolDelete - // - this.toolDelete.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.toolDelete.Image = ((System.Drawing.Image)(resources.GetObject("toolDelete.Image"))); - this.toolDelete.ImageTransparentColor = System.Drawing.Color.Magenta; - this.toolDelete.Name = "toolDelete"; - this.toolDelete.Size = new System.Drawing.Size(76, 22); - this.toolDelete.Text = "删除字段"; - this.toolDelete.Click += new System.EventHandler(this.toolDelete_Click); - // - // toolSave - // - this.toolSave.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.toolSave.Image = ((System.Drawing.Image)(resources.GetObject("toolSave.Image"))); - this.toolSave.ImageTransparentColor = System.Drawing.Color.Magenta; - this.toolSave.Name = "toolSave"; - this.toolSave.Size = new System.Drawing.Size(44, 22); - this.toolSave.Text = "保存"; - this.toolSave.Click += new System.EventHandler(this.toolSave_Click); - // - // toolStripButton1 - // - this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.toolStripButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton1.Image"))); - this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta; - this.toolStripButton1.Name = "toolStripButton1"; - this.toolStripButton1.Size = new System.Drawing.Size(44, 22); - this.toolStripButton1.Text = "关闭"; - this.toolStripButton1.Click += new System.EventHandler(this.toolStripButton1_Click); - // - // gbTable - // - this.gbTable.Controls.Add(this.combDbType); - this.gbTable.Controls.Add(this.txtTableRemark); - this.gbTable.Controls.Add(this.txtTableName); - this.gbTable.Controls.Add(this.label3); - this.gbTable.Controls.Add(this.label2); - this.gbTable.Controls.Add(this.label1); - this.gbTable.Dock = System.Windows.Forms.DockStyle.Top; - this.gbTable.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.gbTable.Location = new System.Drawing.Point(0, 25); - this.gbTable.Name = "gbTable"; - this.gbTable.Size = new System.Drawing.Size(934, 90); - this.gbTable.TabIndex = 3; - this.gbTable.TabStop = false; - this.gbTable.Text = "表基本信息"; - // - // combDbType - // - this.combDbType.DisplayMember = "Name"; - this.combDbType.FormattingEnabled = true; - this.combDbType.Location = new System.Drawing.Point(111, 53); - this.combDbType.Name = "combDbType"; - this.combDbType.Size = new System.Drawing.Size(219, 24); - this.combDbType.TabIndex = 5; - this.combDbType.ValueMember = "Type"; - // - // txtTableRemark - // - this.txtTableRemark.Location = new System.Drawing.Point(441, 21); - this.txtTableRemark.Multiline = true; - this.txtTableRemark.Name = "txtTableRemark"; - this.txtTableRemark.Size = new System.Drawing.Size(487, 23); - this.txtTableRemark.TabIndex = 4; - // - // txtTableName - // - this.txtTableName.Location = new System.Drawing.Point(111, 18); - this.txtTableName.Name = "txtTableName"; - this.txtTableName.Size = new System.Drawing.Size(219, 26); - this.txtTableName.TabIndex = 3; - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(25, 58); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(88, 16); - this.label3.TabIndex = 2; - this.label3.Text = "数据库类型"; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(379, 24); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(56, 16); - this.label2.TabIndex = 1; - this.label2.Text = "表说明"; - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(73, 24); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(40, 16); - this.label1.TabIndex = 0; - this.label1.Text = "表名"; - // - // AddTable - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.gbTable); - this.Controls.Add(this.dgvColumns); - this.Controls.Add(this.toolStrip1); - this.Name = "AddTable"; - this.Size = new System.Drawing.Size(934, 360); - ((System.ComponentModel.ISupportInitialize)(this.dgvColumns)).EndInit(); - this.toolStrip1.ResumeLayout(false); - this.toolStrip1.PerformLayout(); - this.gbTable.ResumeLayout(false); - this.gbTable.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.DataGridView dgvColumns; - private System.Windows.Forms.ToolStripButton toolAddColumns; - private System.Windows.Forms.ToolStripButton toolEidtColumn; - private System.Windows.Forms.ToolStripButton toolAddIndex; - private System.Windows.Forms.ToolStripButton toolAddRelation; - private System.Windows.Forms.ToolStrip toolStrip1; - private System.Windows.Forms.GroupBox gbTable; - private System.Windows.Forms.Label label1; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.Label label3; - private System.Windows.Forms.TextBox txtTableRemark; - private System.Windows.Forms.TextBox txtTableName; - private System.Windows.Forms.ComboBox combDbType; - private System.Windows.Forms.ToolStripButton toolSave; - private System.Windows.Forms.ToolStripButton toolStripButton1; - private System.Windows.Forms.ToolStripButton toolDelete; - } -} diff --git a/XCoder/NewModelForm/AddTable.cs b/XCoder/NewModelForm/AddTable.cs deleted file mode 100644 index 28f75997..00000000 --- a/XCoder/NewModelForm/AddTable.cs +++ /dev/null @@ -1,120 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Drawing; -using System.Data; -using System.Text; -using System.Windows.Forms; - -using XCode; -using XCode.DataAccessLayer; - -namespace XCoder -{ - public partial class AddTable : UserControl - { - private IDataTable CurrentTable; - - private BindingList list; - - public AddTable() - { - InitializeComponent(); - } - public AddTable(IDataTable table) - { - InitializeComponent(); - combDbType.DataSource = BindComboxEnumType.BindTyps; - //combDbType.DisplayMember = "Name"; - //combDbType.ValueMember = "Type"; - - CurrentTable = table; - //绑定Table信息到文本框 - txtTableName.Text = CurrentTable.TableName; - txtTableRemark.Text = CurrentTable.Description; - combDbType.SelectedValue = CurrentTable.DbType; - - list = new BindingList(); - - //绑定字段到表格 - if (CurrentTable.Columns.Count > 0) dgvColumns.DataSource = CurrentTable.Columns; - - BandingDGV(); - } - - private void BandingDGV() - { - if (CurrentTable.Columns.Count > 0) - { - list.Clear(); - foreach (var item in CurrentTable.Columns) - { - list.Add(item); - } - dgvColumns.DataSource = null; - dgvColumns.DataSource = list; - } - else dgvColumns.DataSource = null; - } - - public static BaseForm CreateForm(IDataTable table) - { - var frm = new AddTable(table); - frm.Dock = DockStyle.Fill; - return WinFormHelper.CreateForm(frm, "添加表"); - } - - private void toolAddColumns_Click(Object sender, EventArgs e) - { - var dc = CurrentTable.CreateColumn(); - //CurrentTable.Columns.Add(dc); - var id = CurrentTable.Columns.Count + 1; - dc.ColumnName = "Column" + id; - dc.Description = "字段" + id; - var dr = AddField.CreateForm(dc, true).ShowDialog(); - if (dr != DialogResult.Cancel) - { - CurrentTable.Columns.Add(dc); - BandingDGV(); - } - } - - private void toolEidtColumn_Click(Object sender, EventArgs e) - { - - var row = dgvColumns.Rows[dgvColumns.CurrentCell.RowIndex]; - if (row == null) return; - - AddField.CreateForm((IDataColumn)row.DataBoundItem, false).ShowDialog(); - - BandingDGV(); - } - - private void toolStripButton1_Click(Object sender, EventArgs e) - { - if (MessageBox.Show("是否需要保存数据?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) - { - toolSave_Click(sender, e); - } - else - { - ParentForm.Close(); - } - } - - private void toolSave_Click(Object sender, EventArgs e) - { - CurrentTable.TableName = txtTableName.Text.Trim(); - CurrentTable.Description = txtTableRemark.Text.Trim(); - CurrentTable.DbType = (DatabaseType)Enum.Parse(typeof(DatabaseType), combDbType.SelectedValue.ToString()); - - BandingDGV(); - } - - private void toolDelete_Click(Object sender, EventArgs e) - { - CurrentTable.Columns.RemoveAt(dgvColumns.CurrentCell.RowIndex); - BandingDGV(); - } - } -} diff --git a/XCoder/NewModelForm/AddTable.resx b/XCoder/NewModelForm/AddTable.resx deleted file mode 100644 index cecf6266..00000000 --- a/XCoder/NewModelForm/AddTable.resx +++ /dev/null @@ -1,229 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG - YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 - 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw - bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc - VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 - c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 - Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo - mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ - kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D - TgDQASA1MVpwzwAAAABJRU5ErkJggg== - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG - YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 - 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw - bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc - VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 - c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 - Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo - mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ - kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D - TgDQASA1MVpwzwAAAABJRU5ErkJggg== - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG - YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 - 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw - bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc - VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 - c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 - Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo - mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ - kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D - TgDQASA1MVpwzwAAAABJRU5ErkJggg== - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG - YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 - 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw - bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc - VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 - c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 - Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo - mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ - kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D - TgDQASA1MVpwzwAAAABJRU5ErkJggg== - - - - 17, 17 - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG - YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 - 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw - bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc - VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 - c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 - Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo - mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ - kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D - TgDQASA1MVpwzwAAAABJRU5ErkJggg== - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG - YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 - 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw - bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc - VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 - c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 - Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo - mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ - kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D - TgDQASA1MVpwzwAAAABJRU5ErkJggg== - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG - YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 - 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw - bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc - VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 - c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 - Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo - mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ - kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D - TgDQASA1MVpwzwAAAABJRU5ErkJggg== - - - \ No newline at end of file diff --git a/XCoder/NewModelForm/BaseForm.cs b/XCoder/NewModelForm/BaseForm.cs deleted file mode 100644 index 2e89ca86..00000000 --- a/XCoder/NewModelForm/BaseForm.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; - -namespace XCoder -{ - public partial class BaseForm : Form - { - public BaseForm() - { - InitializeComponent(); - } - } -} diff --git a/XCoder/NewModelForm/BaseForm.designer.cs b/XCoder/NewModelForm/BaseForm.designer.cs deleted file mode 100644 index 62ed3543..00000000 --- a/XCoder/NewModelForm/BaseForm.designer.cs +++ /dev/null @@ -1,49 +0,0 @@ -namespace XCoder -{ - partial class BaseForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.SuspendLayout(); - // - // FormModel - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(532, 317); - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "FormModel"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "TestForm"; - this.ResumeLayout(false); - - } - - #endregion - } -} \ No newline at end of file diff --git a/XCoder/NewModelForm/BaseForm.resx b/XCoder/NewModelForm/BaseForm.resx deleted file mode 100644 index 29dcb1b3..00000000 --- a/XCoder/NewModelForm/BaseForm.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/XCoder/NewModelForm/NewModel.Designer.cs b/XCoder/NewModelForm/NewModel.Designer.cs deleted file mode 100644 index 8ce1a118..00000000 --- a/XCoder/NewModelForm/NewModel.Designer.cs +++ /dev/null @@ -1,161 +0,0 @@ -namespace XCoder -{ - partial class NewModel - { - /// - /// 必需的设计器变量。 - /// - private System.ComponentModel.IContainer components = null; - - /// - /// 清理所有正在使用的资源。 - /// - /// 如果应释放托管资源,为 true;否则为 false。 - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region 组件设计器生成的代码 - - /// - /// 设计器支持所需的方法 - 不要 - /// 使用代码编辑器修改此方法的内容。 - /// - private void InitializeComponent() - { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NewModel)); - this.dgvTables = new System.Windows.Forms.DataGridView(); - this.toolStrip1 = new System.Windows.Forms.ToolStrip(); - this.toolAddTable = new System.Windows.Forms.ToolStripButton(); - this.toolEidtTable = new System.Windows.Forms.ToolStripButton(); - this.toolDeleteTable = new System.Windows.Forms.ToolStripButton(); - this.toolAddRelation = new System.Windows.Forms.ToolStripButton(); - this.toolSaveModel = new System.Windows.Forms.ToolStripButton(); - this.toolClose = new System.Windows.Forms.ToolStripButton(); - this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); - ((System.ComponentModel.ISupportInitialize)(this.dgvTables)).BeginInit(); - this.toolStrip1.SuspendLayout(); - this.SuspendLayout(); - // - // dgvTables - // - this.dgvTables.AllowUserToAddRows = false; - this.dgvTables.AllowUserToDeleteRows = false; - this.dgvTables.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dgvTables.Dock = System.Windows.Forms.DockStyle.Fill; - this.dgvTables.Location = new System.Drawing.Point(0, 25); - this.dgvTables.Name = "dgvTables"; - this.dgvTables.ReadOnly = true; - this.dgvTables.RowTemplate.Height = 23; - this.dgvTables.Size = new System.Drawing.Size(909, 391); - this.dgvTables.TabIndex = 4; - // - // toolStrip1 - // - this.toolStrip1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolAddTable, - this.toolEidtTable, - this.toolDeleteTable, - this.toolAddRelation, - this.toolSaveModel, - this.toolClose}); - this.toolStrip1.Location = new System.Drawing.Point(0, 0); - this.toolStrip1.Name = "toolStrip1"; - this.toolStrip1.Size = new System.Drawing.Size(909, 25); - this.toolStrip1.TabIndex = 3; - this.toolStrip1.Text = "toolStrip1"; - // - // toolAddTable - // - this.toolAddTable.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.toolAddTable.Image = ((System.Drawing.Image)(resources.GetObject("toolAddTable.Image"))); - this.toolAddTable.ImageTransparentColor = System.Drawing.Color.Magenta; - this.toolAddTable.Name = "toolAddTable"; - this.toolAddTable.Size = new System.Drawing.Size(60, 22); - this.toolAddTable.Text = "添加表"; - this.toolAddTable.Click += new System.EventHandler(this.toolAddTable_Click); - // - // toolEidtTable - // - this.toolEidtTable.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.toolEidtTable.Image = ((System.Drawing.Image)(resources.GetObject("toolEidtTable.Image"))); - this.toolEidtTable.ImageTransparentColor = System.Drawing.Color.Magenta; - this.toolEidtTable.Name = "toolEidtTable"; - this.toolEidtTable.Size = new System.Drawing.Size(92, 22); - this.toolEidtTable.Text = "编辑选中表"; - this.toolEidtTable.Click += new System.EventHandler(this.toolEidtTable_Click); - // - // toolDeleteTable - // - this.toolDeleteTable.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.toolDeleteTable.Image = ((System.Drawing.Image)(resources.GetObject("toolDeleteTable.Image"))); - this.toolDeleteTable.ImageTransparentColor = System.Drawing.Color.Magenta; - this.toolDeleteTable.Name = "toolDeleteTable"; - this.toolDeleteTable.Size = new System.Drawing.Size(60, 22); - this.toolDeleteTable.Text = "删除表"; - this.toolDeleteTable.Click += new System.EventHandler(this.toolDeleteTable_Click); - // - // toolAddRelation - // - this.toolAddRelation.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.toolAddRelation.Image = ((System.Drawing.Image)(resources.GetObject("toolAddRelation.Image"))); - this.toolAddRelation.ImageTransparentColor = System.Drawing.Color.Magenta; - this.toolAddRelation.Name = "toolAddRelation"; - this.toolAddRelation.Size = new System.Drawing.Size(76, 22); - this.toolAddRelation.Text = "添加关系"; - // - // toolSaveModel - // - this.toolSaveModel.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.toolSaveModel.Image = ((System.Drawing.Image)(resources.GetObject("toolSaveModel.Image"))); - this.toolSaveModel.ImageTransparentColor = System.Drawing.Color.Magenta; - this.toolSaveModel.Name = "toolSaveModel"; - this.toolSaveModel.Size = new System.Drawing.Size(76, 22); - this.toolSaveModel.Text = "保存模型"; - this.toolSaveModel.Click += new System.EventHandler(this.toolStripButton1_Click); - // - // toolClose - // - this.toolClose.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.toolClose.Image = ((System.Drawing.Image)(resources.GetObject("toolClose.Image"))); - this.toolClose.ImageTransparentColor = System.Drawing.Color.Magenta; - this.toolClose.Name = "toolClose"; - this.toolClose.Size = new System.Drawing.Size(44, 22); - this.toolClose.Text = "关闭"; - this.toolClose.Click += new System.EventHandler(this.toolClose_Click); - // - // NewModel - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.dgvTables); - this.Controls.Add(this.toolStrip1); - this.Name = "NewModel"; - this.Size = new System.Drawing.Size(909, 416); - ((System.ComponentModel.ISupportInitialize)(this.dgvTables)).EndInit(); - this.toolStrip1.ResumeLayout(false); - this.toolStrip1.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.DataGridView dgvTables; - private System.Windows.Forms.ToolStrip toolStrip1; - private System.Windows.Forms.ToolStripButton toolEidtTable; - private System.Windows.Forms.ToolStripButton toolDeleteTable; - private System.Windows.Forms.ToolStripButton toolAddRelation; - private System.Windows.Forms.ToolStripButton toolAddTable; - private System.Windows.Forms.ToolStripButton toolSaveModel; - private System.Windows.Forms.ToolStripButton toolClose; - private System.Windows.Forms.SaveFileDialog saveFileDialog1; - } -} diff --git a/XCoder/NewModelForm/NewModel.cs b/XCoder/NewModelForm/NewModel.cs deleted file mode 100644 index f6cef2b5..00000000 --- a/XCoder/NewModelForm/NewModel.cs +++ /dev/null @@ -1,100 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Windows.Forms; -using NewLife.Model; -using XCode.DataAccessLayer; - -namespace XCoder -{ - public partial class NewModel : UserControl - { - public List Tables { get; set; } - - - public NewModel() - { - InitializeComponent(); - Tables = new List(); - } - - public static BaseForm CreateForm() - { - var frm = new NewModel(); - frm.Dock = DockStyle.Fill; - - return WinFormHelper.CreateForm(frm, "添加模型"); - } - - private void toolAddTable_Click(Object sender, EventArgs e) - { - //为了触发XCodeService的静态构造函数 - var temp = ModelResolver.Current; - if (temp == null) return; - - var current = ObjectContainer.Current.Resolve(); - Tables.Add(current); - var id = Tables.Count; - current.TableName = "NewTable" + id; - current.Description = "新建表" + id; - current.DbType = DatabaseType.SqlServer; - current.Description = "默认说明"; - - AddTable.CreateForm(current).ShowDialog(); - - dgvTables.DataSource = null; - dgvTables.DataSource = Tables; - } - - private void toolEidtTable_Click(Object sender, EventArgs e) - { - var row = dgvTables.Rows[dgvTables.CurrentCell.RowIndex]; - if (row == null) return; - - AddTable.CreateForm((IDataTable)row.DataBoundItem).ShowDialog(); - } - - private void toolClose_Click(Object sender, EventArgs e) - { - if (MessageBox.Show("是否需要保存?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) - { - toolStripButton1_Click(sender, e); - } - else - { - ParentForm.Close(); - } - } - - //保存模型 - private void toolStripButton1_Click(Object sender, EventArgs e) - { - if (Tables == null || Tables.Count < 1) - { - MessageBox.Show(Text, "数据库架构为空!", MessageBoxButtons.OK, MessageBoxIcon.Warning); - return; - } - if (saveFileDialog1.ShowDialog() != DialogResult.OK || String.IsNullOrEmpty(saveFileDialog1.FileName)) return; - try - { - var xml = DAL.Export(Tables); - File.WriteAllText(saveFileDialog1.FileName, xml); - - MessageBox.Show("保存模型成功!", "保存模型", MessageBoxButtons.OK); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - - private void toolDeleteTable_Click(Object sender, EventArgs e) - { - Tables.RemoveAt(dgvTables.CurrentCell.RowIndex); - - dgvTables.DataSource = null; - dgvTables.DataSource = Tables; - } - } -} diff --git a/XCoder/NewModelForm/NewModel.resx b/XCoder/NewModelForm/NewModel.resx deleted file mode 100644 index 51537342..00000000 --- a/XCoder/NewModelForm/NewModel.resx +++ /dev/null @@ -1,217 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 17, 17 - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIISURBVDhPpZP7S1NxGMbPPxKaXVUkMEq8IpKUCoY/hGgI - ymqkDYYXcCjDZOANURSjCNGFQUTsl4GXVMxKk62YU4fXQpaIlygHQxBRH8/zwvyaIAYe+HLgnPN8nue9 - HA3nvDTq63oW/jm13XOwvPTB3DYFY5MH+bXfcN8ygfTSMSSXfESicQDxBqdYHwH29g9w2tnZ3UcguIvN - rR3417exuBJE5N1n/wfwLgXEOc38Bc6xNRHb+/y4nm49G0Bnit2zf9H6bkliE/jKuYxrd6oVgDWfjB+K - TWeKMyrGEVfowITvD9re/9ABVQrAhh0HHK+ZselMMaN/mvwtDb+aVqkA7HYIwIj3ysfluPTorJnP6Ezx - oHsD1s5ZXEktUwCOioB5f1CEPR9+wTG6iuiserTo8dkwng7HT/R+XUPF8xlcTjErAOdMcW6NW8STiwG8 - 7vej8oUPN/PsEv3t8Ao0TZP3T1u8uJRkUgAuSYHtO97oLxmXd5t9Ho8aPTK+GzntqNfrLm2fFoihwYOI - xGIF4KjoGBLzY1OrF9k6OOFxnwDC4wxIMX1G0pMhgVyMNyoA13PAtS7OrJk1PrC69LUdQWxuF6IybHrX - LRI7JrtZdoDAo1XmbjMyD+tjSXxGcXRmnYg5ttD9QuxDhN0uUgDOmbvNTpPOJaGAo2K36cyaGZvOFIfd - KlSA8/zRh9ABIDUG+1JpAAAAAElFTkSuQmCC - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIISURBVDhPpZP7S1NxGMbPPxKaXVUkMEq8IpKUCoY/hGgI - ymqkDYYXcCjDZOANURSjCNGFQUTsl4GXVMxKk62YU4fXQpaIlygHQxBRH8/zwvyaIAYe+HLgnPN8nue9 - HA3nvDTq63oW/jm13XOwvPTB3DYFY5MH+bXfcN8ygfTSMSSXfESicQDxBqdYHwH29g9w2tnZ3UcguIvN - rR3417exuBJE5N1n/wfwLgXEOc38Bc6xNRHb+/y4nm49G0Bnit2zf9H6bkliE/jKuYxrd6oVgDWfjB+K - TWeKMyrGEVfowITvD9re/9ABVQrAhh0HHK+ZselMMaN/mvwtDb+aVqkA7HYIwIj3ysfluPTorJnP6Ezx - oHsD1s5ZXEktUwCOioB5f1CEPR9+wTG6iuiserTo8dkwng7HT/R+XUPF8xlcTjErAOdMcW6NW8STiwG8 - 7vej8oUPN/PsEv3t8Ao0TZP3T1u8uJRkUgAuSYHtO97oLxmXd5t9Ho8aPTK+GzntqNfrLm2fFoihwYOI - xGIF4KjoGBLzY1OrF9k6OOFxnwDC4wxIMX1G0pMhgVyMNyoA13PAtS7OrJk1PrC69LUdQWxuF6IybHrX - LRI7JrtZdoDAo1XmbjMyD+tjSXxGcXRmnYg5ttD9QuxDhN0uUgDOmbvNTpPOJaGAo2K36cyaGZvOFIfd - KlSA8/zRh9ABIDUG+1JpAAAAAElFTkSuQmCC - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIISURBVDhPpZP7S1NxGMbPPxKaXVUkMEq8IpKUCoY/hGgI - ymqkDYYXcCjDZOANURSjCNGFQUTsl4GXVMxKk62YU4fXQpaIlygHQxBRH8/zwvyaIAYe+HLgnPN8nue9 - HA3nvDTq63oW/jm13XOwvPTB3DYFY5MH+bXfcN8ygfTSMSSXfESicQDxBqdYHwH29g9w2tnZ3UcguIvN - rR3417exuBJE5N1n/wfwLgXEOc38Bc6xNRHb+/y4nm49G0Bnit2zf9H6bkliE/jKuYxrd6oVgDWfjB+K - TWeKMyrGEVfowITvD9re/9ABVQrAhh0HHK+ZselMMaN/mvwtDb+aVqkA7HYIwIj3ysfluPTorJnP6Ezx - oHsD1s5ZXEktUwCOioB5f1CEPR9+wTG6iuiserTo8dkwng7HT/R+XUPF8xlcTjErAOdMcW6NW8STiwG8 - 7vej8oUPN/PsEv3t8Ao0TZP3T1u8uJRkUgAuSYHtO97oLxmXd5t9Ho8aPTK+GzntqNfrLm2fFoihwYOI - xGIF4KjoGBLzY1OrF9k6OOFxnwDC4wxIMX1G0pMhgVyMNyoA13PAtS7OrJk1PrC69LUdQWxuF6IybHrX - LRI7JrtZdoDAo1XmbjMyD+tjSXxGcXRmnYg5ttD9QuxDhN0uUgDOmbvNTpPOJaGAo2K36cyaGZvOFIfd - KlSA8/zRh9ABIDUG+1JpAAAAAElFTkSuQmCC - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIISURBVDhPpZP7S1NxGMbPPxKaXVUkMEq8IpKUCoY/hGgI - ymqkDYYXcCjDZOANURSjCNGFQUTsl4GXVMxKk62YU4fXQpaIlygHQxBRH8/zwvyaIAYe+HLgnPN8nue9 - HA3nvDTq63oW/jm13XOwvPTB3DYFY5MH+bXfcN8ygfTSMSSXfESicQDxBqdYHwH29g9w2tnZ3UcguIvN - rR3417exuBJE5N1n/wfwLgXEOc38Bc6xNRHb+/y4nm49G0Bnit2zf9H6bkliE/jKuYxrd6oVgDWfjB+K - TWeKMyrGEVfowITvD9re/9ABVQrAhh0HHK+ZselMMaN/mvwtDb+aVqkA7HYIwIj3ysfluPTorJnP6Ezx - oHsD1s5ZXEktUwCOioB5f1CEPR9+wTG6iuiserTo8dkwng7HT/R+XUPF8xlcTjErAOdMcW6NW8STiwG8 - 7vej8oUPN/PsEv3t8Ao0TZP3T1u8uJRkUgAuSYHtO97oLxmXd5t9Ho8aPTK+GzntqNfrLm2fFoihwYOI - xGIF4KjoGBLzY1OrF9k6OOFxnwDC4wxIMX1G0pMhgVyMNyoA13PAtS7OrJk1PrC69LUdQWxuF6IybHrX - LRI7JrtZdoDAo1XmbjMyD+tjSXxGcXRmnYg5ttD9QuxDhN0uUgDOmbvNTpPOJaGAo2K36cyaGZvOFIfd - KlSA8/zRh9ABIDUG+1JpAAAAAElFTkSuQmCC - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIISURBVDhPpZP7S1NxGMbPPxKaXVUkMEq8IpKUCoY/hGgI - ymqkDYYXcCjDZOANURSjCNGFQUTsl4GXVMxKk62YU4fXQpaIlygHQxBRH8/zwvyaIAYe+HLgnPN8nue9 - HA3nvDTq63oW/jm13XOwvPTB3DYFY5MH+bXfcN8ygfTSMSSXfESicQDxBqdYHwH29g9w2tnZ3UcguIvN - rR3417exuBJE5N1n/wfwLgXEOc38Bc6xNRHb+/y4nm49G0Bnit2zf9H6bkliE/jKuYxrd6oVgDWfjB+K - TWeKMyrGEVfowITvD9re/9ABVQrAhh0HHK+ZselMMaN/mvwtDb+aVqkA7HYIwIj3ysfluPTorJnP6Ezx - oHsD1s5ZXEktUwCOioB5f1CEPR9+wTG6iuiserTo8dkwng7HT/R+XUPF8xlcTjErAOdMcW6NW8STiwG8 - 7vej8oUPN/PsEv3t8Ao0TZP3T1u8uJRkUgAuSYHtO97oLxmXd5t9Ho8aPTK+GzntqNfrLm2fFoihwYOI - xGIF4KjoGBLzY1OrF9k6OOFxnwDC4wxIMX1G0pMhgVyMNyoA13PAtS7OrJk1PrC69LUdQWxuF6IybHrX - LRI7JrtZdoDAo1XmbjMyD+tjSXxGcXRmnYg5ttD9QuxDhN0uUgDOmbvNTpPOJaGAo2K36cyaGZvOFIfd - KlSA8/zRh9ABIDUG+1JpAAAAAElFTkSuQmCC - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIISURBVDhPpZP7S1NxGMbPPxKaXVUkMEq8IpKUCoY/hGgI - ymqkDYYXcCjDZOANURSjCNGFQUTsl4GXVMxKk62YU4fXQpaIlygHQxBRH8/zwvyaIAYe+HLgnPN8nue9 - HA3nvDTq63oW/jm13XOwvPTB3DYFY5MH+bXfcN8ygfTSMSSXfESicQDxBqdYHwH29g9w2tnZ3UcguIvN - rR3417exuBJE5N1n/wfwLgXEOc38Bc6xNRHb+/y4nm49G0Bnit2zf9H6bkliE/jKuYxrd6oVgDWfjB+K - TWeKMyrGEVfowITvD9re/9ABVQrAhh0HHK+ZselMMaN/mvwtDb+aVqkA7HYIwIj3ysfluPTorJnP6Ezx - oHsD1s5ZXEktUwCOioB5f1CEPR9+wTG6iuiserTo8dkwng7HT/R+XUPF8xlcTjErAOdMcW6NW8STiwG8 - 7vej8oUPN/PsEv3t8Ao0TZP3T1u8uJRkUgAuSYHtO97oLxmXd5t9Ho8aPTK+GzntqNfrLm2fFoihwYOI - xGIF4KjoGBLzY1OrF9k6OOFxnwDC4wxIMX1G0pMhgVyMNyoA13PAtS7OrJk1PrC69LUdQWxuF6IybHrX - LRI7JrtZdoDAo1XmbjMyD+tjSXxGcXRmnYg5ttD9QuxDhN0uUgDOmbvNTpPOJaGAo2K36cyaGZvOFIfd - KlSA8/zRh9ABIDUG+1JpAAAAAElFTkSuQmCC - - - - 127, 17 - - \ No newline at end of file diff --git a/XCoder/NewModelForm/WinFormHelper.cs b/XCoder/NewModelForm/WinFormHelper.cs deleted file mode 100644 index ea0cd686..00000000 --- a/XCoder/NewModelForm/WinFormHelper.cs +++ /dev/null @@ -1,125 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Windows.Forms; -using System.Drawing; - -namespace XCoder -{ - public class WinFormHelper - { - #region 获取FormModel窗体,传入一个控件 - /// - /// 获取控件的窗体,并设置标题 - /// - /// 控件 - /// 标题文本 - public static BaseForm CreateForm(Control cl, String titleText = "") - { - var tf = new BaseForm(); - tf.Size = new Size(cl.Width + 15, cl.Size.Height + 40); - tf.Controls.Add(cl);//将控件添加到窗体中 - tf.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - tf.Text = titleText; - return tf; - } - #endregion - - #region 设置控件只能输入数字 - /// - /// 设置控件只能输入数字 - /// - /// - /// - public static void SetControlOnlyValue(Object sender, KeyPressEventArgs e) - { - e.Handled = !(Char.IsNumber(e.KeyChar) || e.KeyChar == (Char)8 || e.KeyChar == '.' || e.KeyChar == '-'); - if (!e.Handled) - (sender as TextBox).Tag = (sender as TextBox).Text;//记录最后一次正确输入 - } - /// - /// 只能输入正数 - /// - /// - /// - public static void SetControlOnlyZS(Object sender, KeyPressEventArgs e) - { - e.Handled = !(Char.IsNumber(e.KeyChar) || e.KeyChar == (Char)8 || e.KeyChar == '.'); - if (!e.Handled) - (sender as TextBox).Tag = (sender as TextBox).Text;//记录最后一次正确输入 - } - #endregion - } - - /// 用于Combox显示绑定的对象 - public class BindComboxEnumType - { - /// 类型的名字 - public String Name { get; set; } - - /// 类型 - public T Type { get; set; } - - private static readonly List> bindTyps; - - static BindComboxEnumType() - { - bindTyps = new List>(); - - foreach (var name in Enum.GetNames(typeof(T))) - { - bindTyps.Add(new BindComboxEnumType() - { - Name = name, - Type = (T)Enum.Parse(typeof(T), name) - }); - } - } - - /// 绑定的类型数据 - public static List> BindTyps - { - get { return bindTyps; } - } - } - - /// 暂时支持的数据类型,常规的 - public enum SupportDataType - { - Boolean = 3, - DateTime = 6, - Double = 8, - Int32 = 9, - Int64 = 10, - SByte = 11, - String = 12 - } - - /// 模型设计所支持的数据类型,每一种类型的很多参数都固定了,所以写了这么个类 - public class PrimitiveType - { - /// 原始类型名称 - public String Name { get; set; } - /// 类型长度 - public Int32 Length { get; set; } - ///// 字节数/summary> - //public Int32 NumOfByte { get; set; } - /// 精度 - public Int32 Precision { get; set; } - /// 数据类型 - public String DataType { get; set; } - - public static List TypeList; - - static PrimitiveType() - { - TypeList = new List(); - TypeList.Add(new PrimitiveType() { Name = "bool", Length = 1, DataType = "System.Boolean", Precision = 1 }); - TypeList.Add(new PrimitiveType() { Name = "int", Length = 10, DataType = "System.Int32", Precision = 10 }); - TypeList.Add(new PrimitiveType() { Name = "double", Length = 22, DataType = "System.Double", Precision = 22 }); - TypeList.Add(new PrimitiveType() { Name = "nvarchar", Length = 20, DataType = "System.String", Precision = 20 }); - TypeList.Add(new PrimitiveType() { Name = "ntext", Length = 65535, DataType = "System.String", Precision = 65535 }); - TypeList.Add(new PrimitiveType() { Name = "datetime", Length = 20, DataType = "System.DateTime", Precision = 20 }); - } - } -} \ No newline at end of file diff --git a/XCoder/XCoder.csproj b/XCoder/XCoder.csproj index 193b798f..55d7bf09 100644 --- a/XCoder/XCoder.csproj +++ b/XCoder/XCoder.csproj @@ -1,367 +1,50 @@ - - + - Debug - AnyCPU - 9.0.30729 - 2.0 - {3EB3A5F1-F785-4672-A21D-A3117FC12129} + net45 WinExe - Properties - XCoder - XCoder + 新生命码神工具 + 众多开发者工具 + 新生命开发团队 + ©2002-2025 NewLife + 8.0 + $([System.DateTime]::Now.ToString(`yyyy.MMdd`)) + $(VersionPrefix).$(VersionSuffix) + $(Version) + $(VersionPrefix).$([System.DateTime]::Now.ToString(`yyyy.MMdd`)) + ..\Bin\XCoder\ + false leaf.ico latest - enable latest + true + true - - v4.5 - true - ..\Bin\XCoder\ - TRACE;DEBUG - full - AnyCPU - false - - - v4.5 - ..\Bin\XCoder\ - TRACE - true - pdbonly - AnyCPU - 3 - false - - Properties\app.manifest + + + - - - - - - - - - - - - Form - - - FrmRedis.cs - - - Form - - - FrmRedisConfig.cs - - - - - - Form - - - FrmMain.cs - - - Form - - - FrmSplitFile.cs - - - Form - - - FrmMDI.cs - - - - - - - Form - - - FrmBackup.cs - - - Form - - - FrmMD5.cs - - - Form - - - FrmSymmetric.cs - - - Form - - - FrmSecurity.cs - - - Form - - - FrmSpeak.cs - - - - - Form - - - FrmMain.cs - - - + UserControl - - SerialPortList.cs - - - - - - Form - - - FrmIp.cs - - - Form - - - FrmModbusMaster.cs - - - Form - - - FrmModbusSlave.cs - - - Form - - - FrmMqtt.cs - - - Form - - - FrmSsh.cs - - - - - - - - - - - - - Form - - - FrmGPS.cs - - - Form - - - FrmInclude.cs - - - Form - - - FrmMain.cs - - - Form - - - FrmMain.cs - - - - Form - - - FrmMain.cs - - - - - - - Form - - - FrmMain.cs - - - Form - - - FrmMain.cs - - - FrmRedis.cs - - - FrmRedisConfig.cs - - - FrmMain.cs - - - FrmMDI.cs - - - FrmBackup.cs - - - FrmMD5.cs - - - FrmSymmetric.cs - - - FrmSecurity.cs - - - FrmSpeak.cs - - - FrmMain.cs - - - SerialPortList.cs - - - FrmIp.cs - - - FrmModbusMaster.cs - - - FrmModbusSlave.cs - - - FrmMqtt.cs - - - FrmSsh.cs - - - Form - - - FrmMain.cs - - - Form - - - FrmModel.cs - - - Form - - - FrmQuery.cs - - - Form - - - FrmSchema.cs - - - Form - - - FrmText.cs - - - - - FrmGPS.cs - - - FrmInclude.cs - - - FrmMain.cs - - - FrmModel.cs - - - FrmQuery.cs - - - FrmSchema.cs - - - FrmText.cs - - - FrmMain.cs - Designer - - - - Designer - - - - - - FrmMain.cs - - - FrmMain.cs - - - FrmMain.cs - - - FrmMain.cs - - @@ -413,15 +96,7 @@ - del "$(TargetDir)*.xml" /q - \ No newline at end of file diff --git a/XCoder/XMessage/FrmMain.cs b/XCoder/XMessage/FrmMain.cs deleted file mode 100644 index 8f16d87d..00000000 --- a/XCoder/XMessage/FrmMain.cs +++ /dev/null @@ -1,439 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Threading.Tasks; -using System.Windows.Forms; -using NewLife.Log; -using NewLife.Messaging; -using NewLife.Net; -using NewLife.Reflection; -using NewLife.Threading; -using NewLife.Windows; -using XCoder; -#if !NET4 -using TaskEx = System.Threading.Tasks.Task; -#endif - -namespace XMessage -{ - [DisplayName("消息调试工具")] - public partial class FrmMain : Form, IXForm - { - NetServer _Server; - ISocketClient _Client; - IPacket _Packet; - - static Task _packets; - //static Task _factorys; - - /// 业务日志输出 - ILog BizLog; - - #region 窗体 - static FrmMain() - { - //_packets = TaskEx.Run(() => typeof(IPacket).GetAllSubclasses(true).ToArray()); - _packets = TaskEx.Run(() => typeof(IPacketFactory).GetAllSubclasses(true).ToArray()); - } - - public FrmMain() - { - InitializeComponent(); - - Icon = IcoHelper.GetIcon("消息"); - } - - private void FrmMain_Load(Object sender, EventArgs e) - { - var log = TextFileLog.Create(null, "Message_{0:yyyy_MM_dd}.log"); - BizLog = txtReceive.Combine(log); - txtReceive.UseWinFormControl(); - - txtReceive.SetDefaultStyle(12); - txtSend.SetDefaultStyle(12); - numMutilSend.SetDefaultStyle(12); - - gbReceive.Tag = gbReceive.Text; - gbSend.Tag = gbSend.Text; - - var cfg = MessageConfig.Current; - cbMode.SelectedItem = cbMode.Items[0] + ""; - if (!cfg.Address.IsNullOrEmpty()) - { - //cbAddr.DropDownStyle = ComboBoxStyle.DropDownList; - cbAddr.DataSource = cfg.Address.Split(";"); - } - - // 加载封包协议 - foreach (var item in _packets.Result) - { - cbPacket.Items.Add(item.GetDisplayName() ?? item.Name); - } - cbPacket.SelectedIndex = 0; - - // 加载保存的颜色 - UIConfig.Apply(txtReceive); - - LoadConfig(); - - // 语音识别 - Task.Factory.StartNew(() => - { - var sp = SpeechRecognition.Current; - if (!sp.Enable) return; - - sp.Register("打开", () => this.Invoke(Connect)) - .Register("关闭", () => this.Invoke(Disconnect)) - .Register("退出", () => Application.Exit()) - .Register("发送", () => this.Invoke(() => btnSend_Click(null, null))); - - BizLog.Info("语音识别前缀:{0} 可用命令:{1}", sp.Name, sp.GetAllKeys().Join()); - }); - } - #endregion - - #region 加载/保存 配置 - void LoadConfig() - { - var cfg = MessageConfig.Current; - mi显示应用日志.Checked = cfg.ShowLog; - mi显示网络日志.Checked = cfg.ShowSocketLog; - mi显示接收字符串.Checked = cfg.ShowReceiveString; - mi显示发送数据.Checked = cfg.ShowSend; - mi显示接收数据.Checked = cfg.ShowReceive; - mi显示统计信息.Checked = cfg.ShowStat; - miHexSend.Checked = cfg.HexSend; - - txtSend.Text = cfg.SendContent; - numMutilSend.Value = cfg.SendTimes; - numSleep.Value = cfg.SendSleep; - numThreads.Value = cfg.SendUsers; - mi日志着色.Checked = cfg.ColorLog; - } - - void SaveConfig() - { - var cfg = MessageConfig.Current; - cfg.ShowLog = mi显示应用日志.Checked; - cfg.ShowSocketLog = mi显示网络日志.Checked; - cfg.ShowReceiveString = mi显示接收字符串.Checked; - cfg.ShowSend = mi显示发送数据.Checked; - cfg.ShowReceive = mi显示接收数据.Checked; - cfg.ShowStat = mi显示统计信息.Checked; - cfg.HexSend = miHexSend.Checked; - - cfg.SendContent = txtSend.Text; - cfg.SendTimes = (Int32)numMutilSend.Value; - cfg.SendSleep = (Int32)numSleep.Value; - cfg.SendUsers = (Int32)numThreads.Value; - cfg.ColorLog = mi日志着色.Checked; - - cfg.Save(); - } - #endregion - - #region 收发数据 - void Connect() - { - _Server = null; - _Client = null; - - var uri = new NetUri(cbAddr.Text); - // 网络封包 - var idx = cbPacket.SelectedIndex; - var fact = idx < 0 ? null : _packets.Result[idx].CreateInstance() as IPacketFactory; - _Packet = fact.Create(); - - var cfg = MessageConfig.Current; - var log = BizLog; - - switch (cbMode.Text) - { - case "服务端": - var svr = new NetServer(); - svr.Log = cfg.ShowLog ? log : Logger.Null; - svr.SocketLog = cfg.ShowSocketLog ? log : Logger.Null; - svr.Port = uri.Port; - if (uri.IsTcp || uri.IsUdp) svr.ProtocolType = uri.Type; - svr.MessageReceived += OnReceived; - - svr.LogSend = cfg.ShowSend; - svr.LogReceive = cfg.ShowReceive; - - // 加大会话超时时间到1天 - //svr.SessionTimeout = 24 * 3600; - - svr.SessionPacket = fact; - - svr.Start(); - - "正在监听{0}".F(svr.Port).SpeechTip(); - - if (uri.Port == 0) uri.Port = svr.Port; - _Server = svr; - break; - case "客户端": - var client = uri.CreateRemote(); - client.Log = cfg.ShowLog ? log : Logger.Null; - client.MessageReceived += OnReceived; - - client.LogSend = cfg.ShowSend; - client.LogReceive = cfg.ShowReceive; - - client.Packet = _Packet; - - client.Open(); - - "已连接服务器".SpeechTip(); - - if (uri.Port == 0) uri.Port = client.Port; - _Client = client; - break; - default: - return; - } - - pnlSetting.Enabled = false; - btnConnect.Text = "关闭"; - - // 添加地址 - var addr = uri.ToString(); - var list = cfg.Address.Split(";").ToList(); - if (!list.Contains(addr)) - { - list.Insert(0, addr); - cfg.Address = list.Join(";"); - } - - cfg.Save(); - - _timer = new TimerX(ShowStat, null, 5000, 5000); - } - - void Disconnect() - { - if (_Client != null) - { - _Client.Dispose(); - _Client = null; - - "关闭连接".SpeechTip(); - } - if (_Server != null) - { - "停止监听{0}".F(_Server.Port).SpeechTip(); - _Server.Dispose(); - _Server = null; - } - if (_timer != null) - { - _timer.Dispose(); - _timer = null; - } - - pnlSetting.Enabled = true; - btnConnect.Text = "打开"; - } - - TimerX _timer; - String _lastStat; - void ShowStat(Object state) - { - if (!MessageConfig.Current.ShowStat) return; - - var msg = ""; - if (_Client != null) - msg = _Client.GetStat(); - else if (_Server != null) - msg = _Server.GetStat(); - - if (!msg.IsNullOrEmpty() && msg != _lastStat) - { - _lastStat = msg; - BizLog.Info(msg); - } - } - - private void btnConnect_Click(Object sender, EventArgs e) - { - SaveConfig(); - - var btn = sender as Button; - if (btn.Text == "打开") - Connect(); - else - Disconnect(); - } - - void OnReceived(Object sender, MessageEventArgs e) - { - var session = sender as ISocketSession; - if (session == null) - { - var ns = sender as INetSession; - if (ns == null) return; - session = ns.Session; - } - - if (MessageConfig.Current.ShowReceiveString) - { - var line = e.Message.Payload.ToStr(); - BizLog.Info(line); - } - } - - Int32 _pColor = 0; - Int32 BytesOfReceived = 0; - Int32 BytesOfSent = 0; - Int32 lastReceive = 0; - Int32 lastSend = 0; - private void timer1_Tick(Object sender, EventArgs e) - { - //if (!pnlSetting.Enabled) - { - var rcount = BytesOfReceived; - var tcount = BytesOfSent; - if (rcount != lastReceive) - { - gbReceive.Text = (gbReceive.Tag + "").Replace("0", rcount + ""); - lastReceive = rcount; - } - if (tcount != lastSend) - { - gbSend.Text = (gbSend.Tag + "").Replace("0", tcount + ""); - lastSend = tcount; - } - - var set = MessageConfig.Current; - if (set.ColorLog) txtReceive.ColourDefault(_pColor); - _pColor = txtReceive.TextLength; - } - } - - private void btnSend_Click(Object sender, EventArgs e) - { - var str = txtSend.Text; - if (String.IsNullOrEmpty(str)) - { - MessageBox.Show("发送内容不能为空!", Text); - txtSend.Focus(); - return; - } - - // 多次发送 - var count = (Int32)numMutilSend.Value; - var sleep = (Int32)numSleep.Value; - var ths = (Int32)numThreads.Value; - if (count <= 0) count = 1; - if (sleep <= 0) sleep = 1; - - SaveConfig(); - - var cfg = MessageConfig.Current; - - // 处理换行 - str = str.Replace("\n", "\r\n"); - var buf = cfg.HexSend ? str.ToHex() : str.GetBytes(); - - // 构造消息 - var msg = _Packet.CreateMessage(buf); - //buf = msg.ToArray(); - var pk = msg.ToPacket(); - - if (_Client != null) - { - if (ths <= 1) - { - _Client.SendMulti(pk, count, sleep); - } - else - { - Parallel.For(0, ths, n => - { - var client = _Client.Remote.CreateRemote(); - client.StatSend = _Client.StatSend; - client.StatReceive = _Client.StatReceive; - client.SendMulti(pk, count, sleep); - }); - } - } - else if (_Server != null) - { - buf = pk.ToArray(); - TaskEx.Run(async () => - { - for (var i = 0; i < count; i++) - { - var cs = await _Server.SendAllAsync(buf); - BizLog.Info("已向[{0}]个客户端发送[{1}]数据", cs, buf.Length); - if (sleep > 0) await TaskEx.Delay(sleep); - } - }); - } - } - #endregion - - #region 右键菜单 - private void mi清空_Click(Object sender, EventArgs e) - { - txtReceive.Clear(); - BytesOfReceived = 0; - } - - private void mi清空2_Click(Object sender, EventArgs e) - { - txtSend.Clear(); - BytesOfSent = 0; - } - - private void mi显示应用日志_Click(Object sender, EventArgs e) - { - var mi = sender as ToolStripMenuItem; - mi.Checked = !mi.Checked; - } - - private void mi显示网络日志_Click(Object sender, EventArgs e) - { - var mi = sender as ToolStripMenuItem; - mi.Checked = !mi.Checked; - } - - private void mi显示发送数据_Click(Object sender, EventArgs e) - { - var mi = sender as ToolStripMenuItem; - mi.Checked = !mi.Checked; - } - - private void mi显示接收数据_Click(Object sender, EventArgs e) - { - var mi = sender as ToolStripMenuItem; - mi.Checked = !mi.Checked; - } - - private void mi显示统计信息_Click(Object sender, EventArgs e) - { - var mi = sender as ToolStripMenuItem; - MessageConfig.Current.ShowStat = mi.Checked = !mi.Checked; - } - - private void mi显示接收字符串_Click(Object sender, EventArgs e) - { - var mi = sender as ToolStripMenuItem; - MessageConfig.Current.ShowReceiveString = mi.Checked = !mi.Checked; - } - - private void miHex发送_Click(Object sender, EventArgs e) - { - var mi = sender as ToolStripMenuItem; - MessageConfig.Current.HexSend = mi.Checked = !mi.Checked; - } - - private void miCheck_Click(Object sender, EventArgs e) - { - var mi = sender as ToolStripMenuItem; - mi.Checked = !mi.Checked; - } - #endregion - } -} \ No newline at end of file diff --git a/XCoder/XMessage/FrmMain.designer.cs b/XCoder/XMessage/FrmMain.designer.cs deleted file mode 100644 index 06b2daa6..00000000 --- a/XCoder/XMessage/FrmMain.designer.cs +++ /dev/null @@ -1,480 +0,0 @@ -namespace XMessage -{ - partial class FrmMain - { - /// - /// 必需的设计器变量。 - /// - private System.ComponentModel.IContainer components = null; - - /// - /// 清理所有正在使用的资源。 - /// - /// 如果应释放托管资源,为 true;否则为 false。 - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows 窗体设计器生成的代码 - - /// - /// 设计器支持所需的方法 - 不要 - /// 使用代码编辑器修改此方法的内容。 - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.gbReceive = new System.Windows.Forms.GroupBox(); - this.txtReceive = new System.Windows.Forms.RichTextBox(); - this.menuReceive = new System.Windows.Forms.ContextMenuStrip(this.components); - this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripSeparator(); - this.mi显示应用日志 = new System.Windows.Forms.ToolStripMenuItem(); - this.mi显示网络日志 = new System.Windows.Forms.ToolStripMenuItem(); - this.mi显示接收字符串 = new System.Windows.Forms.ToolStripMenuItem(); - this.mi显示发送数据 = new System.Windows.Forms.ToolStripMenuItem(); - this.mi显示接收数据 = new System.Windows.Forms.ToolStripMenuItem(); - this.mi显示统计信息 = new System.Windows.Forms.ToolStripMenuItem(); - this.menuSend = new System.Windows.Forms.ContextMenuStrip(this.components); - this.miHexSend = new System.Windows.Forms.ToolStripMenuItem(); - this.mi清空2 = new System.Windows.Forms.ToolStripMenuItem(); - this.btnConnect = new System.Windows.Forms.Button(); - this.timer1 = new System.Windows.Forms.Timer(this.components); - this.fontDialog1 = new System.Windows.Forms.FontDialog(); - this.colorDialog1 = new System.Windows.Forms.ColorDialog(); - this.label1 = new System.Windows.Forms.Label(); - this.lbAddr = new System.Windows.Forms.Label(); - this.cbMode = new System.Windows.Forms.ComboBox(); - this.cbAddr = new System.Windows.Forms.ComboBox(); - this.pnlSetting = new System.Windows.Forms.Panel(); - this.cbPacket = new System.Windows.Forms.ComboBox(); - this.label3 = new System.Windows.Forms.Label(); - this.gbSend = new System.Windows.Forms.GroupBox(); - this.numThreads = new System.Windows.Forms.NumericUpDown(); - this.numSleep = new System.Windows.Forms.NumericUpDown(); - this.txtSend = new System.Windows.Forms.RichTextBox(); - this.btnSend = new System.Windows.Forms.Button(); - this.numMutilSend = new System.Windows.Forms.NumericUpDown(); - this.label2 = new System.Windows.Forms.Label(); - this.label7 = new System.Windows.Forms.Label(); - this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); - this.mi日志着色 = new System.Windows.Forms.ToolStripMenuItem(); - this.gbReceive.SuspendLayout(); - this.menuReceive.SuspendLayout(); - this.menuSend.SuspendLayout(); - this.pnlSetting.SuspendLayout(); - this.gbSend.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.numThreads)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.numSleep)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.numMutilSend)).BeginInit(); - this.SuspendLayout(); - // - // gbReceive - // - this.gbReceive.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.gbReceive.Controls.Add(this.txtReceive); - this.gbReceive.Location = new System.Drawing.Point(9, 43); - this.gbReceive.Name = "gbReceive"; - this.gbReceive.Size = new System.Drawing.Size(652, 234); - this.gbReceive.TabIndex = 4; - this.gbReceive.TabStop = false; - this.gbReceive.Text = "接收区:已接收0字节"; - // - // txtReceive - // - this.txtReceive.ContextMenuStrip = this.menuReceive; - this.txtReceive.Dock = System.Windows.Forms.DockStyle.Fill; - this.txtReceive.HideSelection = false; - this.txtReceive.Location = new System.Drawing.Point(3, 17); - this.txtReceive.Name = "txtReceive"; - this.txtReceive.Size = new System.Drawing.Size(646, 214); - this.txtReceive.TabIndex = 1; - this.txtReceive.Text = ""; - // - // menuReceive - // - this.menuReceive.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripMenuItem1, - this.mi日志着色, - this.toolStripMenuItem3, - this.mi显示应用日志, - this.mi显示网络日志, - this.mi显示接收字符串, - this.mi显示发送数据, - this.mi显示接收数据, - this.mi显示统计信息}); - this.menuReceive.Name = "menuSend"; - this.menuReceive.Size = new System.Drawing.Size(161, 208); - // - // toolStripMenuItem1 - // - this.toolStripMenuItem1.Name = "toolStripMenuItem1"; - this.toolStripMenuItem1.Size = new System.Drawing.Size(160, 22); - this.toolStripMenuItem1.Text = "清空"; - this.toolStripMenuItem1.Click += new System.EventHandler(this.mi清空_Click); - // - // toolStripMenuItem3 - // - this.toolStripMenuItem3.Name = "toolStripMenuItem3"; - this.toolStripMenuItem3.Size = new System.Drawing.Size(157, 6); - // - // mi显示应用日志 - // - this.mi显示应用日志.Name = "mi显示应用日志"; - this.mi显示应用日志.Size = new System.Drawing.Size(160, 22); - this.mi显示应用日志.Text = "显示应用日志"; - this.mi显示应用日志.Click += new System.EventHandler(this.mi显示应用日志_Click); - // - // mi显示网络日志 - // - this.mi显示网络日志.Name = "mi显示网络日志"; - this.mi显示网络日志.Size = new System.Drawing.Size(160, 22); - this.mi显示网络日志.Text = "显示网络日志"; - this.mi显示网络日志.Click += new System.EventHandler(this.mi显示网络日志_Click); - // - // mi显示接收字符串 - // - this.mi显示接收字符串.Name = "mi显示接收字符串"; - this.mi显示接收字符串.Size = new System.Drawing.Size(160, 22); - this.mi显示接收字符串.Text = "显示接收字符串"; - this.mi显示接收字符串.Click += new System.EventHandler(this.mi显示接收字符串_Click); - // - // mi显示发送数据 - // - this.mi显示发送数据.Name = "mi显示发送数据"; - this.mi显示发送数据.Size = new System.Drawing.Size(160, 22); - this.mi显示发送数据.Text = "显示发送数据"; - this.mi显示发送数据.Click += new System.EventHandler(this.mi显示发送数据_Click); - // - // mi显示接收数据 - // - this.mi显示接收数据.Name = "mi显示接收数据"; - this.mi显示接收数据.Size = new System.Drawing.Size(160, 22); - this.mi显示接收数据.Text = "显示接收数据"; - this.mi显示接收数据.Click += new System.EventHandler(this.mi显示接收数据_Click); - // - // mi显示统计信息 - // - this.mi显示统计信息.Name = "mi显示统计信息"; - this.mi显示统计信息.Size = new System.Drawing.Size(160, 22); - this.mi显示统计信息.Text = "显示统计信息"; - this.mi显示统计信息.Click += new System.EventHandler(this.mi显示统计信息_Click); - // - // menuSend - // - this.menuSend.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.miHexSend, - this.mi清空2}); - this.menuSend.Name = "menuSend"; - this.menuSend.Size = new System.Drawing.Size(123, 48); - // - // miHexSend - // - this.miHexSend.Name = "miHexSend"; - this.miHexSend.Size = new System.Drawing.Size(122, 22); - this.miHexSend.Text = "Hex发送"; - this.miHexSend.Click += new System.EventHandler(this.miHex发送_Click); - // - // mi清空2 - // - this.mi清空2.Name = "mi清空2"; - this.mi清空2.Size = new System.Drawing.Size(122, 22); - this.mi清空2.Text = "清空"; - this.mi清空2.Click += new System.EventHandler(this.mi清空2_Click); - // - // btnConnect - // - this.btnConnect.Location = new System.Drawing.Point(587, 9); - this.btnConnect.Name = "btnConnect"; - this.btnConnect.Size = new System.Drawing.Size(67, 29); - this.btnConnect.TabIndex = 3; - this.btnConnect.Text = "打开"; - this.btnConnect.UseVisualStyleBackColor = true; - this.btnConnect.Click += new System.EventHandler(this.btnConnect_Click); - // - // timer1 - // - this.timer1.Enabled = true; - this.timer1.Interval = 300; - this.timer1.Tick += new System.EventHandler(this.timer1_Tick); - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(7, 7); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(41, 12); - this.label1.TabIndex = 6; - this.label1.Text = "模式:"; - // - // lbAddr - // - this.lbAddr.AutoSize = true; - this.lbAddr.Location = new System.Drawing.Point(147, 7); - this.lbAddr.Name = "lbAddr"; - this.lbAddr.Size = new System.Drawing.Size(41, 12); - this.lbAddr.TabIndex = 7; - this.lbAddr.Text = "地址:"; - // - // cbMode - // - this.cbMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cbMode.FormattingEnabled = true; - this.cbMode.Items.AddRange(new object[] { - "服务端", - "客户端"}); - this.cbMode.Location = new System.Drawing.Point(48, 3); - this.cbMode.Name = "cbMode"; - this.cbMode.Size = new System.Drawing.Size(93, 20); - this.cbMode.TabIndex = 9; - // - // cbAddr - // - this.cbAddr.FormattingEnabled = true; - this.cbAddr.Location = new System.Drawing.Point(184, 3); - this.cbAddr.Name = "cbAddr"; - this.cbAddr.Size = new System.Drawing.Size(149, 20); - this.cbAddr.TabIndex = 10; - // - // pnlSetting - // - this.pnlSetting.Controls.Add(this.cbPacket); - this.pnlSetting.Controls.Add(this.label3); - this.pnlSetting.Controls.Add(this.cbAddr); - this.pnlSetting.Controls.Add(this.label1); - this.pnlSetting.Controls.Add(this.lbAddr); - this.pnlSetting.Controls.Add(this.cbMode); - this.pnlSetting.Location = new System.Drawing.Point(9, 8); - this.pnlSetting.Name = "pnlSetting"; - this.pnlSetting.Size = new System.Drawing.Size(471, 31); - this.pnlSetting.TabIndex = 13; - // - // cbPacket - // - this.cbPacket.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cbPacket.FormattingEnabled = true; - this.cbPacket.Location = new System.Drawing.Point(375, 3); - this.cbPacket.Name = "cbPacket"; - this.cbPacket.Size = new System.Drawing.Size(93, 20); - this.cbPacket.TabIndex = 12; - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(339, 7); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(41, 12); - this.label3.TabIndex = 11; - this.label3.Text = "封包:"; - // - // gbSend - // - this.gbSend.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.gbSend.Controls.Add(this.numThreads); - this.gbSend.Controls.Add(this.numSleep); - this.gbSend.Controls.Add(this.txtSend); - this.gbSend.Controls.Add(this.btnSend); - this.gbSend.Controls.Add(this.numMutilSend); - this.gbSend.Controls.Add(this.label2); - this.gbSend.Controls.Add(this.label7); - this.gbSend.Location = new System.Drawing.Point(9, 283); - this.gbSend.Name = "gbSend"; - this.gbSend.Size = new System.Drawing.Size(652, 84); - this.gbSend.TabIndex = 15; - this.gbSend.TabStop = false; - this.gbSend.Text = "发送区:已发送0字节"; - // - // numThreads - // - this.numThreads.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.numThreads.Location = new System.Drawing.Point(593, 22); - this.numThreads.Maximum = new decimal(new int[] { - 100000, - 0, - 0, - 0}); - this.numThreads.Minimum = new decimal(new int[] { - 1, - 0, - 0, - 0}); - this.numThreads.Name = "numThreads"; - this.numThreads.Size = new System.Drawing.Size(52, 21); - this.numThreads.TabIndex = 18; - this.numThreads.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; - this.toolTip1.SetToolTip(this.numThreads, "模拟多客户端发送,用于压力测试!"); - this.numThreads.Value = new decimal(new int[] { - 1, - 0, - 0, - 0}); - // - // numSleep - // - this.numSleep.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.numSleep.Location = new System.Drawing.Point(538, 54); - this.numSleep.Maximum = new decimal(new int[] { - 1000000, - 0, - 0, - 0}); - this.numSleep.Name = "numSleep"; - this.numSleep.Size = new System.Drawing.Size(52, 21); - this.numSleep.TabIndex = 16; - this.numSleep.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; - this.numSleep.Value = new decimal(new int[] { - 1000, - 0, - 0, - 0}); - // - // txtSend - // - this.txtSend.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.txtSend.ContextMenuStrip = this.menuSend; - this.txtSend.HideSelection = false; - this.txtSend.Location = new System.Drawing.Point(0, 19); - this.txtSend.Name = "txtSend"; - this.txtSend.Size = new System.Drawing.Size(497, 59); - this.txtSend.TabIndex = 2; - this.txtSend.Text = ""; - // - // btnSend - // - this.btnSend.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.btnSend.Location = new System.Drawing.Point(596, 49); - this.btnSend.Name = "btnSend"; - this.btnSend.Size = new System.Drawing.Size(50, 30); - this.btnSend.TabIndex = 1; - this.btnSend.Text = "发送"; - this.btnSend.UseVisualStyleBackColor = true; - this.btnSend.Click += new System.EventHandler(this.btnSend_Click); - // - // numMutilSend - // - this.numMutilSend.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.numMutilSend.Location = new System.Drawing.Point(538, 22); - this.numMutilSend.Maximum = new decimal(new int[] { - 10000, - 0, - 0, - 0}); - this.numMutilSend.Minimum = new decimal(new int[] { - 1, - 0, - 0, - 0}); - this.numMutilSend.Name = "numMutilSend"; - this.numMutilSend.Size = new System.Drawing.Size(52, 21); - this.numMutilSend.TabIndex = 14; - this.numMutilSend.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; - this.numMutilSend.Value = new decimal(new int[] { - 1, - 0, - 0, - 0}); - // - // label2 - // - this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(503, 58); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(41, 12); - this.label2.TabIndex = 17; - this.label2.Text = "间隔:"; - // - // label7 - // - this.label7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(503, 26); - this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(41, 12); - this.label7.TabIndex = 15; - this.label7.Text = "次数:"; - // - // mi日志着色 - // - this.mi日志着色.Name = "mi日志着色"; - this.mi日志着色.Size = new System.Drawing.Size(160, 22); - this.mi日志着色.Text = "日志着色"; - this.mi日志着色.Click += new System.EventHandler(this.miCheck_Click); - // - // FrmMain - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(667, 379); - this.Controls.Add(this.gbSend); - this.Controls.Add(this.pnlSetting); - this.Controls.Add(this.btnConnect); - this.Controls.Add(this.gbReceive); - this.Name = "FrmMain"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "网络调试"; - this.Load += new System.EventHandler(this.FrmMain_Load); - this.gbReceive.ResumeLayout(false); - this.menuReceive.ResumeLayout(false); - this.menuSend.ResumeLayout(false); - this.pnlSetting.ResumeLayout(false); - this.pnlSetting.PerformLayout(); - this.gbSend.ResumeLayout(false); - this.gbSend.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.numThreads)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.numSleep)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.numMutilSend)).EndInit(); - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.GroupBox gbReceive; - private System.Windows.Forms.Button btnConnect; - private System.Windows.Forms.Timer timer1; - private System.Windows.Forms.ContextMenuStrip menuSend; - private System.Windows.Forms.ToolStripMenuItem mi清空2; - private System.Windows.Forms.RichTextBox txtReceive; - private System.Windows.Forms.FontDialog fontDialog1; - private System.Windows.Forms.ColorDialog colorDialog1; - private System.Windows.Forms.Label label1; - private System.Windows.Forms.Label lbAddr; - private System.Windows.Forms.ComboBox cbMode; - private System.Windows.Forms.ComboBox cbAddr; - private System.Windows.Forms.Panel pnlSetting; - private System.Windows.Forms.ContextMenuStrip menuReceive; - private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; - private System.Windows.Forms.ToolStripSeparator toolStripMenuItem3; - private System.Windows.Forms.GroupBox gbSend; - private System.Windows.Forms.NumericUpDown numSleep; - private System.Windows.Forms.RichTextBox txtSend; - private System.Windows.Forms.Button btnSend; - private System.Windows.Forms.NumericUpDown numMutilSend; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.Label label7; - private System.Windows.Forms.ToolStripMenuItem mi显示发送数据; - private System.Windows.Forms.ToolStripMenuItem mi显示接收数据; - private System.Windows.Forms.ToolStripMenuItem mi显示统计信息; - private System.Windows.Forms.NumericUpDown numThreads; - private System.Windows.Forms.ToolStripMenuItem mi显示接收字符串; - private System.Windows.Forms.ToolStripMenuItem mi显示应用日志; - private System.Windows.Forms.ToolStripMenuItem mi显示网络日志; - private System.Windows.Forms.ToolTip toolTip1; - private System.Windows.Forms.ToolStripMenuItem miHexSend; - private System.Windows.Forms.Label label3; - private System.Windows.Forms.ComboBox cbPacket; - private System.Windows.Forms.ToolStripMenuItem mi日志着色; - } -} - diff --git a/XCoder/XMessage/FrmMain.resx b/XCoder/XMessage/FrmMain.resx deleted file mode 100644 index fdafb9b2..00000000 --- a/XCoder/XMessage/FrmMain.resx +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 104, 13 - - - 237, 17 - - - 17, 17 - - - 352, 17 - - - 474, 17 - - - 601, 17 - - - 601, 17 - - \ No newline at end of file diff --git a/XCoder/XMessage/MessageConfig.cs b/XCoder/XMessage/MessageConfig.cs deleted file mode 100644 index 36df5a12..00000000 --- a/XCoder/XMessage/MessageConfig.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.ComponentModel; -using System.Text; -using System.Xml.Serialization; -using NewLife.Xml; - -namespace XMessage -{ - /// 网络口配置 - [XmlConfigFile("Config\\Message.config")] - public class MessageConfig : XmlConfig - { - /// 地址 - [Description("地址")] - public String Address { get; set; } = ""; - - /// 文本编码 - [XmlIgnore] - public Encoding Encoding { get; set; } = Encoding.UTF8; - - /// 编码 - [Description("编码 gb2312/us-ascii/utf-8")] - public String WebEncoding { get { return Encoding?.WebName; } set { Encoding = Encoding.GetEncoding(value); } } - - /// 十六进制显示 - [Description("十六进制显示")] - public Boolean HexShow { get; set; } - - /// 十六进制发送 - [Description("十六进制发送")] - public Boolean HexSend { get; set; } - - /// 发送内容 - [Description("发送内容")] - public String SendContent { get; set; } = "新生命开发团队,学无先后达者为师"; - - /// 发送次数 - [Description("发送次数")] - public Int32 SendTimes { get; set; } = 1; - - /// 发送间隔。毫秒 - [Description("发送间隔。毫秒")] - public Int32 SendSleep { get; set; } = 1000; - - /// 发送用户数 - [Description("发送用户数")] - public Int32 SendUsers { get; set; } = 1; - - /// 显示应用日志 - [Description("显示应用日志")] - public Boolean ShowLog { get; set; } = true; - - /// 显示网络日志 - [Description("显示网络日志")] - public Boolean ShowSocketLog { get; set; } = true; - - /// 显示接收字符串 - [Description("显示接收字符串")] - public Boolean ShowReceiveString { get; set; } = true; - - /// 显示发送数据 - [Description("显示发送数据")] - public Boolean ShowSend { get; set; } = true; - - /// 显示接收数据 - [Description("显示接收数据")] - public Boolean ShowReceive { get; set; } = true; - - /// 显示统计信息 - [Description("显示统计信息")] - public Boolean ShowStat { get; set; } = true; - - /// 日志着色 - [Description("日志着色")] - public Boolean ColorLog { get; set; } = true; - - public MessageConfig() - { - } - } -} \ No newline at end of file diff --git a/XCoder/Yun/FrmMap.Designer.cs b/XCoder/Yun/FrmMap.Designer.cs deleted file mode 100644 index ebb34389..00000000 --- a/XCoder/Yun/FrmMap.Designer.cs +++ /dev/null @@ -1,307 +0,0 @@ -namespace XCoder.Yun -{ - partial class FrmMap - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.lbMethod = new System.Windows.Forms.Label(); - this.label6 = new System.Windows.Forms.Label(); - this.cbCoordtype = new System.Windows.Forms.ComboBox(); - this.cbMethod = new System.Windows.Forms.ComboBox(); - this.label5 = new System.Windows.Forms.Label(); - this.label4 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.chkFormatAddress = new System.Windows.Forms.CheckBox(); - this.label1 = new System.Windows.Forms.Label(); - this.txtAddress = new System.Windows.Forms.TextBox(); - this.cbMap = new System.Windows.Forms.ComboBox(); - this.pgResult = new System.Windows.Forms.PropertyGrid(); - this.colorDialog1 = new System.Windows.Forms.ColorDialog(); - this.fontDialog1 = new System.Windows.Forms.FontDialog(); - this.btnInvoke = new System.Windows.Forms.Button(); - this.txtReceive = new System.Windows.Forms.RichTextBox(); - this.txtCity = new System.Windows.Forms.TextBox(); - this.gbReceive = new System.Windows.Forms.GroupBox(); - this.label3 = new System.Windows.Forms.Label(); - this.txtLocation = new System.Windows.Forms.TextBox(); - this.button1 = new System.Windows.Forms.Button(); - this.label7 = new System.Windows.Forms.Label(); - this.txtLocation2 = new System.Windows.Forms.TextBox(); - this.gbReceive.SuspendLayout(); - this.SuspendLayout(); - // - // gbReceive - // - this.gbReceive.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.gbReceive.Controls.Add(this.txtReceive); - this.gbReceive.Location = new System.Drawing.Point(2, 108); - this.gbReceive.Name = "gbReceive"; - this.gbReceive.Size = new System.Drawing.Size(381, 378); - this.gbReceive.TabIndex = 24; - this.gbReceive.TabStop = false; - // - // lbMethod - // - this.lbMethod.AutoSize = true; - this.lbMethod.Location = new System.Drawing.Point(490, 16); - this.lbMethod.Name = "lbMethod"; - this.lbMethod.Size = new System.Drawing.Size(53, 12); - this.lbMethod.TabIndex = 39; - this.lbMethod.Text = "方法签名"; - // - // label6 - // - this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(155, 16); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(53, 12); - this.label6.TabIndex = 35; - this.label6.Text = "坐标系:"; - // - // cbCoordtype - // - this.cbCoordtype.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cbCoordtype.FormattingEnabled = true; - this.cbCoordtype.Location = new System.Drawing.Point(214, 12); - this.cbCoordtype.Name = "cbCoordtype"; - this.cbCoordtype.Size = new System.Drawing.Size(77, 20); - this.cbCoordtype.TabIndex = 34; - // - // cbMethod - // - this.cbMethod.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cbMethod.FormattingEnabled = true; - this.cbMethod.Location = new System.Drawing.Point(344, 12); - this.cbMethod.Name = "cbMethod"; - this.cbMethod.Size = new System.Drawing.Size(128, 20); - this.cbMethod.TabIndex = 33; - // - // label5 - // - this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(297, 16); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(41, 12); - this.label5.TabIndex = 32; - this.label5.Text = "接口:"; - // - // label4 - // - this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(16, 16); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(41, 12); - this.label4.TabIndex = 31; - this.label4.Text = "地图:"; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(342, 48); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(41, 12); - this.label2.TabIndex = 30; - this.label2.Text = "城市:"; - // - // chkFormatAddress - // - this.chkFormatAddress.AutoSize = true; - this.chkFormatAddress.Checked = true; - this.chkFormatAddress.CheckState = System.Windows.Forms.CheckState.Checked; - this.chkFormatAddress.Location = new System.Drawing.Point(482, 46); - this.chkFormatAddress.Name = "chkFormatAddress"; - this.chkFormatAddress.Size = new System.Drawing.Size(84, 16); - this.chkFormatAddress.TabIndex = 38; - this.chkFormatAddress.Text = "格式化地址"; - this.chkFormatAddress.UseVisualStyleBackColor = true; - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(16, 48); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(41, 12); - this.label1.TabIndex = 29; - this.label1.Text = "地址:"; - // - // txtAddress - // - this.txtAddress.Location = new System.Drawing.Point(63, 44); - this.txtAddress.Name = "txtAddress"; - this.txtAddress.Size = new System.Drawing.Size(256, 21); - this.txtAddress.TabIndex = 27; - this.txtAddress.Text = "陆家嘴银城中路501号"; - // - // cbMap - // - this.cbMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cbMap.FormattingEnabled = true; - this.cbMap.Location = new System.Drawing.Point(63, 12); - this.cbMap.Name = "cbMap"; - this.cbMap.Size = new System.Drawing.Size(89, 20); - this.cbMap.TabIndex = 26; - this.cbMap.SelectedIndexChanged += new System.EventHandler(this.cbMap_SelectedIndexChanged); - // - // pgResult - // - this.pgResult.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Right))); - this.pgResult.LineColor = System.Drawing.SystemColors.ControlDark; - this.pgResult.Location = new System.Drawing.Point(386, 108); - this.pgResult.Name = "pgResult"; - this.pgResult.PropertySort = System.Windows.Forms.PropertySort.NoSort; - this.pgResult.Size = new System.Drawing.Size(281, 375); - this.pgResult.TabIndex = 25; - // - // btnInvoke - // - this.btnInvoke.Location = new System.Drawing.Point(559, 8); - this.btnInvoke.Name = "btnInvoke"; - this.btnInvoke.Size = new System.Drawing.Size(67, 29); - this.btnInvoke.TabIndex = 23; - this.btnInvoke.Text = "调用"; - this.btnInvoke.UseVisualStyleBackColor = true; - this.btnInvoke.Click += new System.EventHandler(this.btnInvoke_Click); - // - // txtReceive - // - this.txtReceive.Dock = System.Windows.Forms.DockStyle.Fill; - this.txtReceive.HideSelection = false; - this.txtReceive.Location = new System.Drawing.Point(3, 17); - this.txtReceive.Name = "txtReceive"; - this.txtReceive.Size = new System.Drawing.Size(375, 358); - this.txtReceive.TabIndex = 22; - this.txtReceive.Text = ""; - // - // txtCity - // - this.txtCity.Location = new System.Drawing.Point(392, 44); - this.txtCity.Name = "txtCity"; - this.txtCity.Size = new System.Drawing.Size(75, 21); - this.txtCity.TabIndex = 28; - this.txtCity.Text = "上海"; - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(18, 77); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(41, 12); - this.label3.TabIndex = 36; - this.label3.Text = "坐标:"; - // - // txtLocation - // - this.txtLocation.Location = new System.Drawing.Point(63, 73); - this.txtLocation.Name = "txtLocation"; - this.txtLocation.Size = new System.Drawing.Size(211, 21); - this.txtLocation.TabIndex = 37; - // - // button1 - // - this.button1.Location = new System.Drawing.Point(0, 0); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(75, 23); - this.button1.TabIndex = 0; - // - // label7 - // - this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(299, 77); - this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(65, 12); - this.label7.TabIndex = 39; - this.label7.Text = "第二坐标:"; - // - // txtLocation2 - // - this.txtLocation2.Location = new System.Drawing.Point(370, 73); - this.txtLocation2.Name = "txtLocation2"; - this.txtLocation2.Size = new System.Drawing.Size(211, 21); - this.txtLocation2.TabIndex = 40; - // - // FrmMap - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(670, 488); - this.Controls.Add(this.label7); - this.Controls.Add(this.txtLocation2); - this.Controls.Add(this.label6); - this.Controls.Add(this.cbCoordtype); - this.Controls.Add(this.cbMethod); - this.Controls.Add(this.label5); - this.Controls.Add(this.label4); - this.Controls.Add(this.label2); - this.Controls.Add(this.label1); - this.Controls.Add(this.txtCity); - this.Controls.Add(this.txtAddress); - this.Controls.Add(this.cbMap); - this.Controls.Add(this.pgResult); - this.Controls.Add(this.btnInvoke); - this.Controls.Add(this.gbReceive); - this.Controls.Add(this.label3); - this.Controls.Add(this.txtLocation); - this.Controls.Add(this.chkFormatAddress); - this.Name = "FrmMap"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "地图接口"; - this.Load += new System.EventHandler(this.FrmMain_Load); - this.gbReceive.ResumeLayout(false); - this.ResumeLayout(false); - } - - #endregion - - private System.Windows.Forms.Label lbMethod; - private System.Windows.Forms.Label label6; - private System.Windows.Forms.ComboBox cbCoordtype; - private System.Windows.Forms.ComboBox cbMethod; - private System.Windows.Forms.Label label5; - private System.Windows.Forms.Label label4; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.CheckBox chkFormatAddress; - private System.Windows.Forms.Label label1; - private System.Windows.Forms.TextBox txtAddress; - private System.Windows.Forms.ComboBox cbMap; - private System.Windows.Forms.PropertyGrid pgResult; - private System.Windows.Forms.ColorDialog colorDialog1; - private System.Windows.Forms.FontDialog fontDialog1; - private System.Windows.Forms.Button btnInvoke; - private System.Windows.Forms.RichTextBox txtReceive; - private System.Windows.Forms.TextBox txtCity; - private System.Windows.Forms.GroupBox gbReceive; - private System.Windows.Forms.Label label3; - private System.Windows.Forms.TextBox txtLocation; - private System.Windows.Forms.Button button1; - private System.Windows.Forms.Label label7; - private System.Windows.Forms.TextBox txtLocation2; - } -} \ No newline at end of file diff --git a/XCoder/Yun/FrmMap.cs b/XCoder/Yun/FrmMap.cs deleted file mode 100644 index dc7db2d7..00000000 --- a/XCoder/Yun/FrmMap.cs +++ /dev/null @@ -1,251 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Reflection; -using System.Threading.Tasks; -using System.Windows.Forms; -using NewLife; -using NewLife.Data; -using NewLife.Log; -using NewLife.Map; -using NewLife.Reflection; -using NewLife.Serialization; -using NewLife.Yun; - -namespace XCoder.Yun -{ - [Category("地理信息")] - [DisplayName("地图接口")] - public partial class FrmMap : Form, IXForm - { - /// 业务日志输出 - ILog BizLog; - - //IDictionary Maps = new Dictionary(); - //IDictionary Methods = new Dictionary(); - - #region 窗体 - public FrmMap() - { - InitializeComponent(); - - // 动态调节宽度高度,兼容高DPI - this.FixDpi(); - - Icon = IcoHelper.GetIcon("地图"); - } - - private void FrmMain_Load(Object sender, EventArgs e) - { - var log = TextFileLog.Create(null, "Map_{0:yyyy_MM_dd}.log"); - BizLog = txtReceive.Combine(log); - txtReceive.UseWinFormControl(); - - txtReceive.SetDefaultStyle(12); - - // 加载保存的颜色 - UIConfig.Apply(txtReceive); - - LoadConfig(); - - var cfg = Setting; - - var cb = cbMap; - cb.Items.Clear(); - cb.DisplayMember = "Name"; - foreach (var item in typeof(IMap).GetAllSubclasses()) - { - //var name = item.GetDisplayName() ?? item.Name; - //Maps[name] = item; - //cb.Items.Add(name); - cb.Items.Add(item); - - if (cfg.Map == item.Name) cb.SelectedItem = item; - } - //if (cb.Items.Count > 0) cb.SelectedText = cfg.Map; - } - #endregion - - #region 配置 - MapSetting Setting; - - void LoadConfig() - { - var cfg = Setting = MapSetting.Current; - - txtAddress.Text = cfg.Address; - txtCity.Text = cfg.City; - txtLocation.Text = cfg.Location; - txtLocation2.Text = cfg.Location2; - chkFormatAddress.Checked = cfg.FormatAddress; - - //cbMap.SelectedValue = cfg.Map; - //cbMethod.SelectedValue = cfg.Method; - //cbCoordtype.SelectedValue = cfg.Coordtype; - } - - void SaveConfig() - { - var cfg = Setting = MapSetting.Current; - - cfg.Address = txtAddress.Text; - cfg.City = txtCity.Text; - cfg.Location = txtLocation.Text; - cfg.Location2 = txtLocation2.Text; - cfg.FormatAddress = chkFormatAddress.Checked; - - cfg.Map = (cbMap.SelectedItem as Type)?.Name; - cfg.Method = (cbMethod.SelectedItem as MethodInfo)?.Name; - cfg.Coordtype = cbCoordtype.SelectedItem as String; - - cfg.Save(); - } - #endregion - - #region 收发数据 - private void btnInvoke_Click(Object sender, EventArgs e) - { - var type = cbMap.SelectedItem as Type; - if (type == null) return; - - var method = cbMethod.SelectedItem as MethodInfo; - if (method == null) return; - - SaveConfig(); - var cfg = Setting; - - var map = type.CreateInstance() as Map; - map.Log = XTrace.Log; - map.CoordType = cfg.Coordtype; - - // 准备参数 - var addr = txtAddress.Text; - var city = txtCity.Text; - var point = new GeoPoint(txtLocation.Text); - var point2 = new GeoPoint(txtLocation2.Text); - - var mps = method.GetParameters(); - - Task.Factory.StartNew(async () => - { - Object result = null; - //var point = new GeoPoint(cfg.Location); - //var point2 = new GeoPoint(cfg.Location2); - try - { - var im = map as IMap; - if (method.Name == nameof(im.GetGeocoderAsync) && mps.Length == 2) - { - result = await im.GetGeocoderAsync(addr,city); - } - else if (method.Name == nameof(im.GetGeocoderAsync) && mps.Length == 1) - { - result = await im.GetGeocoderAsync(point); - } - else if (method.Name == nameof(im.GetGeoAsync) && mps.Length == 3) - { - result = await im.GetGeoAsync(addr, city, cfg.FormatAddress); - } - else if (method.Name == nameof(im.GetGeoAsync) && mps.Length == 1) - { - result = await im.GetGeoAsync(point); - } - else if (method.Name == nameof(im.GetDistanceAsync)) - { - result = await im.GetDistanceAsync(point, point2); - } - else if (map is BaiduMap bd && method.Name == nameof(bd.PlaceSearchAsync)) - { - result = await bd.PlaceSearchAsync(addr, null, city, cfg.FormatAddress); - } - else if (map is AMap am && method.Name == nameof(am.GetAreaAsync)) - { - result = (await am.GetAreaAsync(city))?.ToArray(); - } - else - { - var ps = new Dictionary(); - if (mps.Any(k => k.Name.EqualIgnoreCase("address"))) ps["address"] = addr; - if (mps.Any(k => k.Name.EqualIgnoreCase("city"))) ps["city"] = cfg.City; - - var task = map.InvokeWithParams(method, ps) as Task; - await task; - - result = task.GetValue("Result"); - } - } - catch (Exception ex) - { - ex = ex.GetTrue(); - if (ex.GetType() == typeof(Exception)) - XTrace.WriteLine(ex.Message); - else - XTrace.WriteException(ex); - return; - } - - this.Invoke(() => - { - pgResult.SelectedObject = result; - - if (result is GeoAddress geo) - txtLocation.Text = geo.Location + ""; - else if (result is GeoPoint gp) - txtLocation.Text = gp + ""; - }); - - //XTrace.WriteLine(map.LastUrl); - - var js = new JsonParser(map.LastString).Decode(); - XTrace.WriteLine(js.ToJson(true)); - }); - } - #endregion - - private void cbMap_SelectedIndexChanged(Object sender, EventArgs e) - { - //var name = cbMap.SelectedItem + ""; - //if (!Maps.TryGetValue(name, out var type)) return; - var type = cbMap.SelectedItem as Type; - if (type == null) return; - - var cfg = Setting; - - var cb = cbMethod; - cb.Items.Clear(); - //Methods.Clear(); - cb.DisplayMember = "Name"; - foreach (var item in type.GetMethods()) - { - if (item.DeclaringType != type) continue; - - //var name = item.Name; - //Methods.Add(name, name); - - cb.Items.Add(item); - if (cfg.Method == item.Name) cb.SelectedItem = item; - } - //if (cb.Items.Count > 0) cb.SelectedIndex = 0; - - cb = cbCoordtype; - cb.Items.Clear(); - - if (type.Name.Contains("Baidu")) - { - cb.Items.Add("bd09ll"); - cb.Items.Add("bd09mc"); - } - //else if (name.Contains("高德")) - //{ - - //} - - cb.Items.Add("gcj02ll"); - cb.Items.Add("wgs84ll"); - - //cb.SelectedIndex = 0; - cb.SelectedItem = cfg.Coordtype; - } - } -} \ No newline at end of file diff --git a/XCoder/Yun/FrmMap.resx b/XCoder/Yun/FrmMap.resx deleted file mode 100644 index 6335d46f..00000000 --- a/XCoder/Yun/FrmMap.resx +++ /dev/null @@ -1,126 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 17, 17 - - - 144, 17 - - \ No newline at end of file diff --git a/XCoder/Yun/MapSetting.cs b/XCoder/Yun/MapSetting.cs deleted file mode 100644 index 78ee6a65..00000000 --- a/XCoder/Yun/MapSetting.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using NewLife.Xml; - -namespace XCoder.Yun -{ - [XmlConfigFile("Config\\Map.config", 15000)] - class MapSetting : XmlConfig - { - #region 属性 - /// 接口 - [Description("接口")] - public String Map { get; set; } - - /// 坐标系 - [Description("坐标系")] - public String Coordtype { get; set; } - - /// 方法 - [Description("方法")] - public String Method { get; set; } - - /// 地址 - [Description("地址")] - public String Address { get; set; } = "陆家嘴银城中路501号"; - - /// 城市 - [Description("城市")] - public String City { get; set; } = "上海"; - - /// 坐标 - [Description("坐标")] - public String Location { get; set; } - - /// 坐标2 - [Description("坐标2")] - public String Location2 { get; set; } - - /// 格式化地址 - [Description("格式化地址")] - public Boolean FormatAddress { get; set; } = true; - #endregion - } -} \ No newline at end of file From efe7a1f8ce424622671ab446eb456808fcea7753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=BA=E8=83=BD=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Wed, 14 May 2025 18:31:37 +0800 Subject: [PATCH 11/12] =?UTF-8?q?=E4=B8=BA=E4=BA=86=E6=8A=8AXCoder?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=BC=95=E5=AF=BC=E5=88=B0=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E6=9C=BA=E5=88=B6=EF=BC=8C=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E7=AB=99=E7=9A=84/XCoder/=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=EF=BC=8C=E6=A0=B9=E7=9B=AE=E5=BD=95=E5=88=99=E6=94=BE=E7=BD=AE?= =?UTF-8?q?v6.9=E4=BF=AE=E6=AD=A3=E5=8D=87=E7=BA=A7=E5=8C=85=EF=BC=8C?= =?UTF-8?q?=E4=B8=BA=E4=BA=86=E8=AE=A9v6.9=E5=92=8Cv7.*=E6=88=90=E5=8A=9F?= =?UTF-8?q?=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XCoder/FrmMDI.cs | 333 ++++++++++++++++++++++++----------------------- 1 file changed, 170 insertions(+), 163 deletions(-) diff --git a/XCoder/FrmMDI.cs b/XCoder/FrmMDI.cs index 5f4b79d8..2f1bb2ee 100644 --- a/XCoder/FrmMDI.cs +++ b/XCoder/FrmMDI.cs @@ -1,222 +1,229 @@ -using System; -using System.Linq; +using System.ComponentModel; using System.Diagnostics; using System.Reflection; -using System.Threading.Tasks; -using System.Windows.Forms; -using NewLife.Reflection; -using NewLife.Net; -using System.IO; +using NewLife; using NewLife.Log; +using NewLife.Net; +using NewLife.Reflection; using NewLife.Threading; -using NewLife; -using System.ComponentModel; -using System.Collections.Generic; -namespace XCoder +namespace XCoder; + +public partial class FrmMDI : Form { - public partial class FrmMDI : Form + #region 窗口初始化 + Task _load; + + public FrmMDI() { - #region 窗口初始化 - Task _load; + _load = Task.Factory.StartNew(() => typeof(IXForm).GetAllSubclasses().ToArray()); - public FrmMDI() - { - _load = Task.Factory.StartNew(() => typeof(IXForm).GetAllSubclasses().ToArray()); + InitializeComponent(); - InitializeComponent(); + // 动态调节宽度高度,兼容高DPI + this.FixDpi(); - // 动态调节宽度高度,兼容高DPI - this.FixDpi(); + Icon = Source.GetIcon(); + } - Icon = Source.GetIcon(); + private void FrmMDI_Shown(Object sender, EventArgs e) + { + var set = XConfig.Current; + if (set.Width > 0 || set.Height > 0) + { + Width = set.Width; + Height = set.Height; + Top = set.Top; + Left = set.Left; } - private void FrmMDI_Shown(Object sender, EventArgs e) - { - var set = XConfig.Current; - if (set.Width > 0 || set.Height > 0) - { - Width = set.Width; - Height = set.Height; - Top = set.Top; - Left = set.Left; - } + var asm = AssemblyX.Create(Assembly.GetExecutingAssembly()); + if (set.Title.IsNullOrEmpty()) set.Title = asm.Title; + Text = String.Format("{2} v{0} {1:HH:mm:ss}", asm.Version, asm.Compile, set.Title); - var asm = AssemblyX.Create(Assembly.GetExecutingAssembly()); - if (set.Title.IsNullOrEmpty()) set.Title = asm.Title; - Text = String.Format("{2} v{0} {1:HH:mm:ss}", asm.Version, asm.Compile, set.Title); + _load.ContinueWith(t => LoadForms(t.Result)); - _load.ContinueWith(t => LoadForms(t.Result)); + ThreadPoolX.QueueUserWorkItem(() => CheckUpdate(true)); + } - ThreadPoolX.QueueUserWorkItem(() => CheckUpdate(true)); - } + void LoadForms(Type[] ts) + { + if (ts.Length == 0) ts = typeof(IXForm).GetAllSubclasses().ToArray(); - void LoadForms(Type[] ts) + var name = XConfig.Current.LastTool + ""; + foreach (var item in ts) { - if (ts.Length == 0) ts = typeof(IXForm).GetAllSubclasses().ToArray(); - - var name = XConfig.Current.LastTool + ""; - foreach (var item in ts) + if (item.FullName.EqualIgnoreCase(name)) { - if (item.FullName.EqualIgnoreCase(name)) - { - this.Invoke(() => CreateForm(item.CreateInstance() as Form)); + this.Invoke(() => CreateForm(item.CreateInstance() as Form)); - break; - } + break; } + } - ts = ts.OrderBy(t => t.FullName).ToArray(); + ts = ts.OrderBy(t => t.FullName).ToArray(); - this.Invoke(() => + this.Invoke(() => + { + var ms = new Dictionary(); + foreach (ToolStripMenuItem item in menuStrip.Items) + { + var name2 = item.Text.Substring(null, "("); + ms[name2] = item; + } + var idx = 1; + foreach (var item in ts) { - var ms = new Dictionary(); - foreach (ToolStripMenuItem item in menuStrip.Items) + var att = item.GetCustomAttribute(); + var cat = att?.Category; + if (cat == null) cat = "工具"; + + if (!ms.TryGetValue(cat, out var root)) { - var name2 = item.Text.Substring(null, "("); - ms[name2] = item; + //root = menuStrip.Items.Add(cat) as ToolStripMenuItem; + root = new ToolStripMenuItem(cat); + menuStrip.Items.Insert(idx++, root); + ms[cat] = root; } - var idx = 1; - foreach (var item in ts) - { - var att = item.GetCustomAttribute(); - var cat = att?.Category; - if (cat == null) cat = "工具"; - if (!ms.TryGetValue(cat, out var root)) - { - //root = menuStrip.Items.Add(cat) as ToolStripMenuItem; - root = new ToolStripMenuItem(cat); - menuStrip.Items.Insert(idx++, root); - ms[cat] = root; - } - - var mi = root.DropDownItems.Add(item.GetDisplayName() ?? item.FullName); - mi.Tag = item; - mi.Click += (s, e) => - { - var tsi = s as ToolStripItem; - var type = tsi.Tag as Type; - CreateForm(type.CreateInstance() as Form); - }; - } - }); - } + var mi = root.DropDownItems.Add(item.GetDisplayName() ?? item.FullName); + mi.Tag = item; + mi.Click += (s, e) => + { + var tsi = s as ToolStripItem; + var type = tsi.Tag as Type; + CreateForm(type.CreateInstance() as Form); + }; + } + }); + } - private void FrmMDI_FormClosing(Object sender, FormClosingEventArgs e) + private void FrmMDI_FormClosing(Object sender, FormClosingEventArgs e) + { + var set = XConfig.Current; + var area = Screen.PrimaryScreen.WorkingArea; + if (Left >= 0 && Top >= 0 && Width < area.Width - 60 && Height < area.Height - 60) { - var set = XConfig.Current; - var area = Screen.PrimaryScreen.WorkingArea; - if (Left >= 0 && Top >= 0 && Width < area.Width - 60 && Height < area.Height - 60) - { - set.Width = Width; - set.Height = Height; - set.Top = Top; - set.Left = Left; - set.Save(); - } + set.Width = Width; + set.Height = Height; + set.Top = Top; + set.Left = Left; + set.Save(); } - #endregion + } + #endregion - #region 应用窗口 - void CreateForm() where TForm : Form, new() + #region 应用窗口 + void CreateForm() where TForm : Form, new() + { + var name = typeof(TForm).FullName; + var cfg = XConfig.Current; + if (name != cfg.LastTool) { - var name = typeof(TForm).FullName; - var cfg = XConfig.Current; - if (name != cfg.LastTool) - { - cfg.LastTool = name; - cfg.Save(); - } - - var frm = new TForm(); - CreateForm(frm); + cfg.LastTool = name; + cfg.Save(); } - void CreateForm(Form frm) - { - var name = frm.GetType().FullName; - var cfg = XConfig.Current; - if (name != cfg.LastTool) - { - cfg.LastTool = name; - cfg.Save(); - } + var frm = new TForm(); + CreateForm(frm); + } - frm.MdiParent = this; - frm.WindowState = FormWindowState.Maximized; - frm.Show(); + void CreateForm(Form frm) + { + var name = frm.GetType().FullName; + var cfg = XConfig.Current; + if (name != cfg.LastTool) + { + cfg.LastTool = name; + cfg.Save(); } - #endregion - #region 菜单控制 - private void ShowNewForm(Object sender, EventArgs e) { } + frm.MdiParent = this; + frm.WindowState = FormWindowState.Maximized; + frm.Show(); + } + #endregion - private void CascadeToolStripMenuItem_Click(Object sender, EventArgs e) { LayoutMdi(MdiLayout.Cascade); } + #region 菜单控制 + private void ShowNewForm(Object sender, EventArgs e) { } - private void TileVerticalToolStripMenuItem_Click(Object sender, EventArgs e) { LayoutMdi(MdiLayout.TileVertical); } + private void CascadeToolStripMenuItem_Click(Object sender, EventArgs e) { LayoutMdi(MdiLayout.Cascade); } - private void TileHorizontalToolStripMenuItem_Click(Object sender, EventArgs e) { LayoutMdi(MdiLayout.TileHorizontal); } + private void TileVerticalToolStripMenuItem_Click(Object sender, EventArgs e) { LayoutMdi(MdiLayout.TileVertical); } - private void ArrangeIconsToolStripMenuItem_Click(Object sender, EventArgs e) { LayoutMdi(MdiLayout.ArrangeIcons); } + private void TileHorizontalToolStripMenuItem_Click(Object sender, EventArgs e) { LayoutMdi(MdiLayout.TileHorizontal); } - private void CloseAllToolStripMenuItem_Click(Object sender, EventArgs e) - { - foreach (var childForm in MdiChildren) - { - childForm.Close(); - } - } + private void ArrangeIconsToolStripMenuItem_Click(Object sender, EventArgs e) { LayoutMdi(MdiLayout.ArrangeIcons); } - private void aboutToolStripMenuItem_Click(Object sender, EventArgs e) + private void CloseAllToolStripMenuItem_Click(Object sender, EventArgs e) + { + foreach (var childForm in MdiChildren) { - Process.Start("http://www.NewLifeX.com"); + childForm.Close(); } - #endregion + } - #region 自动更新 - private void 检查更新ToolStripMenuItem_Click(Object sender, EventArgs e) - { - ThreadPoolX.QueueUserWorkItem(() => CheckUpdate(false)); - } + private void aboutToolStripMenuItem_Click(Object sender, EventArgs e) + { + Process.Start("https://NewLifeX.com"); + } + #endregion - private void CheckUpdate(Boolean auto) - { - if (auto) XTrace.WriteLine("自动更新!"); + #region 自动更新 + private void 检查更新ToolStripMenuItem_Click(Object sender, EventArgs e) + { + ThreadPoolX.QueueUserWorkItem(() => CheckUpdate(false)); + } - var up = new Upgrade(); - up.DeleteBackup("."); + private void CheckUpdate(Boolean auto) + { + if (auto) XTrace.WriteLine("自动更新!"); - var cfg = XConfig.Current; - if (cfg.LastUpdate.Date < DateTime.Now.Date || !auto) - { - cfg.LastUpdate = DateTime.Now; - cfg.Save(); + var up = new Upgrade + { + Log = XTrace.Log, + Name = "XCoder" + }; + up.DeleteBackup("."); - var root = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - up.Log = XTrace.Log; - up.Name = "XCoder"; + var cfg = XConfig.Current; + if (cfg.LastUpdate.Date < DateTime.Now.Date || !auto) + { + cfg.LastUpdate = DateTime.Now; + cfg.Save(); + + // 为了把XCoder升级引导到新的升级机制,搜索下载站的/XCoder/目录,根目录则放置v6.9修正升级包,为了让v6.9和v7.*成功升级 + var uri = new Uri(cfg.UpdateServer); + if (uri.AbsolutePath.IsNullOrEmpty() || uri.AbsolutePath == "/") + up.Server = cfg.UpdateServer + "XCoder"; + else up.Server = cfg.UpdateServer; - up.UpdatePath = root.CombinePath(up.UpdatePath); - if (up.Check()) + + var root = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + up.UpdatePath = root.CombinePath(up.UpdatePath); + if (up.Check()) + { + up.Download(); + if (!auto || MessageBox.Show($"发现新版本{up.Link.Time},是否更新?", "自动更新", MessageBoxButtons.YesNo) == DialogResult.Yes) { - up.Download(); - if (!auto || MessageBox.Show($"发现新版本{up.Link.Time},是否更新?", "自动更新", MessageBoxButtons.YesNo) == DialogResult.Yes) + var rs = up.Update(); + MessageBox.Show("更新" + (rs ? "成功" : "失败"), "自动更新"); + + if (rs) { - var rs = up.Update(); - MessageBox.Show("更新" + (rs ? "成功" : "失败"), "自动更新"); + Process.Start("XCoder.exe"); + Application.Exit(); } } - else if (!auto) - { - if (up.Link != null) - MessageBox.Show($"没有可用更新!最新{up.Link.Time}", "自动更新"); - else - MessageBox.Show("没有可用更新!", "自动更新"); - } + } + else if (!auto) + { + if (up.Link != null) + MessageBox.Show($"没有可用更新!最新{up.Link.Time}", "自动更新"); + else + MessageBox.Show("没有可用更新!", "自动更新"); } } - #endregion } + #endregion } \ No newline at end of file From 19f13e8aadf0efaafaa655578ad2fcd8fbc8ae57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=BA=E8=83=BD=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Wed, 14 May 2025 18:48:18 +0800 Subject: [PATCH 12/12] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XCoder/FrmMDI.cs | 2 +- XCoder/XCoder.csproj | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/XCoder/FrmMDI.cs b/XCoder/FrmMDI.cs index 2f1bb2ee..f6e2dfb1 100644 --- a/XCoder/FrmMDI.cs +++ b/XCoder/FrmMDI.cs @@ -204,7 +204,7 @@ private void CheckUpdate(Boolean auto) if (up.Check()) { up.Download(); - if (!auto || MessageBox.Show($"发现新版本{up.Link.Time},是否更新?", "自动更新", MessageBoxButtons.YesNo) == DialogResult.Yes) + if (!auto || MessageBox.Show($"发现新版本v{up.Link.Version},是否更新?", "自动更新", MessageBoxButtons.YesNo) == DialogResult.Yes) { var rs = up.Update(); MessageBox.Show("更新" + (rs ? "成功" : "失败"), "自动更新"); diff --git a/XCoder/XCoder.csproj b/XCoder/XCoder.csproj index 55d7bf09..571f585d 100644 --- a/XCoder/XCoder.csproj +++ b/XCoder/XCoder.csproj @@ -93,10 +93,4 @@ 2020.0.2 - - - - - del "$(TargetDir)*.xml" /q - \ No newline at end of file