예제 #1
0
        public async Task<XCollection<Book>> GetAndRefreshMyBooks(CancellationToken cancellationToken)
		{
			string limit = string.Format("{0},{1}", 0, BooksInPage);

			var parameters = new Dictionary<string, object>
					{
						{"my", 1},			
#if PDF_ENABLED	
                        {"search_types", "0,4"},	
#else
                        {"search_types", "0"},	
#endif
						{"limit", limit},					
					};
			
			var books = await _client.GetMyBooks(parameters, cancellationToken);

            if (_myBooksByTime == null)
            {
                _myBooksByTime = new XCollection<Book>();
                _myBooksByTime.Update(books.Books);
            }

			if (books != null && books.Books != null && books.Books.Count > 0)
			{
				books.Books.ForEach( x => x.IsMyBook = true );

                if(_myBooksByTime != null && _myBooksByTime.Count > 0)
                {
                    var selfServiceMessage = new StringBuilder();
                    _myBooksByTime.ForEach(myBook =>
                    {
                        try
                        {
                            var book = books.Books.First(bk => bk.Id.Equals(myBook.Id));

                            if (!string.IsNullOrEmpty(myBook.SelfServiceMyRequest) && myBook.SelfServiceMyRequest.Equals("1"))
                            {
                                if (!string.IsNullOrEmpty(book.SelfServiceMyRequest) && book.SelfServiceMyRequest.Equals("0"))
                                {
                                    myBook.SelfService = book.SelfService;
                                    myBook.SelfServiceMyRequest = book.SelfServiceMyRequest;
                                    myBook.ExpiredDateStr = book.ExpiredDateStr;
                                    selfServiceMessage.AppendLine(book.Description.Hidden.TitleInfo.BookTitle);
                                }                                
                            }

                            books.Books.Remove(book);
                        }
                        catch (Exception ex)
                        {}                                                
                    });

                    if (books.Books != null && books.Books.Count > 0)
                    {
                        _myBooksByTime.AddRange(books.Books);
                    }

                    if (selfServiceMessage.Length > 0)
                    {
                        await new MessageDialog("Вам выданы книги:", selfServiceMessage.ToString()).ShowAsync();
                        //Deployment.Current.Dispatcher.BeginInvoke(() => MessageBox.Show(selfServiceMessage.ToString(), "Вам выданы книги:", MessageBoxButton.OK));
                    }
                }

                _myBooksByTime.BeginUpdate();
                _myBooksByTime.EndUpdate();

                _dataCacheService.PutItem(_myBooksByTime, ReadingBooksCacheItemName, cancellationToken);

                AddIdsToMyBooks(_myBooksByTime);
                CheckBooks();
			}
            			
			return _myBooksByTime;
		}