Example #1
0
        private void LoadMyCategories()
        {
            var categoryStringList   = TransferInterface.HandleCategoryLoadRequest();
            var restoredCategoryList = FeedCategory.ConvertToCategoryList(categoryStringList);

            FeedCategory.CategoryList = restoredCategoryList;
        }
Example #2
0
        private async Task <List <FeedItem> > GetCategoryFeedItemsFromDb(FeedCategory category, int skip, int take)
        {
            var db = _dbFactory.CreateDbContext();
            List <ServerCore.Models.FeedItem> feedItems;

            if (category == FeedCategory.Default)
            {
                feedItems = await db.FeedItems
                            .Include(f => f.Feed)
                            .Where(f => f.Feed.Category == "Default" || string.IsNullOrEmpty(f.Feed.Category))
                            .OrderByDescending(f => f.PublishTimeInUtc)
                            .Skip(skip)
                            .Take(take).ToListAsync();
            }
            else
            {
                feedItems = await db.FeedItems
                            .Include(f => f.Feed)
                            .Where(f => f.Feed.Category == category.ToString())
                            .OrderByDescending(f => f.PublishTimeInUtc)
                            .Skip(skip)
                            .Take(take).ToListAsync();
            }
            return(feedItems);
        }
Example #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (!CategoryId.HasValue)
            {
                var category = new FeedCategory
                {
                    Name = this.Name
                };

                this.context.FeedCategories.Add(category);
            }
            else
            {
                var existingCategory = await this.context.FeedCategories.SingleAsync(f => f.Id == CategoryId.Value);

                existingCategory.Name = this.Name;

                this.context.Attach(existingCategory).State = EntityState.Modified;
            }

            await this.context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Example #4
0
        private void btnAddCategory_Click(object sender, RoutedEventArgs e)
        {
            if (!(Tests.Validation.noText(txtAddCategory) ||
                  Tests.Validation.restrictLength(txtAddCategory) ||
                  Tests.Validation.restrictMinLength(txtAddCategory)))
            {
                try
                {
                    var  newCategory = txtAddCategory.Text;
                    bool categoryExists;
                    FeedCategory.CategoryMatcher(newCategory, out categoryExists);

                    if (categoryExists == false)
                    {
                        FeedCategory.AddCategory(newCategory);

                        txtAddCategory.Clear();
                        FillWithCategories();
                    }
                    else
                    {
                        MessageBox.Show("Kategorin finns redan", "Notis");
                    }
                }
                catch (Exception sigma)
                {
                    MessageBox.Show(sigma.Message);
                }
            }
        }
Example #5
0
 private void Window_Initialized(object sender, EventArgs e)
 {
     LoadMyCollection();
     UpdateFeedList();
     LoadMyCategories();
     FeedCategory.FillWithDummyCategories();
     FillWithCategories();
 }
Example #6
0
        public async Task <List <FeedItem> > GetFeedItemsByCategory(FeedCategory feedCategory, int page)
        {
            var res = await _apiClient.GetFeedsByCategoryAsync(new Protos.GetFeedsByCategoryRequest
            {
                Category = feedCategory,
                Page     = page
            });

            return(res.FeedItems.Select(f => GetFeedItem(f)).ToList());
        }
Example #7
0
        public async Task <CategoryDTO> Create(CategoryDTO dto)
        {
            FeedCategory category = new FeedCategory()
            {
                Name = dto.Name
            };

            var newCategory = await _categoryRepository.Save(category);

            dto.Id = newCategory.Id;
            return(dto);
        }
Example #8
0
        public async Task Update(CategoryDTO dto)
        {
            var repoObj = new FeedCategory()
            {
                Id    = dto.Id.Value,
                Name  = dto.Name,
                Feeds = dto.RssFeeds.Select(a => new RSSFeed()
                {
                    Name = a.Name, Id = a.Id.Value, XMLFileAddress = a.XMLFileAddress
                }).ToList()
            };

            await _categoryRepository.Update(repoObj);
        }
        public async Task <FeedListDocument> GetCategoryAsync(FeedCategory category, int page = 1)
        {
            string url = string.Format(CultureInfo.InvariantCulture, CATEGORY_LINK_TEMPLATE, (int)category, page);
            Uri    uri = new Uri(url, UriKind.Absolute);
            string json;

            using (HttpClient client = new HttpClient())
            {
                json = await client.GetStringAsync(uri);
            }
            FeedListDocument document = JsonConvert.DeserializeObject <FeedListDocument>(json);

            return(document);
        }
Example #10
0
        private static Subscription subscribe(FeedCategory category, String name, int orderId, User user, FeedSource feedsrc)
        {
            Subscription subscription = new Subscription();

            subscription.FeedSource = feedsrc;
            subscription.Category   = category;
            subscription.User       = user;
            subscription.Name       = strUtil.HasText(name) ? name : feedsrc.Title;
            subscription.AppId      = category.AppId;
            subscription.OrderId    = orderId;

            db.insert(subscription);

            return(subscription);
        }
        public async Task<DataResultBase<ResultList<Feed>>> GetFeedListAsync(FeedCategory category, int page = 1)
        {
            if (Enum.IsDefined(typeof(FeedCategory), category) == false)
            {
                throw new ArgumentException($"{nameof(category)} is not defined.", nameof(category));
            }
            if (page <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(page), "page should greater than zero.");
            }

            string url = string.Format(CategoryListTemplate, (int)category, page);
            using (HttpClient client = new HttpClient())
            {
                return await client.GetJsonAsync<DataResultBase<ResultList<Feed>>>(new Uri(url));
            }
        }
Example #12
0
        public virtual void Show(long id)
        {
            FeedCategory category = categoryService.GetById(id);

            bindCategory(category);

            String feedIds = subscriptionService.GetFeedIdsByCategoryId(id);

            if (strUtil.IsNullOrEmpty(feedIds))
            {
                content("<div style=\"margin:30px;\" class=\"warning\">no items</div>");
                return;
            }

            DataPage <FeedEntry> list = entryService.GetPage(feedIds);

            bindItemList(id, category, list);
        }
        public void Create()
        {
            String rssLink = ctx.Post("Link");

            if (strUtil.IsNullOrEmpty(rssLink))
            {
                echoError("rss url can not be empty");
                return;
            }

            int          categoryId = ctx.PostInt("CategoryId");
            FeedCategory category   = categoryService.GetById(categoryId);
            String       name       = ctx.Post("Name");

            Subscription s = feedService.Create(rssLink, category, name, 0, (User)ctx.owner.obj);

            redirect(Show, s.Id);
        }
Example #14
0
        private void bindItemList(long id, FeedCategory category, DataPage <FeedEntry> list)
        {
            set("feed.Title", category.Name);
            set("feed.Link", to(Show, id));
            set("LastRefreshTime", "");

            IBlock itemBlock = getBlock("item");

            foreach (FeedEntry item in list.Results)
            {
                itemBlock.Set("item.Title", item.Title);
                itemBlock.Set("item.Link", to(new EntryController().Show, item.Id));
                itemBlock.Set("item.PubDate", item.PubDate);
                itemBlock.Set("item.Description", item.Abstract);
                itemBlock.Next();
            }

            set("page", list.PageBar);
        }
Example #15
0
        private void btnRemoveCategory_Click(object sender, RoutedEventArgs e)
        {
            try {
                if (lbCategory.SelectedItem != null)
                {
                    var categoryToRemove = lbCategory.SelectedItem as FeedCategory;
                    FeedCategory.RemoveCategory(categoryToRemove);

                    FillWithCategories();
                }
                else
                {
                    MessageBox.Show("Du måste välja en kategori", "Notis");
                }
            }
            catch (Exception upsilon)
            {
                MessageBox.Show(upsilon.Message);
            }
        }
        public static string GetName(this FeedCategory category)
        {
            switch (category)
            {
            case FeedCategory.Home:
                return("首页");

            case FeedCategory.Weibo:
                return("微博");

            case FeedCategory.Video:
                return("影像");

            case FeedCategory.Image:
                return("图画");

            case FeedCategory.Game:
                return("游戏");

            case FeedCategory.Audio:
                return("音频");

            case FeedCategory.Text:
                return("文字");

            case FeedCategory.Mix:
                return("杂粹");

            case FeedCategory.Piao:
                return("漂流");

            case FeedCategory.Fair:
                return("集市");

            case FeedCategory.Tasty:
                return("短品");

            default:
                throw new ArgumentNullException(nameof(category));
            }
        }
Example #17
0
        public virtual Subscription Create(String url, FeedCategory category, String name, int orderId, User user)
        {
            FeedSource feedsrc = GetByLink(url);

            if (feedsrc == null)
            {
                feedsrc = createNewSource(url);
                saveFeedItems(feedsrc);
            }

            // 检查是否已经订阅
            Subscription s = subscriptionService.GetByFeedAndUser(feedsrc.Id, user.Id);

            if (s != null)
            {
                return(s);
            }

            Subscription subscription = subscribe(category, name, orderId, user, feedsrc);

            return(subscription);
        }
Example #18
0
        /* ÄNDRA feedinfo (url och kategori)
         * då man trycker på ändraknappen */
        private void btn_change_Click(object sender, RoutedEventArgs e)
        {
            if (!(Tests.Validation.noText(txtUrl_Change) ||
                  Tests.Validation.restrictLongerLength(txtUrl_Change) ||
                  Tests.Validation.CorrectStartString(txtUrl_Change) ||
                  Tests.Validation.minLengthLong(txtUrl_Change)))
            {
                try
                {
                    String changeUrl      = txtUrl_Change.Text;
                    String changeCategory = cbCategory_Change.SelectedItem.ToString();

                    Feed selectedFeed = (Feed)FeedList.SelectedItem;

                    if (mainCollection != null && mainCollection.Count > 0 && selectedFeed != null)
                    {
                        selectedFeed.Url = changeUrl;
                        var realChangeCategory = FeedCategory.CategoryMatcher(changeCategory);
                        selectedFeed.FeedCategory = realChangeCategory;

                        selectedFeed.FeedItems.Clear();
                        FeedItemList.Items.Clear();
                        TransferInterface.UpdateChecker(selectedFeed);
                        selectedFeed.TimeLastChecked = DateTime.Now;
                        UpdateFeedItemList();
                        SortByCategory();

                        MessageBox.Show("Feeden har ändrats", "Notis:");
                    }
                }
                catch (Exception myException)
                {
                    MessageBox.Show(myException.Message);
                }
            }
        }
Example #19
0
        public async Task <List <FeedItem> > GetCategoryFeedItems(FeedCategory category, int page)
        {
            if (page * 50 >= 1000)
            {
                // Remote cache only has 1000 items. Fetch from db directly.
                return(await GetCategoryFeedItemsFromDb(category, skip : page * 50, take : 50));
            }

            // Try to get from local cache first.
            List <FeedItem> items;
            var             key = Consts.CACHE_KEY_LATEST_FEEDITEMS_CATEGORY_PREFIX + category.ToString();

            if (!_memCache.TryGetValue <List <FeedItem> >(key, out items))
            {
                // Can't find from local cache, try to get from remote cache.
                var content = await _remoteCache.GetStringAsync(key);

                if (string.IsNullOrEmpty(content))
                {
                    // Remote cache doesn't have. Get from db directly.
                    items = await GetCategoryFeedItemsFromDb(category, skip : 0, take : 1000);

                    // Save to remote cache.
                    await _remoteCache.SetStringAsync(key, JsonSerializer.Serialize(items));
                }
                else
                {
                    items = JsonSerializer.Deserialize <List <FeedItem> >(content);
                }

                // Save to local cache.
                _memCache.Set(key, items, absoluteExpirationRelativeToNow: TimeSpan.FromMinutes(1));
            }

            return(items.Skip(page * 50).Take(50).ToList());
        }
Example #20
0
        /// <summary>
        /// Main Atom parsing method.
        /// </summary>
        /// <param name="parent">Parent stack for current node.</param>
        /// <param name="reader">Current xml feed reader.</param>
        /// <param name="feed">Current feed result.</param>
        /// <param name="root">Flag indicating if parser is the default root parser.</param>
        /// <returns>Flag indicating if current node should be parsed or if next node should be retrieved.</returns>
        public override async Task <bool> Parse(Stack <NodeInformation> parent, XmlReader reader, Feed feed, bool root = true)
        {
            //Init
            bool result;

            //Verify Element Node
            if (result = reader.NodeType == XmlNodeType.Element && (!reader.IsEmptyElement || reader.HasAttributes))
            {
                //Init
                ICommonAtom      target      = feed;
                ICommonAtomFeed? targetFeed  = feed;
                ICommonAtomEntry?targetEntry = feed.CurrentItem;
                NodeInformation  nodeInfo    = reader.NodeInformation();

                //Verify feed type
                if (feed.Type == FeedType.Atom)
                {
                    //Set common target
                    if (feed.CurrentItem != null)
                    {
                        target = feed.CurrentItem;
                    }
                }
                else
                {
                    //Add Atom to feed content type
                    ICommonFeed feedTarget = feed.CurrentItem ?? (ICommonFeed)feed;
                    feedTarget.ContentType |= FeedContentType.Atom;

                    //Set common target
                    if (feed.CurrentItem != null)
                    {
                        feed.CurrentItem.Atom ??= new AtomEntry();
                        target = feed.CurrentItem.Atom;
                    }
                    else
                    {
                        feed.Atom ??= new AtomFeed();
                        target = feed.Atom;
                    }
                    targetFeed  = feed.Atom;
                    targetEntry = feed.CurrentItem?.Atom;
                }

                //Identify node name
                switch (reader.LocalName)
                {
                    #region Common

                case "author":     //Names one author of the feed entry.
                {
                    //Get author properties
                    target.Author = new FeedPerson();
                    var authorElements = await reader.AllSubTreeElements().ConfigureAwait(false);

                    foreach (var element in authorElements)
                    {
                        switch (element.Key)
                        {
                        case "email":
                        {
                            try
                            {
                                //Attempt to parse author email
                                target.Author.Email = element.Value.ToMailAddress();
                            }
                            catch (Exception ex) when(ex is ArgumentException || ex is ArgumentNullException || ex is FormatException)
                            {
                                //Unknown node format
                                SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, element.Value, $"Node: {element.Key}, {ex.Message}");
                            }
                            break;
                        }

                        case "name": target.Author.Name = element.Value; break;

                        case "uri":
                        {
                            try
                            {
                                //Attempt to parse author URI
                                target.Author.Uri = new Uri(element.Value);
                            }
                            catch (Exception ex) when(ex is ArgumentNullException || ex is UriFormatException)
                            {
                                //Unknown node format
                                SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, element.Value, $"Node: {element.Key}, {ex.Message}");
                            }
                            break;
                        }

                        default:
                        {
                            //Unknown node
                            SetParseError(ParseErrorType.UnknownSubNode, nodeInfo, feed, element.Value, element.Key);
                            break;
                        }
                        }
                    }
                    break;
                }

                case "category":     //One or more categories that the feed/entry belongs to.
                {
                    //Verify link node
                    if (reader.HasAttributes && reader.GetAttribute("term") != null)
                    {
                        //Parse and add category to feed/entry catergories list
                        var category = new FeedCategory()
                        {
                            Category = reader.GetAttribute("domain"),
                            Label    = reader.GetAttribute("label")
                        };

                        //Attempt to get category scheme
                        var scheme = reader.GetAttribute("scheme");
                        if (scheme != null)
                        {
                            try
                            {
                                //Attempt to parse category scheme URI
                                category.Scheme = new Uri(scheme);
                            }
                            catch (Exception ex) when(ex is ArgumentNullException || ex is UriFormatException)
                            {
                                //Unknown node format
                                SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, scheme, $"Node: scheme, {ex.Message}");
                            }
                        }

                        //Add category to categories list
                        target.Categories ??= new List <FeedCategory>();
                        target.Categories.Add(category);
                    }
                    else
                    {
                        //Missing href attribute
                        SetParseError(ParseErrorType.MissingAttribute, nodeInfo, feed, null, "term");
                    }
                    break;
                }

                case "contributor":     //Name of one or more contributors to the feed entry.
                {
                    //Init
                    var contributor = new FeedPerson();

                    //Get contributor properties
                    var contributorElements = await reader.AllSubTreeElements().ConfigureAwait(false);

                    foreach (var element in contributorElements)
                    {
                        switch (element.Key)
                        {
                        case "email":
                        {
                            try
                            {
                                //Attempt to parse contributor email
                                contributor.Email = element.Value.ToMailAddress();
                            }
                            catch (Exception ex) when(ex is ArgumentException || ex is ArgumentNullException || ex is FormatException)
                            {
                                //Unknown node format
                                SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, element.Value, $"Node: {element.Key}, {ex.Message}");
                            }
                            break;
                        }

                        case "name": contributor.Name = element.Value; break;

                        case "uri":
                        {
                            try
                            {
                                //Attempt to parse author URI
                                contributor.Uri = new Uri(element.Value);
                            }
                            catch (Exception ex) when(ex is ArgumentNullException || ex is UriFormatException)
                            {
                                //Unknown node format
                                SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, element.Value, $"Node: {element.Key}, {ex.Message}");
                            }
                            break;
                        }

                        default:
                        {
                            //Unknown node
                            SetParseError(ParseErrorType.UnknownSubNode, nodeInfo, feed, element.Value, element.Key);
                            break;
                        }
                        }
                    }

                    //Add contributor to contributors list
                    target.Contributors ??= new List <FeedPerson>();
                    target.Contributors.Add(contributor);
                    break;
                }

                case "entry":     //Feed entry start, add new feed item to feed.
                {
                    //Add new item
                    if (feed.CurrentParseType == ParseType.Feed)
                    {
                        feed.AddItem();
                    }
                    break;
                }

                case "id":     //Identifies the feed/entry using a universally unique and permanent URI.
                {
                    //Get id
                    var content = await reader.ReadStartElementAndContentAsStringAsync().ConfigureAwait(false);

                    try
                    {
                        //Attempt to parse id URI
                        target.Id = new Uri(content);
                    }
                    catch (Exception ex) when(ex is ArgumentNullException || ex is UriFormatException)
                    {
                        //Unknown node format
                        SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, content, ex.Message);
                    }
                    break;
                }

                case "link":     //Link to the referenced resource (typically a Web page)
                {
                    //Verify link node
                    if (reader.HasAttributes && reader.GetAttribute("href") != null)
                    {
                        //Init
                        var link = new FeedLink();

                        //Get link attributes
                        while (reader.MoveToNextAttribute())
                        {
                            //Attempt to parse attribute
                            switch (reader.LocalName)
                            {
                            case "href":
                            {
                                try
                                {
                                    //Attempt to parse link href
                                    link.Url = new Uri(reader.Value);
                                }
                                catch (Exception ex) when(ex is ArgumentNullException || ex is UriFormatException)
                                {
                                    //Unknown node format
                                    SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, reader.Value, $"Node: {reader.LocalName}, {ex.Message}");
                                }
                                break;
                            }

                            case "hreflang":
                            {
                                try
                                {
                                    //Attempt to parse link hrefLang
                                    link.Language = CultureInfo.GetCultureInfo(reader.Value);
                                }
                                catch (Exception ex) when(ex is ArgumentException || ex is CultureNotFoundException)
                                {
                                    //Unknown node format
                                    SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, reader.Value, $"Node: {reader.LocalName}, {ex.Message}");
                                }
                                break;
                            }

                            case "length":
                            {
                                //Attempt to parse link length
                                if (long.TryParse(reader.Value, out var length))
                                {
                                    link.Length = length;
                                }
                                else
                                {
                                    //Unknown node format
                                    SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, reader.Value, $"Node: {reader.LocalName}");
                                }
                                break;
                            }

                            case "rel":
                            {
                                //Attempt to parse link rel
                                switch (reader.Value)
                                {
                                case "alternate": link.Type = FeedLinkType.Alternate; break;

                                case "enclosure": link.Type = FeedLinkType.Enclosure; break;

                                case "related": link.Type = FeedLinkType.Related; break;

                                case "self": link.Type = FeedLinkType.Self; break;

                                case "via": link.Type = FeedLinkType.Via; break;

                                default: SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, reader.Value, $"Node: {reader.LocalName}"); break;
                                }
                                break;
                            }

                            case "title": link.Text = reader.Value; break;

                            case "type": link.MediaType = reader.Value; break;

                            default:
                            {
                                //Unknown node
                                SetParseError(ParseErrorType.UnknownSubNode, nodeInfo, feed, reader.Value, reader.LocalName);
                                break;
                            }
                            }
                        }

                        //Add link to links collection
                        target.Links ??= new List <FeedLink>();
                        target.Links.Add(link);
                    }
                    else
                    {
                        //Missing href attribute
                        SetParseError(ParseErrorType.MissingAttribute, nodeInfo, feed, null, "href");
                    }
                    break;
                }

                case "rights":     //Conveys information about rights, e.g. copyrights, held in and over the feed.
                {
                    //Attemp to parse rights
                    target.Rights = new FeedText()
                    {
                        Type = reader.GetAttribute("type")
                    };
                    target.Rights.Text = await reader.ReadStartElementAndContentAsStringAsync(target.Rights.Type).ConfigureAwait(false);

                    break;
                }

                case "title":     //The name of the feed/entry.
                {
                    //Attemp to parse title
                    target.Title = new FeedText()
                    {
                        Type = reader.GetAttribute("type")
                    };
                    target.Title.Text = await reader.ReadStartElementAndContentAsStringAsync(target.Title.Type).ConfigureAwait(false);

                    break;
                }

                case "updated":     //Indicates the last time the feed/entry was modified in a significant way.
                {
                    //Init
                    var content = await reader.ReadStartElementAndContentAsStringAsync().ConfigureAwait(false);

                    //Attempt to parse updated date
                    if (DateTime.TryParse(content, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out var updated))
                    {
                        target.Updated = updated;
                    }
                    else
                    {
                        //Unknown node format
                        SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, content);
                    }
                    break;
                }

                    #endregion Common

                    #region Feed

                case "icon":     //Identifies a small image which provides iconic visual identification for the feed.
                {
                    if (targetFeed != null)
                    {
                        //Get icon
                        var content = await reader.ReadStartElementAndContentAsStringAsync().ConfigureAwait(false);

                        try
                        {
                            //Attempt to parse icon URI
                            targetFeed.Icon = new Uri(content);
                        }
                        catch (Exception ex) when(ex is ArgumentNullException || ex is UriFormatException)
                        {
                            //Unknown node format
                            SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, content, ex.Message);
                        }
                    }
                    else
                    {
                        //Feed Atom object missing
                        throw new ArgumentNullException("Feed.Atom");
                    }
                    break;
                }

                case "generator":     //Indicating the program used to generate the feed.
                {
                    if (targetFeed != null)
                    {
                        //Init
                        targetFeed.Generator = new FeedGenerator();

                        //Attempt to parse optional attributes
                        var uri = reader.GetAttribute("uri");
                        if (uri != null)
                        {
                            try
                            {
                                //Attempt to parse generator uri
                                targetFeed.Generator.Uri = new Uri(uri);
                            }
                            catch (Exception ex) when(ex is ArgumentNullException || ex is UriFormatException)
                            {
                                //Unknown node format
                                SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, uri, $"Node: uri, {ex.Message}");
                            }
                        }
                        targetFeed.Generator.Version = reader.GetAttribute("version");

                        //Attempt to parse feed generator
                        targetFeed.Generator.Generator = await reader.ReadStartElementAndContentAsStringAsync().ConfigureAwait(false);
                    }
                    else
                    {
                        //Feed Atom object missing
                        throw new ArgumentNullException("Feed.Atom");
                    }
                    break;
                }

                case "logo":     //Identifies a larger image which provides visual identification for the feed.
                {
                    if (targetFeed != null)
                    {
                        //Init
                        targetFeed.Logo = new FeedImage();

                        //Get logo
                        var content = await reader.ReadStartElementAndContentAsStringAsync().ConfigureAwait(false);

                        try
                        {
                            //Attempt to parse logo URI
                            targetFeed.Logo.Url = new Uri(content);
                        }
                        catch (Exception ex) when(ex is ArgumentNullException || ex is UriFormatException)
                        {
                            //Unknown node format
                            SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, content, ex.Message);
                        }
                    }
                    else
                    {
                        //Feed Atom object missing
                        throw new ArgumentNullException("Feed.Atom");
                    }
                    break;
                }

                case "subtitle":     //Contains a human-readable description or subtitle for the feed.
                {
                    if (targetFeed != null)
                    {
                        //Attemp to parse subtitle
                        targetFeed.Subtitle = new FeedText()
                        {
                            Type = reader.GetAttribute("type")
                        };
                        targetFeed.Subtitle.Text = await reader.ReadStartElementAndContentAsStringAsync(targetFeed.Subtitle.Type).ConfigureAwait(false);
                    }
                    else
                    {
                        //Feed Atom object missing
                        throw new ArgumentNullException("Feed.Atom");
                    }
                    break;
                }

                    #endregion Feed

                    #region Entry

                case "content":     //Contains or links to the complete content of the entry.
                {
                    if (targetEntry != null)
                    {
                        //Attemp to parse content
                        targetEntry.Content = new FeedContent()
                        {
                            Type = reader.GetAttribute("type")
                        };
                        targetEntry.Content.Text = await reader.ReadStartElementAndContentAsStringAsync(targetEntry.Content.Type).ConfigureAwait(false);

                        //Attempt to get content src
                        var src = reader.GetAttribute("src");
                        if (src != null)
                        {
                            try
                            {
                                //Attempt to parse content src
                                targetEntry.Content.Source = new Uri(src);
                            }
                            catch (Exception ex) when(ex is ArgumentNullException || ex is UriFormatException)
                            {
                                //Unknown node format
                                SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, src, $"Node: src, {ex.Message}");
                            }
                        }
                    }
                    else
                    {
                        if (feed.Type == FeedType.Atom)
                        {
                            //Feed item object missing
                            throw new ArgumentNullException("Feed.CurrentItem");
                        }
                        else
                        {
                            //Feed CurrentItem Atom object missing
                            throw new ArgumentNullException("Feed.CurrentItem.Atom");
                        }
                    }
                    break;
                }

                case "published":
                {
                    if (targetEntry != null)
                    {
                        //Get published
                        var content = await reader.ReadStartElementAndContentAsStringAsync().ConfigureAwait(false);

                        //Attemp to parser published
                        if (DateTime.TryParse(content, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out var published))
                        {
                            targetEntry.Published = published;
                        }
                        else
                        {
                            //Unknown node format
                            SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, content);
                        }
                    }
                    else
                    {
                        if (feed.Type == FeedType.Atom)
                        {
                            //Feed item object missing
                            throw new ArgumentNullException("Feed.CurrentItem");
                        }
                        else
                        {
                            //Feed CurrentItem Atom object missing
                            throw new ArgumentNullException("Feed.CurrentItem.Atom");
                        }
                    }
                    break;
                }

                case "source":
                {
                    if (targetEntry != null)
                    {
                        //Init
                        targetEntry.Source = new FeedLink();

                        //Get source properties
                        var sourceElements = await reader.AllSubTreeElements().ConfigureAwait(false);

                        foreach (var element in sourceElements)
                        {
                            switch (element.Key)
                            {
                            case "id":
                            {
                                try
                                {
                                    //Attempt to parse id URI
                                    targetEntry.Source.Url = new Uri(element.Value);
                                }
                                catch (Exception ex) when(ex is ArgumentNullException || ex is UriFormatException)
                                {
                                    //Unknown node format
                                    SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, element.Value, $"Node: {element.Key}, {ex.Message}");
                                }
                                break;
                            }

                            case "title":
                            {
                                //Set title text
                                targetEntry.Source.Text = element.Value;
                                break;
                            }

                            case "updated":
                            {
                                //Attempt to parse updated date
                                if (DateTime.TryParse(element.Value, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out var updated))
                                {
                                    targetEntry.Source.Updated = updated;
                                }
                                else
                                {
                                    //Unknown node format
                                    SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, element.Value, $"Node: {element.Key}");
                                }
                                break;
                            }

                            default:
                            {
                                //Unknown node
                                SetParseError(ParseErrorType.UnknownSubNode, nodeInfo, feed, element.Value, element.Key);
                                break;
                            }
                            }
                        }
                    }
                    else
                    {
                        if (feed.Type == FeedType.Atom)
                        {
                            //Feed item object missing
                            throw new ArgumentNullException("Feed.CurrentItem");
                        }
                        else
                        {
                            //Feed CurrentItem Atom object missing
                            throw new ArgumentNullException("Feed.CurrentItem.Atom");
                        }
                    }
                    break;
                }

                case "summary":     //Conveys a short summary, abstract, or excerpt of the entry.
                {
                    if (targetEntry != null)
                    {
                        //Attemp to parse summary
                        targetEntry.Summary = new FeedText()
                        {
                            Type = reader.GetAttribute("type")
                        };
                        targetEntry.Summary.Text = await reader.ReadStartElementAndContentAsStringAsync(targetEntry.Summary.Type).ConfigureAwait(false);
                    }
                    else
                    {
                        if (feed.Type == FeedType.Atom)
                        {
                            //Feed item object missing
                            throw new ArgumentNullException("Feed.CurrentItem");
                        }
                        else
                        {
                            //Feed CurrentItem Atom object missing
                            throw new ArgumentNullException("Feed.CurrentItem.Atom");
                        }
                    }
                    break;
                }

                    #endregion Entry

                default:     //Unknown feed/entry node, continue to next.
                {
                    result = false;
                    if (root)
                    {
                        SetParseError(ParseErrorType.UnknownNode, nodeInfo, feed);
                    }
                    break;
                }
                }
            }
            else if (result = reader.NodeType == XmlNodeType.EndElement)
            {
                switch (reader.LocalName)
                {
                case "entry":     //Feed entry end, close current feed item.
                {
                    feed.CloseItem();
                    break;
                }
                }
            }

            //Return result
            return(result);
        }
Example #21
0
 private void bindCategory(FeedCategory category)
 {
     bind("c", category);
 }
Example #22
0
 public void RemoveFeedCategory(FeedCategory feedCategory)
 {
     _unitOfWork.FeedCategory.Remove(feedCategory);
 }
Example #23
0
        private void SaveMyCategories()
        {
            var categoryStringList = FeedCategory.ConvertToStringList();

            TransferInterface.HandleCategorySaveRequest(categoryStringList);
        }
Example #24
0
 public Task <List <FeedItem> > GetFeedItemsByCategory(FeedCategory feedCategory, int page)
 {
     return(_api.GetFeedItemsByCategory(feedCategory, page));
 }
Example #25
0
 public bool Validate(string urlValue, FeedCategory category)
 {
     throw new NotImplementedException();
 }
Example #26
0
 public IncrementalLoadingFeedCollection(IFeedService feedService, FeedCategory category)
 {
     _feedService = feedService;
     _category    = category;
     _currentPage = 0;
 }
Example #27
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            FeedCategory category = (FeedCategory)value;

            return(category.GetName());
        }