2020-11-27 18:51:02 +08:00
|
|
|
using System;
|
2020-12-16 19:12:36 +08:00
|
|
|
using System.Runtime.Serialization;
|
2023-07-04 08:34:11 +08:00
|
|
|
using System.Text;
|
2021-05-18 22:36:37 +08:00
|
|
|
using System.Threading.Tasks;
|
2020-11-27 18:51:02 +08:00
|
|
|
using System.Windows;
|
2022-05-16 23:28:31 +08:00
|
|
|
using BililiveRecorder.Core.Api;
|
2022-05-11 19:07:21 +08:00
|
|
|
using BililiveRecorder.Core.Scripting;
|
2021-07-05 23:30:13 +08:00
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using Serilog;
|
2020-11-27 18:51:02 +08:00
|
|
|
|
2021-07-05 23:30:13 +08:00
|
|
|
#nullable enable
|
2020-11-27 18:51:02 +08:00
|
|
|
namespace BililiveRecorder.WPF.Pages
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Interaction logic for AdvancedSettingsPage.xaml
|
|
|
|
/// </summary>
|
|
|
|
public partial class AdvancedSettingsPage
|
|
|
|
{
|
2021-07-05 23:30:13 +08:00
|
|
|
private static readonly ILogger logger = Log.ForContext<AdvancedSettingsPage>();
|
2023-07-16 16:01:50 +08:00
|
|
|
private readonly ICookieTester? httpApiClient;
|
2022-05-11 19:07:21 +08:00
|
|
|
private readonly UserScriptRunner? userScriptRunner;
|
2021-07-05 23:30:13 +08:00
|
|
|
|
2023-07-16 16:01:50 +08:00
|
|
|
public AdvancedSettingsPage(ICookieTester? httpApiClient, UserScriptRunner? userScriptRunner)
|
2020-11-27 18:51:02 +08:00
|
|
|
{
|
2021-01-01 14:46:27 +08:00
|
|
|
this.InitializeComponent();
|
2021-07-05 23:30:13 +08:00
|
|
|
this.httpApiClient = httpApiClient;
|
2022-05-11 19:07:21 +08:00
|
|
|
this.userScriptRunner = userScriptRunner;
|
2021-07-05 23:30:13 +08:00
|
|
|
}
|
|
|
|
|
2022-05-11 19:07:21 +08:00
|
|
|
public AdvancedSettingsPage()
|
|
|
|
: this(
|
2023-07-16 16:01:50 +08:00
|
|
|
(ICookieTester?)(RootPage.ServiceProvider?.GetService(typeof(ICookieTester))),
|
2022-05-11 19:07:21 +08:00
|
|
|
(UserScriptRunner?)(RootPage.ServiceProvider?.GetService(typeof(UserScriptRunner)))
|
|
|
|
)
|
|
|
|
{ }
|
2020-12-16 19:12:36 +08:00
|
|
|
|
2021-05-18 22:36:37 +08:00
|
|
|
private void Crash_Click(object sender, RoutedEventArgs e) => throw new TestException("test crash triggered");
|
2020-12-16 19:12:36 +08:00
|
|
|
|
|
|
|
public class TestException : Exception
|
|
|
|
{
|
|
|
|
public TestException() { }
|
|
|
|
public TestException(string message) : base(message) { }
|
|
|
|
public TestException(string message, Exception innerException) : base(message, innerException) { }
|
|
|
|
protected TestException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
|
|
|
}
|
2021-05-18 22:36:37 +08:00
|
|
|
|
|
|
|
private void Throw_In_Task_Click(object sender, RoutedEventArgs e) => _ = Task.Run(() =>
|
|
|
|
{
|
|
|
|
throw new TestException("test task exception triggered");
|
|
|
|
});
|
2021-07-05 23:30:13 +08:00
|
|
|
|
|
|
|
#pragma warning disable VSTHRD100 // Avoid async void methods
|
|
|
|
private async void TestCookie_Click(object sender, RoutedEventArgs e)
|
|
|
|
#pragma warning restore VSTHRD100 // Avoid async void methods
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
await this.TestCookieAsync().ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
logger.Warning(ex, "Exception in TestCookie");
|
|
|
|
MessageBox.Show(ex.ToString(), "Cookie Test - Error", MessageBoxButton.OK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private async Task TestCookieAsync()
|
|
|
|
{
|
2023-07-16 16:01:50 +08:00
|
|
|
bool succeed;
|
|
|
|
string message;
|
2021-07-05 23:30:13 +08:00
|
|
|
|
2023-07-16 16:01:50 +08:00
|
|
|
if (this.httpApiClient is null)
|
|
|
|
(succeed, message) = (false, "No Http Client Available");
|
|
|
|
else
|
|
|
|
(succeed, message) = await this.httpApiClient.TestCookieAsync().ConfigureAwait(false);
|
2023-07-04 08:34:11 +08:00
|
|
|
|
2023-07-16 16:01:50 +08:00
|
|
|
if (succeed)
|
|
|
|
MessageBox.Show(message, "Cookie Test - Succeed", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
|
else
|
|
|
|
MessageBox.Show(message, "Cookie Test - Failed", MessageBoxButton.OK, MessageBoxImage.Warning);
|
2021-07-05 23:30:13 +08:00
|
|
|
}
|
2022-05-11 19:07:21 +08:00
|
|
|
|
|
|
|
private void TestScript_Click(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
_ = Task.Run(() => this.userScriptRunner?.CallOnTest(Log.Logger, str => MessageBox.Show(str)));
|
|
|
|
}
|
2020-11-27 18:51:02 +08:00
|
|
|
}
|
|
|
|
}
|