Ejemplo n.º 1
0
        //public InteractionRequest<Notification> AddRequest { get; } = new InteractionRequest<Notification>();

        //public InteractionRequest<Notification> EditRequest { get; } = new InteractionRequest<Notification>();

        public MetadataImportSettingDialogViewModel(IDirectoryNameParserManager directoryNameParserManager)
        {
            DirectoryNameParserManager = directoryNameParserManager;
            DirectoryNameParsers       = DirectoryNameParserManager
                                         .Items
                                         .ToReadOnlyReactiveCollection(x => new DirectoryNameParserViewModel(DirectoryNameParserManager, x));
            UpCommand = SelectedParser
                        .Select(x => x != null &&
                                DirectoryNameParserManager.Items.Count >= 2 &&
                                GetIndex(x.Model) > 0)
                        .ToReactiveCommand();
            UpCommand
            .Subscribe(() => Up());
            DownCommand = SelectedParser
                          .Select(x => x != null &&
                                  DirectoryNameParserManager.Items.Count >= 2 &&
                                  GetIndex(x.Model) < DirectoryNameParserManager.Items.Count - 1)
                          .ToReactiveCommand();
            DownCommand
            .Subscribe(() => Down());
            AddCommand
            .Select(_ => new DirectoryNameParser())
            .Subscribe(x =>
                       throw new NotImplementedException()
                       //AddRequest.Raise(new Notification
                       //{
                       //    Title = Resources.EditMetadataImportSettingDialogTitle_Add,
                       //    Content = x
                       //})
                       );
            EditCommand = SelectedParser
                          .Select(x => x != null)
                          .ToReactiveCommand();
            EditCommand
            .Select(_ => SelectedParser.Value.Model)
            .Subscribe(x =>
                       throw new NotImplementedException()
                       //EditRequest.Raise(new Notification
                       //{
                       //    Title = Resources.EditMetadataImportSettingDialogTitle_Edit,
                       //    Content = x
                       //})
                       );
            RemoveCommand = SelectedParser
                            .Select(x => x != null)
                            .ToReactiveCommand();
            RemoveCommand
            .Subscribe(() => Remove());
            CloseCommand
            .Subscribe(dialog =>
            {
                DirectoryNameParserManager.Save();
                dialog.DialogResult = true;
            });
        }
        public CollectionViewModel(TProperty property, ViewModelFactory factory) : base(property)
        {
            Collection = property.Collection.ToReadOnlyReactiveCollection(x =>
            {
                IPropertyViewModel vm = null;
                try
                {
                    vm = factory.Create(x);
                }
                catch (Exception e)
                {
                    OnErrorSubject.OnNext(e);
                    return(null);
                }
                vm.OnChanged.Subscribe(y => OnChangedSubject.OnNext(Unit.Default));
                vm.OnError.Subscribe(e => OnErrorSubject.OnNext(e));
                return(vm);
            });

            FormatedString = Property.Count.Select(x => $"Count = {x}")
                             .ToReactiveProperty(mode: ReactivePropertyMode.RaiseLatestValueOnSubscribe);

            AddCommand.Subscribe(x =>
            {
                try
                {
                    Property.AddNewElement();
                }
                catch (Exception e)
                {
                    OnErrorSubject.OnNext(e);
                }
                OnChangedSubject.OnNext(Unit.Default);
            });
            RemoveCommand.Subscribe(x =>
            {
                try
                {
                    Property.RemoveElementAt(x);
                }
                catch (Exception e)
                {
                    OnErrorSubject.OnNext(e);
                }
                OnChangedSubject.OnNext(Unit.Default);
            });
            EditCommand.Subscribe(x => ShowDetailSubject.OnNext(this));

            UpCommand.Subscribe(x =>
            {
                Property.Move(x - 1, x);
                SelectedIndex.Value = x - 1;
            });
            DownCommand.Subscribe(x =>
            {
                Property.Move(x + 1, x);
                SelectedIndex.Value = x;
            });

            DuplicateCommand.Subscribe(x =>
            {
                Property.Duplicate(x, x + 1);
            });
        }