Skip to content

Update GeneralUpdate NuGet packages to 10.4.6, fix API breakages, and improve samples/docs#42

Merged
JusterZhu merged 3 commits intomainfrom
copilot/generalupdate-samples-code-improvement
Apr 11, 2026
Merged

Update GeneralUpdate NuGet packages to 10.4.6, fix API breakages, and improve samples/docs#42
JusterZhu merged 3 commits intomainfrom
copilot/generalupdate-samples-code-improvement

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 11, 2026

All GeneralUpdate sample projects were referencing stale package versions (9.1.4–10.2.1). This updates every project to 10.4.6, fixes breaking API changes, and improves sample code and documentation to align with the current GeneralUpdate API.

Package updates

Sample Package Old New
Client, Push, OSSClientSample GeneralUpdate.ClientCore 9.1.4 10.4.6
Upgrade, Compress, Diff, OSSUpgradeSample GeneralUpdate.Core 9.1.4 / 9.1.5 10.4.6
BowlSample GeneralUpdate.Bowl 9.1.4 10.4.6
ExtensionSample GeneralUpdate.Extension 10.2.1 10.4.6
DrivelutionSample GeneralUpdate.Drivelution 10.2.1 10.4.6
dotnet10_scripts/upgrade.cs GeneralUpdate.Core 9.5.10 10.4.6

Breaking API fix — DifferentialCore

The Instance singleton was removed in 10.x. Clean/Dirty are now static and require explicit strategy objects:

// Before (broken in 10.x)
await DifferentialCore.Instance?.Clean(source, target, patch);
await DifferentialCore.Instance?.Dirty(source, patch);

// After
await DifferentialCore.Clean(source, target, patch, new DefaultCleanStrategy(new DefaultCleanMatcher()));
await DifferentialCore.Dirty(source, patch, new DefaultDirtyStrategy(new DefaultDirtyMatcher()));

Null-safety fixes

  • Event handler callbacks in Client, Upgrade, and dotnet10_scripts/upgrade.cs used unsafe version.Version after an as cast — changed to version?.Version.
  • Server DTOs had non-nullable string properties without initializers — added = string.Empty.
  • HttpResponseDTO.Success(null, …) replaced with Enumerable.Empty<>() to avoid passing a null where non-nullable is expected.

PushSample enhancements

Rewrote src/Push/Program.cs to demonstrate the full UpgradeHubService API:

  • AddListenerReceive — receive server-pushed version update messages
  • AddListenerOnline — online/offline status notifications
  • AddListenerReconnected — reconnection notifications
  • AddListenerClosed — connection closed notifications
  • StartAsync / StopAsync / DisposeAsync — full connection lifecycle management

Client sample API alignment

Updated src/Client/Program.cs to match the current GeneralUpdate API:

  • Fixed stale BlackDirectories comment — the correct field name is SkipDirectorys
  • Added AddListenerUpdateInfo — receives the full VersionRespDTO returned by the server after update check
  • Added AddListenerUpdatePrecheck — callback to skip or proceed with the update before downloading begins (forcibly-required versions always proceed regardless)

UpgradeHub documentation rewrite

Rewrote website/docs/doc/UpgradeHub.md from a minimal English stub into a comprehensive Chinese-language reference doc matching the style of all other component docs (GeneralUpdate.Core.md, GeneralUpdate.Bowl.md, etc.). Includes:

  • Component overview and core features
  • Quick-start guide with installation and initialization example
  • Dependency-injection usage example (Prism)
  • Full API reference: constructor parameters and all 7 methods with signatures and descriptions
  • Three complete usage examples (basic subscription, full lifecycle management, combined with GeneralClientBootstrap)
  • Notes, best practices, platform support table, and related resource links

Copilot AI linked an issue Apr 11, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Review and enhance GeneralUpdate sample code Update GeneralUpdate NuGet packages to 10.4.6 and fix resulting API breakages Apr 11, 2026
Copilot AI requested a review from JusterZhu April 11, 2026 07:22
@JusterZhu
Copy link
Copy Markdown
Collaborator

@copilot
1.请再仔细核对https://github.com/GeneralLibrary/GeneralUpdate 现有代码和samples示例代码之间的差异,把不一样的地方更新一下。
2.UpgradeHubService的PushSample,需要更新或补充。
3.UpgradeHubService的使用在website的在线文档中需要补充,模仿其他文档的写法补全。

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 11, 2026

@copilot
1.请再仔细核对https://github.com/GeneralLibrary/GeneralUpdate 现有代码和samples示例代码之间的差异,把不一样的地方更新一下。
2.UpgradeHubService的PushSampl...

已在 commit 6f0102d 中完成以下三项:

  1. 代码差异核对:对照主仓库 API,修正了 Client 示例中错误的 BlackDirectories 注释(正确字段名为 SkipDirectorys),并补充了 10.x 新增的两个监听器 AddListenerUpdateInfo(接收服务端返回的完整版本信息)和 AddListenerUpdatePrecheck(更新前预检回调,可跳过或继续更新)。

  2. PushSample 补充:完整展示了 UpgradeHubService 的所有 API——AddListenerReceiveAddListenerOnlineAddListenerReconnectedAddListenerClosedStartAsyncStopAsyncDisposeAsync,并附中英双语注释说明每个步骤的用途。

  3. UpgradeHub.md 在线文档:将原有的英文简介彻底重写,遵循 GeneralUpdate.Core.md / GeneralUpdate.Bowl.md 的中文文档风格,包含:组件概览、核心特性、快速开始、完整 API 参考(构造函数 + 7 个方法)、3 个使用示例(基本订阅、完整生命周期、与 GeneralClientBootstrap 搭配使用)、注意事项与最佳实践、适用平台及相关资源链接。

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/GeneralLibrary/GeneralUpdate/contents/src/c%23
    • Triggering command: /usr/bin/curl curl -s REDACTED (http block)
  • https://api.github.com/repos/GeneralLibrary/GeneralUpdate/contents/src/c%23/GeneralUpdate.ClientCore/Hubs
    • Triggering command: /usr/bin/curl curl -s REDACTED (http block)
    • Triggering command: /usr/bin/curl curl -s -H User-Agent: Mozilla/5.0 REDACTED (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Update GeneralUpdate NuGet packages to 10.4.6 and fix resulting API breakages Update GeneralUpdate NuGet packages to 10.4.6, fix API breakages, and improve samples/docs Apr 11, 2026
@JusterZhu JusterZhu marked this pull request as ready for review April 11, 2026 07:47
Copilot AI review requested due to automatic review settings April 11, 2026 07:47
@JusterZhu JusterZhu merged commit 5ffa4e1 into main Apr 11, 2026
1 check passed
@JusterZhu JusterZhu deleted the copilot/generalupdate-samples-code-improvement branch April 11, 2026 07:47
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the GeneralUpdate sample solution and documentation to align with GeneralUpdate 10.4.6, addressing breaking API changes (notably DifferentialCore) and tightening null-safety in sample event handlers and DTOs.

Changes:

  • Bump all sample project/package references (and the dotnet10_scripts/upgrade.cs script) to GeneralUpdate 10.4.6.
  • Update samples to match 10.x APIs (e.g., DifferentialCore static usage + strategies; new ClientCore listeners).
  • Improve null-safety and DTO initialization, and rewrite UpgradeHub documentation with expanded examples/reference.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
website/docs/doc/UpgradeHub.md Major rewrite into a comprehensive UpgradeHubService reference + examples
src/Upgrade/UpgradeSample.csproj Update GeneralUpdate.Core to 10.4.6
src/Upgrade/Program.cs Null-safe logging for version?.Version in event handlers
src/Server/Program.cs Avoid passing null to HttpResponseDTO.Success by returning Enumerable.Empty<>()
src/Server/DTOs/VerificationResultDTO.cs Initialize non-nullable Format with string.Empty
src/Server/DTOs/HttpResponseDTO.cs Initialize non-nullable Message with string.Empty
src/Push/PushSample.csproj Update GeneralUpdate.ClientCore to 10.4.6
src/Push/Program.cs Rewrite Push sample to demonstrate full UpgradeHubService lifecycle + listeners
src/OSS/OSSUpgradeSample/OSSUpgradeSample.csproj Update GeneralUpdate.Core to 10.4.6
src/OSS/OSSClientSample/OSSClientSample.csproj Update GeneralUpdate.ClientCore to 10.4.6
src/Extension/ExtensionSample/ExtensionSample.csproj Update GeneralUpdate.Extension to 10.4.6
src/Drivelution/DrivelutionSample/DrivelutionSample.csproj Update GeneralUpdate.Drivelution to 10.4.6
src/dotnet10_scripts/upgrade.cs Update script package ref to 10.4.6 + null-safe version logging
src/Diff/Program.cs Fix DifferentialCore API break by using static methods + explicit strategies/matchers
src/Diff/DiffSample.csproj Update GeneralUpdate.Core to 10.4.6
src/Compress/CompressSample/CompressSample.csproj Update GeneralUpdate.Core to 10.4.6
src/Client/Program.cs Align Client sample with new listeners (UpdateInfo, UpdatePrecheck) + null-safe version logging
src/Client/ClientSample.csproj Update GeneralUpdate.ClientCore to 10.4.6
src/Bowl/BowlSample/BowlSample.csproj Update GeneralUpdate.Bowl to 10.4.6

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +100 to +110
// 建立 SignalR 连接
await hub.StartAsync();

//2. In projects with dependency injection capability, you can also use dependency injection, for example: Prism
Console.WriteLine("已连接,等待服务端推送...");
Console.ReadLine();

// 停止连接(可在应用进入后台时调用,保留重连能力)
await hub.StopAsync();

// 释放资源(不可再复用)
await hub.DisposeAsync();
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在“快速开始”示例里,StartAsync() 后直接执行 ReadLine(),随后再调用 StopAsync()/DisposeAsync();如果 StartAsync() 期间抛异常或示例被提前中断,会导致连接/资源释放不被执行。建议将 StopAsync + DisposeAsync 放入 try/finally(或使用 await using)以保证清理逻辑始终执行。

Copilot uses AI. Check for mistakes.
Comment on lines +123 to 130
public MainWindowViewModel(IUpgradeHubService hubService)
{
service.StartAsync();
//...
hubService.AddListenerReceive((message) =>
{
Console.WriteLine($"收到推送: {message}");
});
_ = hubService.StartAsync();
}
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prism/DI 示例在构造函数内使用 _ = hubService.StartAsync(); 丢弃返回的 Task,异常可能变成未观察到的异常且不易定位。建议在可 await 的生命周期方法(如初始化/Loaded 回调)里启动连接,或至少保存并显式处理该任务的异常(例如记录日志)。

Copilot uses AI. Check for mistakes.
Comment on lines +106 to +110
// 停止连接(可在应用进入后台时调用,保留重连能力)
await hub.StopAsync();

// 释放资源(不可再复用)
await hub.DisposeAsync();
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

快速开始示例在 StopAsync() 上方的注释写到“保留重连能力”,但紧接着又调用了 DisposeAsync()(释放后不可复用),这会让读者误以为 Stop+Dispose 仍可重连。建议调整注释或拆成两种退出路径:仅 StopAsync(可恢复) vs DisposeAsync(彻底释放)。

Suggested change
// 停止连接(可在应用进入后台时调用,保留重连能力)
await hub.StopAsync();
// 释放资源(不可再复用)
await hub.DisposeAsync();
// 退出方式 1:仅停止连接(例如应用进入后台时),后续仍可重新调用 StartAsync()
await hub.StopAsync();
// 退出方式 2:彻底释放资源(例如应用退出时),释放后当前实例不可再复用
// await hub.DisposeAsync();

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GeneralUpdate samples补充更新

3 participants