Exemplo n.º 1
0
 public void LoadHistory()
 {
   _history.Clear();
   if (System.IO.File.Exists(_historyFileName))
   {
     BookInfo info = null;
     string[] lines = System.IO.File.ReadAllLines(_historyFileName, Encoding.UTF8);
     foreach (string s in lines)
     {
       int i = s.IndexOf(' ');
       if (i == -1) continue;
       string tag = s.Substring(0, i );
       string value = s.Substring(i + 1);
       switch (tag)
       {
         case "file":
           info = new BookInfo() { FileName = value };
           if (System.IO.File.Exists(info.FileName))
           {
             _history.Add(info);
           }
           break;
         case "bookmarks":
           {
             info.Bookmarks = new List<int>();
             string[] marks = value.Split(' ');
             for (int k = 0; k < marks.Length; k++)
             {
               if (string.IsNullOrEmpty(marks[k])) continue;
               info.Bookmarks.Add(int.Parse(marks[k]));
             }
           }
           break;
         case "wordindex":
           info.WordIndex = int.Parse(value);
           break;
         case "lasttime":
           info.LastTime = DateTime.Parse(value);
           break;
         case "title":
           info.Title = value;
           break;
         case "author":
           info.Author = value;
           break;
         case "comment":
           info.Comment = value;
           break;
       }
     }
   }
   if(_history.Count > 0)
   {
     this.CurrentBook = _history[0];
   }
 }
Exemplo n.º 2
0
 public BookInfo GetBookInfo(Guid idBook)
 {
   BookInfo book = new BookInfo();
   DataRow[] rows = this.DataSource.Select("id='" + idBook.ToString() + "'");
   if (rows.Length == 1)
   {
     book.Id = idBook;
     book.WordIndex = (int)rows[0]["WordIndex"];
     book.Location = (string)rows[0]["Location"];
   }
   return book;
 }
Exemplo n.º 3
0
 public void SaveBookInfo(BookInfo book)
 {
   DataRow[] rows = this.DataSource.Select("id='" + book.Id.ToString() + "'");
   if (rows.Length == 1)
   {
     rows[0]["WordIndex"] = book.WordIndex;
     rows[0]["LastOpenDate"] = DateTime.Now;
     this.Save();
   }
 }
Exemplo n.º 4
0
 public BookInfo SetCurrentBook(string fileName)
 {
   this.CurrentBook = _history.Find((book) => { return book.FileName.Equals(fileName, StringComparison.InvariantCultureIgnoreCase); });
   this.CurrentBook.LastTime = DateTime.Now;
   return this.CurrentBook;
 }
Exemplo n.º 5
0
 public void Add(string fileName)
 {
   fileName = fileName.Replace('\\', '/');
   BookInfo info = _history.Find((book) => { return book.FileName.Equals(fileName, StringComparison.InvariantCultureIgnoreCase); });
   if(info == null)
   {
     info = new BookInfo();
     info.FileName = fileName;
     _history.Add(info);
   }
   this.SetCurrentBook(fileName);
   this.SaveHistory();
 }