public void AddFeed(Feed addfeed) { using (RssEntities addcontext = new RssEntities()) { try { addcontext.Feeds.AddObject(addfeed); addcontext.SaveChanges(); } catch (Exception e) { string msg = e.Message; string reason = "AddFeed Feeds.AddObject Exception"; throw new FaultException<DBRequestFault> (new DBRequestFault(msg), reason); } try { List<News> feedNews = LoadNewsFromFeed(addfeed); foreach (News item in feedNews) { addcontext.News.AddObject(item); } addcontext.SaveChanges(); } catch (Exception e) { string msg = e.Message; string reason = "AddFeed News.AddObjectt Exception"; throw new FaultException<DBRequestFault> (new DBRequestFault(msg), reason); } } }
private void UpdateFeed(Feed feed) { try { using (XmlReader reader = XmlReader.Create(feed.URL)) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(reader); //compare the item.LastbuildDate int result = DateTime.Compare(feed.LastTimeUpdate, GetLastBuildDate(xmlDoc)); if (result < 0 || feed.News.Count == 0) { using (RssEntities localContext = new RssEntities()) { Feed delFeed = localContext.Feeds.First(f => f.ID == feed.ID); localContext.Feeds.DeleteObject(delFeed); localContext.SaveChanges(); using (RssEntities addContext = new RssEntities()) { Feed addfeed = new Feed { ID = feed.ID, Name = feed.Name, URL = feed.URL }; addContext.Feeds.AddObject(addfeed); addContext.SaveChanges(); List<News> feedNews = LoadNewsFromFeed(addfeed); foreach (News item in feedNews) { addContext.News.AddObject(item); } addContext.SaveChanges(); } } } } } catch (FileNotFoundException fnfEx) { string msg = fnfEx.Message; string reason = "UpdateFeed FileNotFoundException"; throw new FaultException<DBRequestFault> (new DBRequestFault(msg), reason); } catch (Exception ex) { string msg = ex.Message; string reason = "UpdateFeed Exception"; throw new FaultException<DBRequestFault> (new DBRequestFault(msg), reason); } }
public RssService() { context = new RssEntities(); }