<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ServiceStack.Common.Web;
using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface;
using Terradue.News;
using Terradue.OpenSearch;
using Terradue.OpenSearch.Engine;
using Terradue.OpenSearch.Result;
using Terradue.OpenSearch.Tumblr;
using Terradue.Portal;
using Terradue.Tep.WebServer;
using Terradue.WebService.Model;

namespace Terradue.Tep.WebServer.Services {
    [Api("Tep Terradue webserver")]
    [Restrict(EndpointAttributes.InSecure | EndpointAttributes.InternalNetworkAccess | EndpointAttributes.Json,
              EndpointAttributes.Secure | EndpointAttributes.External | EndpointAttributes.Json)]
    public class TumblrNewsServiceTep : ServiceStack.ServiceInterface.Service {

        [AddHeader(ContentType="application/atom+xml")]
        public object Get(SearchTumblrNews request) {
            IfyWebContext context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);
            IOpenSearchResultCollection result = null;
            try{
                context.Open();

                // Load the complete request
                HttpRequest httpRequest = HttpContext.Current.Request;

                OpenSearchEngine ose = MasterCatalogue.OpenSearchEngine;

                Type type = OpenSearchFactory.ResolveTypeFromRequest(httpRequest, ose);

                List<TumblrFeed> tumblrs = TumblrNews.LoadTumblrFeeds(context);

                MultiGenericOpenSearchable multiOSE = new MultiGenericOpenSearchable(tumblrs.Cast<IOpenSearchable>().ToList(), ose);

                result = ose.Query(multiOSE, httpRequest.QueryString, type);

                context.Close ();
            }catch(Exception e) {
                context.Close ();
                throw e;
            }

            return new HttpResult(result.SerializeToString(), result.ContentType);
        }

        public object Get(GetTumblrNewsFeeds request) {
            IfyWebContext context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);
            List<WebNews> result = new List<WebNews>();
            try{
                context.Open();

                List<TumblrFeed> tumblrs = TumblrNews.LoadTumblrFeeds(context);
                List<TumblrNews> tumblrfeeds = new List<TumblrNews>();
                foreach(TumblrFeed tumblr in tumblrs) tumblrfeeds.AddRange(TumblrNews.FromFeeds(context, tumblr.GetFeeds()));
                foreach(TumblrNews feed in tumblrfeeds) result.Add(new WebNews(feed));
                
                context.Close ();
            }catch(Exception e) {
                context.Close ();
                throw e;
            }

            return result;
        }

        public object Get(GetAllTumblrNews request) {
            IfyWebContext context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);
            List<WebNews> result = new List<WebNews>();
            try{
                context.Open();

                EntityList<TumblrNews> articles = new EntityList<TumblrNews>(context);
                articles.Load();
                foreach(TumblrNews article in articles) result.Add(new WebNews(article));

                context.Close ();
            }catch(Exception e) {
                context.Close ();
                throw e;
            }

            return result;
        }
<commit_msg>add id for tumblr feeds<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ServiceStack.Common.Web;
using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface;
using Terradue.News;
using Terradue.OpenSearch;
using Terradue.OpenSearch.Engine;
using Terradue.OpenSearch.Result;
using Terradue.OpenSearch.Tumblr;
using Terradue.Portal;
using Terradue.Tep.WebServer;
using Terradue.WebService.Model;

namespace Terradue.Tep.WebServer.Services {
    [Api("Tep Terradue webserver")]
    [Restrict(EndpointAttributes.InSecure | EndpointAttributes.InternalNetworkAccess | EndpointAttributes.Json,
              EndpointAttributes.Secure | EndpointAttributes.External | EndpointAttributes.Json)]
    public class TumblrNewsServiceTep : ServiceStack.ServiceInterface.Service {

        [AddHeader(ContentType="application/atom+xml")]
        public object Get(SearchTumblrNews request) {
            IfyWebContext context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);
            IOpenSearchResultCollection result = null;
            try{
                context.Open();

                // Load the complete request
                HttpRequest httpRequest = HttpContext.Current.Request;

                OpenSearchEngine ose = MasterCatalogue.OpenSearchEngine;

                Type type = OpenSearchFactory.ResolveTypeFromRequest(httpRequest, ose);

                List<TumblrFeed> tumblrs = TumblrNews.LoadTumblrFeeds(context);

                MultiGenericOpenSearchable multiOSE = new MultiGenericOpenSearchable(tumblrs.Cast<IOpenSearchable>().ToList(), ose);

                result = ose.Query(multiOSE, httpRequest.QueryString, type);


                context.Close ();
            }catch(Exception e) {
                context.Close ();
                throw e;
            }

            return new HttpResult(result.SerializeToString(), result.ContentType);
        }

        public object Get(GetTumblrNewsFeeds request) {
            IfyWebContext context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);
            List<WebNews> result = new List<WebNews>();
            try{
                context.Open();

                List<TumblrFeed> tumblrs = TumblrNews.LoadTumblrFeeds(context);
                List<TumblrNews> tumblrfeeds = new List<TumblrNews>();
                foreach(TumblrFeed tumblr in tumblrs) tumblrfeeds.AddRange(TumblrNews.FromFeeds(context, tumblr.GetFeeds()));
                int i=0;
                foreach(TumblrNews feed in tumblrfeeds){
                    WebNews wn = new WebNews(feed);
                    wn.Id = i++;
                    result.Add(wn);
                }
                
                context.Close ();
            }catch(Exception e) {
                context.Close ();
                throw e;
            }

            return result;
        }

        public object Get(GetAllTumblrNews request) {
            IfyWebContext context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);
            List<WebNews> result = new List<WebNews>();
            try{
                context.Open();

                EntityList<TumblrNews> articles = new EntityList<TumblrNews>(context);
                articles.Load();
                foreach(TumblrNews article in articles) result.Add(new WebNews(article));

                context.Close ();
            }catch(Exception e) {
                context.Close ();
                throw e;
            }

            return result;
        }

{'fraction_non_alphanumeric': 0.08559919436052367, 'fraction_numerical': 0.00014386419220256078, 'mean_word_length': 2.225986078886311, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '979958', 'n_tokens_mistral': 1936, 'n_tokens_neox': 1780, 'n_words': 343}