Пример #1
0
        public async Task RefreshAsync(bool saveNewQuestions = true)
        {
            // Load tags from file
            var localTags = await _LocalStorageService.LoadFromFileAsync <ObservableCollection <string> >("tags.json");

            if (localTags != null)
            {
                Tags = localTags;
            }

            if (Tags.Count == 0)
            {
                // Preset some tags
                Tags.Add("windows-10");
                Tags.Add("office365");
                Tags.Add("azure");
            }

            // Load questions for all tags
            var questionLists = new List <IEnumerable <Question> >();

            foreach (var tag in Tags)
            {
                var questionsForTag = await _StackOverflowService.GetUnansweredQuestionByTag(tag);

                questionLists.Add(questionsForTag);
            }

            // Merge and oder questions, remove dublicates
            var orderedQuestions = _StackOverflowService.MergeQuestions(questionLists);

            // Mark new questions
            var oldQuestions = await _LocalStorageService.LoadFromFileAsync <ObservableCollection <Question> >("questions.json");

            if (oldQuestions != null)
            {
                NewQuestionCount = _StackOverflowService.MarkNewQuestions(orderedQuestions, oldQuestions);
            }

            // Sync questions with ViewModel
            Questions = new ObservableCollection <Question>(orderedQuestions);

            // Save questions locally
            if (saveNewQuestions)
            {
                await _LocalStorageService.SaveToFileAsync("questions.json", Questions);
            }
        }
Пример #2
0
        public async Task LoadSettingsAsync()
        {
            var configuration = await _LocalStorageService.LoadFromFileAsync <Settings>(_SettingsFileName);

            if (configuration != null)
            {
                Settings = configuration;
            }
            else
            {
                Settings = new Settings();
            }

            IsLoaded = true;
        }