Skip to content

Commit 0a246e6

Browse files
committed
Upgrade UT & samples to .NET 6 LTS.
Keep targeting WCL at .NET Standard 2.1 / .NET 5 for now.
1 parent d0293df commit 0a246e6

File tree

12 files changed

+437
-501
lines changed

12 files changed

+437
-501
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ jobs:
2828
WCL_IS_CI_BUILD: 1
2929
BUILD_SECRET_KEY: "${{ secrets.BUILD_SECRET }}"
3030
steps:
31-
# Need to wait for https://github.com/actions/setup-dotnet/issues/25 to be resolved.
32-
# - uses: actions/setup-dotnet@v1
33-
# with:
34-
# dotnet-version: '3.0.100'
31+
- uses: actions/setup-dotnet@v1
32+
with:
33+
dotnet-version: |
34+
3.1.x
35+
5.0.x
36+
6.0.x
3537
- uses: actions/checkout@v2
3638
with:
3739
submodules: true
@@ -65,10 +67,12 @@ jobs:
6567
WCL_IS_CI_BUILD: 1
6668
BUILD_SECRET_KEY: "${{ secrets.BUILD_SECRET }}"
6769
steps:
68-
# Need to wait for https://github.com/actions/setup-dotnet/issues/25 to be resolved.
69-
# - uses: actions/setup-dotnet@v1
70-
# with:
71-
# dotnet-version: '3.0.100'
70+
- uses: actions/setup-dotnet@v1
71+
with:
72+
dotnet-version: |
73+
3.1.x
74+
5.0.x
75+
6.0.x
7276
- uses: actions/checkout@v1
7377
with:
7478
submodules: true

Samples/ConsoleTestApplication1/ConsoleTestApplication1.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>net5.0</TargetFrameworks>
5+
<TargetFrameworks>net6.0</TargetFrameworks>
66
<RootNamespace>WikiClientLibrary.Samples.ConsoleTestApplication1</RootNamespace>
77
<Nullable>Enable</Nullable>
8+
<ImplicitUsings>Enable</ImplicitUsings>
89
</PropertyGroup>
910

1011
<ItemGroup>

Samples/ConsoleTestApplication1/Program.cs

Lines changed: 201 additions & 207 deletions
Large diffs are not rendered by default.

Samples/LinqToCargo/LinqToCargo.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<RootNamespace>WikiClientLibrary.Samples.LinqToCargo</RootNamespace>
77
<Nullable>Enable</Nullable>
8+
<ImplicitUsings>Enable</ImplicitUsings>
89
</PropertyGroup>
910

1011
<ItemGroup>

Samples/LinqToCargo/Program.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel.DataAnnotations.Schema;
4-
using System.Linq;
1+
using System.ComponentModel.DataAnnotations.Schema;
52
using Microsoft.Extensions.Logging;
63
using Microsoft.Extensions.Logging.Console;
74
using WikiClientLibrary.Cargo.Linq;
Lines changed: 105 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,144 @@
1-
using System;
2-
using System.Linq;
3-
using System.Reflection;
1+
using System.Reflection;
42
using System.Runtime.InteropServices;
5-
using System.Threading.Tasks;
63
using WikiClientLibrary.Client;
74
using WikiClientLibrary.Scribunto;
85
using WikiClientLibrary.Sites;
96

10-
namespace WikiClientLibrary.Samples.ScribuntoInteractive
7+
namespace WikiClientLibrary.Samples.ScribuntoInteractive;
8+
9+
internal static class Program
1110
{
12-
internal static class Program
13-
{
1411

15-
internal static async Task Main(string[] args)
12+
internal static async Task Main(string[] args)
13+
{
14+
var endPoint = args.Length > 0 ? args[0] : "https://test2.wikipedia.org/w/api.php";
15+
using var client = new WikiClient { ClientUserAgent = "ScribuntoConsoleTestApplication1/0.1" };
16+
var site = new WikiSite(client, endPoint);
17+
await site.Initialization;
18+
var sc = new ScribuntoConsole(site);
19+
await ResetSessionAsync(sc);
20+
var eofShortcut = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "Ctrl + Z" : "Ctrl + D";
21+
Console.WriteLine("* Enter any Lua expression to evaluate. EOF ({0}) to exit.", eofShortcut);
22+
Console.WriteLine("* Precede a line with '=' to evaluate it as an expression or use \x1b[36mprint()\x1b[0m. Use \x1b[36mmw.logObject()\x1b[0m for tables.");
23+
Console.WriteLine("* Use \x1b[36mmw.log()\x1b[0m and \x1b[36mmw.logObject()\x1b[0m in module code to send messages to this console.");
24+
Console.WriteLine("* Enter .help for a list of local commands.");
25+
while (true)
1626
{
17-
var endPoint = args.Length > 0 ? args[0] : "https://test2.wikipedia.org/w/api.php";
18-
using var client = new WikiClient { ClientUserAgent = "ScribuntoConsoleTestApplication1/0.1" };
19-
var site = new WikiSite(client, endPoint);
20-
await site.Initialization;
21-
var sc = new ScribuntoConsole(site);
22-
await ResetSessionAsync(sc);
23-
var eofShortcut = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "Ctrl + Z" : "Ctrl + D";
24-
Console.WriteLine("* Enter any Lua expression to evaluate. EOF ({0}) to exit.", eofShortcut);
25-
Console.WriteLine("* Precede a line with '=' to evaluate it as an expression or use \x1b[36mprint()\x1b[0m. Use \x1b[36mmw.logObject()\x1b[0m for tables.");
26-
Console.WriteLine("* Use \x1b[36mmw.log()\x1b[0m and \x1b[36mmw.logObject()\x1b[0m in module code to send messages to this console.");
27-
Console.WriteLine("* Enter .help for a list of local commands.");
28-
while (true)
27+
Console.Write("> ");
28+
var l = Console.ReadLine();
29+
if (l == null)
30+
break;
31+
if (string.IsNullOrWhiteSpace(l))
32+
continue;
33+
if (l.StartsWith("."))
2934
{
30-
Console.Write("> ");
31-
var l = Console.ReadLine();
32-
if (l == null)
35+
if (string.Equals(l, ".exit", StringComparison.OrdinalIgnoreCase))
3336
break;
34-
if (string.IsNullOrWhiteSpace(l))
35-
continue;
36-
if (l.StartsWith("."))
37+
await ExecuteCommandAsync(l[1..], sc);
38+
continue;
39+
}
40+
try
41+
{
42+
var result = await sc.EvaluateAsync(l);
43+
if (result.IsNewSession)
3744
{
38-
if (string.Equals(l, ".exit", StringComparison.OrdinalIgnoreCase))
39-
break;
40-
await ExecuteCommandAsync(l[1..], sc);
41-
continue;
45+
Console.WriteLine("---------- Session Cleared ----------");
4246
}
43-
try
47+
if (!string.IsNullOrEmpty(result.Output))
4448
{
45-
var result = await sc.EvaluateAsync(l);
46-
if (result.IsNewSession)
47-
{
48-
Console.WriteLine("---------- Session Cleared ----------");
49-
}
50-
if (!string.IsNullOrEmpty(result.Output))
51-
{
52-
Console.WriteLine(result.Output);
53-
}
54-
if (!string.IsNullOrEmpty(result.ReturnValue))
55-
{
56-
Console.ForegroundColor = ConsoleColor.White;
57-
Console.WriteLine(result.ReturnValue);
58-
Console.ResetColor();
59-
}
49+
Console.WriteLine(result.Output);
6050
}
61-
catch (ScribuntoConsoleException ex)
51+
if (!string.IsNullOrEmpty(result.ReturnValue))
6252
{
63-
if (!string.IsNullOrEmpty(ex.EvaluationResult?.Output))
64-
{
65-
Console.WriteLine(ex.EvaluationResult.Output);
66-
}
67-
WriteError($"{ex.ErrorCode}: {ex.ErrorMessage}");
53+
Console.ForegroundColor = ConsoleColor.White;
54+
Console.WriteLine(result.ReturnValue);
55+
Console.ResetColor();
6856
}
6957
}
70-
}
71-
72-
private static void WriteError(string message)
73-
{
74-
Console.ForegroundColor = ConsoleColor.Red;
75-
Console.Error.WriteLine(message);
76-
Console.ResetColor();
77-
}
78-
79-
80-
private static async Task ExecuteCommandAsync(string command, ScribuntoConsole sc)
81-
{
82-
var method = typeof(Program).GetMethods(BindingFlags.Static | BindingFlags.NonPublic)
83-
.FirstOrDefault(m => string.Equals(m.GetCustomAttribute<ConsoleCommandAttribute>()?.Command, command, StringComparison.OrdinalIgnoreCase));
84-
if (method == null)
58+
catch (ScribuntoConsoleException ex)
8559
{
86-
WriteError("Invalid command: " + command + ".");
87-
return;
60+
if (!string.IsNullOrEmpty(ex.EvaluationResult?.Output))
61+
{
62+
Console.WriteLine(ex.EvaluationResult.Output);
63+
}
64+
WriteError($"{ex.ErrorCode}: {ex.ErrorMessage}");
8865
}
89-
var result = method.Invoke(null, new object[] { sc });
90-
if (result is Task t)
91-
await t;
9266
}
67+
}
9368

94-
[ConsoleCommand("reset", "Clears the Lua evaluation session.")]
95-
private static async Task ResetSessionAsync(ScribuntoConsole sc)
96-
{
97-
await sc.ResetAsync();
98-
Console.WriteLine("Initialized Scribunto console on {0} with session ID {1}.", sc.Site.SiteInfo.SiteName, sc.SessionId);
99-
}
69+
private static void WriteError(string message)
70+
{
71+
Console.ForegroundColor = ConsoleColor.Red;
72+
Console.Error.WriteLine(message);
73+
Console.ResetColor();
74+
}
10075

101-
[ConsoleCommand("help", "Shows the command list.")]
102-
private static void ShowHelp(ScribuntoConsole sc)
103-
{
104-
var commands = typeof(Program).GetMethods(BindingFlags.Static | BindingFlags.NonPublic)
105-
.Select(m => (method: m, attr: m.GetCustomAttribute<ConsoleCommandAttribute>()))
106-
.Where(t => t.attr != null)
107-
.Select(t => (command: t.attr!.Command, desc: t.attr.Description, method: t.method))
108-
.OrderBy(t => t.command);
109-
foreach ((string command, string desc, _) in commands)
110-
{
111-
Console.WriteLine(".{0,-15} {1}", command, desc);
112-
}
113-
}
11476

115-
[ConsoleCommand("memory", "Shows the server-side memory usage.")]
116-
private static void ShowMemory(ScribuntoConsole sc)
77+
private static async Task ExecuteCommandAsync(string command, ScribuntoConsole sc)
78+
{
79+
var method = typeof(Program).GetMethods(BindingFlags.Static | BindingFlags.NonPublic)
80+
.FirstOrDefault(m => string.Equals(m.GetCustomAttribute<ConsoleCommandAttribute>()?.Command, command, StringComparison.OrdinalIgnoreCase));
81+
if (method == null)
11782
{
118-
Console.WriteLine("Memory used / maximum allowed: {0}/{1}", sc.SessionSize, sc.SessionMaxSize);
83+
WriteError("Invalid command: " + command + ".");
84+
return;
11985
}
86+
var result = method.Invoke(null, new object[] { sc });
87+
if (result is Task t)
88+
await t;
89+
}
90+
91+
[ConsoleCommand("reset", "Clears the Lua evaluation session.")]
92+
private static async Task ResetSessionAsync(ScribuntoConsole sc)
93+
{
94+
await sc.ResetAsync();
95+
Console.WriteLine("Initialized Scribunto console on {0} with session ID {1}.", sc.Site.SiteInfo.SiteName, sc.SessionId);
96+
}
12097

121-
[ConsoleCommand("exit", "Exits the interactive console.")]
122-
private static void Exit(ScribuntoConsole sc)
98+
[ConsoleCommand("help", "Shows the command list.")]
99+
private static void ShowHelp(ScribuntoConsole sc)
100+
{
101+
var commands = typeof(Program).GetMethods(BindingFlags.Static | BindingFlags.NonPublic)
102+
.Select(m => (method: m, attr: m.GetCustomAttribute<ConsoleCommandAttribute>()))
103+
.Where(t => t.attr != null)
104+
.Select(t => (command: t.attr!.Command, desc: t.attr.Description, method: t.method))
105+
.OrderBy(t => t.command);
106+
foreach ((string command, string desc, _) in commands)
123107
{
124-
// Stub
108+
Console.WriteLine(".{0,-15} {1}", command, desc);
125109
}
110+
}
126111

112+
[ConsoleCommand("memory", "Shows the server-side memory usage.")]
113+
private static void ShowMemory(ScribuntoConsole sc)
114+
{
115+
Console.WriteLine("Memory used / maximum allowed: {0}/{1}", sc.SessionSize, sc.SessionMaxSize);
127116
}
128117

129-
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
130-
sealed class ConsoleCommandAttribute : Attribute
118+
[ConsoleCommand("exit", "Exits the interactive console.")]
119+
private static void Exit(ScribuntoConsole sc)
131120
{
121+
// Stub
122+
}
132123

133-
public string Command { get; }
124+
}
134125

135-
public string? Description { get; }
126+
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
127+
sealed class ConsoleCommandAttribute : Attribute
128+
{
136129

137-
public ConsoleCommandAttribute(string command) : this(command, null)
138-
{
139-
}
130+
public string Command { get; }
140131

141-
public ConsoleCommandAttribute(string command, string? description)
142-
{
143-
Command = command;
144-
Description = description;
145-
}
132+
public string? Description { get; }
146133

134+
public ConsoleCommandAttribute(string command) : this(command, null)
135+
{
147136
}
148137

149-
}
138+
public ConsoleCommandAttribute(string command, string? description)
139+
{
140+
Command = command;
141+
Description = description;
142+
}
143+
144+
}

Samples/ScribuntoInteractive/ScribuntoInteractive.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<RootNamespace>WikiClientLibrary.Samples.ScribuntoInteractive</RootNamespace>
77
<Nullable>Enable</Nullable>
8+
<ImplicitUsings>Enable</ImplicitUsings>
89
</PropertyGroup>
910

1011
<ItemGroup>
Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Configuration;
4-
using System.Data;
5-
using System.Linq;
6-
using System.Threading.Tasks;
7-
using System.Windows;
1+
using System.Windows;
82

9-
namespace WikiClientLibrary.Samples.WpfTestApplication1
3+
namespace WikiClientLibrary.Samples.WpfTestApplication1;
4+
5+
/// <summary>
6+
/// App.xaml 的交互逻辑
7+
/// </summary>
8+
public partial class App : Application
109
{
11-
/// <summary>
12-
/// App.xaml 的交互逻辑
13-
/// </summary>
14-
public partial class App : Application
15-
{
16-
}
1710
}

0 commit comments

Comments
 (0)