Exemple #1
0
        private void RefreshItems(SavedSearchesConfigFile savedSearches)
        {
            var searches = savedSearches
                           .OrderBy(s => s.Alias)
                           .Select(s => new SavedSearchModel(s, LoadItem, DeleteItem));

            using (SavedSearches.EnterMassUpdate())
            {
                SavedSearches.Clear();
                SavedSearches.AddRange(searches);
            }

            void LoadItem(SavedSearchModel item) =>
            _relay.Send(this, new SearchChangedMessage {
                SearchTags = item.Tags
            });

            async void DeleteItem(SavedSearchModel item)
            {
                var configs = SavedSearchConfigs;

                configs.Remove(item.Config);
                await SaveAndRefreshAsync(configs);
            }
        }
Exemple #2
0
        public async Task UpdateSavedSearches(bool forceUpdate = false)
        {
            if (UpdatingSavedSearches)
            {
                return;
            }

            if (!forceUpdate && _savedSearchesLastUpdate + TimeSpan.FromMinutes(15) > DateTime.Now &&
                _savedSearchesLastScreenName == Tokens.ScreenName)
            {
                return;
            }

            UpdatingSavedSearches = true;

            SavedSearchesScreenName = Tokens.ScreenName;

            SavedSearches.Clear();
            try
            {
                var savedSearches = await Tokens.SavedSearches.ListAsync();

                if (savedSearches.Count == 0)
                {
                    UpdatingSavedSearches = false;
                    return;
                }

                SavedSearches.Clear();
                foreach (var savedSearch in savedSearches)
                {
                    SavedSearches.Add(savedSearch);
                }

                _savedSearchesLastUpdate     = DateTime.Now;
                _savedSearchesLastScreenName = Tokens.ScreenName;
            }
            catch
            {
                UpdatingSavedSearches = false;
                return;
            }

            UpdatingSavedSearches = false;
        }