diff --git a/KoeBook.Common/Characters.cs b/KoeBook.Common/Characters.cs deleted file mode 100644 index b302d46..0000000 --- a/KoeBook.Common/Characters.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace KoeBook.Common; -internal class Characters -{ - public static Dictionary Mapping { get; set; } = new(); -} diff --git a/KoeBook.Common/ScriptLine.cs b/KoeBook.Common/ScriptLine.cs deleted file mode 100644 index f918d9d..0000000 --- a/KoeBook.Common/ScriptLine.cs +++ /dev/null @@ -1,11 +0,0 @@ -using CommunityToolkit.Mvvm.ComponentModel; - -namespace KoeBook.Common; -internal partial class ScriptLine : ObservableObject -{ - [ObservableProperty] private string _text = string.Empty; - [ObservableProperty] private string _character = string.Empty; - [ObservableProperty] private string _style = string.Empty; - - public string SpeakingModel => Characters.Mapping[Character]; -} diff --git a/KoeBook.Common/ScriptTextEntity.cs b/KoeBook.Common/ScriptTextEntity.cs deleted file mode 100644 index 26e4db5..0000000 --- a/KoeBook.Common/ScriptTextEntity.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace KoeBook.Common; -internal class ScriptTextEntity -{ - public required ScriptLine[] ScriptLines { get; set; } -} diff --git a/KoeBook.Core/Contracts/Services/IAnalyzerService.cs b/KoeBook.Core/Contracts/Services/IAnalyzerService.cs new file mode 100644 index 0000000..4cd1e2c --- /dev/null +++ b/KoeBook.Core/Contracts/Services/IAnalyzerService.cs @@ -0,0 +1,12 @@ +using KoeBook.Core.Models; + +namespace KoeBook.Core.Contracts.Services; + +public interface IAnalyzerService +{ + /// + /// 本の情報の取得・解析を行います + /// + /// 編集前の読み上げテキスト + ValueTask AnalyzeAsync(BookProperties bookProperties, CancellationToken cancellationToken); +} diff --git a/KoeBook.Core/Contracts/Services/IDisplayStateChangeService.cs b/KoeBook.Core/Contracts/Services/IDisplayStateChangeService.cs new file mode 100644 index 0000000..0896753 --- /dev/null +++ b/KoeBook.Core/Contracts/Services/IDisplayStateChangeService.cs @@ -0,0 +1,16 @@ +using KoeBook.Core.Models; + +namespace KoeBook.Core.Contracts.Services; + +public interface IDisplayStateChangeService +{ + /// + /// 状態を更新します + /// + void UpdateState(BookProperties bookProperties, GenerationState state); + + /// + /// プログレスバーを更新します + /// + void UpdateProgress(BookProperties bookProperties, int progress, int maximum); +} diff --git a/KoeBook.Core/Contracts/Services/IEpubGenerateService.cs b/KoeBook.Core/Contracts/Services/IEpubGenerateService.cs new file mode 100644 index 0000000..5ea8556 --- /dev/null +++ b/KoeBook.Core/Contracts/Services/IEpubGenerateService.cs @@ -0,0 +1,12 @@ +using KoeBook.Core.Models; + +namespace KoeBook.Core.Contracts.Services; + +public interface IEpubGenerateService +{ + /// + /// 読み上げ音声を生成し、Epubを作成します。 + /// + /// 生成したEpubのパス + ValueTask GenerateEpubAsync(BookScripts bookScripts, string tempDirectory, CancellationToken cancellationToken); +} diff --git a/KoeBook.Core/KoeBook.Core.csproj b/KoeBook.Core/KoeBook.Core.csproj index 6ead6af..79db428 100644 --- a/KoeBook.Core/KoeBook.Core.csproj +++ b/KoeBook.Core/KoeBook.Core.csproj @@ -8,10 +8,6 @@ enable - - - - diff --git a/KoeBook.Core/Models/BookOptions.cs b/KoeBook.Core/Models/BookOptions.cs new file mode 100644 index 0000000..7dbfc66 --- /dev/null +++ b/KoeBook.Core/Models/BookOptions.cs @@ -0,0 +1,15 @@ +namespace KoeBook.Core.Models; + +/// +/// 本ごとの設定 +/// +/// キャラクターとモデルの紐づけ +public class BookOptions(Dictionary characterMapping) +{ + public BookOptions() : this([]) { } + + /// + /// キャラクターとモデルの紐づけ。Key: キャラクター, Value: モデル + /// + public Dictionary CharacterMapping { get; } = characterMapping; +} diff --git a/KoeBook.Core/Models/BookProperties.cs b/KoeBook.Core/Models/BookProperties.cs new file mode 100644 index 0000000..ebe3618 --- /dev/null +++ b/KoeBook.Core/Models/BookProperties.cs @@ -0,0 +1,13 @@ +namespace KoeBook.Core.Models; + +/// +/// 読み上げる本の情報 +/// +public class BookProperties(Guid id, string source, SourceType sourceType) +{ + public Guid Id { get; } = id; + + public string Source { get; } = source; + + public SourceType SourceType { get; } = sourceType; +} diff --git a/KoeBook.Core/Models/BookScripts.cs b/KoeBook.Core/Models/BookScripts.cs new file mode 100644 index 0000000..0f4dc82 --- /dev/null +++ b/KoeBook.Core/Models/BookScripts.cs @@ -0,0 +1,19 @@ +namespace KoeBook.Core.Models; + +/// +/// 本の読み上げ情報 +/// +public class BookScripts(BookProperties bookProperties, BookOptions options) +{ + public BookProperties BookProperties { get; } = bookProperties; + + /// + /// 本の読み上げ設定 + /// + public BookOptions Options { get; } = options; + + /// + /// 読み上げテキストの配列 + /// + public required ScriptLine[] ScriptLines { get; set; } +} diff --git a/KoeBook/Models/GenerationState.cs b/KoeBook.Core/Models/GenerationState.cs similarity index 94% rename from KoeBook/Models/GenerationState.cs rename to KoeBook.Core/Models/GenerationState.cs index b1a09c5..9dfe9c1 100644 --- a/KoeBook/Models/GenerationState.cs +++ b/KoeBook.Core/Models/GenerationState.cs @@ -1,6 +1,6 @@ using System.Runtime.Serialization; -namespace KoeBook.Models; +namespace KoeBook.Core.Models; public enum GenerationState { diff --git a/KoeBook.Core/Models/ScriptLine.cs b/KoeBook.Core/Models/ScriptLine.cs new file mode 100644 index 0000000..b79f015 --- /dev/null +++ b/KoeBook.Core/Models/ScriptLine.cs @@ -0,0 +1,27 @@ +namespace KoeBook.Core.Models; + +/// +/// 読み上げ1行分 +/// +public class ScriptLine(string id, string text, string character, string style) +{ + /// + /// 読み上げ位置との関連付け + /// + public string Id { get; } = id; + + /// + /// 読み上げテキスト + /// + public string Text { get; } = text; + + /// + /// 話者 + /// + public string Character { get; set; } = character; + + /// + /// 話者のスタイル + /// + public string Style { get; set; } = style; +} diff --git a/KoeBook/Models/SourceType.cs b/KoeBook.Core/Models/SourceType.cs similarity index 85% rename from KoeBook/Models/SourceType.cs rename to KoeBook.Core/Models/SourceType.cs index 10bb4ce..bc59068 100644 --- a/KoeBook/Models/SourceType.cs +++ b/KoeBook.Core/Models/SourceType.cs @@ -1,6 +1,6 @@ using System.Runtime.Serialization; -namespace KoeBook.Models; +namespace KoeBook.Core.Models; public enum SourceType { diff --git a/KoeBook/App.xaml.cs b/KoeBook/App.xaml.cs index 2686ae7..9658cb1 100644 --- a/KoeBook/App.xaml.cs +++ b/KoeBook/App.xaml.cs @@ -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() 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."); } @@ -48,47 +45,48 @@ public App() { InitializeComponent(); - Host = Microsoft.Extensions.Hosting.Host. - CreateDefaultBuilder(). - UseContentRoot(AppContext.BaseDirectory). - ConfigureServices((context, services) => - { - // Default Activation Handler - services.AddTransient, DefaultActivationHandler>(); - - // Other Activation Handlers - services.AddTransient(); - - // Services - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddTransient(); - services.AddSingleton(); - - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - - // Core Services - services.AddSingleton(); - - // Views and ViewModels - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - - // Configuration - services.Configure(context.Configuration.GetSection(nameof(LocalSettingsOptions))); - }). - Build(); + Host = Microsoft.Extensions.Hosting.Host + .CreateDefaultBuilder() + .UseContentRoot(AppContext.BaseDirectory) + .ConfigureServices((context, services) => + { + // Default Activation Handler + services.AddTransient, DefaultActivationHandler>(); + + // Other Activation Handlers + services.AddTransient(); + + // Services + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddTransient(); + services.AddSingleton(); + + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + + // Core Services + services.AddSingleton(); + + // Views and ViewModels + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + // Configuration + services.Configure(context.Configuration.GetSection(nameof(LocalSettingsOptions))); + }) + .Build(); App.GetService().Initialize(); @@ -105,8 +103,8 @@ protected override async void OnLaunched(LaunchActivatedEventArgs args) { base.OnLaunched(args); - App.GetService().Show(string.Format("AppNotificationSamplePayload".GetLocalized(), AppContext.BaseDirectory)); + GetService().Show(string.Format("AppNotificationSamplePayload".GetLocalized(), AppContext.BaseDirectory)); - await App.GetService().ActivateAsync(args); + await GetService().ActivateAsync(args); } } diff --git a/KoeBook/Components/StateProgressBar.xaml.cs b/KoeBook/Components/StateProgressBar.xaml.cs index 4fdb6e9..4bc22c0 100644 --- a/KoeBook/Components/StateProgressBar.xaml.cs +++ b/KoeBook/Components/StateProgressBar.xaml.cs @@ -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; diff --git a/KoeBook/KoeBook.csproj b/KoeBook/KoeBook.csproj index 74966d7..a8f17d5 100644 --- a/KoeBook/KoeBook.csproj +++ b/KoeBook/KoeBook.csproj @@ -58,6 +58,10 @@ + + + + true diff --git a/KoeBook/Models/GenerationTask.cs b/KoeBook/Models/GenerationTask.cs index 122b0d4..a552685 100644 --- a/KoeBook/Models/GenerationTask.cs +++ b/KoeBook/Models/GenerationTask.cs @@ -1,5 +1,6 @@ using CommunityToolkit.Mvvm.ComponentModel; using FastEnumUtility; +using KoeBook.Core.Models; namespace KoeBook.Models; diff --git a/KoeBook/Services/DisplayStateChangeService.cs b/KoeBook/Services/DisplayStateChangeService.cs new file mode 100644 index 0000000..13e6b63 --- /dev/null +++ b/KoeBook/Services/DisplayStateChangeService.cs @@ -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; + }); + } +} diff --git a/KoeBook/Services/GenerationTaskService.cs b/KoeBook/Services/GenerationTaskService.cs index bbdedd3..c684a47 100644 --- a/KoeBook/Services/GenerationTaskService.cs +++ b/KoeBook/Services/GenerationTaskService.cs @@ -1,4 +1,5 @@ using KoeBook.Contracts.Services; +using KoeBook.Core.Models; using KoeBook.Models; namespace KoeBook.Services; diff --git a/KoeBook/ViewModels/MainViewModel.cs b/KoeBook/ViewModels/MainViewModel.cs index 0461be4..127d7ed 100644 --- a/KoeBook/ViewModels/MainViewModel.cs +++ b/KoeBook/ViewModels/MainViewModel.cs @@ -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;