Skip to content

Commit

Permalink
Upgrade UT & samples to .NET 6 LTS.
Browse files Browse the repository at this point in the history
Keep targeting WCL at .NET Standard 2.1 / .NET 5 for now.
  • Loading branch information
CXuesong committed Feb 9, 2022
1 parent d0293df commit 0a246e6
Show file tree
Hide file tree
Showing 12 changed files with 437 additions and 501 deletions.
20 changes: 12 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ jobs:
WCL_IS_CI_BUILD: 1
BUILD_SECRET_KEY: "${{ secrets.BUILD_SECRET }}"
steps:
# Need to wait for https://github.com/actions/setup-dotnet/issues/25 to be resolved.
# - uses: actions/setup-dotnet@v1
# with:
# dotnet-version: '3.0.100'
- uses: actions/setup-dotnet@v1
with:
dotnet-version: |
3.1.x
5.0.x
6.0.x
- uses: actions/checkout@v2
with:
submodules: true
Expand Down Expand Up @@ -65,10 +67,12 @@ jobs:
WCL_IS_CI_BUILD: 1
BUILD_SECRET_KEY: "${{ secrets.BUILD_SECRET }}"
steps:
# Need to wait for https://github.com/actions/setup-dotnet/issues/25 to be resolved.
# - uses: actions/setup-dotnet@v1
# with:
# dotnet-version: '3.0.100'
- uses: actions/setup-dotnet@v1
with:
dotnet-version: |
3.1.x
5.0.x
6.0.x
- uses: actions/checkout@v1
with:
submodules: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net5.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<RootNamespace>WikiClientLibrary.Samples.ConsoleTestApplication1</RootNamespace>
<Nullable>Enable</Nullable>
<ImplicitUsings>Enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
Expand Down
408 changes: 201 additions & 207 deletions Samples/ConsoleTestApplication1/Program.cs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Samples/LinqToCargo/LinqToCargo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>WikiClientLibrary.Samples.LinqToCargo</RootNamespace>
<Nullable>Enable</Nullable>
<ImplicitUsings>Enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 1 addition & 4 deletions Samples/LinqToCargo/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
using WikiClientLibrary.Cargo.Linq;
Expand Down
215 changes: 105 additions & 110 deletions Samples/ScribuntoInteractive/Program.cs
Original file line number Diff line number Diff line change
@@ -1,149 +1,144 @@
using System;
using System.Linq;
using System.Reflection;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using WikiClientLibrary.Client;
using WikiClientLibrary.Scribunto;
using WikiClientLibrary.Sites;

namespace WikiClientLibrary.Samples.ScribuntoInteractive
namespace WikiClientLibrary.Samples.ScribuntoInteractive;

internal static class Program
{
internal static class Program
{

internal static async Task Main(string[] args)
internal static async Task Main(string[] args)
{
var endPoint = args.Length > 0 ? args[0] : "https://test2.wikipedia.org/w/api.php";
using var client = new WikiClient { ClientUserAgent = "ScribuntoConsoleTestApplication1/0.1" };
var site = new WikiSite(client, endPoint);
await site.Initialization;
var sc = new ScribuntoConsole(site);
await ResetSessionAsync(sc);
var eofShortcut = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "Ctrl + Z" : "Ctrl + D";
Console.WriteLine("* Enter any Lua expression to evaluate. EOF ({0}) to exit.", eofShortcut);
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.");
Console.WriteLine("* Use \x1b[36mmw.log()\x1b[0m and \x1b[36mmw.logObject()\x1b[0m in module code to send messages to this console.");
Console.WriteLine("* Enter .help for a list of local commands.");
while (true)
{
var endPoint = args.Length > 0 ? args[0] : "https://test2.wikipedia.org/w/api.php";
using var client = new WikiClient { ClientUserAgent = "ScribuntoConsoleTestApplication1/0.1" };
var site = new WikiSite(client, endPoint);
await site.Initialization;
var sc = new ScribuntoConsole(site);
await ResetSessionAsync(sc);
var eofShortcut = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "Ctrl + Z" : "Ctrl + D";
Console.WriteLine("* Enter any Lua expression to evaluate. EOF ({0}) to exit.", eofShortcut);
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.");
Console.WriteLine("* Use \x1b[36mmw.log()\x1b[0m and \x1b[36mmw.logObject()\x1b[0m in module code to send messages to this console.");
Console.WriteLine("* Enter .help for a list of local commands.");
while (true)
Console.Write("> ");
var l = Console.ReadLine();
if (l == null)
break;
if (string.IsNullOrWhiteSpace(l))
continue;
if (l.StartsWith("."))
{
Console.Write("> ");
var l = Console.ReadLine();
if (l == null)
if (string.Equals(l, ".exit", StringComparison.OrdinalIgnoreCase))
break;
if (string.IsNullOrWhiteSpace(l))
continue;
if (l.StartsWith("."))
await ExecuteCommandAsync(l[1..], sc);
continue;
}
try
{
var result = await sc.EvaluateAsync(l);
if (result.IsNewSession)
{
if (string.Equals(l, ".exit", StringComparison.OrdinalIgnoreCase))
break;
await ExecuteCommandAsync(l[1..], sc);
continue;
Console.WriteLine("---------- Session Cleared ----------");
}
try
if (!string.IsNullOrEmpty(result.Output))
{
var result = await sc.EvaluateAsync(l);
if (result.IsNewSession)
{
Console.WriteLine("---------- Session Cleared ----------");
}
if (!string.IsNullOrEmpty(result.Output))
{
Console.WriteLine(result.Output);
}
if (!string.IsNullOrEmpty(result.ReturnValue))
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(result.ReturnValue);
Console.ResetColor();
}
Console.WriteLine(result.Output);
}
catch (ScribuntoConsoleException ex)
if (!string.IsNullOrEmpty(result.ReturnValue))
{
if (!string.IsNullOrEmpty(ex.EvaluationResult?.Output))
{
Console.WriteLine(ex.EvaluationResult.Output);
}
WriteError($"{ex.ErrorCode}: {ex.ErrorMessage}");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(result.ReturnValue);
Console.ResetColor();
}
}
}

private static void WriteError(string message)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.WriteLine(message);
Console.ResetColor();
}


private static async Task ExecuteCommandAsync(string command, ScribuntoConsole sc)
{
var method = typeof(Program).GetMethods(BindingFlags.Static | BindingFlags.NonPublic)
.FirstOrDefault(m => string.Equals(m.GetCustomAttribute<ConsoleCommandAttribute>()?.Command, command, StringComparison.OrdinalIgnoreCase));
if (method == null)
catch (ScribuntoConsoleException ex)
{
WriteError("Invalid command: " + command + ".");
return;
if (!string.IsNullOrEmpty(ex.EvaluationResult?.Output))
{
Console.WriteLine(ex.EvaluationResult.Output);
}
WriteError($"{ex.ErrorCode}: {ex.ErrorMessage}");
}
var result = method.Invoke(null, new object[] { sc });
if (result is Task t)
await t;
}
}

[ConsoleCommand("reset", "Clears the Lua evaluation session.")]
private static async Task ResetSessionAsync(ScribuntoConsole sc)
{
await sc.ResetAsync();
Console.WriteLine("Initialized Scribunto console on {0} with session ID {1}.", sc.Site.SiteInfo.SiteName, sc.SessionId);
}
private static void WriteError(string message)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.WriteLine(message);
Console.ResetColor();
}

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

[ConsoleCommand("memory", "Shows the server-side memory usage.")]
private static void ShowMemory(ScribuntoConsole sc)
private static async Task ExecuteCommandAsync(string command, ScribuntoConsole sc)
{
var method = typeof(Program).GetMethods(BindingFlags.Static | BindingFlags.NonPublic)
.FirstOrDefault(m => string.Equals(m.GetCustomAttribute<ConsoleCommandAttribute>()?.Command, command, StringComparison.OrdinalIgnoreCase));
if (method == null)
{
Console.WriteLine("Memory used / maximum allowed: {0}/{1}", sc.SessionSize, sc.SessionMaxSize);
WriteError("Invalid command: " + command + ".");
return;
}
var result = method.Invoke(null, new object[] { sc });
if (result is Task t)
await t;
}

[ConsoleCommand("reset", "Clears the Lua evaluation session.")]
private static async Task ResetSessionAsync(ScribuntoConsole sc)
{
await sc.ResetAsync();
Console.WriteLine("Initialized Scribunto console on {0} with session ID {1}.", sc.Site.SiteInfo.SiteName, sc.SessionId);
}

[ConsoleCommand("exit", "Exits the interactive console.")]
private static void Exit(ScribuntoConsole sc)
[ConsoleCommand("help", "Shows the command list.")]
private static void ShowHelp(ScribuntoConsole sc)
{
var commands = typeof(Program).GetMethods(BindingFlags.Static | BindingFlags.NonPublic)
.Select(m => (method: m, attr: m.GetCustomAttribute<ConsoleCommandAttribute>()))
.Where(t => t.attr != null)
.Select(t => (command: t.attr!.Command, desc: t.attr.Description, method: t.method))
.OrderBy(t => t.command);
foreach ((string command, string desc, _) in commands)
{
// Stub
Console.WriteLine(".{0,-15} {1}", command, desc);
}
}

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

[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
sealed class ConsoleCommandAttribute : Attribute
[ConsoleCommand("exit", "Exits the interactive console.")]
private static void Exit(ScribuntoConsole sc)
{
// Stub
}

public string Command { get; }
}

public string? Description { get; }
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
sealed class ConsoleCommandAttribute : Attribute
{

public ConsoleCommandAttribute(string command) : this(command, null)
{
}
public string Command { get; }

public ConsoleCommandAttribute(string command, string? description)
{
Command = command;
Description = description;
}
public string? Description { get; }

public ConsoleCommandAttribute(string command) : this(command, null)
{
}

}
public ConsoleCommandAttribute(string command, string? description)
{
Command = command;
Description = description;
}

}
3 changes: 2 additions & 1 deletion Samples/ScribuntoInteractive/ScribuntoInteractive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>WikiClientLibrary.Samples.ScribuntoInteractive</RootNamespace>
<Nullable>Enable</Nullable>
<ImplicitUsings>Enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
Expand Down
21 changes: 7 additions & 14 deletions Samples/WpfTestApplication1/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows;

namespace WikiClientLibrary.Samples.WpfTestApplication1
namespace WikiClientLibrary.Samples.WpfTestApplication1;

/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
}
}
Loading

0 comments on commit 0a246e6

Please sign in to comment.