Esempio n. 1
0
        public void Update(SetInfo set)
        {
            SetInfo oldSet;

            if (!sets.TryGetValue(set.ID, out oldSet))
            {
                sets.Add(set.ID, set);
            }
            else if (oldSet.Modified < set.Modified || oldSet.Terms == null || oldSet.Terms.Count == 0)
            {
                sets[set.ID] = set;
            }
        }
Esempio n. 2
0
        public void AddSetInfo(SetInfo si)
        {
            SetInfo existing;

            if (sets.TryGetValue(si.ID, out existing) && existing.Modified > si.Modified)
            {
                return;
            }

            if (!sets.ContainsKey(si.ID))
            {
                sets[si.ID] = si;
            }
        }
Esempio n. 3
0
        void LoadIndex()
        {
            try {
                using (var stream = storage.OpenFile("Index", FileMode.Open)) {
                    using (var reader = new BinaryReader(stream)) {
                        string accessToken = reader.ReadString();
                        string userName    = reader.ReadString();
                        var    tokenExpiry = new DateTime(reader.ReadInt64());
                        Credentials = new Credentials(accessToken, userName, tokenExpiry);

                        string profileImage = reader.ReadString();
                        ProfileImage = string.IsNullOrEmpty(profileImage) ? null : new Uri(profileImage, UriKind.Absolute);

                        indexDate = new DateTime(reader.ReadInt64());

                        int setCount = reader.ReadInt32();

                        sets = new Dictionary <long, SetInfo>();
                        while (setCount-- > 0)
                        {
                            var si = new SetInfo {
                                ID                     = reader.ReadInt64(),
                                Title                  = reader.ReadString(),
                                Author                 = reader.ReadString(),
                                Description            = reader.ReadString(),
                                Uri                    = new Uri(reader.ReadString()),
                                TermCount              = reader.ReadInt32(),
                                Created                = new DateTime(reader.ReadInt64()),
                                Modified               = new DateTime(reader.ReadInt64()),
                                TermLanguageCode       = reader.ReadBoolean() ? reader.ReadString() : null,
                                DefinitionLanguageCode = reader.ReadBoolean() ? reader.ReadString() : null,
                                Subjects               = new List <string>()
                            };

                            int subjectCount = reader.ReadInt32();
                            while (subjectCount-- > 0)
                            {
                                si.Subjects.Add(reader.ReadString());
                            }

                            si.Visibility = reader.ReadString();
                            si.Editable   = reader.ReadString();
                            si.HasAccess  = reader.ReadBoolean();

                            bool hasTerms = reader.ReadBoolean();

                            sets[si.ID] = si;

                            /*if (hasTerms)
                             *      LoadSetTerms(si.ID);*/
                        }

                        int groupCount = reader.ReadInt32();
                        groups = new Dictionary <long, GroupInfo>();

                        while (groupCount-- > 0)
                        {
                            var gi = new GroupInfo {
                                ID            = reader.ReadInt64(),
                                Name          = reader.ReadString(),
                                Description   = reader.ReadString(),
                                Created       = new DateTime(reader.ReadInt64()),
                                UserCount     = reader.ReadInt32(),
                                IsPublic      = reader.ReadBoolean(),
                                HasAccess     = reader.ReadBoolean(),
                                HasPassword   = reader.ReadBoolean(),
                                HasDiscussion = reader.ReadBoolean(),
                                MemberAddSets = reader.ReadBoolean(),
                                Sets          = new List <SetInfo>()
                            };

                            int groupSetCount = reader.ReadInt32();
                            while (groupSetCount-- > 0)
                            {
                                SetInfo si;
                                if (!sets.TryGetValue(reader.ReadInt64(), out si))
                                {
                                    throw new CacheException("Unknown group specified as member of a group");
                                }

                                // Don't need to make a copy; GroupInfo is a value type
                                gi.Sets.Add(si);
                            }
                            groups[gi.ID] = gi;
                        }

                        mySets        = ReadList(reader, r => r.ReadInt64());
                        favouriteSets = ReadList(reader, r => r.ReadInt64());
                        recentSets    = ReadList(reader, r => r.ReadInt64());
                    }
                }
            } catch (IsolatedStorageException e) {
                // The only non-fatal error.
                throw new CacheIndexMissingException("Unable to load application cache because the master cache file is missing", e);
            } catch (IOException) {
                // Might as well delete the cache.
                storage.DeleteFile("Index");

                // We can't have a partially-loaded cache.
                sets          = new Dictionary <long, SetInfo>();
                groups        = new Dictionary <long, GroupInfo>();
                mySets        = new List <long>();
                recentSets    = new List <long>();
                favouriteSets = new List <long>();

                // I suppose if we managed to load credentials, we can use them.
                // Thus, no need to reset them.
            }
        }