示例#1
0
        private async Task GetFeedItem(
            SyndicationFeed feed,
            List <FeedIndex> indices)
        {
            List <SyndicationItem> items = new List <SyndicationItem>();

            for (int i = 0; i < indices.Count; i++)
            {
                FeedIndex index = indices[i];
                items.Add(await GetItem(index));
            }
            feed.Items    = items;
            feed.Language = config.Language;
        }
示例#2
0
        private async Task <SyndicationItem> GetItem(FeedIndex index)
        {
            string text = "";

            if (config.EnableContent)
            {
                string filepath = ConfigReader.GetFileContentURL(
                    config.ContentFileRoot,
                    index.Name
                    );
                HttpResponseMessage resp = await httpClient.GetAsync(filepath);

                if (resp.IsSuccessStatusCode)
                {
                    text = await resp.Content.ReadAsStringAsync();
                }
            }

            string          blogpath = config.BlogUrl;
            string          link     = string.Format("{0}/{1}", blogpath, index.Name);
            var             pubDate  = DateTime.Parse(index.Date).ToUniversalTime();
            SyndicationItem item     =
                new SyndicationItem(
                    index.Title,
                    text,
                    new Uri(link),
                    link,
                    pubDate
                    );

            if (config.EnableContent)
            {
                string substr = text.Length > MAX_CONTENT_LENGTH
                    ? text.Substring(0, MAX_CONTENT_LENGTH)
                    : text;

                item.Content = SyndicationContent.CreateHtmlContent(substr);
            }
            item.PublishDate = pubDate;
            return(item);
        }