Beispiel #1
0
        public void SendNewsItems(FeedItem[] items, string[] addresses)
        {
            if (items == null)
                throw new ArgumentNullException(nameof(items));

            foreach (var item in items)
                SendNewsItem(item, addresses);
        }
Beispiel #2
0
        public void SendNewsItem(FeedItem item, string[] addresses)
        {
            if (item == null)
                throw new ArgumentNullException(nameof(item));
            if (addresses == null)
                throw new ArgumentNullException(nameof(addresses));
            if (addresses.Length < 1)
                return;

            var message = new MailMessage();
            message.From = new MailAddress(senderAddress);
            foreach (var address in addresses)
            {
                message.To.Add(new MailAddress(address));
            }
            message.Subject = item.Title;
            message.Body = item.Summary;
            message.IsBodyHtml = true;

            smtpClient.Send(message);
        }
Beispiel #3
0
 public void SendNewsItems(FeedItem[] items)
 {
     SendNewsItems(items, recipientAddresses);
 }
Beispiel #4
0
 public void SendNewsItem(FeedItem item)
 {
     SendNewsItem(item, recipientAddresses);
 }
Beispiel #5
0
        internal static List <FeedItem> GetFeedItems(string url)
        {
            List <FeedItem> feedItemsList = new List <FeedItem>();

            try
            {
                WebRequest  webRequest  = WebRequest.Create(url);
                WebResponse webResponse = webRequest.GetResponse();

                Stream      stream      = webResponse.GetResponseStream();
                XmlDocument xmlDocument = new XmlDocument();

                xmlDocument.Load(stream);

                XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDocument.NameTable);
                nsmgr.AddNamespace("dc", xmlDocument.DocumentElement.GetNamespaceOfPrefix("dc"));
                nsmgr.AddNamespace("", xmlDocument.NamespaceURI);
                nsmgr.AddNamespace("rdf", xmlDocument.DocumentElement.GetNamespaceOfPrefix("rdf"));
                nsmgr.AddNamespace("enc", xmlDocument.DocumentElement.GetNamespaceOfPrefix("enc"));
                nsmgr.AddNamespace("media", xmlDocument.DocumentElement.GetNamespaceOfPrefix("media"));

                XmlNodeList itemNodes = xmlDocument.SelectNodes("*")[0].ChildNodes;

                for (int i = 1; i < itemNodes.Count; i++)
                {
                    FeedItem feedItem = new FeedItem();


//					if (itemNodes[i].SelectSingleNode("title") != null)
                    if (itemNodes[i].ChildNodes[0] != null)
                    {
//						feedItem.Title = itemNodes[i].SelectSingleNode("title").InnerText;
                        feedItem.Title = itemNodes[i].ChildNodes[0].InnerText;
                    }

                    if (itemNodes[i].ChildNodes[1] != null)
                    {
                        feedItem.Description = itemNodes[i].ChildNodes[1].InnerText;
                    }

                    if (itemNodes[i].ChildNodes[2] != null)
                    {
                        feedItem.Link = itemNodes[i].ChildNodes[2].InnerText;
                    }

                    if (itemNodes[i].SelectSingleNode("dc:creator", nsmgr) != null)
                    {
                        feedItem.Creator = itemNodes[i].SelectSingleNode("dc:creator", nsmgr).InnerText;
                    }

                    if (itemNodes[i].SelectSingleNode("dc:date", nsmgr) != null)
                    {
                        feedItem.PubDate = Convert.ToDateTime(itemNodes[i].SelectSingleNode("dc:date", nsmgr).InnerText);
                    }

                    else
                    {
                        feedItem.Content = feedItem.Description;
                    }

                    feedItemsList.Add(feedItem);
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(feedItemsList);
        }