Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Coreとの連携を行うインターフェースを追加 #21

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions KoeBook.Common/Characters.cs

This file was deleted.

11 changes: 0 additions & 11 deletions KoeBook.Common/ScriptLine.cs

This file was deleted.

5 changes: 0 additions & 5 deletions KoeBook.Common/ScriptTextEntity.cs

This file was deleted.

12 changes: 12 additions & 0 deletions KoeBook.Core/Contracts/Services/IAnalyzerService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using KoeBook.Core.Models;

namespace KoeBook.Core.Contracts.Services;

public interface IAnalyzerService
{
/// <summary>
/// 本の情報の取得・解析を行います
/// </summary>
/// <returns>編集前の読み上げテキスト</returns>
ValueTask<BookScripts> AnalyzeAsync(BookProperties bookProperties, CancellationToken cancellationToken);
}
16 changes: 16 additions & 0 deletions KoeBook.Core/Contracts/Services/IDisplayStateChangeService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using KoeBook.Core.Models;

namespace KoeBook.Core.Contracts.Services;

public interface IDisplayStateChangeService
{
/// <summary>
/// 状態を更新します
/// </summary>
void UpdateState(BookProperties bookProperties, GenerationState state);

/// <summary>
/// プログレスバーを更新します
/// </summary>
void UpdateProgress(BookProperties bookProperties, int progress, int maximum);
}
12 changes: 12 additions & 0 deletions KoeBook.Core/Contracts/Services/IEpubGenerateService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using KoeBook.Core.Models;

namespace KoeBook.Core.Contracts.Services;

public interface IEpubGenerateService
{
/// <summary>
/// 読み上げ音声を生成し、Epubを作成します。
/// </summary>
/// <returns>生成したEpubのパス</returns>
ValueTask<string> GenerateEpubAsync(BookScripts bookScripts, string tempDirectory, CancellationToken cancellationToken);
}
4 changes: 0 additions & 4 deletions KoeBook.Core/KoeBook.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FastEnum" Version="1.8.0" />
</ItemGroup>
Expand Down
15 changes: 15 additions & 0 deletions KoeBook.Core/Models/BookOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace KoeBook.Core.Models;

/// <summary>
/// 本ごとの設定
/// </summary>
/// <param name="characterMapping">キャラクターとモデルの紐づけ</param>
public class BookOptions(Dictionary<string, string> characterMapping)
{
public BookOptions() : this([]) { }

/// <summary>
/// キャラクターとモデルの紐づけ。Key: キャラクター, Value: モデル
/// </summary>
public Dictionary<string, string> CharacterMapping { get; } = characterMapping;
}
13 changes: 13 additions & 0 deletions KoeBook.Core/Models/BookProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace KoeBook.Core.Models;

/// <summary>
/// 読み上げる本の情報
/// </summary>
public class BookProperties(Guid id, string source, SourceType sourceType)
{
public Guid Id { get; } = id;

public string Source { get; } = source;

public SourceType SourceType { get; } = sourceType;
}
19 changes: 19 additions & 0 deletions KoeBook.Core/Models/BookScripts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace KoeBook.Core.Models;

/// <summary>
/// 本の読み上げ情報
/// </summary>
public class BookScripts(BookProperties bookProperties, BookOptions options)
{
public BookProperties BookProperties { get; } = bookProperties;

/// <summary>
/// 本の読み上げ設定
/// </summary>
public BookOptions Options { get; } = options;

/// <summary>
/// 読み上げテキストの配列
/// </summary>
public required ScriptLine[] ScriptLines { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Runtime.Serialization;

namespace KoeBook.Models;
namespace KoeBook.Core.Models;

public enum GenerationState
{
Expand Down
27 changes: 27 additions & 0 deletions KoeBook.Core/Models/ScriptLine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace KoeBook.Core.Models;

/// <summary>
/// 読み上げ1行分
/// </summary>
public class ScriptLine(string id, string text, string character, string style)
{
/// <summary>
/// 読み上げ位置との関連付け
/// </summary>
public string Id { get; } = id;

/// <summary>
/// 読み上げテキスト
/// </summary>
public string Text { get; } = text;

/// <summary>
/// 話者
/// </summary>
public string Character { get; set; } = character;

/// <summary>
/// 話者のスタイル
/// </summary>
public string Style { get; set; } = style;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Runtime.Serialization;

namespace KoeBook.Models;
namespace KoeBook.Core.Models;

public enum SourceType
{
Expand Down
94 changes: 46 additions & 48 deletions KoeBook/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@ public partial class App : Application
// https://docs.microsoft.com/dotnet/core/extensions/dependency-injection
// https://docs.microsoft.com/dotnet/core/extensions/configuration
// https://docs.microsoft.com/dotnet/core/extensions/logging
public IHost Host
{
get;
}
public IHost Host { get; }

public static T GetService<T>()
where T : class
{
if ((App.Current as App)!.Host.Services.GetService(typeof(T)) is not T service)
if ((Current as App)!.Host.Services.GetService(typeof(T)) is not T service)
{
throw new ArgumentException($"{typeof(T)} needs to be registered in ConfigureServices within App.xaml.cs.");
}
Expand All @@ -48,47 +45,48 @@ public App()
{
InitializeComponent();

Host = Microsoft.Extensions.Hosting.Host.
CreateDefaultBuilder().
UseContentRoot(AppContext.BaseDirectory).
ConfigureServices((context, services) =>
{
// Default Activation Handler
services.AddTransient<ActivationHandler<LaunchActivatedEventArgs>, DefaultActivationHandler>();

// Other Activation Handlers
services.AddTransient<IActivationHandler, AppNotificationActivationHandler>();

// Services
services.AddSingleton<IAppNotificationService, AppNotificationService>();
services.AddSingleton<ILocalSettingsService, LocalSettingsService>();
services.AddSingleton<IThemeSelectorService, ThemeSelectorService>();
services.AddTransient<INavigationViewService, NavigationViewService>();
services.AddSingleton<ITabViewService, TabViewService>();

services.AddSingleton<IGenerationTaskService, GenerationTaskService>();
services.AddSingleton<IActivationService, ActivationService>();
services.AddSingleton<IPageService, PageService>();
services.AddSingleton<INavigationService, NavigationService>();
services.AddSingleton<IDialogService, DialogService>();

// Core Services
services.AddSingleton<IFileService, FileService>();

// Views and ViewModels
services.AddTransient<SettingsViewModel>();
services.AddTransient<SettingsPage>();
services.AddTransient<MainViewModel>();
services.AddTransient<TaskListViewModel>();
services.AddTransient<MainPage>();
services.AddTransient<ShellPage>();
services.AddTransient<ShellViewModel>();
services.AddTransient<EditDetailsViewModel>();

// Configuration
services.Configure<LocalSettingsOptions>(context.Configuration.GetSection(nameof(LocalSettingsOptions)));
}).
Build();
Host = Microsoft.Extensions.Hosting.Host
.CreateDefaultBuilder()
.UseContentRoot(AppContext.BaseDirectory)
.ConfigureServices((context, services) =>
{
// Default Activation Handler
services.AddTransient<ActivationHandler<LaunchActivatedEventArgs>, DefaultActivationHandler>();

// Other Activation Handlers
services.AddTransient<IActivationHandler, AppNotificationActivationHandler>();

// Services
services.AddSingleton<IAppNotificationService, AppNotificationService>();
services.AddSingleton<ILocalSettingsService, LocalSettingsService>();
services.AddSingleton<IThemeSelectorService, ThemeSelectorService>();
services.AddTransient<INavigationViewService, NavigationViewService>();
services.AddSingleton<ITabViewService, TabViewService>();

services.AddSingleton<IGenerationTaskService, GenerationTaskService>();
services.AddSingleton<IActivationService, ActivationService>();
services.AddSingleton<IPageService, PageService>();
services.AddSingleton<INavigationService, NavigationService>();
services.AddSingleton<IDialogService, DialogService>();
services.AddSingleton<IDisplayStateChangeService, DisplayStateChangeService>();

// Core Services
services.AddSingleton<IFileService, FileService>();

// Views and ViewModels
services.AddTransient<SettingsViewModel>();
services.AddTransient<SettingsPage>();
services.AddTransient<MainViewModel>();
services.AddTransient<TaskListViewModel>();
services.AddTransient<MainPage>();
services.AddTransient<ShellPage>();
services.AddTransient<ShellViewModel>();
services.AddTransient<EditDetailsViewModel>();

// Configuration
services.Configure<LocalSettingsOptions>(context.Configuration.GetSection(nameof(LocalSettingsOptions)));
})
.Build();

App.GetService<IAppNotificationService>().Initialize();

Expand All @@ -105,8 +103,8 @@ protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
base.OnLaunched(args);

App.GetService<IAppNotificationService>().Show(string.Format("AppNotificationSamplePayload".GetLocalized(), AppContext.BaseDirectory));
GetService<IAppNotificationService>().Show(string.Format("AppNotificationSamplePayload".GetLocalized(), AppContext.BaseDirectory));

await App.GetService<IActivationService>().ActivateAsync(args);
await GetService<IActivationService>().ActivateAsync(args);
}
}
3 changes: 1 addition & 2 deletions KoeBook/Components/StateProgressBar.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.ComponentModel;
using KoeBook.Contracts.Services;
using KoeBook.Core.Models;
using KoeBook.Models;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Windows.UI.ViewManagement;

namespace KoeBook.Components;

Expand Down
4 changes: 4 additions & 0 deletions KoeBook/KoeBook.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<ProjectCapability Include="Msix" />
</ItemGroup>

<ItemGroup>
<Folder Include="Services\CoreMocks\" />
</ItemGroup>

<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
Expand Down
1 change: 1 addition & 0 deletions KoeBook/Models/GenerationTask.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CommunityToolkit.Mvvm.ComponentModel;
using FastEnumUtility;
using KoeBook.Core.Models;

namespace KoeBook.Models;

Expand Down
30 changes: 30 additions & 0 deletions KoeBook/Services/DisplayStateChangeService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using KoeBook.Contracts.Services;
using KoeBook.Core.Contracts.Services;
using KoeBook.Core.Models;

namespace KoeBook.Services;

internal class DisplayStateChangeService(IGenerationTaskService taskService) : IDisplayStateChangeService
{
private readonly IGenerationTaskService _taskService = taskService;

public void UpdateProgress(BookProperties bookProperties, int progress, int maximum)
{
var taskService = _taskService; // thisをキャプチャしないようにする
_ = App.MainWindow.DispatcherQueue.TryEnqueue(() =>
{
var task = taskService.GetProcessingTask(bookProperties.Id);
task.MaximumProgress = maximum;
task.Progress = progress;
});
}

public void UpdateState(BookProperties bookProperties, GenerationState state)
{
var taskService = _taskService; // thisをキャプチャしないようにする
_ = App.MainWindow.DispatcherQueue.TryEnqueue(() =>
{
taskService.GetProcessingTask(bookProperties.Id).State = state;
});
}
}
1 change: 1 addition & 0 deletions KoeBook/Services/GenerationTaskService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using KoeBook.Contracts.Services;
using KoeBook.Core.Models;
using KoeBook.Models;

namespace KoeBook.Services;
Expand Down
2 changes: 1 addition & 1 deletion KoeBook/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using KoeBook.Contracts.Services;
using KoeBook.Models;
using KoeBook.Core.Models;
using Microsoft.UI.Xaml.Controls;
using Windows.Storage.Pickers;
using WinRT.Interop;
Expand Down
Loading