输出aria2错误信息到UI

pull/671/head
leiurayer 2 years ago
parent 9f55fde526
commit cc4dd706fe

@ -5,8 +5,6 @@ using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace DownKyi.Core.Aria2cNet.Server
{
@ -22,7 +20,7 @@ namespace DownKyi.Core.Aria2cNet.Server
/// <param name="output"></param>
/// <param name="window"></param>
/// <returns></returns>
public static async Task<bool> StartServerAsync(AriaConfig config, TextBox output = null, Window window = null)
public static async Task<bool> StartServerAsync(AriaConfig config, Action<string> action)
{
// aria端口
ListenPort = config.ListenPort;
@ -114,17 +112,11 @@ namespace DownKyi.Core.Aria2cNet.Server
null, (s, e) =>
{
if (e.Data == null || e.Data == "" || e.Data.Replace(" ", "") == "") { return; }
Utils.Debugging.Console.PrintLine(e.Data);
LogManager.Debug("AriaServer", e.Data);
if (output != null && window != null)
{
window.Dispatcher.Invoke(new Action(() =>
{
output.Text += e.Data + "\n";
output.ScrollToEnd();
}));
}
action.Invoke(e.Data);
});
});

@ -15,7 +15,9 @@ using DownKyi.Views.Friends;
using DownKyi.Views.Settings;
using DownKyi.Views.Toolbox;
using DownKyi.Views.UserSpace;
using Prism.DryIoc;
using Prism.Ioc;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@ -132,7 +134,7 @@ namespace DownKyi
downloadService = new BuiltinDownloadService(DownloadingList, DownloadedList);
break;
case Downloader.ARIA:
downloadService = new AriaDownloadService(DownloadingList, DownloadedList);
downloadService = new AriaDownloadService(DownloadingList, DownloadedList, (IDialogService)Container.GetContainer().GetService(typeof(IDialogService)));
break;
case Downloader.CUSTOM_ARIA:
downloadService = new CustomAriaDownloadService(DownloadingList, DownloadedList);

@ -50,7 +50,7 @@ namespace DownKyi.Services
return ShowMessage(image, title, message);
}
private ButtonResult ShowMessage(VectorImage image, string type, string message)
public ButtonResult ShowMessage(VectorImage image, string type, string message)
{
ButtonResult result = ButtonResult.None;
if (dialogService == null)

@ -7,9 +7,11 @@ using DownKyi.Core.BiliApi.VideoStream.Models;
using DownKyi.Core.Logging;
using DownKyi.Core.Settings;
using DownKyi.Core.Utils;
using DownKyi.Images;
using DownKyi.Models;
using DownKyi.Utils;
using DownKyi.ViewModels.DownloadManager;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@ -24,9 +26,16 @@ namespace DownKyi.Services.Download
/// </summary>
public class AriaDownloadService : DownloadService, IDownloadService
{
public AriaDownloadService(ObservableCollection<DownloadingItem> downloadingList, ObservableCollection<DownloadedItem> downloadedList) : base(downloadingList, downloadedList)
private readonly IDialogService dialogService;
public AriaDownloadService(
ObservableCollection<DownloadingItem> downloadingList,
ObservableCollection<DownloadedItem> downloadedList,
IDialogService dialogService = null) :
base(downloadingList, downloadedList)
{
Tag = "AriaDownloadService";
this.dialogService = dialogService;
}
#region 音视频
@ -327,8 +336,24 @@ namespace DownKyi.Services.Download
FileAllocation = SettingsManager.GetInstance().GetAriaFileAllocation(),
Headers = header
};
var task = await AriaServer.StartServerAsync(config);
string errorMessage = null;
var task = await AriaServer.StartServerAsync(config, new Action<string>((output) =>
{
errorMessage += output + "\n";
}));
if (task) { Console.WriteLine("Start ServerAsync Completed"); }
// 显示错误信息
if (dialogService != null && errorMessage != null && errorMessage.Contains("ERROR"))
{
AlertService alertService = new AlertService(dialogService);
ButtonResult result = alertService.ShowMessage(SystemIcon.Instance().Error,
$"Aria2 {DictionaryResource.GetString("Error")}",
errorMessage);
return;
}
for (int i = 0; i < 10; i++)
{
var globOpt = await AriaClient.GetGlobalOptionAsync();

@ -1,6 +1,7 @@
using DownKyi.Images;
using Prism.Commands;
using Prism.Services.Dialogs;
using System.Windows;
namespace DownKyi.ViewModels.Dialogs
{
@ -20,8 +21,23 @@ namespace DownKyi.ViewModels.Dialogs
private string message;
public string Message
{
get { return message; }
set { SetProperty(ref message, value); }
get => message;
set => SetProperty(ref message, value);
}
private Visibility aloneButton;
public Visibility AloneButton
{
get => aloneButton;
set => SetProperty(ref aloneButton, value);
}
private Visibility twoButton;
public Visibility TwoButton
{
get => twoButton;
set => SetProperty(ref twoButton, value);
}
#endregion
@ -57,6 +73,17 @@ namespace DownKyi.ViewModels.Dialogs
Image = parameters.GetValue<VectorImage>("image");
Title = parameters.GetValue<string>("title");
Message = parameters.GetValue<string>("message");
if (Image == SystemIcon.Instance().Error)
{
AloneButton = Visibility.Visible;
TwoButton = Visibility.Collapsed;
}
else
{
AloneButton = Visibility.Collapsed;
TwoButton = Visibility.Visible;
}
}
#endregion

@ -109,7 +109,19 @@
TextTrimming="CharacterEllipsis"
TextWrapping="WrapWithOverflow" />
<Grid Grid.Row="1">
<Button
Grid.Row="1"
Width="75"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
Command="{Binding AllowCommand}"
Content="{DynamicResource Allow}"
FontSize="12"
Foreground="{DynamicResource BrushText}"
Style="{StaticResource BtnStyle}"
Visibility="{Binding AloneButton}" />
<Grid Grid.Row="1" Visibility="{Binding TwoButton}">
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="100" />
<ColumnDefinition MinWidth="100" />

Loading…
Cancel
Save