ソースを参照

发布工具添加设置界面

yuzhengyang 7 年 前
コミット
650cf1dcbf

+ 194 - 0
Fork.Net/Oreo.Plugins/Oreo.BigBirdDeployer/Parts/ProjectItemPart.Designer.cs

@@ -0,0 +1,194 @@
+namespace Oreo.BigBirdDeployer.Parts
+{
+    partial class ProjectItemPart
+    {
+        /// <summary> 
+        /// 必需的设计器变量。
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary> 
+        /// 清理所有正在使用的资源。
+        /// </summary>
+        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region 组件设计器生成的代码
+
+        /// <summary> 
+        /// 设计器支持所需的方法 - 不要修改
+        /// 使用代码编辑器修改此方法的内容。
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.BTStartOrStop = new System.Windows.Forms.Button();
+            this.BTConfig = new System.Windows.Forms.Button();
+            this.LBProjectName = new System.Windows.Forms.Label();
+            this.LBStatus = new System.Windows.Forms.Label();
+            this.panel1 = new System.Windows.Forms.Panel();
+            this.PBLoading = new System.Windows.Forms.PictureBox();
+            this.LBDesc = new System.Windows.Forms.Label();
+            this.LBCpu = new System.Windows.Forms.Label();
+            this.LBRam = new System.Windows.Forms.Label();
+            this.TBConsole = new System.Windows.Forms.TextBox();
+            this.LBProcessName = new System.Windows.Forms.Label();
+            this.panel1.SuspendLayout();
+            ((System.ComponentModel.ISupportInitialize)(this.PBLoading)).BeginInit();
+            this.SuspendLayout();
+            // 
+            // BTStartOrStop
+            // 
+            this.BTStartOrStop.Location = new System.Drawing.Point(341, 14);
+            this.BTStartOrStop.Name = "BTStartOrStop";
+            this.BTStartOrStop.Size = new System.Drawing.Size(75, 44);
+            this.BTStartOrStop.TabIndex = 0;
+            this.BTStartOrStop.Text = "启动/停止";
+            this.BTStartOrStop.UseVisualStyleBackColor = true;
+            this.BTStartOrStop.Click += new System.EventHandler(this.BTStartOrStop_Click);
+            // 
+            // BTConfig
+            // 
+            this.BTConfig.Location = new System.Drawing.Point(427, 14);
+            this.BTConfig.Name = "BTConfig";
+            this.BTConfig.Size = new System.Drawing.Size(75, 44);
+            this.BTConfig.TabIndex = 1;
+            this.BTConfig.Text = "配置";
+            this.BTConfig.UseVisualStyleBackColor = true;
+            this.BTConfig.Click += new System.EventHandler(this.BTConfig_Click);
+            // 
+            // LBProjectName
+            // 
+            this.LBProjectName.BackColor = System.Drawing.Color.SandyBrown;
+            this.LBProjectName.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.LBProjectName.ForeColor = System.Drawing.Color.White;
+            this.LBProjectName.Location = new System.Drawing.Point(0, 0);
+            this.LBProjectName.Name = "LBProjectName";
+            this.LBProjectName.Size = new System.Drawing.Size(195, 44);
+            this.LBProjectName.TabIndex = 2;
+            this.LBProjectName.Text = "工程名称";
+            this.LBProjectName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+            // 
+            // LBStatus
+            // 
+            this.LBStatus.BackColor = System.Drawing.Color.MediumTurquoise;
+            this.LBStatus.Dock = System.Windows.Forms.DockStyle.Right;
+            this.LBStatus.ForeColor = System.Drawing.Color.White;
+            this.LBStatus.Location = new System.Drawing.Point(195, 0);
+            this.LBStatus.Name = "LBStatus";
+            this.LBStatus.Size = new System.Drawing.Size(73, 44);
+            this.LBStatus.TabIndex = 3;
+            this.LBStatus.Text = "状态显示";
+            this.LBStatus.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+            // 
+            // panel1
+            // 
+            this.panel1.Controls.Add(this.LBProjectName);
+            this.panel1.Controls.Add(this.LBStatus);
+            this.panel1.Location = new System.Drawing.Point(13, 14);
+            this.panel1.Name = "panel1";
+            this.panel1.Size = new System.Drawing.Size(268, 44);
+            this.panel1.TabIndex = 4;
+            // 
+            // PBLoading
+            // 
+            this.PBLoading.Location = new System.Drawing.Point(288, 14);
+            this.PBLoading.Name = "PBLoading";
+            this.PBLoading.Size = new System.Drawing.Size(47, 44);
+            this.PBLoading.TabIndex = 5;
+            this.PBLoading.TabStop = false;
+            // 
+            // LBDesc
+            // 
+            this.LBDesc.AutoSize = true;
+            this.LBDesc.ForeColor = System.Drawing.Color.White;
+            this.LBDesc.Location = new System.Drawing.Point(11, 73);
+            this.LBDesc.Name = "LBDesc";
+            this.LBDesc.Size = new System.Drawing.Size(29, 12);
+            this.LBDesc.TabIndex = 7;
+            this.LBDesc.Text = "描述";
+            // 
+            // LBCpu
+            // 
+            this.LBCpu.AutoSize = true;
+            this.LBCpu.ForeColor = System.Drawing.Color.White;
+            this.LBCpu.Location = new System.Drawing.Point(305, 73);
+            this.LBCpu.Name = "LBCpu";
+            this.LBCpu.Size = new System.Drawing.Size(53, 12);
+            this.LBCpu.TabIndex = 8;
+            this.LBCpu.Text = "CPU:0 %";
+            // 
+            // LBRam
+            // 
+            this.LBRam.AutoSize = true;
+            this.LBRam.ForeColor = System.Drawing.Color.White;
+            this.LBRam.Location = new System.Drawing.Point(387, 73);
+            this.LBRam.Name = "LBRam";
+            this.LBRam.Size = new System.Drawing.Size(65, 12);
+            this.LBRam.TabIndex = 9;
+            this.LBRam.Text = "内存:0 MB";
+            // 
+            // TBConsole
+            // 
+            this.TBConsole.Location = new System.Drawing.Point(13, 100);
+            this.TBConsole.Multiline = true;
+            this.TBConsole.Name = "TBConsole";
+            this.TBConsole.ScrollBars = System.Windows.Forms.ScrollBars.Both;
+            this.TBConsole.Size = new System.Drawing.Size(487, 240);
+            this.TBConsole.TabIndex = 6;
+            // 
+            // LBProcessName
+            // 
+            this.LBProcessName.AutoSize = true;
+            this.LBProcessName.ForeColor = System.Drawing.Color.White;
+            this.LBProcessName.Location = new System.Drawing.Point(111, 73);
+            this.LBProcessName.Name = "LBProcessName";
+            this.LBProcessName.Size = new System.Drawing.Size(41, 12);
+            this.LBProcessName.TabIndex = 10;
+            this.LBProcessName.Text = "进程名";
+            // 
+            // ProjectItemPart
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.BackColor = System.Drawing.Color.DimGray;
+            this.Controls.Add(this.LBProcessName);
+            this.Controls.Add(this.LBRam);
+            this.Controls.Add(this.LBCpu);
+            this.Controls.Add(this.LBDesc);
+            this.Controls.Add(this.TBConsole);
+            this.Controls.Add(this.PBLoading);
+            this.Controls.Add(this.panel1);
+            this.Controls.Add(this.BTConfig);
+            this.Controls.Add(this.BTStartOrStop);
+            this.Name = "ProjectItemPart";
+            this.Size = new System.Drawing.Size(513, 95);
+            this.Load += new System.EventHandler(this.ProjectItemPart_Load);
+            this.panel1.ResumeLayout(false);
+            ((System.ComponentModel.ISupportInitialize)(this.PBLoading)).EndInit();
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Button BTStartOrStop;
+        private System.Windows.Forms.Button BTConfig;
+        private System.Windows.Forms.Label LBProjectName;
+        private System.Windows.Forms.Label LBStatus;
+        private System.Windows.Forms.Panel panel1;
+        private System.Windows.Forms.PictureBox PBLoading;
+        private System.Windows.Forms.Label LBDesc;
+        private System.Windows.Forms.Label LBCpu;
+        private System.Windows.Forms.Label LBRam;
+        private System.Windows.Forms.TextBox TBConsole;
+        private System.Windows.Forms.Label LBProcessName;
+    }
+}

+ 251 - 0
Fork.Net/Oreo.Plugins/Oreo.BigBirdDeployer/Parts/ProjectItemPart.cs

@@ -0,0 +1,251 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.Data;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+using System.Diagnostics;
+using Oreo.BigBirdDeployer.Models;
+using Azylee.Core.WindowsUtils.CMDUtils;
+using Azylee.Core.DataUtils.CollectionUtils;
+using System.Threading.Tasks;
+using System.Threading;
+using Oreo.BigBirdDeployer.Views;
+using Azylee.Core.AppUtils;
+using Azylee.Core.IOUtils.DirUtils;
+using Azylee.Core.ProcessUtils;
+
+namespace Oreo.BigBirdDeployer.Parts
+{
+    public partial class ProjectItemPart : UserControl
+    {
+        const int STATUS_INTERVAL = 1000;//刷新状态时间间隔
+        private WorkStatus Status { get; set; }
+        private ProjectModel Project { get; set; }
+        private Process Process { get; set; }
+        public ProjectItemPart()
+        {
+            InitializeComponent();
+            Project = new ProjectModel();
+        }
+        private void ProjectItemPart_Load(object sender, EventArgs e)
+        {
+            //加载启动按钮默认不可用(Init初始化后变为可用)
+            BTStartOrStop.Enabled = false;
+        }
+        public void SetProject(ProjectModel model)
+        {
+            //初始化设置项目
+            Project = model;
+            //获取当前端口进程
+            if (GetProcess())
+            {
+                //初始化时有进程占用端口号
+                StatusUI(WorkStatus.端口占用);
+            }
+            else
+            {
+                //没有进程占用端口号
+                StatusUI(WorkStatus.准备就绪);
+            }
+            //为控件更新显示
+            LBProjectName.Text = Project.Name;
+            BTStartOrStop.Enabled = true;
+
+            //持续监控端口及端口进程状态
+            ProcessStatus();
+        }
+        private void BTStartOrStop_Click(object sender, EventArgs e)
+        {
+            //没有端口占用则正常启动
+            if (!GetProcess())
+            {
+                Start();
+            }
+            else
+            {
+                Stop();
+            }
+        }
+
+        private void BTConfig_Click(object sender, EventArgs e)
+        {
+            new ProjectConfigForm(this, Project).Show();
+        }
+
+        #region 功能方法
+        /// <summary>
+        /// 通过设置的工程端口号获取进程
+        /// </summary>
+        /// <returns></returns>
+        private bool GetProcess()
+        {
+            try
+            {
+                var pid = CMDNetstatTool.FindByPort(Project.Port, false);
+                if (ListTool.HasElements(pid))
+                {
+                    var p = Process.GetProcessById(pid.First().Item2);
+                    if (p != null)
+                    {
+                        Process = p;
+                        return true;
+                    }
+                }
+            }
+            catch { }
+            return false;
+        }
+        /// <summary>
+        /// 根据工程设置启动服务
+        /// </summary>
+        /// <returns></returns>
+        private void Start()
+        {
+            Task.Factory.StartNew(() =>
+            {
+                StatusUI(WorkStatus.正在启动);
+                CMDProcessTool.StartExecute($"java -jar {DirTool.Combine(Project.Folder, Project.JarFile)}",
+                    new Action<string>((s) =>
+                    {
+                        //ConsoleUI(s);
+                        if (s.Contains("*****************************"))
+                        {
+                            StatusUI(WorkStatus.启动成功);
+                            GetProcess();
+                        }
+                    }));
+
+                if (Status == WorkStatus.启动成功 || Status == WorkStatus.端口占用)
+                {
+                    StatusUI(WorkStatus.正在关闭);
+                    Stop();
+                }
+                else
+                {
+                    StatusUI(WorkStatus.启动失败);
+                }
+            });
+        }
+        /// <summary>
+        /// 关闭工程服务
+        /// </summary>
+        /// <returns></returns>
+        private void Stop()
+        {
+            Task.Factory.StartNew(() =>
+            {
+                try
+                {
+                    //如果能获取到端口的进程
+                    while (GetProcess())
+                    {
+                        //停止进程
+                        Process?.Kill();
+                        Thread.Sleep(1000);
+                    }
+                    StatusUI(WorkStatus.准备就绪);
+                }
+                catch { StatusUI(WorkStatus.端口占用); }
+            });
+        }
+        private void ProcessStatus()
+        {
+            Task.Factory.StartNew(() =>
+            {
+                TimeSpan pin = TimeSpan.Zero;
+                while (!IsDisposed)
+                {
+                    try
+                    {
+                        if (Process != null && !Process.HasExited)
+                        {
+                            BeginInvoke(new Action(() =>
+                            {
+                                double cpu = AppInfoTool.CalcCpuRate(Process, pin, STATUS_INTERVAL);
+                                pin = Process.TotalProcessorTime;
+
+                                LBProcessName.Text = Process.ProcessName;
+                                LBCpu.Text = $"CPU:{Math.Round(cpu, 1)} %";
+                                LBRam.Text = $"内存:{AppInfoTool.RAM(Process.Id) / 1024} MB";
+
+
+                            }));
+                        }
+                        else
+                        {
+                            BeginInvoke(new Action(() =>
+                            {
+                                LBCpu.Text = $"CPU:0 %";
+                                LBRam.Text = $"内存:0 MB";
+                            }));
+                            GetProcess();
+                        }
+                    }
+                    catch { }
+                    Thread.Sleep(STATUS_INTERVAL);
+                }
+            });
+        }
+        #endregion
+        #region UI操作
+        private void StatusUI(WorkStatus status)
+        {
+            Status = status;
+            try
+            {
+                BeginInvoke(new Action(() =>
+                {
+                    LBStatus.Text = status.ToString();
+                    switch (status)
+                    {
+                        case WorkStatus.准备就绪:
+                            BTStartOrStop.Text = "启动";
+                            BTStartOrStop.Enabled = true;
+                            break;
+                        case WorkStatus.启动成功:
+                            BTStartOrStop.Text = "停止";
+                            BTStartOrStop.Enabled = true;
+                            break;
+
+                        case WorkStatus.正在启动:
+                            BTStartOrStop.Text = "启动中.";
+                            BTStartOrStop.Enabled = false;
+                            break;
+                        case WorkStatus.正在关闭:
+                            BTStartOrStop.Text = "关闭中.";
+                            BTStartOrStop.Enabled = false;
+                            break;
+
+                        case WorkStatus.端口占用:
+                            BTStartOrStop.Text = "停止";
+                            BTStartOrStop.Enabled = true;
+                            break;
+                        case WorkStatus.启动失败:
+                            BTStartOrStop.Text = "启动";
+                            BTStartOrStop.Enabled = true;
+                            break;
+                    }
+                }));
+            }
+            catch { }
+        }
+        private void ConsoleUI(string s)
+        {
+            try
+            {
+                BeginInvoke(new Action(() =>
+                {
+                    TBConsole.AppendText(s);
+                }));
+            }
+            catch { }
+        }
+
+        #endregion
+
+
+    }
+}

+ 120 - 0
Fork.Net/Oreo.Plugins/Oreo.BigBirdDeployer/Parts/ProjectItemPart.resx

@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>