コード例 #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();
        }
コード例 #2
0
        private async Task UpdateIssue(Issue issue)
        {
            var localIssue = IssuesBacking.FirstOrDefault(x => x.Url == issue.Url);

            if (localIssue == null)
            {
                return;
            }

            var index = IssuesBacking.IndexOf(localIssue);

            if (index < 0)
            {
                return;
            }

            var matches = System.Text.RegularExpressions.Regex.Matches(issue.Url.AbsolutePath, "/repos/([^/]+)/([^/]+)/.+");

            if (matches.Count != 1 || matches[0].Groups.Count != 3)
            {
                return;
            }

            IssuesBacking[index] = await _sessionService.GitHubClient.Issue.Get(matches[0].Groups[1].Value, matches[0].Groups[2].Value, issue.Number);

            IssuesBacking.Reset();
        }