Esempio n. 1
0
        public bool Equals(DestinyRecordComponent input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     State == input.State ||
                     (State != null && State.Equals(input.State))
                     ) &&
                 (
                     Objectives == input.Objectives ||
                     (Objectives != null && Objectives.SequenceEqual(input.Objectives))
                 ) &&
                 (
                     IntervalObjectives == input.IntervalObjectives ||
                     (IntervalObjectives != null && IntervalObjectives.SequenceEqual(input.IntervalObjectives))
                 ) &&
                 (
                     IntervalsRedeemedCount == input.IntervalsRedeemedCount ||
                     (IntervalsRedeemedCount.Equals(input.IntervalsRedeemedCount))
                 ) &&
                 (
                     CompletedCount == input.CompletedCount ||
                     (CompletedCount.Equals(input.CompletedCount))
                 ) &&
                 (
                     RewardVisibilty == input.RewardVisibilty ||
                     (RewardVisibilty != null && RewardVisibilty.SequenceEqual(input.RewardVisibilty))
                 ));
        }
Esempio n. 2
0
        public async void StartDownload()
        {
            try
            {
                var taskCount = App.IsPro ? 15 : 1;
                var groups    = Book.CatalogList.Split <BookCatalog>(taskCount);

                var enumerable = groups as IEnumerable <BookCatalog>[] ?? groups.ToArray();
                if (groups == null || !enumerable.Any())
                {
                    return;
                }

                var tasks = new Task[enumerable.Length];

                _timer = new DispatcherTimer {
                    Interval = TimeSpan.FromMilliseconds(1000)
                };
                _timer.Tick += Timer_Tick;
                _timer.Start();

                for (var i = 0; i < enumerable.Length; i++)
                {
                    if (IsDelete)
                    {
                        break;
                    }

                    tasks[i] = await Task.Factory.StartNew(async() =>
                    {
                        var catalogs = enumerable[i];
                        foreach (var bookCatalog in catalogs)
                        {
                            try
                            {
                                if (IsDelete)
                                {
                                    break;
                                }

                                bookCatalog.CatalogContent =
                                    await AnalisysSourceHelper.GetCatalogContent(bookCatalog.CatalogUrl);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e);
                            }
                            finally
                            {
                                lock (_obj)
                                {
                                    _completedCount += 1;
                                    _progress        = double.Parse(CompletedCount.ToString()) /
                                                       double.Parse(TotalCount.ToString()) * 100;
                                }
                            }
                        }
                    });
                }

                await Task.Factory.ContinueWhenAll(tasks, (obj) =>
                {
                    if (CompletedCount < TotalCount - 10)
                    {
                        if (!IsDelete)
                        {
                            ToastHelper.ShowMessage(Book.BookName + "下载失败", false);
                        }
                        ViewModelInstance.Instance.DownloadCenter.RemoveDownItem(this);
                        return;
                    }
                    IsCompleted = true;
                    InsertOrUpdateBookCatalogs(Book);

                    DispatcherHelper.CheckBeginInvokeOnUI(() =>
                    {
                        _timer?.Stop();
                    });
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }