
| Revision | 684982186e889eb40e9dc0277d4349aef053aea8 (tree) |
|---|---|
| Time | 2022-08-16 01:06:06 |
| Author | yoshy <yoshy.org.bitbucket@gz.j...> |
| Commiter | yoshy |
initial revision
| @@ -0,0 +1,14 @@ | ||
| 1 | +namespace CleanAuLait.Adaptor.Boundary.Gateway.UI.Dialog | |
| 2 | +{ | |
| 3 | + public interface IUserDialogProxy | |
| 4 | + { | |
| 5 | + void ShowInfo(string msg); | |
| 6 | + void ShowInfo(string msg, string caption); | |
| 7 | + void ShowWarn(string msg); | |
| 8 | + void ShowWarn(string msg, string caption); | |
| 9 | + void ShowError(Exception e); | |
| 10 | + void ShowError(Exception e, string caption); | |
| 11 | + void ShowError(string msg); | |
| 12 | + void ShowError(string msg, string caption); | |
| 13 | + } | |
| 14 | +} | |
| \ No newline at end of file |
| @@ -0,0 +1,7 @@ | ||
| 1 | +namespace CleanAuLait.Adaptor.Boundary.Gateway.UI | |
| 2 | +{ | |
| 3 | + public interface IShowChildWindowProxy | |
| 4 | + { | |
| 5 | + void ShowChildWindow(); | |
| 6 | + } | |
| 7 | +} |
| @@ -0,0 +1,24 @@ | ||
| 1 | +using CleanAuLait.Adaptor.Boundary.Controller; | |
| 2 | +using Prism.Ioc; | |
| 3 | + | |
| 4 | +namespace CleanAuLait.Adaptor.Controller | |
| 5 | +{ | |
| 6 | + public class AsyncHandlerContextFactoryRegistrar : | |
| 7 | + AbstractHandlerContextFactoryRegistrar<IAsyncHandlerContextFactory, AsyncHandlerContextFactory> | |
| 8 | + { | |
| 9 | + private readonly IContainerRegistry containerRegistry; | |
| 10 | + | |
| 11 | + public AsyncHandlerContextFactoryRegistrar(IContainerRegistry containerRegistry) | |
| 12 | + { | |
| 13 | + this.containerRegistry = containerRegistry; | |
| 14 | + } | |
| 15 | + | |
| 16 | + public override void Register() | |
| 17 | + { | |
| 18 | + var factory = CreateFactoryFactory(); | |
| 19 | + | |
| 20 | + this.containerRegistry.RegisterSingleton<IAsyncHandlerContextFactory>(factory); | |
| 21 | + } | |
| 22 | + | |
| 23 | + } | |
| 24 | +} |
| @@ -0,0 +1,25 @@ | ||
| 1 | +using CleanAuLait.Core.DI; | |
| 2 | +using Prism.Ioc; | |
| 3 | + | |
| 4 | +namespace CleanAuLait.Adaptor.Controller.DI | |
| 5 | +{ | |
| 6 | + internal class RequestScopeGenerator : IRequestScopeGenerator | |
| 7 | + { | |
| 8 | + public IRequestScopedProvider CreateScope() | |
| 9 | + { | |
| 10 | + try | |
| 11 | + { | |
| 12 | + return new RequestScopedProvider(GetContainer().CreateScope()); | |
| 13 | + } | |
| 14 | + catch (Exception e) | |
| 15 | + { | |
| 16 | + throw new DIException(e); | |
| 17 | + } | |
| 18 | + } | |
| 19 | + | |
| 20 | + protected virtual IContainerProvider GetContainer() | |
| 21 | + { | |
| 22 | + return ContainerLocator.Container; | |
| 23 | + } | |
| 24 | + } | |
| 25 | +} |
| @@ -0,0 +1,32 @@ | ||
| 1 | +using CleanAuLait.Core.DI; | |
| 2 | +using Prism.Ioc; | |
| 3 | + | |
| 4 | +namespace CleanAuLait.Adaptor.Controller.DI; | |
| 5 | + | |
| 6 | +internal class RequestScopedProvider : IRequestScopedProvider | |
| 7 | +{ | |
| 8 | + private readonly IScopedProvider scopedProvider; | |
| 9 | + | |
| 10 | + public RequestScopedProvider(IScopedProvider scopedProvider) | |
| 11 | + { | |
| 12 | + this.scopedProvider = scopedProvider; | |
| 13 | + } | |
| 14 | + | |
| 15 | + public object Resolve(Type type) | |
| 16 | + { | |
| 17 | + try | |
| 18 | + { | |
| 19 | + return this.scopedProvider.Resolve(type); | |
| 20 | + } | |
| 21 | + catch (ContainerResolutionException e) | |
| 22 | + { | |
| 23 | + throw new DIException(e); | |
| 24 | + } | |
| 25 | + } | |
| 26 | + | |
| 27 | + public void Dispose() | |
| 28 | + { | |
| 29 | + this.scopedProvider?.Dispose(); | |
| 30 | + } | |
| 31 | + | |
| 32 | +} | |
| \ No newline at end of file |
| @@ -0,0 +1,40 @@ | ||
| 1 | +using CleanAuLait.Adaptor.Boundary.Gateway.UI.Dialog; | |
| 2 | +using CleanAuLait.UseCase.Request; | |
| 3 | +using CleanAuLait.UseCase.Response; | |
| 4 | + | |
| 5 | +namespace CleanAuLait.Adaptor.Controller.Handler | |
| 6 | +{ | |
| 7 | + public abstract class AbstractErrorHandler | |
| 8 | + { | |
| 9 | + private readonly IUserDialogProxy dialog; | |
| 10 | + | |
| 11 | + public AbstractErrorHandler(IUserDialogProxy dialog) | |
| 12 | + { | |
| 13 | + this.dialog = dialog; | |
| 14 | + } | |
| 15 | + | |
| 16 | + protected UseCaseResponse HandleResponse(UseCaseRequest _, UseCaseResponse res) | |
| 17 | + { | |
| 18 | + if (res == null) | |
| 19 | + { | |
| 20 | + res = UseCaseResponse.AbortWithSomeErrors<UseCaseResponse>( | |
| 21 | + "[Bug Check] コマンドの処理結果が未設定です。ハンドラマップの設定漏れの可能性があります"); | |
| 22 | + } | |
| 23 | + | |
| 24 | + //string statusText = !String.IsNullOrEmpty(res.Message) ? res.Message : AppConst.STATUS_BAR_READY; | |
| 25 | + | |
| 26 | + if (res.HasSomeErrors) | |
| 27 | + { | |
| 28 | + //dialog.ShowError(res.Message, req.UIInfo); | |
| 29 | + dialog.ShowError(res.Message); | |
| 30 | + } | |
| 31 | + else if (res.IsAborted) | |
| 32 | + { | |
| 33 | + //dialog.ShowInfo(res.Message, req.UIInfo); | |
| 34 | + dialog.ShowInfo(res.Message); | |
| 35 | + } | |
| 36 | + | |
| 37 | + return res; | |
| 38 | + } | |
| 39 | + } | |
| 40 | +} | |
| \ No newline at end of file |
| @@ -0,0 +1,36 @@ | ||
| 1 | +using CleanAuLait.Adaptor.Boundary.Controller; | |
| 2 | +using CleanAuLait.Adaptor.Boundary.Controller.Handler; | |
| 3 | +using CleanAuLait.Adaptor.Boundary.Gateway.UI.Dialog; | |
| 4 | +using CleanAuLait.UseCase.Request; | |
| 5 | +using CleanAuLait.UseCase.Response; | |
| 6 | +using NLog; | |
| 7 | + | |
| 8 | +namespace CleanAuLait.Adaptor.Controller.Handler | |
| 9 | +{ | |
| 10 | + public class AsyncSimpleUserDialogErrorHandler : AbstractErrorHandler, IAsyncRequestHandler | |
| 11 | + { | |
| 12 | + private static readonly ILogger logger = LogManager.GetCurrentClassLogger(); | |
| 13 | + | |
| 14 | + public AsyncSimpleUserDialogErrorHandler(IUserDialogProxy dialog) : base(dialog) | |
| 15 | + { | |
| 16 | + } | |
| 17 | + | |
| 18 | + public async Task<UseCaseResponse> HandleAsync(UseCaseRequest req, IAsyncHandlerContext context) | |
| 19 | + { | |
| 20 | + UseCaseResponse res; | |
| 21 | + | |
| 22 | + try | |
| 23 | + { | |
| 24 | + res = await context.HandleNextAsync(req, context); | |
| 25 | + } | |
| 26 | + catch (Exception e) | |
| 27 | + { | |
| 28 | + logger.Error(e); | |
| 29 | + res = UseCaseResponse.AbortWithSomeErrors<UseCaseResponse>( | |
| 30 | + $"Handling Async UseCase failed. {e.Message}"); | |
| 31 | + } | |
| 32 | + | |
| 33 | + return HandleResponse(req, res); | |
| 34 | + } | |
| 35 | + } | |
| 36 | +} |
| @@ -0,0 +1,36 @@ | ||
| 1 | +using CleanAuLait.Adaptor.Boundary.Controller; | |
| 2 | +using CleanAuLait.Adaptor.Boundary.Controller.Handler; | |
| 3 | +using CleanAuLait.Adaptor.Boundary.Gateway.UI.Dialog; | |
| 4 | +using CleanAuLait.UseCase.Request; | |
| 5 | +using CleanAuLait.UseCase.Response; | |
| 6 | +using NLog; | |
| 7 | + | |
| 8 | +namespace CleanAuLait.Adaptor.Controller.Handler | |
| 9 | +{ | |
| 10 | + public class SimpleUserDialogErrorHandler : AbstractErrorHandler, IRequestHandler | |
| 11 | + { | |
| 12 | + private static readonly ILogger logger = LogManager.GetCurrentClassLogger(); | |
| 13 | + | |
| 14 | + public SimpleUserDialogErrorHandler(IUserDialogProxy dialog) : base(dialog) | |
| 15 | + { | |
| 16 | + } | |
| 17 | + | |
| 18 | + public UseCaseResponse Handle(UseCaseRequest req, IHandlerContext context) | |
| 19 | + { | |
| 20 | + UseCaseResponse res; | |
| 21 | + | |
| 22 | + try | |
| 23 | + { | |
| 24 | + res = context.HandleNext(req, context); | |
| 25 | + } | |
| 26 | + catch (Exception e) | |
| 27 | + { | |
| 28 | + logger.Error(e); | |
| 29 | + res = UseCaseResponse.AbortWithSomeErrors<UseCaseResponse>( | |
| 30 | + $"Handling UseCase failed. {e.Message}"); | |
| 31 | + } | |
| 32 | + | |
| 33 | + return HandleResponse(req, res); | |
| 34 | + } | |
| 35 | + } | |
| 36 | +} |
| @@ -0,0 +1,23 @@ | ||
| 1 | +using CleanAuLait.Adaptor.Boundary.Controller; | |
| 2 | +using Prism.Ioc; | |
| 3 | + | |
| 4 | +namespace CleanAuLait.Adaptor.Controller | |
| 5 | +{ | |
| 6 | + public class HandlerContextFactoryRegistrar : | |
| 7 | + AbstractHandlerContextFactoryRegistrar<IHandlerContextFactory, HandlerContextFactory> | |
| 8 | + { | |
| 9 | + private readonly IContainerRegistry containerRegistry; | |
| 10 | + | |
| 11 | + public HandlerContextFactoryRegistrar(IContainerRegistry containerRegistry) | |
| 12 | + { | |
| 13 | + this.containerRegistry = containerRegistry; | |
| 14 | + } | |
| 15 | + | |
| 16 | + public override void Register() | |
| 17 | + { | |
| 18 | + var factory = CreateFactoryFactory(); | |
| 19 | + | |
| 20 | + this.containerRegistry.RegisterSingleton<IHandlerContextFactory>(factory); | |
| 21 | + } | |
| 22 | + } | |
| 23 | +} |
| @@ -0,0 +1,20 @@ | ||
| 1 | +<Project Sdk="Microsoft.NET.Sdk"> | |
| 2 | + <PropertyGroup> | |
| 3 | + <TargetFramework>net6.0-windows10.0.19041.0</TargetFramework> | |
| 4 | + <TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion> | |
| 5 | + <RootNamespace>CleanAuLait.Prism.WinUI3</RootNamespace> | |
| 6 | + <RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers> | |
| 7 | + <ImplicitUsings>enable</ImplicitUsings> | |
| 8 | + <UseWinUI>true</UseWinUI> | |
| 9 | + </PropertyGroup> | |
| 10 | + | |
| 11 | + <ItemGroup> | |
| 12 | + <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.1.4" /> | |
| 13 | + <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.1" /> | |
| 14 | + </ItemGroup> | |
| 15 | + | |
| 16 | + <ItemGroup> | |
| 17 | + <ProjectReference Include="..\CleanAuLait\CleanAuLait.csproj" /> | |
| 18 | + <ProjectReference Include="D:\Repo\gitroot\Prism\src\WinUi\Prism.Unity.WinUI\Prism.Unity.WinUI.csproj" /> | |
| 19 | + </ItemGroup> | |
| 20 | +</Project> |
| @@ -0,0 +1,105 @@ | ||
| 1 | +#if false | |
| 2 | +using CleanAuLait.Adaptor.Boundary.Gateway.UI; | |
| 3 | +using CleanAuLait.Adaptor.Boundary.Gateway.UI.Dialog; | |
| 4 | +using CleanAuLait.Adaptor.Boundary.Gateway.UI.Dialog.Shell; | |
| 5 | +using CleanAuLait.Adaptor.Boundary.Gateway.ViewModel.Dialog; | |
| 6 | +using CleanAuLait.Adaptor.Gateway.UI; | |
| 7 | +using CleanAuLait.Adaptor.Gateway.UI.Dialog; | |
| 8 | +using CleanAuLait.Adaptor.Gateway.UI.Dialog.Service; | |
| 9 | +using CleanAuLait.Adaptor.Gateway.UI.Dialog.Shell; | |
| 10 | +using CleanAuLait.Adaptor.Gateway.ViewModel; | |
| 11 | +using CleanAuLait.OuterEdge.UI.Dialog; | |
| 12 | +#endif | |
| 13 | +using NLog; | |
| 14 | +using CleanAuLait.Adaptor.Controller.DI; | |
| 15 | +using CleanAuLait.Core.Resource; | |
| 16 | +using Prism.Ioc; | |
| 17 | +using Prism.Modularity; | |
| 18 | +using CleanAuLait.Adaptor.Boundary.Gateway.UI.Dialog; | |
| 19 | +using CleanAuLait.Adaptor.Gateway.UI.Dialog; | |
| 20 | +#if false | |
| 21 | +using Prism.Mvvm; | |
| 22 | +using Prism.Services.Dialogs; | |
| 23 | +#endif | |
| 24 | + | |
| 25 | +namespace CleanAuLait | |
| 26 | +{ | |
| 27 | + public class CleanAuLaitPrismWinUI3Module : IModule | |
| 28 | + { | |
| 29 | + private static readonly ILogger logger = LogManager.GetCurrentClassLogger(); | |
| 30 | + | |
| 31 | + public void RegisterTypes(IContainerRegistry containerRegistry) | |
| 32 | + { | |
| 33 | + // | |
| 34 | + // Request Scope | |
| 35 | + // | |
| 36 | + | |
| 37 | + containerRegistry.RegisterSingleton<IRequestScopeGenerator, RequestScopeGenerator>(); | |
| 38 | + | |
| 39 | + /// | |
| 40 | + /// Resources | |
| 41 | + /// | |
| 42 | + | |
| 43 | + containerRegistry.RegisterSingleton<ICaptionFormatter, CaptionFormatter>(); | |
| 44 | + | |
| 45 | + // | |
| 46 | + // Dialog Proxy | |
| 47 | + // | |
| 48 | + | |
| 49 | + containerRegistry.RegisterSingleton<IUserDialogProxy, UserDialogProxy>(); | |
| 50 | +#if false | |
| 51 | + containerRegistry.RegisterSingleton<IUniversalDialogProxy, UniversalDialogProxy>(); | |
| 52 | + | |
| 53 | + // | |
| 54 | + // Dialog Service | |
| 55 | + // | |
| 56 | + | |
| 57 | + containerRegistry.RegisterSingleton<IDialogService, UniversalDialogService>(); | |
| 58 | + | |
| 59 | + // | |
| 60 | + // Dialog Proxy | |
| 61 | + // | |
| 62 | + | |
| 63 | + containerRegistry.RegisterSingleton<IUserDialogProxy, UserDialogProxy>(); | |
| 64 | + containerRegistry.RegisterSingleton<IUniversalDialogProxy, UniversalDialogProxy>(); | |
| 65 | + | |
| 66 | + // | |
| 67 | + // Dialog View Model | |
| 68 | + // | |
| 69 | + | |
| 70 | + containerRegistry.RegisterSingleton<IUniversalDialogViewModel, UniversalDialogViewModel>(); | |
| 71 | + | |
| 72 | + containerRegistry.RegisterDialog<UniversalDialog, IUniversalDialogViewModel>(); | |
| 73 | + | |
| 74 | + // | |
| 75 | + // UI Proxy | |
| 76 | + // | |
| 77 | + | |
| 78 | + containerRegistry.RegisterSingleton<IStatusBarProxy, StatusBarProxy>(); | |
| 79 | + | |
| 80 | + // | |
| 81 | + // Shell Common Dialog Proxy | |
| 82 | + // | |
| 83 | + | |
| 84 | + containerRegistry.RegisterSingleton<ICommonFolderDialogProxy, CommonFolderDialogProxy>(); | |
| 85 | + containerRegistry.RegisterSingleton<ICommonOpenLoadFileDialogProxy, CommonOpenLoadFileDialogProxy>(); | |
| 86 | +#endif | |
| 87 | + | |
| 88 | + logger.Trace("RegisterTypes end"); | |
| 89 | + } | |
| 90 | + | |
| 91 | + public void OnInitialized(IContainerProvider containerProvider) | |
| 92 | + { | |
| 93 | +#if false | |
| 94 | + // | |
| 95 | + // Views and ViewModels | |
| 96 | + // | |
| 97 | + | |
| 98 | + ViewModelLocationProvider.Register<UniversalDialog>(() => containerProvider.Resolve<IUniversalDialogViewModel>()); | |
| 99 | + | |
| 100 | + logger.Trace("OnInitialized end"); | |
| 101 | +#endif | |
| 102 | + } | |
| 103 | + | |
| 104 | + } | |
| 105 | +} | |
| \ No newline at end of file |
| @@ -0,0 +1,60 @@ | ||
| 1 | +using CleanAuLait.OuterEdge.Repository; | |
| 2 | +using NLog; | |
| 3 | +using System.Reflection; | |
| 4 | + | |
| 5 | +namespace CleanAuLait.Core.Resource | |
| 6 | +{ | |
| 7 | + public class MessageRepository : AbstractMessageRepository | |
| 8 | + { | |
| 9 | + private static readonly ILogger logger = LogManager.GetCurrentClassLogger(); | |
| 10 | + | |
| 11 | + public MessageRepository(string resourcePathPrefix, string resourceRelativePath) : | |
| 12 | + this(resourcePathPrefix, resourceRelativePath, null) | |
| 13 | + { | |
| 14 | + } | |
| 15 | + | |
| 16 | + public MessageRepository(string resourcePathPrefix, string resourceRelativePath, Assembly asm) | |
| 17 | + { | |
| 18 | + ReadMessageFromResource(resourcePathPrefix, resourceRelativePath, asm); | |
| 19 | + } | |
| 20 | + | |
| 21 | + public MessageRepository(string resourcePathPrefix) | |
| 22 | + { | |
| 23 | + ReadMessageFromAsset(resourcePathPrefix); | |
| 24 | + } | |
| 25 | + | |
| 26 | + private async void ReadMessageFromResource(string resourcePathPrefix, string resourceRelativePath, Assembly asm) | |
| 27 | + { | |
| 28 | + string content = await ResourceHelper.LoadTextFromResourceAsync(resourcePathPrefix, resourceRelativePath, asm) | |
| 29 | + .ContinueWith(t => | |
| 30 | + { | |
| 31 | + if (t.Exception != null) | |
| 32 | + { | |
| 33 | + logger.Error(t.Exception); | |
| 34 | + throw new RepositoryException(t.Exception); | |
| 35 | + } | |
| 36 | + | |
| 37 | + return t.Result; | |
| 38 | + }); | |
| 39 | + | |
| 40 | + RegisterMessages(content); | |
| 41 | + } | |
| 42 | + | |
| 43 | + private async void ReadMessageFromAsset(string resourcePathPrefix) | |
| 44 | + { | |
| 45 | + string content = await ResourceHelper.LoadTextFromAssetAsync(null, resourcePathPrefix) | |
| 46 | + .ContinueWith(t => | |
| 47 | + { | |
| 48 | + if (t.Exception != null) | |
| 49 | + { | |
| 50 | + logger.Error(t.Exception); | |
| 51 | + throw new RepositoryException(t.Exception); | |
| 52 | + } | |
| 53 | + | |
| 54 | + return t.Result; | |
| 55 | + }); | |
| 56 | + | |
| 57 | + RegisterMessages(content); | |
| 58 | + } | |
| 59 | + } | |
| 60 | +} |
| @@ -0,0 +1,128 @@ | ||
| 1 | +using Microsoft.UI.Xaml.Media.Imaging; | |
| 2 | +using NLog; | |
| 3 | +using System.Reflection; | |
| 4 | +using Windows.Storage; | |
| 5 | + | |
| 6 | +namespace CleanAuLait.Core.Resource | |
| 7 | +{ | |
| 8 | + public static class ResourceHelper | |
| 9 | + { | |
| 10 | + private static readonly ILogger logger = LogManager.GetCurrentClassLogger(); | |
| 11 | + | |
| 12 | + public static async Task<string> LoadTextFromAssetAsync(string resourcePathPrefix, string resourceRelativePath) | |
| 13 | + { | |
| 14 | + Uri resourceUri = CreateAssetUri(resourcePathPrefix, resourceRelativePath); | |
| 15 | + | |
| 16 | + return await LoadTextFromUriAsync(resourceUri); | |
| 17 | + } | |
| 18 | + | |
| 19 | + | |
| 20 | + public static async Task<string> LoadTextFromResourceAsync(string resourcePathPrefix, string resourceRelativePath, Assembly assembly = null) | |
| 21 | + { | |
| 22 | + Uri resourceUri = CreateResourceUri(assembly, resourcePathPrefix, resourceRelativePath); | |
| 23 | + | |
| 24 | + return await LoadTextFromUriAsync(resourceUri); | |
| 25 | + } | |
| 26 | + | |
| 27 | + private static async Task<string> LoadTextFromUriAsync(Uri resourceUri) | |
| 28 | + { | |
| 29 | + try | |
| 30 | + { | |
| 31 | + var file = await StorageFile.GetFileFromApplicationUriAsync(resourceUri).AsTask().ConfigureAwait(false); | |
| 32 | + var content = await FileIO.ReadTextAsync(file).AsTask().ConfigureAwait(false); | |
| 33 | + | |
| 34 | + return content; | |
| 35 | + } | |
| 36 | + catch (SystemException e) | |
| 37 | + { | |
| 38 | + logger.Error(e); | |
| 39 | + throw new ApplicationException($"リソーステキスト {resourceUri} の読み込みに失敗しました", e); | |
| 40 | + } | |
| 41 | + } | |
| 42 | + | |
| 43 | + public static BitmapImage LoadBitmapFromAsset(string resourcePathPrefix, string resourceRelativePath) | |
| 44 | + { | |
| 45 | + Uri resourceUri = CreateAssetUri(resourcePathPrefix, resourceRelativePath); | |
| 46 | + | |
| 47 | + return LoadBitmapFromUri(resourceUri); | |
| 48 | + } | |
| 49 | + | |
| 50 | + public static BitmapImage LoadBitmapFromResource(string resourcePathPrefix, string resourceRelativePath, Assembly assembly = null) | |
| 51 | + { | |
| 52 | + Uri resourceUri = CreateResourceUri(assembly, resourcePathPrefix, resourceRelativePath); | |
| 53 | + | |
| 54 | + return LoadBitmapFromUri(resourceUri); | |
| 55 | + } | |
| 56 | + | |
| 57 | + private static BitmapImage LoadBitmapFromUri(Uri resourceUri) | |
| 58 | + { | |
| 59 | + try | |
| 60 | + { | |
| 61 | + /// <see cref="https://stackoverflow.com/questions/347614/storing-wpf-image-resources"/> | |
| 62 | + return new BitmapImage(resourceUri); | |
| 63 | + } | |
| 64 | + catch (SystemException e) | |
| 65 | + { | |
| 66 | + logger.Error(e); | |
| 67 | + throw new ApplicationException($"リソース画像 {resourceUri} の読み込みに失敗しました", e); | |
| 68 | + } | |
| 69 | + } | |
| 70 | + | |
| 71 | + private static Uri CreateAssetUri(string resourcePathPrefix, string resourceRelativePath) | |
| 72 | + { | |
| 73 | + string resourcePath = CreateResourcePath(resourcePathPrefix, resourceRelativePath); | |
| 74 | + | |
| 75 | + Uri resourceUri = CreateAssetUri(resourcePath); | |
| 76 | + | |
| 77 | + return resourceUri; | |
| 78 | + } | |
| 79 | + | |
| 80 | + private static Uri CreateResourceUri(Assembly assembly, string resourcePathPrefix, string resourceRelativePath) | |
| 81 | + { | |
| 82 | + if (assembly == null) | |
| 83 | + { | |
| 84 | + assembly = Assembly.GetCallingAssembly(); | |
| 85 | + } | |
| 86 | + | |
| 87 | + string assemblyName = assembly.GetName().Name; | |
| 88 | + | |
| 89 | + string resourcePath = CreateResourcePath(resourcePathPrefix, resourceRelativePath); | |
| 90 | + | |
| 91 | + Uri resourceUri = CreateResourceUri(assemblyName, resourcePath); | |
| 92 | + | |
| 93 | + return resourceUri; | |
| 94 | + } | |
| 95 | + | |
| 96 | + private static string CreateResourcePath(string resourcePathPrefix, string resourceRelativePath) | |
| 97 | + { | |
| 98 | + if (resourcePathPrefix == null) | |
| 99 | + { | |
| 100 | + resourcePathPrefix = String.Empty; | |
| 101 | + } | |
| 102 | + | |
| 103 | + if (resourcePathPrefix.StartsWith("/")) | |
| 104 | + { | |
| 105 | + resourcePathPrefix = resourcePathPrefix[1..]; | |
| 106 | + } | |
| 107 | + | |
| 108 | + string resourcePath = resourcePathPrefix + resourceRelativePath; | |
| 109 | + return resourcePath; | |
| 110 | + } | |
| 111 | + | |
| 112 | + private static Uri CreateAssetUri(string resourcePath) | |
| 113 | + { | |
| 114 | + string resourceUriPath = string.Format(@"ms-appx:///Assets/{0}", resourcePath); | |
| 115 | + Uri resourceUri = new(resourceUriPath, UriKind.Absolute); | |
| 116 | + | |
| 117 | + return resourceUri; | |
| 118 | + } | |
| 119 | + | |
| 120 | + private static Uri CreateResourceUri(string assemblyName, string resourcePath) | |
| 121 | + { | |
| 122 | + string resourceUriPath = string.Format(@"pack://application:,,,/{0};component/{1}", assemblyName, resourcePath); | |
| 123 | + Uri resourceUri = new(resourceUriPath, UriKind.Absolute); | |
| 124 | + | |
| 125 | + return resourceUri; | |
| 126 | + } | |
| 127 | + } | |
| 128 | +} |
| @@ -0,0 +1,66 @@ | ||
| 1 | +using CleanAuLait.Adaptor.Boundary.Gateway.UI.Dialog; | |
| 2 | +using CleanAuLait.Core.Resource; | |
| 3 | +using System.Windows; | |
| 4 | + | |
| 5 | +namespace CleanAuLait.Adaptor.Gateway.UI.Dialog | |
| 6 | +{ | |
| 7 | + public class UserDialogProxy : IUserDialogProxy | |
| 8 | + { | |
| 9 | + private readonly ICaptionFormatter captionFormatter; | |
| 10 | + | |
| 11 | + public UserDialogProxy( | |
| 12 | + ICaptionFormatter captionFormatter) | |
| 13 | + { | |
| 14 | + this.captionFormatter = captionFormatter; | |
| 15 | + } | |
| 16 | + | |
| 17 | + public void ShowInfo(string msg) | |
| 18 | + { | |
| 19 | + ShowInfo(msg, null); | |
| 20 | + } | |
| 21 | + | |
| 22 | + public void ShowInfo(string msg, string caption) | |
| 23 | + { | |
| 24 | + string infoCaption = captionFormatter.GetInfoCaption(caption); | |
| 25 | + ShowNotify(infoCaption, msg); | |
| 26 | + } | |
| 27 | + | |
| 28 | + public void ShowWarn(string msg) | |
| 29 | + { | |
| 30 | + ShowWarn(msg, null); | |
| 31 | + } | |
| 32 | + | |
| 33 | + public void ShowWarn(string msg, string caption) | |
| 34 | + { | |
| 35 | + string warnCaption = captionFormatter.GetWarnCaption(caption); | |
| 36 | + ShowNotify(warnCaption, msg); | |
| 37 | + } | |
| 38 | + | |
| 39 | + public void ShowError(Exception e) | |
| 40 | + { | |
| 41 | + ShowError(e, null); | |
| 42 | + } | |
| 43 | + | |
| 44 | + public void ShowError(Exception e, string caption) | |
| 45 | + { | |
| 46 | + string errorCaption = captionFormatter.GetExceptionCaption(e, caption); | |
| 47 | + ShowNotify(errorCaption, e.Message); | |
| 48 | + } | |
| 49 | + | |
| 50 | + public void ShowError(string msg) | |
| 51 | + { | |
| 52 | + ShowError(msg, null); | |
| 53 | + } | |
| 54 | + | |
| 55 | + public void ShowError(string msg, string caption) | |
| 56 | + { | |
| 57 | + string errorCaption = captionFormatter.GetErrorCaption(caption); | |
| 58 | + ShowNotify(errorCaption, msg); | |
| 59 | + } | |
| 60 | + | |
| 61 | + public void ShowNotify(string caption, string msg) | |
| 62 | + { | |
| 63 | + MessageBox.Show(msg, caption); | |
| 64 | + } | |
| 65 | + } | |
| 66 | +} |