Skip to content

Commit 04266ed

Browse files
committed
每日代码提交
1 parent 2089562 commit 04266ed

4 files changed

Lines changed: 83 additions & 1 deletion

File tree

upgrading/.shared/Package.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class Package
3939
public Package()
4040
{
4141
this.Tags = [];
42+
this.Executors = [];
4243
this.Creation = DateTime.Now;
4344
this.Platform = Utility.Platform;
4445
this.Architecture = Utility.Architecture;
@@ -52,6 +53,7 @@ public Package(string name, string edition, Version version, string[] tags = nul
5253
this.Edition = edition;
5354
this.Version = version;
5455
this.Tags = tags ?? [];
56+
this.Executors = [];
5557
this.Creation = DateTime.Now;
5658
this.Platform = Utility.Platform;
5759
this.Architecture= Utility.Architecture;
@@ -65,6 +67,7 @@ public Package(string name, string edition, Version version, Platform platform,
6567
this.Edition = edition;
6668
this.Version = version;
6769
this.Tags = tags ?? [];
70+
this.Executors = [];
6871
this.Creation = DateTime.Now;
6972
this.Platform = platform;
7073
this.Architecture = architecture;
@@ -102,6 +105,10 @@ public Package(string name, string edition, Version version, Platform platform,
102105
/// <summary>获取或设置描述信息。</summary>
103106
public string Description { get; set; }
104107

108+
/// <summary>获取执行器集合。</summary>
109+
[System.Text.Json.Serialization.JsonObjectCreationHandling(System.Text.Json.Serialization.JsonObjectCreationHandling.Populate)]
110+
public ICollection<Executor> Executors { get; }
111+
105112
/// <summary>获取包的扩展属性集。</summary>
106113
[System.Text.Json.Serialization.JsonExtensionData]
107114
[System.Text.Json.Serialization.JsonObjectCreationHandling(System.Text.Json.Serialization.JsonObjectCreationHandling.Populate)]
@@ -113,4 +120,18 @@ public override string ToString() => string.IsNullOrEmpty(this.Edition) ?
113120
$"{this.Name}@{this.Version}({this.GetRuntimeIdentifier()})":
114121
$"{this.Name}|{this.Edition}@{this.Version}({this.GetRuntimeIdentifier()})";
115122
#endregion
123+
124+
#region 嵌套结构
125+
public struct Executor(string @event, string command)
126+
{
127+
#region 公共字段
128+
public string Event = @event;
129+
public string Command = command;
130+
#endregion
131+
132+
#region 重写方法
133+
public readonly override string ToString() => $"[{this.Event}]{this.Command}";
134+
#endregion
135+
}
136+
#endregion
116137
}

upgrading/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Zongsoft.Upgrading 自动升级插件库
2+
3+
[English](README.md) |
4+
[简体中文](README-zh_CN.md)
5+
6+
-----
7+
8+
## 概述
9+
10+
[**Z**ongsoft.**U**pgrading](https://github.com/Zongsoft/framework/tree/main/upgrading)[_**Z**ongsoft_](https://github.com/Zongsoft/framework) 开源框架的自动升级插件库。
11+
12+
💡 如果将本插件库部署到 [_宿主_](https://github.com/Zongsoft/hosting) 程序中,即可享有自动升级更新之功能。

upgrading/client/Executor.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* _____ ______
3+
* /_ / ____ ____ ____ _________ / __/ /_
4+
* / / / __ \/ __ \/ __ \/ ___/ __ \/ /_/ __/
5+
* / /__/ /_/ / / / / /_/ /\_ \/ /_/ / __/ /_
6+
* /____/\____/_/ /_/\__ /____/\____/_/ \__/
7+
* /____/
8+
*
9+
* Authors:
10+
* 钟峰(Popeye Zhong) <zongsoft@qq.com>
11+
*
12+
* Copyright (C) 2020-2026 Zongsoft Studio <http://www.zongsoft.com>
13+
*
14+
* This file is part of Zongsoft.Upgrading library.
15+
*
16+
* The Zongsoft.Upgrading is free software: you can redistribute it and/or modify
17+
* it under the terms of the GNU Lesser General Public License as published by
18+
* the Free Software Foundation, either version 3.0 of the License,
19+
* or (at your option) any later version.
20+
*
21+
* The Zongsoft.Upgrading is distributed in the hope that it will be useful,
22+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+
* GNU Lesser General Public License for more details.
25+
*
26+
* You should have received a copy of the GNU Lesser General Public License
27+
* along with the Zongsoft.Upgrading library. If not, see <http://www.gnu.org/licenses/>.
28+
*/
29+
30+
using System;
31+
using System.Threading;
32+
using System.Threading.Tasks;
33+
34+
namespace Zongsoft.Upgrading;
35+
36+
public sealed partial class Executor
37+
{
38+
public static async ValueTask ExecuteAsync(Package package, string @event, CancellationToken cancellation = default)
39+
{
40+
if(package == null || package.Executors == null)
41+
return;
42+
43+
foreach(var executor in package.Executors)
44+
{
45+
if(executor.Event != null && executor.Event.StartsWith(@event, StringComparison.OrdinalIgnoreCase))
46+
await Components.CommandExecutor.Default.ExecuteAsync(executor.Command, package, cancellation);
47+
}
48+
}
49+
}

upgrading/client/Fetcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333

3434
namespace Zongsoft.Upgrading;
3535

36-
public sealed class Fetcher
36+
public sealed partial class Fetcher
3737
{
3838
}

0 commit comments

Comments
 (0)