示例#1
0
        public async Task ExecuteTestAsync()
        {
            List <PocketItem> pocketItems = await _pocketClient.GetPocketItemsAsync();

            Assert.IsNotNull(pocketItems);
            Assert.AreNotEqual(0, pocketItems.Count);
            Assert.AreNotEqual(0, pocketItems[0].Authors.Count);
            Assert.IsNotNull(pocketItems[1].Image);
            Assert.IsNotNull(pocketItems[1].Image.ItemId);
            Assert.AreNotEqual(0, pocketItems[1].Image.Source.Length);
            Assert.IsNotNull(pocketItems[1].Images);
            Assert.AreNotEqual(0, pocketItems[1].Images.Count);
        }
示例#2
0
        private async Task <PocketItem> TestAddAsync()
        {
            PocketItem newPocketItem = await _pocketClient.AddPocketItemAsync(new Uri("https://www.theage.com.au/culture/comedy/the-at-home-comedy-festival-20200318-p54bhu.html"));

            List <PocketItem> newPocketItems = await _pocketClient.GetPocketItemsAsync(
                DateTime.Now.ToUniversalTime().Subtract(new TimeSpan(0, 0, 30)));

            Assert.IsNotNull(newPocketItem);
            Assert.IsNotNull(newPocketItem.Id);
            Assert.AreNotEqual(0, newPocketItem.Id.Length);
            Assert.AreNotEqual(0, newPocketItems.Count);
            return(newPocketItem);
        }
示例#3
0
        public async Task SyncArticlesAsync()
        {
            CurrentlySyncing = true;

            try
            {
                DateTime newSyncDateTime = DateTime.UtcNow;
                IEnumerable <PocketItem> newPocketItems = await _pocketClient.GetPocketItemsAsync(LastSyncDateTime);

                foreach (PocketItem pocketItem in newPocketItems)
                {
                    switch (pocketItem.Status)
                    {
                    case "0":
                        if (!PocketItems.Any(pi => pi.Id == pocketItem.Id))
                        {
                            PocketItems.Insert(0, pocketItem);
                        }
                        break;

                    case "1":
                        if (PocketItems.Any(pi => pi.Id == pocketItem.Id))
                        {
                            PocketItems.First(pi => pi.Id == pocketItem.Id).Status = "1";
                        }
                        else
                        {
                            PocketItems.Insert(0, pocketItem);
                        }
                        break;

                    case "2":
                        if (PocketItems.Any(pi => pi.Id == pocketItem.Id))
                        {
                            PocketItems.Remove(PocketItems.First(pi => pi.Id == pocketItem.Id));
                        }
                        break;
                    }
                }

                LastSyncDateTime = newSyncDateTime;
                CurrentlySyncing = false;
            } catch (Exception e)
            {
                CurrentlySyncing = false;
                throw (e);
            }
        }