• R/O
  • HTTP
  • SSH
  • HTTPS

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

なろうブックマーク分析用ツールのPrism+WinUI3サンプル実装


File Info

Rev. 91b05482e5b7288185c0f453ccfc74c20099b04b
大小 2,138 字节
时间 2023-09-30 19:37:53
作者 yoshy
Log Message

[MOD] プロジェクト間の依存関係、外部パッケージへの依存関係の修正
[UPG] ClearAuLaitのCaptionFormatterの変更に伴う修正

Content

using NLog;
using Prism.Navigation;
using Prism.Regions;
using Reactive.Bindings;
using Reactive.Bindings.Extensions;
using System.Reactive.Disposables;
using TestNarou3.Adaptor.Boundary.Controller;
using TestNarou3.Adaptor.Boundary.Gateway.ViewModel;
using TestNarou3.Infra.Boundary.Resource;
using TestNarou3.UseCase.Request;

namespace TestNarou3.Adaptor.Gateway.ViewModel
{
    internal class MainWindowViewModel : IMainWindowViewModel, IDestructible, IDisposable
    {
        private static readonly ILogger logger = LogManager.GetCurrentClassLogger();

        public ReactiveProperty<string> Title { get; }

        private readonly IAppWindowController wc;
        private readonly IRegionManager rm;

        private readonly CompositeDisposable disposables = new();
        private bool disposedValue;

        public MainWindowViewModel(
                IAppCaptionFormatter caption,
                IAppWindowController wc,
                IRegionManager rm)
        {
            this.wc = wc;
            this.rm = rm;

            this.Title = new ReactiveProperty<string>(caption.GetDefaultCaption()).AddTo(disposables);
        }

        public void OnClosing()
        {
            _ = this.wc.Execute(new NarouLogoutRequest());
            _ = this.wc.Execute(new AppConfigSaveRequest());

            this.Dispose();
        }

        #region IDestructible, IDisposable

        public void Destroy()
        {
            this.Dispose();
        }

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    this.disposables.Dispose();

                    logger.Trace("MainWindowViewModel disposed.");

                    foreach (IRegion region in rm.Regions)
                    {
                        region.RemoveAll();
                    }
                }

                disposedValue = true;
            }
        }

        public void Dispose()
        {
            Dispose(disposing: true);
            GC.SuppressFinalize(this);
        }
        #endregion

    }
}