Ejemplo n.º 1
0
        public QuestionBlockListViewModel(Api api, OptionsViewModel options)
        {
            _api           = api;
            QuestionBlocks = new ReactiveList <QuestionBlockViewModel>();

            var selectedSiteList = options.SelectedSites;

            selectedSiteList.Changed
            .Where(args => args.Action == NotifyCollectionChangedAction.Add)
            .SelectMany(args => args.NewItems
                        .OfType <StackExchangeSite>()
                        .Select(site => CreateQuestionBlock(site, options.QuestionsPerBlock)))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(block => QuestionBlocks.Add(block));

            selectedSiteList.Changed
            .Where(args => args.Action == NotifyCollectionChangedAction.Remove)
            .SelectMany(args => args.OldItems
                        .OfType <StackExchangeSite>()
                        .Select(site => QuestionBlocks.FirstOrDefault(qb => qb.Site.api_site_parameter == site.api_site_parameter)))
            .Where(qb => qb != null)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(qb => QuestionBlocks.Remove(qb));

            options.WhenAnyValue(o => o.UpdateInterval)
            .CombineLatest(options.WhenAnyValue(o => o.QuestionsPerBlock), (interval, questionCount) => new { interval, questionCount })
            .Select(a => Observable.Interval(TimeSpan.FromMinutes(a.interval))
                    .Select(_ => a.questionCount)
                    .StartWith(a.questionCount))
            .Switch()
            .SelectMany(questionCount => ReloadAllQuestions(questionCount))
            .Subscribe();
        }
Ejemplo n.º 2
0
        public void AddProcessInstance(IProcessInstanceViewModel instance)
        {
            var subscription = instance.ProcessTerminated.ObserveOnDispatcher().Subscribe(@event =>
            {
                _processInstances.Remove(instance);
            });

            _processInstances.Add(instance);
        }
Ejemplo n.º 3
0
        internal void RemoveBubble(BubbleViewModel bubble)
        {
            if (bubble == null)
            {
                throw new ArgumentNullException("bubble");
            }

            _bubblesInternal.Remove(bubble);
        }
Ejemplo n.º 4
0
        protected BaseMenuViewModel(IAccountsService accountsService)
        {
            AccountsService = accountsService;
            DeletePinnedRepositoryCommand = new ReactiveCommand();
            PinnedRepositories            = new ReactiveList <PinnedRepository>(AccountsService.ActiveAccount.PinnnedRepositories);

            DeletePinnedRepositoryCommand.OfType <PinnedRepository>()
            .Subscribe(x =>
            {
                AccountsService.ActiveAccount.PinnnedRepositories.RemovePinnedRepository(x.Id);
                PinnedRepositories.Remove(x);
            });
        }
Ejemplo n.º 5
0
        private void DoUpdate(IChangeSet <TObject, TKey> changes)
        {
            foreach (var change in changes)
            {
                switch (change.Reason)
                {
                case ChangeReason.Add:
                    _target.Add(change.Current);
                    break;

                case ChangeReason.Remove:
                    _target.Remove(change.Current);
                    break;

                case ChangeReason.Update:
                {
                    _target.Remove(change.Previous.Value);
                    _target.Add(change.Current);
                }
                break;
                }
            }
        }
Ejemplo n.º 6
0
        protected BaseMenuViewModel(IAccountsService accountsService)
        {
            AccountsService = accountsService;
            DeletePinnedRepositoryCommand = ReactiveCommand.Create();
            PinnedRepositories = new ReactiveList<PinnedRepository>(AccountsService.ActiveAccount.PinnnedRepositories);

            DeletePinnedRepositoryCommand.OfType<PinnedRepository>()
                .Subscribe(x =>
                {
                    AccountsService.ActiveAccount.PinnnedRepositories.Remove(x);
                    AccountsService.Update(AccountsService.ActiveAccount);
                    PinnedRepositories.Remove(x);
                });
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Constructor when instantiating self-saving object
        /// </summary>
        /// <param name="path">Path to save</param>
        /// <param name="marshallManager">Marshaller dependency</param>
        public SystemMapping(string path, IMarshallManager marshallManager)
        {
            Mappings = new ReactiveList <Mapping> {
                ChangeTrackingEnabled = true
            };
            Observable.Merge(
                Mappings.ItemChanged.Select(x => Unit.Default),
                Mappings.ItemsAdded.Select(x => Unit.Default),
                Mappings.ItemsRemoved.Select(x => Unit.Default)
                ).Sample(TimeSpan.FromSeconds(1)).Subscribe(x => Save(path, marshallManager));

            // if mapping goes stale, remove it.
            Mappings.ItemChanged.Subscribe(e => {
                var mapping = e.Sender;
                if (mapping.IsStale)
                {
                    Mappings.Remove(mapping);
                }
            });
        }