Ejemplo n.º 1
0
 private BookDataStore(Dispatcher.Dispatcher dispacher)
 {
     this.dispacher         = dispacher;
     Readingbook            = new ReadingBookData();
     Endbook                = new EndingBookData();
     readingBooks           = new List <ReadingBookData>();
     this.dispacher.Action += OnAction;
 }
Ejemplo n.º 2
0
        public void OnAction(ReadingBookAction action)
        {
            switch (action.GetActionType())
            {
            case ActionType.Begin:
            {
                var book = action.GetBookDatas();
                var item = new ReadingBookData()
                {
                    Title = book.Item1, StartTime = book.Item2
                };

                if (readingBooks.Any(x => x.Title == book.Item1))
                {
                    return;
                }
                if (string.IsNullOrEmpty(item.Title))
                {
                    return;
                }

                readingBooks.Add(item);
                Readingbook = item;
                ReadingBookEventHandler?.Invoke(Readingbook);
                break;
            }

            case ActionType.End:
            {
                var book = action.GetBookDatas();
                if (string.IsNullOrEmpty(book.Item1))
                {
                    return;
                }

                TimeSpan time;
                var      findbook = readingBooks.FirstOrDefault(x => x.Title == book.Item1);
                try
                {
                    time = book.Item2 - findbook.StartTime;
                }
                catch (NullReferenceException e)
                {
                    Console.WriteLine("readingbook null :" + e);
                    return;
                }

                var item = new EndingBookData {
                    Title = book.Item1, ReadingTime = time
                };

                Endbook = item;
                EndBookEventHandler?.Invoke(Endbook);
                break;
            }
            }
        }
Ejemplo n.º 3
0
 private void BookDataStore_EndBookEventHandler(EndingBookData books)
 {
     EndReadingBookList.Add(books);
     OnPropertyChanged(nameof(EndReadingBookList));
 }