예제 #1
0
        private async void OnRefreshCommand(object obj)
        {
            if (IsLoading)
            {
                CancleHttpRequest();
            }
            else
            {
                IsLoading = true;
                var result = await AnalysisBookCatalogList.GetCatalogList(CurrentBookEntity.CatalogListUrl, this.CurrentBookEntity.BookID, http = new SoDu.Core.Util.HttpHelper());

                var list = result.Item1;
                if (list != null && list.Count > 0)
                {
                    this.CurrentBookEntity.CatalogList.Clear();
                    foreach (var item in list)
                    {
                        this.CurrentBookEntity.CatalogList.Add(item);
                    }
                }
                IsLoading = false;
            }
        }
예제 #2
0
        private async void CheckUpdate()
        {
            if (IsChecking || IsLoading || IsUpdating)
            {
                return;
            }
            DispatcherHelper.CheckBeginInvokeOnUI(() =>
            {
                IsChecking = true;
            });
            if (this.LocalBookList.Count < 1)
            {
                return;
            }

            Task[] tasks = new Task[this.LocalBookList.Count];

            try
            {
                int i = 0;
                foreach (var item in LocalBookList)
                {
                    tasks[i] = Task.Run(async() =>
                    {
                        try
                        {
                            if (!string.IsNullOrEmpty(item.CatalogListUrl))
                            {
                                var result = await AnalysisBookCatalogList.GetCatalogList(item.CatalogListUrl, item.BookID, new HttpHelper());
                                if (!IsChecking)
                                {
                                    return;
                                }

                                if (result.Item1 != null)
                                {
                                    var list = result.Item1;
                                    var last = DBBookCatalog.SelectBookCatalogs(AppDataPath.GetBookDBPath(item.BookID), item.BookID);


                                    var undownLoad = list.FindAll(p => last?.FirstOrDefault(m => m.CatalogUrl == p.CatalogUrl) == null);

                                    if (undownLoad != null && undownLoad.Count > 0)
                                    {
                                        item.UnDownloadCatalogList = new ObservableCollection <BookCatalog>();
                                        undownLoad.ForEach(p => item.UnDownloadCatalogList.Add(p));
                                        DispatcherHelper.CheckBeginInvokeOnUI(() =>
                                        {
                                            item.UnReadCountData = "  " + undownLoad.Count.ToString();
                                        });
                                    }
                                    else
                                    {
                                        DispatcherHelper.CheckBeginInvokeOnUI(() =>
                                        {
                                            item.UnReadCountData = "";
                                        });
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {
                        }
                    });

                    i++;
                }

                await Task.Factory.ContinueWhenAll(tasks, (obj) =>
                {
                    DispatcherHelper.CheckBeginInvokeOnUI(() =>
                    {
                        IsChecking = false;
                    });
                });
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);

                DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                    IsChecking = false;
                });
            }
        }