<commit_before>﻿using System.Net;
using DEG.ServiceCore.Authentication;
using DEG.ServiceCore.Helpers;
using DEG.ServiceCore.Models;

namespace DEG.ServiceCore
{
    public class ServiceBase
    {
        private readonly IServiceAuth _auth;

        public ServiceBase(IServiceAuth auth)
        {
            _auth = auth;
        }

        public T GetObject<T>(string url) where T : class 
        {
            var resultString = GetString(url);

            T results;
            if (JsonHelper.TryParse(resultString, out results))
                return results;
            if (XmlHelper.TryParse(resultString, out results))
                return results;

            return default(T);
        }

        protected string GetString(string url)
        {
            string resultString;
            using (var client = _auth.GetAuthenticatedWebClient())
            {
                resultString = client.DownloadString(_auth.GetAuthenticatedUrl(url));
            }
            return resultString;
        }

        public TResp SubmitObject<TResp, TReq>(string url, TReq request, DataFormat format = DataFormat.Json) where TResp : class
        {
            string resultString;
            using (var client = _auth.GetAuthenticatedWebClient())
            {
                string requestString;
                if (format == DataFormat.Xml)
                {
                    requestString = XmlHelper.Stringify(request);
                    client.Headers.Add(HttpRequestHeader.ContentType, "application/xml");
                }
                else
                {
                    requestString = JsonHelper.Stringify(request);
                    client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
                }

                resultString = client.UploadString(_auth.GetAuthenticatedUrl(url), requestString);
            }

            TResp results;
            if (JsonHelper.TryParse(resultString, out results))
                return results;
            if (XmlHelper.TryParse(resultString, out results))
                return results;

            return default(TResp);
        }
    }
}
<commit_msg>Add SubmitString to ServiceBase<commit_after>﻿using System;
using System.Net;
using DEG.ServiceCore.Authentication;
using DEG.ServiceCore.Helpers;
using DEG.ServiceCore.Models;

namespace DEG.ServiceCore
{
    public class ServiceBase
    {
        private readonly IServiceAuth _auth;

        public ServiceBase(IServiceAuth auth)
        {
            _auth = auth;
        }

        public T GetObject<T>(string url) where T : class 
        {
            var resultString = GetString(url);

            T results;
            if (JsonHelper.TryParse(resultString, out results))
                return results;
            if (XmlHelper.TryParse(resultString, out results))
                return results;

            return default(T);
        }

        protected string GetString(string url)
        {
            string resultString;
            using (var client = _auth.GetAuthenticatedWebClient())
            {
                resultString = client.DownloadString(_auth.GetAuthenticatedUrl(url));
            }
            return resultString;
        }

        public TResp SubmitObject<TResp, TReq>(string url, TReq request, DataFormat format = DataFormat.Json) where TResp : class
        {
            var contentType = format == DataFormat.Xml ? "application/xml" : "application/json";
            var resultString = SubmitString(url, request, contentType);

            TResp results;
            if (JsonHelper.TryParse(resultString, out results))
                return results;
            if (XmlHelper.TryParse(resultString, out results))
                return results;

            return default(TResp);
        }

        protected string SubmitString<TReq>(string url, TReq request, string contentType)
        {
            string resultString;
            using (var client = _auth.GetAuthenticatedWebClient())
            {
                var requestString = contentType.Equals("application/xml", StringComparison.InvariantCultureIgnoreCase)
                                           ? XmlHelper.Stringify(request)
                                           : JsonHelper.Stringify(request);

                client.Headers.Add(HttpRequestHeader.ContentType, contentType);
                resultString = client.UploadString(_auth.GetAuthenticatedUrl(url), requestString);
            }
            return resultString;
        }
    }
}

{'fraction_non_alphanumeric': 0.07393162393162393, 'fraction_numerical': 0.0, 'mean_word_length': 1.6180089485458613, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2251461', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1083, 'n_words': 248}