예제 #1
0
        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);
        }
예제 #2
0
        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));
        }
예제 #3
0
        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));
        }
예제 #4
0
        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();
            }
        }
예제 #5
0
        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();
            }
        }