Skip to content

Commit

Permalink
Use partial properties
Browse files Browse the repository at this point in the history
  • Loading branch information
ashotjanibekyan committed Nov 13, 2024
1 parent fadfdbd commit a49ad31
Show file tree
Hide file tree
Showing 195 changed files with 3,279 additions and 1,641 deletions.
16 changes: 8 additions & 8 deletions src/CrossWikiEditor.Core/CrossWikiEditor.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0-preview1" />
<PackageReference Include="CXuesong.MW.WikiClientLibrary" Version="0.8.0" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.70" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1" />
<PackageReference Include="Serilog" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="2.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0-preview1"/>
<PackageReference Include="CXuesong.MW.WikiClientLibrary" Version="0.8.0"/>
<PackageReference Include="HtmlAgilityPack" Version="1.11.71" />
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.0" />
<PackageReference Include="Serilog" Version="4.1.0"/>
<PackageReference Include="Serilog.Sinks.Async" Version="2.1.0"/>
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0"/>
<PackageReference Include="System.Net.Http" Version="4.3.4"/>
</ItemGroup>
</Project>
5 changes: 0 additions & 5 deletions src/CrossWikiEditor.Core/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
global using System.Collections.Immutable;
global using System.Collections.ObjectModel;
global using System.Collections.Specialized;

global using System.ComponentModel;
global using System.Globalization;
global using System.Security.Cryptography;
Expand All @@ -11,12 +10,10 @@
global using System.Web;
global using System.Xml;
global using System.Xml.Serialization;

global using CommunityToolkit.Mvvm.ComponentModel;
global using CommunityToolkit.Mvvm.Input;
global using CommunityToolkit.Mvvm.Messaging;
global using CommunityToolkit.Mvvm.Messaging.Messages;

global using CrossWikiEditor.Core.ListProviders;
global using CrossWikiEditor.Core.ListProviders.BaseListProviders;
global using CrossWikiEditor.Core.Messages;
Expand All @@ -33,10 +30,8 @@
global using CrossWikiEditor.Core.ViewModels.ReportViewModels;
global using CrossWikiEditor.Core.WikiClientLibraryUtils;
global using CrossWikiEditor.Core.WikiClientLibraryUtils.Generators;

global using HtmlAgilityPack;
global using Serilog;

global using WikiClientLibrary;
global using WikiClientLibrary.Client;
global using WikiClientLibrary.Generators;
Expand Down
2 changes: 1 addition & 1 deletion src/CrossWikiEditor.Core/IDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public interface IDialog
{
void Close(object? dialogResult);
object? DataContext { get; set; }
void Close(object? dialogResult);
}

public interface IOwner;
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
namespace CrossWikiEditor.Core.ListProviders;

public sealed class AllCategoriesListProvider(ICategoryService categoryService,
public sealed class AllCategoriesListProvider(
ICategoryService categoryService,
IDialogService dialogService,
ISettingsService settingsService) : LimitedListProviderBase(dialogService)
{
public override string Title => "All Categories";
public override string ParamTitle => "Start from";
public override bool CanMake => true;

public override async Task<Result<List<WikiPageModel>>> MakeList(int limit) =>
await categoryService.GetAllCategories(settingsService.CurrentApiUrl, Param, limit);
public override async Task<Result<List<WikiPageModel>>> MakeList(int limit)
{
return await categoryService.GetAllCategories(settingsService.CurrentApiUrl, Param, limit);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
namespace CrossWikiEditor.Core.ListProviders;

public sealed class AllFilesListProvider(IDialogService dialogService,
public sealed class AllFilesListProvider(
IDialogService dialogService,
IPageService pageService,
ISettingsService settingsService) : LimitedListProviderBase(dialogService)
{
public override string Title => "All Files";
public override string ParamTitle => "Start from";
public override bool CanMake => true;

public override async Task<Result<List<WikiPageModel>>> MakeList(int limit) =>
await pageService.GetAllFiles(settingsService.CurrentApiUrl, Param, limit);
public override async Task<Result<List<WikiPageModel>>> MakeList(int limit)
{
return await pageService.GetAllFiles(settingsService.CurrentApiUrl, Param, limit);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
namespace CrossWikiEditor.Core.ListProviders;

public sealed class AllPagesListProvider(IDialogService dialogService,
public sealed class AllPagesListProvider(
IDialogService dialogService,
IPageService pageService,
ISettingsService settingsService,
IViewModelFactory viewModelFactory) : AllPagesListProviderBase(dialogService, pageService, viewModelFactory, settingsService)
{
public override string Title => "All Pages";

public override async Task<Result<List<WikiPageModel>>> MakeList(int limit) =>
await MakeListBase(limit, PropertyFilterOption.Disable, PropertyFilterOption.Disable);
public override async Task<Result<List<WikiPageModel>>> MakeList(int limit)
{
return await MakeListBase(limit, PropertyFilterOption.Disable, PropertyFilterOption.Disable);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
namespace CrossWikiEditor.Core.ListProviders;

public sealed class AllPagesNoRedirectsListProvider(IDialogService dialogService,
public sealed class AllPagesNoRedirectsListProvider(
IDialogService dialogService,
IPageService pageService,
ISettingsService settingsService,
IViewModelFactory viewModelFactory) : AllPagesListProviderBase(dialogService, pageService, viewModelFactory, settingsService)
{
public override string Title => "All Pages (no redirects)";

public override async Task<Result<List<WikiPageModel>>> MakeList(int limit) =>
await MakeListBase(limit, PropertyFilterOption.WithoutProperty, PropertyFilterOption.Disable);
public override async Task<Result<List<WikiPageModel>>> MakeList(int limit)
{
return await MakeListBase(limit, PropertyFilterOption.WithoutProperty, PropertyFilterOption.Disable);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
namespace CrossWikiEditor.Core.ListProviders;

public sealed class AllPagesWithPrefixListProvider(IDialogService dialogService,
public sealed class AllPagesWithPrefixListProvider(
IDialogService dialogService,
IPageService pageService,
ISettingsService settingsService,
IViewModelFactory viewModelFactory) : LimitedListProviderBase(dialogService), INeedNamespacesListProvider
{
private int[]? _namespaces;
public override string Title => "All Pages with prefix (Prefixindex)";
public override string ParamTitle => "Prefix";
public override bool CanMake => _namespaces is { Length: 1 };
public override bool CanMake => _namespaces is {Length: 1};

public async Task GetAdditionalParams() => _namespaces = await this.GetNamespaces(isMultiselect: false, DialogService, viewModelFactory);
public async Task GetAdditionalParams()
{
_namespaces = await this.GetNamespaces(false, DialogService, viewModelFactory);
}

public override async Task<Result<List<WikiPageModel>>> MakeList(int limit) =>
await pageService.GetAllPagesWithPrefix(settingsService.CurrentApiUrl, Param, _namespaces![0], limit);
public override async Task<Result<List<WikiPageModel>>> MakeList(int limit)
{
return await pageService.GetAllPagesWithPrefix(settingsService.CurrentApiUrl, Param, _namespaces![0], limit);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
namespace CrossWikiEditor.Core.ListProviders;

public sealed class AllRedirectsListProvider(IDialogService dialogService,
public sealed class AllRedirectsListProvider(
IDialogService dialogService,
IPageService pageService,
ISettingsService settingsService,
IViewModelFactory viewModelFactory) : AllPagesListProviderBase(dialogService, pageService, viewModelFactory, settingsService)
{
public override string Title => "All Redirects";

public override async Task<Result<List<WikiPageModel>>> MakeList(int limit) =>
await MakeListBase(limit, PropertyFilterOption.WithProperty, PropertyFilterOption.Disable);
public override async Task<Result<List<WikiPageModel>>> MakeList(int limit)
{
return await MakeListBase(limit, PropertyFilterOption.WithProperty, PropertyFilterOption.Disable);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
namespace CrossWikiEditor.Core.ListProviders;

public sealed class AllUsersListProvider(IDialogService dialogService,
public sealed class AllUsersListProvider(
IDialogService dialogService,
ISettingsService settingsService,
IUserService userService) : LimitedListProviderBase(dialogService)
{
public override string Title => "All Users";
public override string ParamTitle => "Start from";

public override async Task<Result<List<WikiPageModel>>> MakeList(int limit) =>
await userService.GetAllUsers(settingsService.CurrentApiUrl, Param, limit);
public override async Task<Result<List<WikiPageModel>>> MakeList(int limit)
{
return await userService.GetAllUsers(settingsService.CurrentApiUrl, Param, limit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ public abstract class AllPagesListProviderBase(
{
private int[]? _namespaces;
public override string ParamTitle => "Start from";
public override bool CanMake => _namespaces is { Length: 1 };
public async Task GetAdditionalParams() => _namespaces = await this.GetNamespaces(isMultiselect: false, DialogService, viewModelFactory);
public override bool CanMake => _namespaces is {Length: 1};

public async Task GetAdditionalParams()
{
_namespaces = await this.GetNamespaces(false, DialogService, viewModelFactory);
}

protected async Task<Result<List<WikiPageModel>>> MakeListBase(int limit, PropertyFilterOption redirectsFilter,
PropertyFilterOption langLinksFilter)
{
return await pageService.GetAllPages(settingsService.CurrentApiUrl, Param, _namespaces![0],
redirectsFilter: redirectsFilter, langLinksFilter: langLinksFilter, limit);
redirectsFilter, langLinksFilter, limit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface ILimitedListProvider : IListProvider
public abstract class LimitedListProviderBase(IDialogService dialogService) : ListProviderBase, ILimitedListProvider
{
protected IDialogService DialogService => dialogService;

public async Task<int> GetLimit()
{
return await dialogService.ShowDialog<int?>(new PromptViewModel("How many page", "Limit: ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class CategoriesOnPageListProvider(
public override string Title => "Categories on page";
public override string ParamTitle => "Page";

public override async Task<Result<List<WikiPageModel>>> MakeList(int limit) =>
await categoryService.GetCategoriesOf(settingsService.CurrentApiUrl, Param, limit);
public override async Task<Result<List<WikiPageModel>>> MakeList(int limit)
{
return await categoryService.GetCategoriesOf(settingsService.CurrentApiUrl, Param, limit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public sealed class CategoriesOnPageNoHiddenCategoriesListProvider(
{
public override string Title => "Categories on page (no hidden categories)";

public override async Task<Result<List<WikiPageModel>>> MakeList(int limit) =>
await CategoryService.GetCategoriesOf(SettingsService.CurrentApiUrl, Param, limit, includeHidden: false);
public override async Task<Result<List<WikiPageModel>>> MakeList(int limit)
{
return await CategoryService.GetCategoriesOf(SettingsService.CurrentApiUrl, Param, limit, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public sealed class CategoriesOnPageOnlyHiddenCategoriesListProvider(
{
public override string Title => "Categories on page (only hidden categories)";

public override async Task<Result<List<WikiPageModel>>> MakeList(int limit) =>
await CategoryService.GetCategoriesOf(SettingsService.CurrentApiUrl, Param, limit, onlyHidden: true);
public override async Task<Result<List<WikiPageModel>>> MakeList(int limit)
{
return await CategoryService.GetCategoriesOf(SettingsService.CurrentApiUrl, Param, limit, onlyHidden: true);
}
}
12 changes: 8 additions & 4 deletions src/CrossWikiEditor.Core/ListProviders/CategoryListProvider.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
namespace CrossWikiEditor.Core.ListProviders;

public sealed class CategoryListProvider(ICategoryService categoryService,
IDialogService dialogService, ISettingsService settingsService) : LimitedListProviderBase(dialogService)
public sealed class CategoryListProvider(
ICategoryService categoryService,
IDialogService dialogService,
ISettingsService settingsService) : LimitedListProviderBase(dialogService)
{
public override string Title => "Category";
public override string ParamTitle => "Category";

public override async Task<Result<List<WikiPageModel>>> MakeList(int limit) =>
await categoryService.GetPagesOfCategory(settingsService.CurrentApiUrl, Param, limit);
public override async Task<Result<List<WikiPageModel>>> MakeList(int limit)
{
return await categoryService.GetPagesOfCategory(settingsService.CurrentApiUrl, Param, limit);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
namespace CrossWikiEditor.Core.ListProviders;

public sealed class CategoryRecursive1LevelListProvider(ICategoryService categoryService,
IDialogService dialogService, ISettingsService settingsService) : LimitedListProviderBase(dialogService)
public sealed class CategoryRecursive1LevelListProvider(
ICategoryService categoryService,
IDialogService dialogService,
ISettingsService settingsService) : LimitedListProviderBase(dialogService)
{
public override string Title => "Category (recursive 1 level)";
public override string ParamTitle => "Category";

public override async Task<Result<List<WikiPageModel>>> MakeList(int limit) =>
await categoryService.GetPagesOfCategory(settingsService.CurrentApiUrl, Param, limit, 1);
public override async Task<Result<List<WikiPageModel>>> MakeList(int limit)
{
return await categoryService.GetPagesOfCategory(settingsService.CurrentApiUrl, Param, limit, 1);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
namespace CrossWikiEditor.Core.ListProviders;

public sealed class CategoryRecursiveListProvider(ICategoryService categoryService,
IDialogService dialogService, ISettingsService settingsService) : LimitedListProviderBase(dialogService)
public sealed class CategoryRecursiveListProvider(
ICategoryService categoryService,
IDialogService dialogService,
ISettingsService settingsService) : LimitedListProviderBase(dialogService)
{
public override string Title => "Category (recursive)";
public override string ParamTitle => "Category";

public override async Task<Result<List<WikiPageModel>>> MakeList(int limit) =>
await categoryService.GetPagesOfCategory(settingsService.CurrentApiUrl, Param, limit, Int32.MaxValue);
public override async Task<Result<List<WikiPageModel>>> MakeList(int limit)
{
return await categoryService.GetPagesOfCategory(settingsService.CurrentApiUrl, Param, limit, int.MaxValue);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
namespace CrossWikiEditor.Core.ListProviders;

public sealed class CategoryRecursiveUserDefinedLevelListProvider(ICategoryService categoryService,
IDialogService dialogService,
ISettingsService settingsService)
public sealed class CategoryRecursiveUserDefinedLevelListProvider(
ICategoryService categoryService,
IDialogService dialogService,
ISettingsService settingsService)
: LimitedListProviderBase(dialogService), INeedAdditionalParamsListProvider
{
private int? _recursionLevel;
Expand All @@ -11,19 +12,6 @@ public sealed class CategoryRecursiveUserDefinedLevelListProvider(ICategoryServi
public override string ParamTitle => "Category";
public override bool CanMake => _recursionLevel is not null && !string.IsNullOrWhiteSpace(Param);

public override async Task<Result<List<WikiPageModel>>> MakeList(int limit)
{
if (_recursionLevel is null)
{
return new Exception("Please select recursive level.");
}

UserSettings userSettings = settingsService.GetCurrentSettings();
Result<List<WikiPageModel>> result = await categoryService.GetPagesOfCategory(userSettings.GetApiUrl(), Param, limit, (int) _recursionLevel);
_recursionLevel = null;
return result;
}

public async Task GetAdditionalParams()
{
int? result = await DialogService.ShowDialog<int?>(new PromptViewModel("Number", "Recursion depth: ")
Expand All @@ -36,4 +24,17 @@ public async Task GetAdditionalParams()
_recursionLevel = result;
}
}

public override async Task<Result<List<WikiPageModel>>> MakeList(int limit)
{
if (_recursionLevel is null)
{
return new Exception("Please select recursive level.");
}

UserSettings userSettings = settingsService.GetCurrentSettings();
Result<List<WikiPageModel>> result = await categoryService.GetPagesOfCategory(userSettings.GetApiUrl(), Param, limit, (int) _recursionLevel);
_recursionLevel = null;
return result;
}
}
Loading

0 comments on commit a49ad31

Please sign in to comment.