Candy.Client.ViewModels.ApplicationViewModel.ApplicationViewModel C# (CSharp) Method

ApplicationViewModel() public method

public ApplicationViewModel ( ApplicationManager manager, Candy.Client.Models.InstalledApplication app ) : System
manager Candy.Client.Models.ApplicationManager
app Candy.Client.Models.InstalledApplication
return System
        public ApplicationViewModel(ApplicationManager manager, InstalledApplication app)
        {
            _app = app;

            DisplayName = app.ObserveProperty(x => x.DisplayName).ToReactiveProperty();
            Definition = app.ObserveProperty(x => x.Definition).ToReactiveProperty();
            DeveloperName = app.ObserveProperty(x => x.DeveloperName).ToReactiveProperty();
            InstalledPath = app.ObserveProperty(x => x.InstalledPath).ToReactiveProperty();
            IsApplicationMissing = InstalledPath.Select(path => !File.Exists(path)).ToReactiveProperty();

            var currentVersion = app.ObserveProperty(x => x.ApplicationVersion).ToReactiveProperty();

            Version = currentVersion.Where(x => x != null)
                                    .Select(x => x.ToString())
                                    .ToReactiveProperty();

            Image64 = InstalledPath.Select(x => GetIcon(x, 64)).ToReactiveProperty();
            Image128 = InstalledPath.Select(x => GetIcon(x, 128)).ToReactiveProperty();

            Latest = app.ObserveProperty(x => x.Latest).ToReactiveProperty();

            HasUpdate = Latest.Select(x => x != null).ToReactiveProperty();
            HasUpdateMessage = HasUpdate.Select(x => x ? "最新版があります" : "お使いのバージョンは最新です").ToReactiveProperty();

            LatestVersion = Latest.CombineLatest(currentVersion, (latest, current) => latest != null ? latest.Version : current)
                                  .Where(x => x != null)
                                  .Select(x => x.ToString())
                                  .ToReactiveProperty();

            ReleaseNote = Latest.Select(x => x != null ? x.ReleaseNote : "更新情報はありません。")
                                .ToReactiveProperty();

            ExecuteCommand = new ReactiveCommand(app.ObserveProperty(x => x.CanExecute));
            ExecuteCommand.Subscribe(_ =>
            {
                app.ExecuteAsync();
            });

            UpdateCommand = new ReactiveCommand(Latest.Select(x => x != null));
            UpdateCommand.Subscribe(async _ =>
            {
                var res = await Messenger.GetResponse(new AsyncConfirmationMessage
                {
                    MessageKey = "Confirm",
                    Caption = "確認",
                    Text = app.UpdateConfirmationMessage

                }).Response;

                if (res != true) return;

                await app.UpdateAsync();

                Messenger.Raise(new AsyncInformationMessage
                {
                    MessageKey = "Close"
                });

                Messenger.Raise(new AsyncInformationMessage
                {
                    MessageKey = "Information",
                    Caption = "完了",
                    Text = "アップデートが完了しました。"
                });
            });

            RemoveCommand = new ReactiveCommand(app.ObserveProperty(x => x.CanRemove));
            RemoveCommand.Subscribe(async _ =>
            {
                var res = await Messenger.GetResponse(new AsyncConfirmationMessage
                {
                    MessageKey = "Confirm",
                    Caption = "確認",
                    Text = "アプリケーションの登録を削除してもよろしいですか?(アプリケーション自体は削除されません)"

                }).Response;

                if (res != true) return;

                await manager.RemoveApplicationAsync(app);

                Messenger.Raise(new AsyncInformationMessage
                {
                    MessageKey = "Close"
                });
            });
        }