Xunet.WinFormium 1.0.17

dotnet add package Xunet.WinFormium --version 1.0.17                
NuGet\Install-Package Xunet.WinFormium -Version 1.0.17                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Xunet.WinFormium" Version="1.0.17" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Xunet.WinFormium --version 1.0.17                
#r "nuget: Xunet.WinFormium, 1.0.17"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Xunet.WinFormium as a Cake Addin
#addin nuget:?package=Xunet.WinFormium&version=1.0.17

// Install Xunet.WinFormium as a Cake Tool
#tool nuget:?package=Xunet.WinFormium&version=1.0.17                

Xunet.WinFormium

A Lightweight WinForm Application Framework For .NET

Support .NET 8.0

Nuget Downloads License Vistors

安装

Xunet.WinFormium 以 NuGet 包的形式提供。您可以使用 NuGet 包控制台窗口安装它:

PM> Install-Package Xunet.WinFormium

使用

Program.cs

using Xunet.WinFormium;
using Xunet.WinFormium.Core;
using Xunet.WinFormium.Tests;
using Xunet.WinFormium.Tests.Models;

var builder = WinFormiumApplication.CreateBuilder();

builder.Services.AddWinFormium<MainForm>(options =>
{
    options.Headers = new()
    {
        {
            HeaderNames.UserAgent,
            "Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B329 MicroMessenger/5.0.1"
        }
    };
    options.Storage = new()
    {
        DataVersion = "24.8.9.1822",
        DbName = "Xunet.WinFormium.Tests",
        EntityTypes = [typeof(CnBlogsModel)]
    };
    options.Snowflake = new()
    {
        WorkerId = 1
    };
});

var app = builder.Build();

app.UseWinFormium();

app.UseSingleApp();

app.Run();

MainForm.cs

namespace Xunet.WinFormium.Tests;

using Xunet.WinFormium.Tests.Models;

public class MainForm : BaseForm
{
    protected override string BaseText => $"测试 - {Version}";

    protected override Size BaseClientSize => new(600, 400);

    protected override int BaseDoWorkInterval => GetConfigValue<int>("DoWorkInterval");

    protected override async Task DoWorkAsync(CancellationToken cancellationToken)
    {
        AppendBox("正在测试,请稍后 ...", ColorTranslator.FromHtml("#1296db"));

        var html = await DefaultClient.GetStringAsync("https://www.cnblogs.com/", cancellationToken);

        CreateHtmlDocument(html);

        var list = FindElementsByXPath("//*[@id=\"post_list\"]/article");

        foreach (var item in list)
        {
            var model = new CnBlogsModel
            {
                Id = CreateNextIdString(),
                Title = FindText(FindElementByXPath(item, "section/div/a")),
                Url = FindAttributeValue(FindElementByXPath(item, "section/div/a"), "href"),
                Summary = Trim(FindText(FindElementByXPath(item, "section/div/p"))),
                CreateTime = DateTime.Now
            };

            AppendBox($"{model.Title} ...");

            await Db.Insertable(model).ExecuteCommandAsync(cancellationToken);

            await Task.Delay(new Random().Next(100, 500), cancellationToken);
        }

        AppendBox("测试完成!", ColorTranslator.FromHtml("#1296db"));

        await Task.CompletedTask;
    }

    protected override async Task DoExceptionAsync(Exception ex, CancellationToken cancellationToken)
    {
        AppendBox("系统异常!", Color.Red);
        AppendBox(ex.ToString(), Color.Red);

        await Task.CompletedTask;
    }

    protected override async Task DoCanceledExceptionAsync(OperationCanceledException ex)
    {
        AppendBox("任务取消!", Color.Red);

        await Task.CompletedTask;
    }
}

CnBlogsModel.cs

namespace Xunet.WinFormium.Tests.Models;

using SqlSugar;

[SugarTable("cnblogs")]
public class CnBlogsModel
{
    [SugarColumn(IsPrimaryKey = true)]
    public string? Id { get; set; }

    public string? Title { get; set; }

    public string? Url { get; set; }

    public string? Summary { get; set; }

    public DateTime? CreateTime { get; set; }
}

appsettings.json

{
  "DoWorkInterval": 60
}

更新日志

CHANGELOG

Product Compatible and additional computed target framework versions.
.NET net8.0-windows7.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.17 72 11/12/2024
1.0.16 84 11/11/2024
1.0.15 88 11/11/2024
1.0.14 72 10/16/2024
1.0.13 80 10/15/2024
1.0.12 83 10/15/2024
1.0.11 121 8/16/2024
1.0.10 104 8/14/2024
1.0.9 104 8/14/2024
1.0.8 107 8/12/2024
1.0.7 115 8/9/2024
1.0.6 95 8/7/2024
1.0.5 93 8/7/2024
1.0.4 95 8/7/2024
1.0.3 93 8/7/2024
1.0.2 76 8/6/2024