Candy.Client.Models.ApplicationManager.RemoveApplicationAsync C# (CSharp) Method

RemoveApplicationAsync() public method

public RemoveApplicationAsync ( Candy.Client.Models.InstalledApplication app ) : System.Threading.Tasks.Task
app Candy.Client.Models.InstalledApplication
return System.Threading.Tasks.Task
        public async Task RemoveApplicationAsync(InstalledApplication app)
        {
            if (!app.CanRemove)
            {
                RaiseError("このアプリケーションを登録解除することはできません。");
            }

            Applications.Remove(app);

            await SaveAsync().ConfigureAwait(false);
        }

Usage Example

Example #1
0
        public ApplicationViewModel(ApplicationManager manager, InstalledApplication app)
        {
            _app = app;

            DisplayName = app.ObserveProperty(x => x.DisplayName).ToReactiveProperty();
            Definition = app.ObserveProperty(x => x.Definition).ToReactiveProperty();
            InstalledPath = app.ObserveProperty(x => x.InstalledPath).ToReactiveProperty();
            IsApplicationMissing = InstalledPath.Select(File.Exists).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"
                });
            });
        }