Пример #1
0
        public async void IllustrationGrid_ItemClicked(object sender, IllustrationWrapper e)
        {
            if (NavigatingToPage)
            {
                return;
            }
            NavigatingToPage = true;

            try
            {
                NavigateTo(typeof(DetailsPage),
                           new Tuple <PixivObservableCollection, IllustrationWrapper>(((IllustrationGrid)sender).ItemSource, e));
            }
            finally
            {
                // this is a quick solution to prevent double-clicking on item and navigating to same page twice
                await Task.Delay(500).ConfigureAwait(false);

                NavigatingToPage = false;
            }
        }
Пример #2
0
 public static string GetIllustrationFileName(IllustrationWrapper illust, int pageIndex)
 => Path.GetFileName(GetImageUrl(illust, pageIndex));
Пример #3
0
 public static string GetImageUrl(IllustrationWrapper illust, int pageIndex)
 => (pageIndex == 0) ? illust.WrappedIllustration.FullImagePath : illust.GetOtherImagePath(pageIndex);
Пример #4
0
        /// <summary>
        /// This controls what Collection will be getting downloaded
        /// </summary>
        /// <param name="collection">Collection to download</param>
        /// <param name="acc">Associated account</param>
        public static void SwitchTo(PixivObservableCollection collection, PixivAccount acc)
        {
            Stop();

            var src = new CancellationTokenSource();

            tokens.Enqueue(src);

            CurrentCollection = collection;

            Task.Run(async() =>
            {
                try
                {
                    while (true)
                    {
                        // check if paused
                        if (IsPaused)
                        {
                            await Task.Delay(500);
                            continue;
                        }

                        // Infinite loop that will initially call the "getItems" callback and later on "getNextItems" on the collection
                        IllustrationResponse r = collection.IsStarted == false ?
                                                 await collection.GetItems(acc) :
                                                 await collection.GetNextItems();

                        foreach (var l in r.Illustrations)
                        {
                            // go through all downloaded illustractions and wrap them up - if duplicates, take existing to save memory
                            src.Token.ThrowIfCancellationRequested();

                            // check blacklisted tag
                            bool containsBl = false;
                            foreach (var btag in MainPage.CurrentInstance.ViewModel.BlacklistedTags)
                            {
                                if (l.Tags.Count(x => x.Name.ToLower().Trim() == btag) > 0)
                                {
                                    containsBl = true;
                                    break;
                                }
                            }

                            IllustrationWrapper wr = null;
                            if (containsBl == false)
                            {
                                // continue adding it normally
                                if (addedIllustrations.ContainsKey(l.Id))
                                {
                                    // take existing Illustration
                                    wr = addedIllustrations[l.Id];
                                }
                                else
                                {
                                    wr = new IllustrationWrapper(l, acc);
                                    addedIllustrations.TryAdd(l.Id, wr);
                                }

                                collection.Add(wr);
                            }
                            else
                            {
                                // skip this one. It's blacklisted.
                                BlacklistedCount++;
                            }
                        }
                    }
                }
                catch (OperationCanceledException)
                {
                }
                catch (EndReachedException)
                {
                    MainPage.Logger.Info("End Reached!");
                }
                catch (COMException cex)
                {
                    var cexvar = cex;
                    MainPage.Logger.Error(cexvar, "COM Exception!");
                }
                catch (LoginException lex)
                {
                    // user is not logged in
                    MainPage.Logger.Error(lex, "User not logged in!");

                    // retry login
                    var vm = MainPage.CurrentInstance.ViewModel;
                    vm.Login(vm.Account.AuthInfo.RefreshToken);
                }
                catch (OffsetLimitException oex)
                {
                    var oexvar = oex;
                    MainPage.Logger.Error(oexvar, "Offset limit reached!");
                }
                catch (Exception ex)
                {
                    var exvar = ex;
                    MainPage.Logger.Error(exvar, "Unknown exception! " + exvar.Message + (exvar.InnerException != null ? exvar.InnerException.Message : ""));
                }
            }, src.Token);
        }