Inheritance: NotificationObject
Ejemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public async Task LoadAsync(ApplicationManager obj)
        {
            var jsonText = await ReadJsonAsync().ConfigureAwait(false);
            if (jsonText == null) return;

            var json = JsonConvert.DeserializeObject<ApplicationManager>(jsonText, new InstalledApplicationConverter());

            Mapper.Map(json, obj);
        }
Ejemplo n.º 2
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            // C:\Users\<User>\AppData\Local\Planet\Candy に保存する。
            // 将来的に、この設定ファイルに Candy.Updater.exe のパスを持たせることで、
            // 各アプリケーションからも更新処理が呼べるようにするため
            var appSettings = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            var settingsDirectory = Path.Combine(appSettings, "Planet", "Candy");
            var repository = new JsonFileStateRepository(Path.Combine(settingsDirectory, "settings.json"));

            var model = new ApplicationManager(repository);
            var window = new MainWindow
            {
                DataContext = new MainWindowViewModel(model)
            };

            window.ShowDialog();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public async Task SaveAsync(ApplicationManager obj)
        {
            var json = JsonConvert.SerializeObject(obj, Formatting.Indented);

            using (await _fileLock.LockAsync())
            {
                var dir = new DirectoryInfo(Path.GetDirectoryName(_settingFilePath));
                if (!dir.Exists)
                {
                    dir.Create();
                }

                using (var stream = File.OpenWrite(_settingFilePath))
                using (var writer = new StreamWriter(stream))
                {
                    stream.SetLength(0);
                    await writer.WriteAsync(json).ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 4
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"
                });
            });
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="manager"></param>
        public MainWindowViewModel(ApplicationManager manager)
        {
            _manager = manager;
            _manager.Error += manager_Error;
            _applications = _manager.Applications.ToSyncedSynchronizationContextCollection(x => new ApplicationViewModel(_manager, x), SynchronizationContext.Current);

            IsSettingsOpen = new ReactiveProperty<bool>(false);
            IsDetailsOpen = new ReactiveProperty<bool>(false);
            IsProgressActive = new ReactiveProperty<bool>(false);

            ShowWindowRightCommands = IsSettingsOpen.CombineLatest(IsDetailsOpen, (a, b) => !a && !b)
                                                    .ToReactiveProperty();

            InitialDirectory = _manager.Settings.ToReactivePropertyAsSynchronized(x => x.ApplicationRootDirectoryPath);

            ShowHelpCommand = new ReactiveCommand();
            ShowHelpCommand.Subscribe(_ => ShowHelp());

            RegisterApplicationCommand = IsProgressActive.Select(x => !x).ToReactiveCommand();
            RegisterApplicationCommand.Subscribe(_ => RegisterApplication());

            InstallApplicationCommand = IsProgressActive.Select(x => !x).ToReactiveCommand();
            InstallApplicationCommand.Subscribe(_ => InstallApplication());

            OpenSettingCommand = new ReactiveCommand();
            OpenSettingCommand.Subscribe(_ => ShowSettings());

            ShowDetailsCommand = new ReactiveCommand<ApplicationViewModel>();
            ShowDetailsCommand.Subscribe(ShowDetails);

            CurrentItem = new ReactiveProperty<ApplicationViewModel>();

            SettingsViewModel = new ReactiveProperty<SettingsViewModel>();
        }