Add basic content processing structure

This commit is contained in:
Stone_Red
2024-04-03 20:59:58 +02:00
parent afd4256a52
commit 942e58ac0f
11 changed files with 83 additions and 6 deletions
+1
View File
@@ -8,3 +8,4 @@ using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Minor Code Smell", "S1075:URIs should not be hardcoded", Justification = "<Pending>")]
[assembly: SuppressMessage("Minor Code Smell", "CS0067:The event 'ChangeThemeCommand.CanExecuteChanged' is never used", Justification = "<Pending>", Scope = "member", Target = "~N:Markdowser.Commands")]
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "<Pending>")]
[assembly: SuppressMessage("Minor Code Smell", "S3267:Loops should be simplified with \"LINQ\" expressions", Justification = "<Pending>", Scope = "member", Target = "~M:Markdowser.Processing.ContentProcessorManager.ProcessContent(System.Net.HttpWebResponse,System.IProgress{Markdowser.Processing.ProcessingProgress})~Markdowser.ViewModels.ContentViewModelBase")]
+5
View File
@@ -37,4 +37,9 @@
<PackageReference Include="ReverseMarkdown" Version="4.3.0" />
<PackageReference Include="Semi.Avalonia" Version="11.0.7.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Processing\Processors\" />
<Folder Include="Views\Content\" />
</ItemGroup>
</Project>
@@ -0,0 +1,24 @@
using Markdowser.ViewModels;
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
namespace Markdowser.Processing;
internal class ContentProcessorManager
{
private readonly List<IContentProcessor> processors = [];
public void RegisterProcessor(IContentProcessor processor)
{
processors.Add(processor);
}
public Task<ContentViewModelBase> ProcessContent(HttpWebResponse response, IProgress<ProcessingProgress> progress)
{
IContentProcessor? processor = processors.Find(processor => processor.CanProcess(response)) ?? throw new InvalidOperationException("No processor found for the given response.");
return processor.Process(response, progress);
}
}
@@ -0,0 +1,14 @@
using Markdowser.ViewModels;
using System;
using System.Net;
using System.Threading.Tasks;
namespace Markdowser.Processing;
internal interface IContentProcessor
{
bool CanProcess(HttpWebResponse response);
Task<ContentViewModelBase> Process(HttpWebResponse response, IProgress<ProcessingProgress> progress);
}
@@ -0,0 +1,9 @@
namespace Markdowser.Processing;
public readonly struct ProcessingProgress(int current, int total)
{
public int Current { get; } = current;
public int Total { get; } = total;
public double Percentage => (double)Current / Total * 100;
}
+1 -1
View File
@@ -13,7 +13,7 @@ internal static class ColumnDefinition
}
else if (!visibility)
{
_ = element.SetValue(LastWidthProperty, element.GetValue(Avalonia.Controls.ColumnDefinition.WidthProperty));
_ = element.SetValue(LastWidthProperty!, element.GetValue(Avalonia.Controls.ColumnDefinition.WidthProperty));
_ = element.SetValue(Avalonia.Controls.ColumnDefinition.WidthProperty, ZeroWidth);
}
return visibility;
@@ -0,0 +1,6 @@
namespace Markdowser.ViewModels.Content;
public class MarkdownContentViewModel(string title, string markdown) : ContentViewModelBase(title)
{
public string Markdown { get; } = markdown;
}
@@ -0,0 +1,6 @@
namespace Markdowser.ViewModels;
public abstract class ContentViewModelBase(string title)
{
public string Title { get; } = title;
}
@@ -35,7 +35,6 @@ public partial class MainWindowViewModel : ViewModelBase
private bool isBusy;
private int progress;
public ObservableCollection<TabItem> Tabs => GlobalState.Tabs;
public string Title => $"{nameof(Markdowser)} - {Assembly.GetExecutingAssembly().GetName().Version?.ToString()}";
public TabItem CurrentTab
{
@@ -178,6 +177,8 @@ public partial class MainWindowViewModel : ViewModelBase
GlobalState.ContentReload += (sender, _) =>
{
// Updatre icon when dark mode changes
this.RaisePropertyChanged(nameof(Icon));
this.RaisePropertyChanged(nameof(Content));
};
}
+12 -1
View File
@@ -1,6 +1,17 @@
using ReactiveUI;
using Avalonia.Controls;
using Avalonia.Platform;
using Markdowser.Models;
using ReactiveUI;
using System.Reflection;
namespace Markdowser.ViewModels;
public class ViewModelBase : ReactiveObject
{
public string Title => $"{nameof(Markdowser)} - {Assembly.GetExecutingAssembly().GetName().Version?.ToString()}";
public WindowIcon Icon => Settings.Current.DarkMode ? new WindowIcon(AssetLoader.Open(new("avares://Markdowser/Assets/Markdowser-Dark-Transparent.ico"))) : new WindowIcon(AssetLoader.Open(new("avares://Markdowser/Assets/Markdowser-Light-Transparent.ico")));
}
+1 -1
View File
@@ -11,7 +11,7 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Markdowser.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
Icon="/Assets/Markdowser-Light-Transparent.ico"
Icon="{Binding Icon}"
Title="{Binding Title}">
<Design.DataContext>