public object Get(GetTwitterNewsFeeds request) { var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView); List <WebNews> result = new List <WebNews>(); try{ context.Open(); context.LogInfo(this, string.Format("/news/twitter/feeds GET")); var twitterCollection = TwitterNews.LoadTwitterCollection(context); var twitters = twitterCollection.GetFeeds(new System.Collections.Specialized.NameValueCollection()); List <TwitterNews> tweetsfeeds = new List <TwitterNews>(); tweetsfeeds.AddRange(TwitterNews.FromFeeds(context, twitters)); foreach (TwitterNews tweetfeed in tweetsfeeds) { result.Add(new WebNews(tweetfeed)); } context.Close(); }catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public object Get(SearchNews request) { var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView); IOpenSearchResultCollection result = null; try{ context.Open(); context.LogInfo(this, string.Format("/news/search GET")); // Load the complete request HttpRequest httpRequest = HttpContext.Current.Request; OpenSearchEngine ose = MasterCatalogue.OpenSearchEngine; Type type = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose); List <Terradue.OpenSearch.IOpenSearchable> osentities = new List <Terradue.OpenSearch.IOpenSearchable>(); //try{ // EntityList<Article> articles = new EntityList<Article>(context); // articles.Load(); // osentities.Add(articles); //}catch(Exception){} try{ var twitters = TwitterNews.LoadTwitterCollection(context); osentities.Add(twitters); }catch (Exception) {} try{ EntityList <RssNews> rsss = new EntityList <RssNews>(context); rsss.Load(); if (rsss != null) { foreach (RssNews rss in rsss) { osentities.Add(rss); } } }catch (Exception) {} var settings = MasterCatalogue.OpenSearchFactorySettings; MultiGenericOpenSearchable multiOSE = new MultiGenericOpenSearchable(osentities, settings); result = ose.Query(multiOSE, httpRequest.QueryString, type); context.Close(); }catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new HttpResult(result.SerializeToString(), result.ContentType)); }
public object Get(GetAllNewsFeeds request) { List <WebNews> result = new List <WebNews>(); var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView); try { context.Open(); context.LogInfo(this, string.Format("/news/feeds GET")); //get internal news //try{ // EntityList<Article> news = new EntityList<Article>(context); // news.Load(); // foreach(Terradue.Portal.Article f in news){ // if(f.GetType() == typeof(Article)) // result.Add(new WebNews(f)); // } //}catch(Exception){} //get twitter news try { var twitterCollection = TwitterNews.LoadTwitterCollection(context); var twitters = twitterCollection.GetFeeds(new System.Collections.Specialized.NameValueCollection()); List <TwitterNews> tweetsfeeds = new List <TwitterNews>(); tweetsfeeds.AddRange(TwitterNews.FromFeeds(context, twitters)); } catch (Exception) { } //get rss news try{ EntityList <RssNews> rsss = new EntityList <RssNews>(context); rsss.Load(); List <RssNews> rssfeeds = new List <RssNews>(); foreach (RssNews rss in rsss) { rssfeeds.AddRange(rss.GetFeeds()); } foreach (RssNews rssfeed in rssfeeds) { result.Add(new WebNews(rssfeed)); } }catch (Exception) {} context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result.OrderByDescending(r => r.Date)); }
public void SearchTwitterFeeds() { var ose = MasterCatalogue.OpenSearchEngine; var settings = new OpenSearchableFactorySettings(ose); var parameters = new NameValueCollection(); parameters.Set("count", "20"); try { var twitters = TwitterNews.LoadTwitterCollection(context); IOpenSearchResultCollection osr = ose.Query(twitters, parameters); Assert.That(osr.TotalResults > 0); } catch (Exception e) { Assert.Fail(e.Message); } finally { context.EndImpersonation(); } }
public void SearchAllFeeds() { var ose = MasterCatalogue.OpenSearchEngine; var settings = new OpenSearchableFactorySettings(ose); List <Terradue.OpenSearch.IOpenSearchable> osentities = new List <Terradue.OpenSearch.IOpenSearchable>(); var parameters = new NameValueCollection(); parameters.Set("count", "20"); context.AccessLevel = EntityAccessLevel.Privilege; try { EntityList <Article> articles = new EntityList <Article>(context); articles.Load(); osentities.Add(articles); var twitters = TwitterNews.LoadTwitterCollection(context); osentities.Add(twitters); EntityList <RssNews> rsss = new EntityList <RssNews>(context); rsss.Load(); if (rsss != null) { foreach (RssNews rss in rsss) { osentities.Add(rss); } } MultiGenericOpenSearchable multiOSE = new MultiGenericOpenSearchable(osentities, settings); IOpenSearchResultCollection osr = ose.Query(multiOSE, parameters); Assert.That(osr.TotalResults > 0); } catch (Exception e) { Assert.Fail(e.Message); } finally { context.EndImpersonation(); } }