Ejemplo n.º 1
0
        public async Task <FullTextEntry> GetEntryWithHash(String hash)
        {
            FullTextEntry entry = new FullTextEntry();

            await Task.Run(() =>
            {
                _db.ReOpenIfNecessary();

                using (SQLiteCommand com = _db.Command())
                {
                    com.CommandText = "SELECT * FROM " + DATABASE_TABLE + " WHERE "
                                      + KEY_ROWID + " LIKE " + "'" + hash + "'";

                    using (SQLiteDataReader reader = com.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            entry = CursorToFullTextEntry(reader);
                        }
                    }
                }
            });

            return(entry);
        }
Ejemplo n.º 2
0
 public void Add(T entry)
 {
     if (typeof(T) == typeof(Article))
     {
         Article a = entry as Article;
         _setOfIds.Add(a?.Regnrs);
     }
     else if (typeof(T) == typeof(FullTextEntry))
     {
         FullTextEntry e = entry as FullTextEntry;
         _setOfIds.Add(e?.Hash);
     }
     _setOfEntries.Add(entry);
 }
Ejemplo n.º 3
0
        private FullTextEntry CursorToFullTextEntry(SQLiteDataReader reader)
        {
            FullTextEntry entry = new FullTextEntry();

            entry.Hash       = reader[KEY_ROWID] as string;
            entry.Keyword    = reader[KEY_KEYWORD] as string;
            entry.IsFavorite = _favorites.Contains(entry.Hash);

            string regnrsAndChapters = reader[KEY_REGNR] as string;

            string[] rac = regnrsAndChapters?.Split('|');
            // Remove double entries by using a set
            var set  = new HashSet <string>(rac);
            var dict = new Dictionary <string, HashSet <string> >();

            foreach (string r in set)
            {
                string chapters = "";
                string regnr    = "";
                // Extract chapters from parentheses, format 58444(6,7,8)
                if (r.Contains("("))
                {
                    int idx = r.IndexOf("(");
                    int len = r.Length - idx - 2;   // Exclude last parenthesis
                    chapters = r.Substring(r.IndexOf("(") + 1, len);
                    regnr    = r.Substring(0, idx); // Registration number
                }
                if (regnr.Length > 0)
                {
                    HashSet <string> chaptersSet = new HashSet <string>();
                    if (dict.ContainsKey(regnr))
                    {
                        chaptersSet = dict[regnr];
                    }
                    string[] c = chapters.Split(',');
                    foreach (string chapter in c)
                    {
                        chaptersSet.Add(chapter.Trim());
                    }
                    // Update dictionary
                    dict[regnr] = chaptersSet;
                }
            }
            entry.RegChaptersDict = dict;

            return(entry);
        }
Ejemplo n.º 4
0
        public async void UpdateFavorites(FullTextEntry entry)
        {
            if (_favorites.Contains(entry?.Hash))
            {
                _favorites.Remove(entry);
            }
            else
            {
                if (entry.Hash != null)
                {
                    _favorites.Add(entry);
                }
            }
            // Save list of favorites to file
            await _favorites.Save();

            // Update list of found entries
            foreach (FullTextEntry e in _foundEntries)
            {
                e.IsFavorite = _favorites.Contains(e?.Hash);
            }
        }
Ejemplo n.º 5
0
 public void Remove(T entry)
 {
     if (typeof(T) == typeof(Article))
     {
         Article a      = entry as Article;
         var     regnrs = a?.Regnrs;
         if (regnrs != null)
         {
             _setOfIds.Remove(regnrs);
             _setOfEntries.RemoveWhere(e1 => (e1 as Article).Regnrs.Equals(regnrs));
         }
     }
     else if (typeof(T) == typeof(FullTextEntry))
     {
         FullTextEntry e    = entry as FullTextEntry;
         var           hash = e?.Hash;
         if (hash != null)
         {
             _setOfIds.Remove(hash);
             _setOfEntries.RemoveWhere(e2 => (e2 as FullTextEntry).Hash.Equals(hash));
         }
     }
 }