private void WriteHeader(IFeed feed) { this.XmlWriter.WriteStartDocument(); this.XmlWriter.WriteStartElement("feed", "http://www.w3.org/2005/Atom"); if(!string.IsNullOrEmpty(feed.Language)) { this.XmlWriter.WriteAttributeString("xml", "lang", null, feed.Language); } this.XmlWriter.WriteElementString("id", feed.Id); this.XmlWriter.WriteElementString("title", feed.Title); this.XmlWriter.WriteStartElement("link"); this.XmlWriter.WriteAttributeString("href", feed.Uri.AbsoluteUri); this.XmlWriter.WriteEndElement(); this.XmlWriter.WriteStartElement("link"); this.XmlWriter.WriteAttributeString("href", feed.FeedUri.AbsoluteUri); this.XmlWriter.WriteAttributeString("rel", "self"); this.XmlWriter.WriteEndElement(); if(feed.Author != null) { this.XmlWriter.WriteStartElement("author"); this.XmlWriter.WriteElementString("name", feed.Author.Name); if(feed.Author.Email != null) { this.XmlWriter.WriteElementString("email", feed.Author.Email); } this.XmlWriter.WriteEndElement(); } this.XmlWriter.WriteElementString("subtitle", feed.Description); if(feed.Image != null) { this.XmlWriter.WriteElementString("logo", feed.Image.Uri.ToString()); } }
protected virtual void TestFeedParseCorrectness(IFeedKnownValueTest testcase, IFeed resultantItem) { //Assert that the resultant item and the test case both originate from the same URI Assert.That(resultantItem.FeedUri.Equals(testcase.FeedUri.OriginalString)); //Assert that the resultant item matches the expected output type of the test case Assert.That(resultantItem.GetType() == testcase.FeedObjectType); //Assert that the feedtypes of the two objects match Assert.That(resultantItem.FeedType == testcase.FeedType); //Feeds with no updated date/time are assigned DateTime.UtcNow - the expected value and actual for this test case //will be off by a minute or so, and shouldn't fail. if(!(testcase.LastUpdated - new TimeSpan(0,0,5) < resultantItem.LastUpdated)) { //Assert that the parsed date matches the expected date Assert.AreEqual(testcase.LastUpdated, resultantItem.LastUpdated); } //Assert that the parsed title matches the expected title Assert.AreEqual(testcase.Title, resultantItem.Title); //Assert that the generator parsed from the feed matches what's supplied in the test case Assert.AreEqual(testcase.Generator, resultantItem.Generator); //Assert that the link parsed from the feed matches what's supplied in the test case Assert.AreEqual(testcase.Link, resultantItem.Link); }
public void Add(IFeed aFeed) { iMutex.WaitOne(); try { iFeedList.Add(aFeed.Title, aFeed); } catch (ArgumentException) { iFeedList[aFeed.Title] = aFeed; } if (!aFeed.Downloaded) { iSemaphore.Set(); } iMutex.ReleaseMutex(); if (EventChanged != null) { EventChanged(this, EventArgs.Empty); } }
/// <summary> /// Creates a new object. /// </summary> /// <param name="feed"></param> /// <param name="snapshot"></param> /// <param name="timestamp"></param> /// <param name="dataVersion"></param> public AircraftListSnapshot(IFeed feed, IList <IAircraft> snapshot, long timestamp, long dataVersion) { Feed = feed; Snapshot = snapshot; Timestamp = timestamp; DataVersion = dataVersion; }
public override void Write(IFeed feed) { if (this.XmlWriter != null) { this.WriteHeader(feed); DateTime lastBuildDate = feed.PublishDate.ToUniversalTime(); if (feed.Items != null) { foreach (IFeedItem item in feed.Items) { DateTime universalPublishDate = item.PublishDate.ToUniversalTime(); if (universalPublishDate > lastBuildDate) { lastBuildDate = universalPublishDate; } } } this.WriteLastUpdated(lastBuildDate); if (feed.Items != null) { foreach (IFeedItem item in feed.Items) { WriteFeedItem(item); } } this.WriteFooter(); } }
public virtual void ApproveAtomFeedItemParse() { IFeed feed = Factory.CreateFeed(feeduri); var strFeedItems = from feeditem in feed.Items select feeditem.ToApprovalString(); Approvals.VerifyAll(strFeedItems, "feed items"); }
public async Task Save(IFeed entity) { var ouw = DIService.Container.Resolve <UnitOfWork>(); await Save(ouw, entity); await ouw.Commit(); }
private Feed MapFeed(IFeed feed) { return new Feed { Title = feed.Title, Items = MapItems(feed.Items) }; }
private static void PrintFeed(IFeed feed) { foreach (var feedItem in feed.Items) { Console.WriteLine("{0} {1}", feedItem.DatePublished, feedItem.Title); Console.WriteLine(feedItem.Link); } }
public static void CollectInput(Farm farm, IFeed animal) { Console.Clear(); for (int i = 0; i < farm.ChickenHouses.Count; i++) { if (farm.ChickenHouses[i].Capacity > farm.ChickenHouses[i].Count) { Console.WriteLine($"{i + 1}. Chicken house ({farm.ChickenHouses[i].Count} existing animals)"); } else { Console.WriteLine($"{i + 1}. Chicken house is at capacity with ({farm.ChickenHouses[i].Count}) chickens"); } } Console.WriteLine(); // How can I output the type of animal chosen here? if (farm.ChickenHouses.Count >= 1) // if the facility exists... { Console.WriteLine($"Place the animal where?"); Console.Write("> "); try { int choice = Int32.Parse(Console.ReadLine()); //take what the user enters int index = choice - 1; //-1 to stay within the range int count = farm.ChickenHouses[index].Count; //get how many animals are in that field double capacity = farm.ChickenHouses[index].Capacity; if (count < capacity) { farm.ChickenHouses[index].AddResource(animal); } else { Console.WriteLine("There is not enough room in the chicken house, hit enter to select a different house."); Console.ReadLine(); CollectInput(farm, animal); } } catch (ArgumentOutOfRangeException) { Console.WriteLine("Hit enter to select the correct facility dummy"); Console.ReadLine(); CollectInput(farm, animal); } } else { Console.WriteLine("You must create a chicken house before purchasing a chicken. Press enter to return to the main menu"); Console.ReadKey(); // CreateFacility.CollectInput(farm); } /* * Couldn't get this to work. Can you? * Stretch goal. Only if the app is fully functional. */ // farm.PurchaseResource<IGrazing>(animal, choice); }
public Article(string content, string link, DateTime publishDate, string name, IFeed feed) { Content = content; Link = link; PublishDate = publishDate; Name = name; Feed = feed; FeedId = feed.Id; }
public void Navigate(IArticle item, IFeed feed) { // MyWebView.NavigateToString(item.Body); Navigate(item.Url); ItemsList.ItemsSource = feed.Articles.OrderByDescending(x => x.Date); ItemsList.SelectedItem = item; ItemsList.ScrollIntoView(item); }
public OfflineViewModel(IAnswer answer, IArticle article, IColumn column, IFeed feed, IQuestion question) : this() { this._answer = answer; this._article = article; this._column = column; this._feed = feed; this._question = question; }
/// <summary> /// Disposes of or finalises the object. /// </summary> /// <param name="disposing"></param> protected virtual void Dispose(bool disposing) { if (disposing) { Factory.Singleton.Resolve <IConfigurationStorage>().Singleton.ConfigurationChanged -= ConfigurationStorage_ConfigurationChanged; Factory.Singleton.Resolve <IFeedManager>().Singleton.FeedsChanged -= FeedManager_FeedsChanged; _Feed = null; } }
public void Initialize() { _factory = new IsolatedStorageFeedFactory(); _rssDocument = _factory.CreateFeed(new Uri(SilverlightTestFileLoader.SampleRssFeeds().First(), UriKind.Relative), FeedType.Rss20, SilverlightTestFileLoader.ReadFeedContents(SilverlightTestFileLoader.SampleRssFeeds().First())); _atomDocument = _factory.CreateFeed(new Uri(SilverlightTestFileLoader.SampleAtomFeeds().First(), UriKind.Relative), FeedType.Atom10, SilverlightTestFileLoader.ReadFeedContents(SilverlightTestFileLoader.SampleAtomFeeds().First())); }
} // GetChildItems protected override string GetChildName(string path) { path = NormalizePath(path); WriteDebug("Getting name for " + path); // Checks if the path represented is a drive if (PathIsDrive(path)) { return(""); }// if (PathIsDrive... if (FeedsManager.ExistsFolder(path)) { IFeedFolder folder = FeedsManager.GetFolder(path) as IFeedFolder; return(folder.Name); } if (FeedsManager.ExistsFeed(path)) { IFeed feed = FeedsManager.GetFeed(path) as IFeed; return(feed.Name); } WriteDebug("Couldn't find drive, folder or feed - checking for item."); string[] chunks = ChunkPath(path); if (chunks.Length > 0) { WriteDebug("Chunks:"); foreach (string chk in chunks) { WriteDebug("chunk: " + chk); } int id; if (int.TryParse(chunks[chunks.Length - 1], out id)) { path = GetParentPath(path, ""); WriteDebug("Looking for feed " + path); if (FeedsManager.ExistsFeed(path)) { WriteDebug("Found feed - looking for item"); IFeed feed = FeedsManager.GetFeed(path) as IFeed; IFeedItem feedItem = feed.GetItem(id) as IFeedItem; if (feedItem != null) { WriteDebug("Found item - returning " + feedItem.LocalId); return(feedItem.LocalId.ToString()); } } } } return(base.GetChildName(path)); }
public DataSourceCollection(bool isHistorical, IFeed feed) { this.Feed = feed; this.IsHistorical = isHistorical; if (isHistorical) { InitHistoricalSources(); } }
public void DoWork(NorthwindConfig config, IFeed feed, Digest digest) { ExecuteDelegate worker = new ExecuteDelegate(Execute); AsyncCallback completedCallback = new AsyncCallback(ExecuteCompletedCallback); AsyncOperation async = AsyncOperationManager.CreateOperation(null); // Begin asynchronous method call worker.BeginInvoke(config, feed, digest, completedCallback, async); }
public List <Article> Process(bool IsDownImage, int maxcount) { HttpFeedFactory factory = new HttpFeedFactory(); IFeed feed = factory.CreateFeed(new Uri(this.rssURL)); List <Article> articles = GetArticles(feed, maxcount, IsDownImage); Console.WriteLine("GET Artilces!"); articles.ForEach(ar => ar.Cat = cat); return(articles); }
public PluginsListBox([NotNull] IFeed feed) { Assert.ArgumentNotNull(feed, nameof(feed)); InitializeComponent(); Feed = feed; PackageInformationPanel.Clear(); Search.Text = string.Empty; }
private static Feed CreateFeed(IFeed feed) { var feedItems = (IFeedsEnum)feed.Items; return(new Feed { Title = feed.Title, Items = feedItems.OfType <IFeedItem>().Select(feedItem => CreateFeedItem(feedItem)).ToArray() }); }
private void ParseAtom10Items(IFeed feed, string xml) { var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); var feedItemNodes = xmlDoc.SelectNodes("/atom:feed/atom:entry", NsManager); foreach(XmlNode node in feedItemNodes) { feed.Items.Add(ParseAtom10SingleItem(node)); } }
internal static FeedModel Map(IFeed feed) { return(new FeedModel { FeedUrl = feed.FeedUrl, Title = feed.Title, Description = feed.Description, ImageUrl = feed.ImageUrl, }); }
public virtual void publishUserAction(IFeed data) { Feed feed = new Feed(); // 区别在这里 feed.DataId = data.Id; populateData(data, feed); db.insert(feed); }
/// <summary> /// Records information we are interested in from the configuration settings. /// </summary> private void LoadConfiguration() { var configuration = Factory.Singleton.Resolve <IConfigurationStorage>().Singleton.Load(); _ShortTrailLengthSeconds = configuration.GoogleMapSettings.ShortTrailLengthSeconds; var feedManager = Factory.Singleton.Resolve <IFeedManager>().Singleton; _Feed = feedManager.GetByUniqueId(configuration.GoogleMapSettings.FlightSimulatorXReceiverId, ignoreInvisibleFeeds: false); }
public static List<FeedItemSummary> SummarizeFeed(IFeed feed, ParentFeed parentFeed, int itemCount = 3) { return feed.Items.Reverse().Skip(Math.Max(0, feed.Items.Count - itemCount)).Select(feedItem => new FeedItemSummary { DatePublished = feedItem.DatePublished, Link = feedItem.Link, ParentFeed = parentFeed, Title = feedItem.Title }).OrderByDescending(x => x.DatePublished).ToList(); }
public static IFeed GetFeedInstance(FeedType feedtype) { IFeed instance = null; if (feedtype == FeedType.StackOverflow) { instance = new StackOverflowFeed(); } return(instance); }
public static FeedSummary SummarizeFeed(IFeed feed, int itemCount) { return new FeedSummary { FeedGuid = Guid.NewGuid(), FeedTitle = feed.Title, FeedUri = feed.FeedUri, FeedLink = new Uri(feed.Link), Items = feed.Items.Reverse().Skip(feed.Items.Count() - itemCount).Select(SummarizeFeedItem).Reverse().ToList() }; }
private void DownloadFeed(Uri aUri) { FormDrop form = new FormDrop(this, iSupport, iLrf); IFeed feed = form.Download(aUri); if (feed != null) { iLrf.Add(feed); } }
public void DoWork(IRequest request, IFeed feed, Digest digest) { // ReturnSample(request); // return; // If an asyncState object already exists, an exception is thrown as the performer only accepts // one call after each other. The Request receiver has to manage a queued execution. // Before calling the performers execution implementation method a new AsyncState object is created // and set to an initial tracking state. lock (_asyncStateObj) { if (null != _asyncStateObj.Tracking) { throw new InvalidOperationException("The performer cannot be executed because it is already running."); } ITracking tracking = new Tracking(); tracking.ElapsedSeconds = 1; tracking.Phase = TrackingPhase.INIT; tracking.PhaseDetail = "Tracking Id was: " + _requestContext.TrackingId.ToString(); tracking.PollingMillis = 100; tracking.RemainingSeconds = 100; _asyncStateObj.Tracking = tracking; } // *** Initialization for the async execution *** // - Read Feed from request stream. // - Read trackingId from request URL // convert tracking ID from request to type Guid string strTrackingId = request.Uri.TrackingID; if (String.IsNullOrEmpty(strTrackingId)) { throw new RequestException("TrackingId is missing"); } GuidConverter converter = new GuidConverter(); this.TrackingId = (Guid)converter.ConvertFrom(strTrackingId); // *** Do work asynchronously *** _asyncPerformer = new InternalAsyncPerformer(this); _asyncPerformer.DoWork(_requestContext.Config, feed, digest); // *** set the tracking to the request response *** this.GetTrackingState(request); }
protected override void TestFeedParseCorrectness(IFeedKnownValueTest testcase, IFeed resultantItem) { Rss20Feed rssItem = (Rss20Feed) resultantItem; RssFeedKnownValueTest rssTest = (RssFeedKnownValueTest) testcase; base.TestFeedParseCorrectness(testcase, resultantItem); //Assert that the two descriptions are equivalent Assert.That(rssItem.Description == rssTest.Description); //Assert that the two languages are equivalent Assert.That(rssItem.Language == rssTest.Language); }
private static void populateData(IFeed data, Feed feed) { feed.Creator = data.Creator; feed.DataType = data.DataType; feed.TitleTemplate = data.TitleTemplate; feed.TitleData = data.TitleData; feed.BodyTemplate = data.BodyTemplate; feed.BodyData = data.BodyData; feed.BodyGeneral = data.BodyGeneral; }
public void Attach(IFeed feed) { if (TimeFrame == TimeFrame.t1) { feed.GetSymbol(Symbol).Ticked += OnTick; } else { throw new NotImplementedException("timeframes other than t1"); } feeds.Add(feed); }
private void ParseRss20Items(IFeed feed, string xml) { var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); var feedItemNodes = xmlDoc.SelectNodes("/rss/channel/item"); foreach (XmlNode item in feedItemNodes) { feed.Items.Add(ParseRss20SingleItem(item)); } }
public void Sync() { var factory = new HttpFeedFactory(); model = factory.CreateFeed(feedUri); OnPropertyChanged("Title"); OnPropertyChanged("FeedUri"); OnPropertyChanged("SiteUri"); OnPropertyChanged("LastUPdated"); Entries.Clear(); model.Items.ToList().ForEach(o => Entries.Add(new EntryViewModel(o))); }
/// <summary> /// Factory to construct the RSSFeed object from the Windows RSS Platform API /// </summary> /// <param name="feed">The Common Feed List feed object</param> /// <returns>An initialized RSSFeed object</returns> internal static RssFeed FromApi(IFeed feed) { RssFeed rssFeed = null; // Skip this feed if there are not items. if (feed != null && ((IFeedsEnum)feed.Items).Count > 0) { rssFeed = new RssFeed(feed); } return(rssFeed); }
public string AddFeed(IFeed feed) { if (feed == null) { Logger?.Log(nameof(RSSAtomFeedCollection), nameof(AddFeed), new ArgumentNullException($"{nameof(feed)} must be not-null")); return(null); } this.Feeds.Add(new RSSAtomFeed(feed.Id, feed.Description, feed.TypeDescription, feed.Link, feed.Title, feed.PublishDate)); return(feed.Id); }
public static void SerializeXml(FeedType feedType, IFeed feed, Stream output, string xsltUrl, bool prettyPrint) { if (feedType == null) { throw new ArgumentNullException(nameof(feedType)); } // Do we need to transform the feed? if (feedType != feed.FeedType) { feed = feedType.GetFeed(feed); } // Setup document formatting, make human readable XmlWriterSettings settings = new XmlWriterSettings { CheckCharacters = true, CloseOutput = true, ConformanceLevel = ConformanceLevel.Document, Encoding = System.Text.Encoding.UTF8 }; if (prettyPrint) { settings.Indent = true; settings.IndentChars = "\t"; } else { settings.Indent = false; settings.NewLineChars = string.Empty; } settings.NewLineHandling = NewLineHandling.Replace; XmlWriter writer = XmlWriter.Create(output, settings); // Add a stylesheet for browser viewing if (!string.IsNullOrEmpty(xsltUrl)) { // Render the XSLT processor instruction writer.WriteProcessingInstruction("xml-stylesheet", $"type=\"text/xsl\" href=\"{xsltUrl}\" version=\"1.0\""); } // Get all namespaces XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(); feed.AddNamespaces(namespaces); // Serialize feed XmlSerializer serializer = new XmlSerializer(feed.GetType()); serializer.Serialize(writer, feed, namespaces); }
private void WriteChannelInfo(XmlTextWriter xtw, IFeed feed) { xtw.WriteElementString("title", feed.Title); xtw.WriteElementString("link", GetLink(feed.Url)); xtw.WriteElementString("description", feed.Tagline); xtw.WriteElementString("language", "en-us"); if(feed.Published != null) xtw.WriteElementString("pubDate", GetDate(feed.Published.Value)); xtw.WriteElementString("lastBuildDate", GetDate(DateTime.Now)); xtw.WriteElementString("generator", "N2 CMS"); xtw.WriteElementString("managingEditor", feed.Author); }
private void ParseAtom10Items(IFeed feed, string xml) { var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); var feedItemNodes = xmlDoc.SelectNodes("/atom:feed/atom:entry", NsManager); foreach (XmlNode node in feedItemNodes) { feed.Items.Add(ParseAtom10SingleItem(node)); } }
/// <summary> /// Serializes the specified feed. /// </summary> /// <param name="feed">The feed.</param> /// <param name="type">The type.</param> /// <returns></returns> public static XmlDocument Serialize(IFeed feed, SerializeType type) { XmlDocument doc = new XmlDocument(); switch (type) { case SerializeType.Rss2: SerializeRss2(doc, (IRssFeed)feed); break; default: throw new NotImplementedException(); } return doc; }
private void ParseAtom10Items(IFeed feed, string xml, int maxItems) { var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); var feedItemNodes = xmlDoc.DocumentElement.GetAttributeNode("/atom:feed/atom:entry"); var itemsParsed = 0; foreach(XmlNode node in feedItemNodes) { if (itemsParsed > maxItems) break; feed.Items.Add(ParseAtom10SingleItem(node)); itemsParsed++; } }
public override void ParseFeed(IFeed feed, string xml, int maxItems = 9999) { switch (feed.FeedType) { case FeedType.Rss20: var rssFeed = feed as Rss20Feed; ParseRss20Header(rssFeed, xml); ParseRss20Items(rssFeed, xml, maxItems); break; case FeedType.Atom10: var atomFeed = feed as Atom10Feed; ParseAtom10Header(atomFeed, xml); ParseAtom10Items(atomFeed, xml, maxItems); break; } }
private RssFeed(IFeed feed) { items = new List<RssItem>(); title = feed.Title; link = feed.Link; description = feed.Description; path = feed.Path; lastWriteTime = feed.LastWriteTime; foreach (IFeedItem item in (IFeedsEnum)feed.Items) { RssItem rssItem = new RssItem(item); // only add items that have enclosures if (rssItem.Enclosure != null) items.Add(rssItem); } }
public void DoWork(IRequest request, IFeed feed, Digest digest) { // ReturnSample(request); // return; // If an asyncState object already exists, an exception is thrown as the performer only accepts // one call after each other. The Request receiver has to manage a queued execution. // Before calling the performers execution implementation method a new AsyncState object is created // and set to an initial tracking state. lock (_asyncStateObj) { if (null != _asyncStateObj.Tracking) throw new InvalidOperationException("The performer cannot be executed because it is already running."); ITracking tracking = new Tracking(); tracking.ElapsedSeconds = 1; tracking.Phase = TrackingPhase.INIT; tracking.PhaseDetail = "Tracking Id was: " + _requestContext.TrackingId.ToString(); tracking.PollingMillis = 100; tracking.RemainingSeconds = 100; _asyncStateObj.Tracking = tracking; } // *** Initialization for the async execution *** // - Read Feed from request stream. // - Read trackingId from request URL // convert tracking ID from request to type Guid string strTrackingId = request.Uri.TrackingID; if (String.IsNullOrEmpty(strTrackingId)) throw new RequestException("TrackingId is missing"); GuidConverter converter = new GuidConverter(); this.TrackingId = (Guid)converter.ConvertFrom(strTrackingId); // *** Do work asynchronously *** _asyncPerformer = new InternalAsyncPerformer(this); _asyncPerformer.DoWork(_requestContext.Config, feed, digest); // *** set the tracking to the request response *** this.GetTrackingState(request); }
private void WriteHeader(IFeed feed) { this.XmlWriter.WriteStartDocument(); this.XmlWriter.WriteStartElement("rss"); this.XmlWriter.WriteAttributeString("version", "2.0"); this.XmlWriter.WriteAttributeString("xmlns", "atom", null, "http://www.w3.org/2005/Atom"); this.XmlWriter.WriteStartElement("channel"); this.XmlWriter.WriteElementString("title", feed.Title); this.XmlWriter.WriteElementString("link", feed.Uri.AbsoluteUri); this.XmlWriter.WriteStartElement("atom", "link", null); this.XmlWriter.WriteAttributeString("href", feed.FeedUri.AbsoluteUri); this.XmlWriter.WriteAttributeString("rel", "self"); this.XmlWriter.WriteAttributeString("type", "application/rss+xml"); this.XmlWriter.WriteEndElement(); this.XmlWriter.WriteElementString("description", feed.Description); if(!feed.PublishDate.Equals(DateTime.MinValue)) { this.XmlWriter.WriteElementString("pubDate", feed.PublishDate.ToUniversalTime().ToString("r", DateTimeFormatInfo.InvariantInfo)); } if(!string.IsNullOrEmpty(feed.Language)) { this.XmlWriter.WriteElementString("language", feed.Language); } if(feed.Image != null) { this.XmlWriter.WriteStartElement("image"); this.XmlWriter.WriteElementString("url", feed.Image.Uri.AbsoluteUri); this.XmlWriter.WriteElementString("title", feed.Title); this.XmlWriter.WriteElementString("link", feed.Uri.AbsoluteUri); if(!string.IsNullOrEmpty(feed.Image.Description)) { this.XmlWriter.WriteElementString("description", feed.Image.Description); } if(!feed.Image.Size.IsEmpty) { int width = feed.Image.Size.Width <= 144 ? feed.Image.Size.Width : 144; int height = feed.Image.Size.Height <= 400 ? feed.Image.Size.Height : 400; this.XmlWriter.WriteElementString("width", width.ToString(NumberFormatInfo.InvariantInfo)); this.XmlWriter.WriteElementString("height", height.ToString(NumberFormatInfo.InvariantInfo)); } this.XmlWriter.WriteEndElement(); } }
//configure /// <summary> /// configure app & feeds from config.json /// </summary> public static void Configure(IConfiguration cfg) { //app daysToShow = Int32.Parse(cfg.Get("app:days_to_show") ?? "0"); //feeds //todo make this more robust //hack in feeds:0 as twitter var fcfg = cfg.GetConfigurationSection("feeds:0"); var ocfg = fcfg.GetConfigurationSection("oauth"); //create OAuthTokenProvider var token = new OAuthAppTokenProvider(ocfg.Get("key"), ocfg.Get("secret"), ocfg.Get("app_token_url"), Int32.Parse(ocfg.Get("cache_for_min") ?? "0")); //create feed services var fiService = new TwitterFeedItemService(new OAuthRequestData(token)); var aService = new AccountFeedService(fiService); //create twitter feed object and save twitterFeed = new Feed("twitter", fcfg.Get("default_account"), fcfg.GetArray("default_accounts"), fiService, aService); }
public virtual void Write(TextWriter output, IFeed feed) { XmlTextWriter xtw = new XmlTextWriter(output); xtw.Formatting = Formatting.Indented; xtw.WriteStartDocument(); using (ElementWriter rssElement = new ElementWriter("rss", xtw)) { rssElement.WriteAttribute("version", "2.0"); rssElement.WriteAttribute("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema"); using (new ElementWriter("channel", xtw)) { IEnumerable<ISyndicatable> items = feed.GetItems(); WriteChannelInfo(xtw, feed); foreach (ISyndicatable item in items) { WriteItem(item, xtw); } } } xtw.WriteEndDocument(); }
private static void populateData( IFeed data, Feed feed ) { feed.Creator = data.Creator; feed.DataType = data.DataType; feed.TitleTemplate = data.TitleTemplate; feed.TitleData = data.TitleData; feed.BodyTemplate = data.BodyTemplate; feed.BodyData = data.BodyData; feed.BodyGeneral = data.BodyGeneral; }
public virtual void publishUserAction( IFeed data ) { Feed feed = new Feed(); // 区别在这里 feed.DataId = data.Id; populateData( data, feed ); db.insert( feed ); }
public RssFeed(IFeed source) { // ** IFeedMetadata // ID Channel.Link = source.ID.ToString(); // Title string title = source.Title; if (!string.IsNullOrWhiteSpace(title)) { Channel.Title = title; } // Description string description = source.Description; if (!string.IsNullOrEmpty(description)) { Channel.Description = description; } // Author string author = source.Author; if (!string.IsNullOrEmpty(author)) { Channel.ManagingEditor = new RssPerson { Name = author }; } // Published DateTime? published = source.Published; if (published.HasValue) { Channel.PubDate = new RssDate(published.Value); } // Updated DateTime? updated = source.Updated; if (updated.HasValue) { Channel.LastBuildDate = new RssDate(updated.Value); } // Link Uri link = source.Link; if (link != null) { Channel.Link = link.ToString(); } // ImageLink Uri imageLink = source.ImageLink; if (imageLink != null) { Channel.Image = new RssImage { Url = imageLink.ToString() }; } // ** IFeed // Copyright string copyright = source.Copyright; if (!string.IsNullOrEmpty(copyright)) { Channel.Copyright = copyright; } // Items IList<IFeedItem> sourceItems = source.Items; if (sourceItems != null) { Channel.Items.AddRange(sourceItems.Select(x => new RssItem(x))); } }
/// <summary> /// Factory to construct the RSSFeed object from the Windows RSS Platform API /// </summary> /// <param name="feed">The Common Feed List feed object</param> /// <returns>An initialized RSSFeed object</returns> internal static RssFeed FromApi(IFeed feed) { RssFeed rssFeed = null; // Skip this feed if there are not items. if (feed != null && ((IFeedsEnum)feed.Items).Count > 0) rssFeed = new RssFeed(feed); return rssFeed; }
public override void Write(IFeed feed) { if(this.XmlWriter != null) { this.WriteHeader(feed); DateTime lastBuildDate = feed.PublishDate.ToUniversalTime(); if(feed.Items != null) { foreach(IFeedItem item in feed.Items) { DateTime universalPublishDate = item.PublishDate.ToUniversalTime(); if(universalPublishDate > lastBuildDate) { lastBuildDate = universalPublishDate; } } } this.WriteLastUpdated(lastBuildDate); if(feed.Items != null) { foreach(IFeedItem item in feed.Items) { WriteFeedItem(item); } } this.WriteFooter(); } }
private void BuildSyndicationFeed(IFeed feed, Stream stream, String contenttype) { var atomFeed = new SyndicationFeed() { Title = new TextSyndicationContent(feed.Link.Title), Id = feed.Link.Href, LastUpdatedTime = new DateTimeOffset(DateTime.UtcNow) }; var feedUri = new Uri(feed.Link.Href); atomFeed.Links.Add( new SyndicationLink { Title = feed.Link.Title, Uri = feedUri, RelationshipType = feed.Link.Rel, MediaType = ATOM_CONTENT_TYPE }); // Add parent, related, tag links to AtomFeed var navigationLinks = new List<LinkItem>(); // if (feed.Parent != null) { navigationLinks.Add(feed.Parent); } // if (feed.Related != null) { navigationLinks.AddRange(feed.Related); } // if (feed.Tags != null) { navigationLinks.AddRange(feed.Tags); } // if (feed.Children != null) { navigationLinks.AddRange(feed.Children); } // if (feed.Static != null) { navigationLinks.AddRange(feed.Static); } // Add pagination information if exist if (feed is IPaginatedFeed) { var paginatedFeed = feed as IPaginatedFeed; if (paginatedFeed.FirstLink != null) { navigationLinks.Add(paginatedFeed.FirstLink); } if (paginatedFeed.LastLink != null) { navigationLinks.Add(paginatedFeed.LastLink); } if (paginatedFeed.NextLink != null) { navigationLinks.Add(paginatedFeed.NextLink); } if (paginatedFeed.PreviousLink != null) { navigationLinks.Add(paginatedFeed.PreviousLink); } } foreach (var link in navigationLinks) { atomFeed.Links.Add( new SyndicationLink { Title = link.Title, Uri = new Uri(link.Href), RelationshipType = link.Rel, MediaType = ATOM_CONTENT_TYPE }); } var items = new List<SyndicationItem>(); if (feed.Entries is IEnumerable) { foreach (var item in feed.Entries) { var syndicationItem = _switchOnType[item.Content.GetType()](item.Content, item.Link, null); items.Add(syndicationItem); } } else { var syndicationItem = _switchOnType[feed.Entries.GetType()](feed.Entries, feed.Link, null); items.Add(syndicationItem); } atomFeed.Items = items; using (var writer = XmlWriter.Create(stream)) { Atom10FeedFormatter atomformatter = new Atom10FeedFormatter(atomFeed); atomformatter.WriteTo(writer); } }
public IFeed GetFeed(IFeed source) => _feedFactory(source);
public static List<FeedItemSummary> SummarizeFeed(IFeed feed, int itemCount = 3) { var parentFeed = new ParentFeed {FeedUri = feed.FeedUri, Link = feed.Link, Title = feed.Title, LastUpdated = DateTime.UtcNow}; return SummarizeFeed(feed, parentFeed, itemCount); }
/// <summary> /// Takes a given FeedConfiItem and iterates through all the available plugins to see if any of them can handle it. /// </summary> private void GetFeedType(FeedConfigItem feedConfigItem) { try { Log.Debug("Getting the Feed Type"); var document = (XmlDocument)FeedwinManager.Fetch(feedConfigItem); foreach (var feedplugin in FeedwinManager.thisinst.Plugins) { Log.Debug("Testing {0} to see if it can handle feed", feedplugin.PluginName); if (!feedplugin.CanHandle(document)) continue; Log.Debug("It can! Yay!"); var reqproxy = feedConfigItem.ProxyType != HttpProxyHelper.ProxyType.Global ? feedConfigItem.Proxy : HttpProxyHelper.GetGlobalProxy(); if (reqproxy != null) { Log.Debug("Set Proxy for feed to {0}", reqproxy.GetProxy(new Uri(feedConfigItem.Url))); } else { Log.Debug("Set Proxy for feed to nothing, nothing at all"); } rssfeed = feedplugin.AddFeed(new Uri(feedConfigItem.Url), feedConfigItem.AuthType, feedConfigItem.UserName, feedConfigItem.Password, reqproxy); rssfeed.UpdateInterval = feedConfigItem.UpdateInterval; break; } } catch (XmlException ex) { errormsg = "Invalid XML Document"; Log.Error("XMLException thrown in parsing the feed", ex); } catch (UriFormatException ex) { errormsg = "Invalid URI"; Log.Error("URIException thrown in fetching the feed", ex); } catch (WebException ex) { errormsg = ex.Message; Log.Error("WebException thrown in fetching the feed", ex); } if (rssfeed == null) { Log.Debug("Didn't find a plugin to handle this feed"); if (errormsg == string.Empty) { errormsg = "No Plugin to handle feed"; } } else { rssfeed.Updated += rssfeed_Updated; Log.Debug("Kicking off the watcher thread"); var t = new Thread(rssfeed.Watch) { IsBackground = true }; t.SetApartmentState(ApartmentState.STA); t.Start(); } RedrawWin(); }
private void ParseRss20Items(IFeed feed, string xml, int maxItems) { var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); var feedItemNodes = xmlDoc.DocumentElement.GetAttributeNode("/rss/channel/item"); var itemsParsed = 0; foreach (XmlNode item in feedItemNodes) { if (itemsParsed > maxItems) break; feed.Items.Add(ParseRss20SingleItem(item)); itemsParsed ++; } }