예제 #1
0
        public void SetStarred(SetViewModel set, bool starred, Action completed, Action <Exception> errorHandler)
        {
            if (starred == set.Starred)
            {
                return;
            }

            api.SetStarred(
                set.ID,
                starred,
                delegate {
                cache.SetStarred(set.ID, starred);

                if (starred)
                {
                    FavouriteSets.Add(set);
                }
                else
                {
                    FavouriteSets.Remove(set);
                }

                set.Starred = starred;
                completed();
            },
                errorHandler,
                new CancellationToken());
        }
예제 #2
0
        public void LoadData()
        {
            if (IsDataLoaded)
            {
                return;
            }

            try {
                Metrics.Measure("MainViewModel.LoadData()", delegate {
                    Metrics.Measure("Load ModelCache", delegate {
                        cache = api.Credentials != null
                                                        ? new ModelCache(api.Credentials)
                                                        : new ModelCache();
                    });

                    if (cache.Credentials == null)
                    {
                        return;
                    }

                    if (!api.Authenticate(cache.Credentials))
                    {
                        cache.LogOut();
                        LogOut();
                        return;
                    }

                    UserName = cache.Credentials.UserName;

                    Metrics.Measure("Create group view models", delegate {
                        foreach (var si in cache.GetMySets())
                        {
                            MySets.Add(new SetViewModel(this, si));
                        }

                        foreach (var si in cache.GetRecentSets().Take(8))
                        {
                            RecentSets.Add(new SetViewModel(this, si));
                        }

                        foreach (var si in cache.GetFavourites())
                        {
                            FavouriteSets.Add(new SetViewModel(this, si)
                            {
                                Starred = true
                            });
                        }
                    });

                    Metrics.Measure("Create group view models", delegate {
                        foreach (var gi in cache.GetGroups())
                        {
                            Groups.Add(new GroupViewModel(this, gi));
                        }
                    });

                    Metrics.Measure("Load profile image", LoadProfileImage);

                    IsDataLoaded = true;
                });
            } catch (CacheIndexMissingException) {
                // XXX This will never happen
            }
        }