Skip to content

Commit

Permalink
添加 AutoStop 和 ReloadOnChange 功能支持
Browse files Browse the repository at this point in the history
在 Model.xml 中添加了 AutoStop 和 ReloadOnChange 列。
在 Stardust.htm 中添加了相应的表格行。
在 ServiceController.cs 中更新 MonitorFileChange 方法,
增加了对 ReloadOnChange 的判断。
  • Loading branch information
猿人易 committed Jul 5, 2024
1 parent feced04 commit 485cb24
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Stardust.Data/Deployment/Model.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<Column Name="UserName" DataType="String" Description="用户名。以该用户执行应用" Category="发布参数" />
<Column Name="MaxMemory" DataType="Int32" Description="最大内存。单位M,超过上限时自动重启应用,默认0不限制" Category="发布参数" />
<Column Name="Mode" DataType="Int32" Description="工作模式。0默认exe/zip;1仅解压;2解压后运行;3仅运行一次;4多实例exe/zip" Type="Stardust.Models.ServiceModes" Category="发布参数" />
<Column Name="AutoStop" DataType="Boolean" Description="是否自动停止。随着宿主的退出,同时停止该应用进程" />
<Column Name="ReloadOnChange" DataType="Boolean" Description="检测文件变动。当文件发生改变时,自动重启应用" />
<Column Name="CreateUserId" DataType="Int32" Description="创建者" Category="扩展" />
<Column Name="CreateTime" DataType="DateTime" Description="创建时间" Category="扩展" />
<Column Name="CreateIP" DataType="String" Description="创建地址" Category="扩展" />
Expand Down
22 changes: 22 additions & 0 deletions Stardust.Data/Deployment/Stardust.htm
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,28 @@ <h3>应用部署(AppDeploy)</h3>
<td>0默认exe/zip;1仅解压;2解压后运行;3仅运行一次;4多实例exe/zip</td>
</tr>

<tr>
<td>AutoStop</td>
<td>是否自动停止</td>
<td>Boolean</td>
<td></td>
<td></td>
<td></td>
<td>N</td>
<td>随着宿主的退出,同时停止该应用进程</td>
</tr>

<tr>
<td>ReloadOnChange</td>
<td>检测文件变动</td>
<td>Boolean</td>
<td></td>
<td></td>
<td></td>
<td>N</td>
<td>当文件发生改变时,自动重启应用</td>
</tr>

<tr>
<td>CreateUserId</td>
<td>创建者</td>
Expand Down
32 changes: 32 additions & 0 deletions Stardust.Data/Deployment/应用部署.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,22 @@ public partial class AppDeploy
[BindColumn("Mode", "工作模式。0默认exe/zip;1仅解压;2解压后运行;3仅运行一次;4多实例exe/zip", "")]
public Stardust.Models.ServiceModes Mode { get => _Mode; set { if (OnPropertyChanging("Mode", value)) { _Mode = value; OnPropertyChanged("Mode"); } } }

private Boolean _AutoStop;
/// <summary>是否自动停止。随着宿主的退出,同时停止该应用进程</summary>
[DisplayName("是否自动停止")]
[Description("是否自动停止。随着宿主的退出,同时停止该应用进程")]
[DataObjectField(false, false, false, 0)]
[BindColumn("AutoStop", "是否自动停止。随着宿主的退出,同时停止该应用进程", "")]
public Boolean AutoStop { get => _AutoStop; set { if (OnPropertyChanging("AutoStop", value)) { _AutoStop = value; OnPropertyChanged("AutoStop"); } } }

private Boolean _ReloadOnChange;
/// <summary>检测文件变动。当文件发生改变时,自动重启应用</summary>
[DisplayName("检测文件变动")]
[Description("检测文件变动。当文件发生改变时,自动重启应用")]
[DataObjectField(false, false, false, 0)]
[BindColumn("ReloadOnChange", "检测文件变动。当文件发生改变时,自动重启应用", "")]
public Boolean ReloadOnChange { get => _ReloadOnChange; set { if (OnPropertyChanging("ReloadOnChange", value)) { _ReloadOnChange = value; OnPropertyChanged("ReloadOnChange"); } } }

private Int32 _CreateUserId;
/// <summary>创建者</summary>
[Category("扩展")]
Expand Down Expand Up @@ -304,6 +320,8 @@ public override Object this[String name]
"UserName" => _UserName,
"MaxMemory" => _MaxMemory,
"Mode" => _Mode,
"AutoStop" => _AutoStop,
"ReloadOnChange" => _ReloadOnChange,
"CreateUserId" => _CreateUserId,
"CreateTime" => _CreateTime,
"CreateIP" => _CreateIP,
Expand Down Expand Up @@ -339,6 +357,8 @@ public override Object this[String name]
case "UserName": _UserName = Convert.ToString(value); break;
case "MaxMemory": _MaxMemory = value.ToInt(); break;
case "Mode": _Mode = (Stardust.Models.ServiceModes)value.ToInt(); break;
case "AutoStop": _AutoStop = value.ToBoolean(); break;
case "ReloadOnChange": _ReloadOnChange = value.ToBoolean(); break;
case "CreateUserId": _CreateUserId = value.ToInt(); break;
case "CreateTime": _CreateTime = value.ToDateTime(); break;
case "CreateIP": _CreateIP = Convert.ToString(value); break;
Expand Down Expand Up @@ -433,6 +453,12 @@ public partial class _
/// <summary>工作模式。0默认exe/zip;1仅解压;2解压后运行;3仅运行一次;4多实例exe/zip</summary>
public static readonly Field Mode = FindByName("Mode");

/// <summary>是否自动停止。随着宿主的退出,同时停止该应用进程</summary>
public static readonly Field AutoStop = FindByName("AutoStop");

/// <summary>检测文件变动。当文件发生改变时,自动重启应用</summary>
public static readonly Field ReloadOnChange = FindByName("ReloadOnChange");

/// <summary>创建者</summary>
public static readonly Field CreateUserId = FindByName("CreateUserId");

Expand Down Expand Up @@ -526,6 +552,12 @@ public partial class __
/// <summary>工作模式。0默认exe/zip;1仅解压;2解压后运行;3仅运行一次;4多实例exe/zip</summary>
public const String Mode = "Mode";

/// <summary>是否自动停止。随着宿主的退出,同时停止该应用进程</summary>
public const String AutoStop = "AutoStop";

/// <summary>检测文件变动。当文件发生改变时,自动重启应用</summary>
public const String ReloadOnChange = "ReloadOnChange";

/// <summary>创建者</summary>
public const String CreateUserId = "CreateUserId";

Expand Down
2 changes: 2 additions & 0 deletions Stardust/Managers/ServiceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,8 @@ private void StartMonitor()

private void MonitorFileChange(Object? state)
{
if (Info?.ReloadOnChange == false) return;

var first = _files.Count == 0;
var changed = "";

Expand Down

0 comments on commit 485cb24

Please sign in to comment.