修改提交

This commit is contained in:
2023-04-12 16:37:44 +08:00
parent fa895afaae
commit b748a2af0d
17 changed files with 626 additions and 1423 deletions
+301
View File
@@ -0,0 +1,301 @@
namespace Start
{
partial class Main
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
groupBox1 = new GroupBox();
connectButton = new Button();
passwordTextBox = new TextBox();
usernameTextBox = new TextBox();
serverTextBox = new TextBox();
label3 = new Label();
label2 = new Label();
label1 = new Label();
groupBox2 = new GroupBox();
portBtn = new Button();
apiPortTBox = new TextBox();
nginxPortTBox = new TextBox();
label4 = new Label();
label5 = new Label();
groupBox3 = new GroupBox();
activeBtn = new Button();
KeySecreteTextBox = new TextBox();
machineTextBox = new TextBox();
machineCodeLB = new Label();
label6 = new Label();
label7 = new Label();
groupBox1.SuspendLayout();
groupBox2.SuspendLayout();
groupBox3.SuspendLayout();
SuspendLayout();
//
// groupBox1
//
groupBox1.Controls.Add(connectButton);
groupBox1.Controls.Add(passwordTextBox);
groupBox1.Controls.Add(usernameTextBox);
groupBox1.Controls.Add(serverTextBox);
groupBox1.Controls.Add(label3);
groupBox1.Controls.Add(label2);
groupBox1.Controls.Add(label1);
groupBox1.Location = new Point(24, 25);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(738, 220);
groupBox1.TabIndex = 0;
groupBox1.TabStop = false;
groupBox1.Text = "数据库";
//
// connectButton
//
connectButton.Location = new Point(531, 86);
connectButton.Name = "connectButton";
connectButton.Size = new Size(128, 49);
connectButton.TabIndex = 6;
connectButton.Text = "测试连接";
connectButton.UseVisualStyleBackColor = true;
connectButton.Click += connectButton_Click;
//
// passwordTextBox
//
passwordTextBox.Location = new Point(193, 144);
passwordTextBox.Name = "passwordTextBox";
passwordTextBox.Size = new Size(271, 23);
passwordTextBox.TabIndex = 5;
passwordTextBox.Text = "123456";
//
// usernameTextBox
//
usernameTextBox.Location = new Point(193, 99);
usernameTextBox.Name = "usernameTextBox";
usernameTextBox.Size = new Size(271, 23);
usernameTextBox.TabIndex = 4;
usernameTextBox.Text = "sa";
//
// serverTextBox
//
serverTextBox.Location = new Point(193, 51);
serverTextBox.Name = "serverTextBox";
serverTextBox.Size = new Size(271, 23);
serverTextBox.TabIndex = 3;
serverTextBox.Text = ".";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(26, 141);
label3.Name = "label3";
label3.Size = new Size(32, 17);
label3.TabIndex = 2;
label3.Text = "密码";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(26, 95);
label2.Name = "label2";
label2.Size = new Size(44, 17);
label2.TabIndex = 1;
label2.Text = "登录名";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(26, 45);
label1.Name = "label1";
label1.Size = new Size(56, 17);
label1.TabIndex = 0;
label1.Text = "服务器名";
//
// groupBox2
//
groupBox2.Controls.Add(portBtn);
groupBox2.Controls.Add(apiPortTBox);
groupBox2.Controls.Add(nginxPortTBox);
groupBox2.Controls.Add(label4);
groupBox2.Controls.Add(label5);
groupBox2.Location = new Point(24, 266);
groupBox2.Name = "groupBox2";
groupBox2.Size = new Size(738, 206);
groupBox2.TabIndex = 1;
groupBox2.TabStop = false;
groupBox2.Text = "Nginx";
//
// portBtn
//
portBtn.Location = new Point(531, 86);
portBtn.Name = "portBtn";
portBtn.Size = new Size(128, 49);
portBtn.TabIndex = 7;
portBtn.Text = "测试端口";
portBtn.UseVisualStyleBackColor = true;
portBtn.Click += portBtn_Click;
//
// apiPortTBox
//
apiPortTBox.Location = new Point(218, 112);
apiPortTBox.Name = "apiPortTBox";
apiPortTBox.Size = new Size(100, 23);
apiPortTBox.TabIndex = 5;
apiPortTBox.Text = "7100";
//
// nginxPortTBox
//
nginxPortTBox.Location = new Point(217, 64);
nginxPortTBox.Name = "nginxPortTBox";
nginxPortTBox.Size = new Size(100, 23);
nginxPortTBox.TabIndex = 4;
nginxPortTBox.Text = "9527";
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(26, 113);
label4.Name = "label4";
label4.Size = new Size(80, 17);
label4.TabIndex = 3;
label4.Text = "服务启动端口";
//
// label5
//
label5.AutoSize = true;
label5.Location = new Point(26, 63);
label5.Name = "label5";
label5.Size = new Size(90, 17);
label5.TabIndex = 2;
label5.Text = "Nginx启动端口";
//
// groupBox3
//
groupBox3.Controls.Add(activeBtn);
groupBox3.Controls.Add(KeySecreteTextBox);
groupBox3.Controls.Add(machineTextBox);
groupBox3.Controls.Add(machineCodeLB);
groupBox3.Controls.Add(label6);
groupBox3.Controls.Add(label7);
groupBox3.Location = new Point(24, 502);
groupBox3.Name = "groupBox3";
groupBox3.Size = new Size(738, 172);
groupBox3.TabIndex = 2;
groupBox3.TabStop = false;
groupBox3.Text = "激活码";
//
// activeBtn
//
activeBtn.Location = new Point(531, 75);
activeBtn.Name = "activeBtn";
activeBtn.Size = new Size(128, 49);
activeBtn.TabIndex = 9;
activeBtn.Text = "激活";
activeBtn.UseVisualStyleBackColor = true;
activeBtn.Click += activeBtn_Click;
//
// KeySecreteTextBox
//
KeySecreteTextBox.Location = new Point(193, 101);
KeySecreteTextBox.Name = "KeySecreteTextBox";
KeySecreteTextBox.Size = new Size(271, 23);
KeySecreteTextBox.TabIndex = 8;
//
// machineTextBox
//
machineTextBox.Location = new Point(193, 51);
machineTextBox.Name = "machineTextBox";
machineTextBox.ReadOnly = true;
machineTextBox.Size = new Size(271, 23);
machineTextBox.TabIndex = 7;
//
// machineCodeLB
//
machineCodeLB.AutoSize = true;
machineCodeLB.Location = new Point(163, 51);
machineCodeLB.Name = "machineCodeLB";
machineCodeLB.Size = new Size(0, 17);
machineCodeLB.TabIndex = 6;
//
// label6
//
label6.AutoSize = true;
label6.Location = new Point(26, 101);
label6.Name = "label6";
label6.Size = new Size(44, 17);
label6.TabIndex = 5;
label6.Text = "激活码";
//
// label7
//
label7.AutoSize = true;
label7.Location = new Point(26, 51);
label7.Name = "label7";
label7.Size = new Size(44, 17);
label7.TabIndex = 4;
label7.Text = "机器码";
//
// Main
//
AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 798);
Controls.Add(groupBox3);
Controls.Add(groupBox2);
Controls.Add(groupBox1);
Name = "Main";
Text = "EI Image Viewer";
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
groupBox2.ResumeLayout(false);
groupBox2.PerformLayout();
groupBox3.ResumeLayout(false);
groupBox3.PerformLayout();
ResumeLayout(false);
}
#endregion
private GroupBox groupBox1;
private Label label3;
private Label label2;
private Label label1;
private TextBox passwordTextBox;
private TextBox usernameTextBox;
private TextBox serverTextBox;
private Button connectButton;
private GroupBox groupBox2;
private TextBox apiPortTBox;
private TextBox nginxPortTBox;
private Label label4;
private Label label5;
private GroupBox groupBox3;
private Button portBtn;
private Label machineCodeLB;
private Label label6;
private Label label7;
private Button activeBtn;
private TextBox KeySecreteTextBox;
private TextBox machineTextBox;
}
}
+193
View File
@@ -0,0 +1,193 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.NetworkInformation;
using System.Windows.Forms;
using System.Net;
using System.Security.Cryptography;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Diagnostics;
namespace Start
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
var physicalAddressList = NetworkInterface.GetAllNetworkInterfaces().Select(t => t.GetPhysicalAddress().ToString());
this.machineTextBox.Text = physicalAddressList.FirstOrDefault()?.ToString();
this.KeySecreteTextBox.Text = Md5($"{this.machineTextBox.Text}_XINGCANG");
}
int apiPort = 0;
private void connectButton_Click(object sender, EventArgs e)
{
string connectionString = $"Server={serverTextBox.Text};User Id={usernameTextBox.Text};Password={passwordTextBox.Text};";
SqlConnection connection = new SqlConnection(connectionString);
try
{
connection.Open();
MessageBox.Show("连接成功!");
}
catch (Exception ex)
{
MessageBox.Show($"连接失败:{ex.Message}");
}
finally
{
connection.Close();
}
}
private void portBtn_Click(object sender, EventArgs e)
{
nginxPortTBox.Text.Trim();
var nginxPort = 0;
if (int.TryParse(nginxPortTBox.Text, out nginxPort) == false || int.TryParse(apiPortTBox.Text, out apiPort) == false)
{
MessageBox.Show("请输入合法的端口");
}
if (IsPortInUse(nginxPort))
{
MessageBox.Show("nginx 设置的端口被占用,请选择其他端口");
}
if (IsPortInUse(apiPort))
{
MessageBox.Show("服务设置的端口被占用,请选择其他端口");
}
}
private static bool IsPortInUse(int port)
{
IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
IPEndPoint[] tcpEndPoints = ipProperties.GetActiveTcpListeners();
foreach (IPEndPoint endPoint in tcpEndPoints)
{
if (endPoint.Port == port)
{
return true;
}
}
return false;
}
public static string Md5(string target)
{
using (MD5 md5 = MD5.Create())
{ // MD5非线程安全
byte[] bytes = md5.ComputeHash(Encoding.UTF8.GetBytes(target));
StringBuilder sb = new StringBuilder(32);
for (int i = 0; i < bytes.Length; ++i)
sb.Append(bytes[i].ToString("x2"));
return sb.ToString();
}
}
private void activeBtn_Click(object sender, EventArgs e)
{
string nginxPath = @"C:\nginx\nginx.exe";
string workingDirectory = @"C:\nginx";
string configFile = @"C:\nginx\conf\nginx.conf";
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = nginxPath;
psi.WorkingDirectory = workingDirectory;
psi.Arguments = "-c \"" + configFile + "\"";
Process.Start(psi);
var configObj = new
{
Key = this.machineTextBox.Text,
Value = this.KeySecreteTextBox.Text.Trim(),
user = usernameTextBox.Text,
server = serverTextBox.Text,
password = passwordTextBox.Text,
database = string.Empty
};
File.WriteAllText($@"C:\ProgramData\.xingcang\config.json", JsonConvert.SerializeObject(configObj));
var serviceConfig = File.ReadAllText("ServiceConfig.json");
var jObject = JObject.Parse(serviceConfig);
var binPath = Path.Combine(AppContext.BaseDirectory, jObject["binPath"].ToString().TrimStart('/'));
var createStr = $@"sc create {jObject["serviceName"].ToString()} binPath= ""{binPath} --urls=""http://127.0.0.1:{apiPort}"" --env CertificateApply"" DisplayName= ""{jObject["serviceDisplayName"].ToString()}"" start= auto";
#region
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.UseShellExecute = false;
process.Start();
//启动nginx
process.StandardInput.WriteLine($"start {Path.Combine(AppContext.BaseDirectory, "nginx-1.4.7/nginx.exe")}" );
// 删除已存在的服务
process.StandardInput.WriteLine($"sc delete {jObject["serviceName"].ToString()}");
// 执行 sc create 命令来创建服务
process.StandardInput.WriteLine(createStr);
process.Exited += (sender, e) =>
{
int exitCode = process.ExitCode;
if (exitCode == 0)
{
// 执行成功
MessageBox.Show("Batch file executed successfully.");
}
else
{
// 执行失败
MessageBox.Show("Batch file execution failed with error code: " + exitCode);
}
};
//执行数据库脚本
process.StandardInput.WriteLine(Path.Combine(AppContext.BaseDirectory, "sql/bin.bat"));
// 关闭进程流并等待进程退出
process.StandardInput.Flush();
process.StandardInput.Close();
process.WaitForExit();
#endregion
}
}
}
+60
View File
@@ -0,0 +1,60 @@
<root>
<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>
+17
View File
@@ -0,0 +1,17 @@
namespace Start
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Main());
}
}
}
+5
View File
@@ -0,0 +1,5 @@
{
"serviceName": "CertificateApply.NetCore.Api",
"serviceDisplayName": "CertificateApplyServiceDisplayName",
"binPath": "/IRacIS.NetCore.API/IRacIS.Core.API.exe"
}
+38
View File
@@ -0,0 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<None Remove="ServiceConfig.Json" />
<None Remove="sql\bin.bat" />
<None Remove="sql\data.sql" />
<None Remove="sql\dbo.sql" />
</ItemGroup>
<ItemGroup>
<Content Include="ServiceConfig.Json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="sql\bin.bat">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="sql\data.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="sql\dbo.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
</ItemGroup>
</Project>
+2
View File
@@ -0,0 +1,2 @@
SQLCMD -i %~dp0\dbo.sql
SQLCMD -i %~dp0\data.sql
Binary file not shown.
BIN
View File
Binary file not shown.