public async Task <TranslateResult> Find(TranslateRequest translateRequest)
        {
            if (!_googleConfiguration.CanSupport() || !_googleConfiguration.IsActive())
            {
                return(new TranslateResult(false, new Maybe <string>()));
            }

            string uri = string.Format(
                _googleConfiguration.Url,
                _applicationConfiguration.ToLanguage.Extension,
                _applicationConfiguration.ToLanguage.Extension,
                HttpUtility.UrlEncode(translateRequest.CurrentText, Encoding.UTF8));

            IRestResponse response = await _restClient.Manipulate(client =>
            {
                client.BaseUrl  = uri.ToUri();
                client.Encoding = Encoding.UTF8;
            })
                                     .ExecuteGetTaskAsync(
                new RestRequest(Method.GET)
                .AddHeader(Headers.AcceptLanguage, AcceptLanguage)
                .AddHeader(Headers.AcceptEncoding, AcceptEncoding)
                .AddHeader(Headers.UserAgent, UserAgent)
                .AddHeader(Headers.Accept, Accept));

            var mean = new Maybe <string>();

            if (response.Ok())
            {
                IMeanOrganizer organizer = _meanOrganizerFactory.GetMeanOrganizers().First(x => x.TranslatorType == TranslatorType);
                mean = await organizer.OrganizeMean(response.Content);
            }

            return(new TranslateResult(true, mean));
        }
        public async Task <TranslateResult> Find(TranslateRequest translateRequest)
        {
            if (!_bingConfiguration.CanSupport() || !_bingConfiguration.IsActive())
            {
                return(new TranslateResult(false, new Maybe <string>()));
            }

            var requestObject = new
            {
                from = _applicationConfiguration.FromLanguage.Name.ToLower(),
                to   = _applicationConfiguration.ToLanguage.Name.ToLower(),
                text = translateRequest.CurrentText
            };

            IRestResponse response = await _restClient
                                     .Manipulate(client => client.BaseUrl = _bingConfiguration.Url.ToUri())
                                     .ExecutePostTaskAsync(new RestRequest(Method.POST)
                                                           .AddHeader(ContentTypeName, ContentType)
                                                           .AddParameter(ContentType, requestObject.ToJsonString(true), ParameterType.RequestBody)
                                                           );

            var mean = new Maybe <string>();

            if (response.Ok())
            {
                IMeanOrganizer meanOrganizer = _meanOrganizerFactory.GetMeanOrganizers().First(x => x.TranslatorType == TranslatorType);
                mean = await meanOrganizer.OrganizeMean(response.Content);
            }

            return(new TranslateResult(true, mean));
        }
        public async Task <TranslateResult> Find(TranslateRequest translateRequest)
        {
            if (!configuration.IsAppropriateForTranslation(TranslatorType, translateRequest.FromLanguageExtension))
            {
                return(new TranslateResult(false, new Maybe <string>()));
            }

            var parameter =
                $"sl=auto&text={Uri.EscapeUriString(translateRequest.CurrentText)}&tl={configuration.ToLanguageExtension}";

            var response = await new RestClient(configuration.SesliSozlukUrl)
            {
                Encoding    = Encoding.UTF8,
                CachePolicy = new HttpRequestCachePolicy(HttpCacheAgeControl.MaxAge, TimeSpan.FromHours(1))
            }.ExecutePostTaskAsync(
                new RestRequest(Method.POST)
                .AddHeader("accept-language", "en-US,en;q=0.8,tr;q=0.6")
                .AddHeader("accept-encoding", "gzip, deflate")
                .AddHeader("content-type", "application/x-www-form-urlencoded")
                .AddHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36")
                .AddHeader("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
                .AddParameter("application/x-www-form-urlencoded", parameter, ParameterType.RequestBody));

            var meanOrganizer = meanOrganizerFactory.GetMeanOrganizers().First(x => x.TranslatorType == TranslatorType);
            var mean          = await meanOrganizer.OrganizeMean(response.Content);

            return(new TranslateResult(true, mean));
        }
Esempio n. 4
0
        public async Task <TranslateResult> Find(TranslateRequest translateRequest)
        {
            if (!configuration.IsAppropriateForTranslation(TranslatorType, translateRequest.FromLanguageExtension))
            {
                return(new TranslateResult(false, new Maybe <string>()));
            }

            var uri = string.Format(configuration.ZarganTranslateUrl, HttpUtility.UrlEncode(translateRequest.CurrentText, Encoding.UTF8));

            var compositeMean = await new RestClient(uri)
            {
                Encoding = Encoding.UTF8
            }
            .ExecuteGetTaskAsync(
                new RestRequest(Method.GET)
                .AddHeader("Accept-Language", "en-US,en;q=0.8,tr;q=0.6")
                .AddHeader("Accept-Encoding", "gzip, deflate, sdch")
                .AddHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36")
                .AddHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"));

            var organizer = meanOrganizerFactory.GetMeanOrganizers().First(x => x.TranslatorType == TranslatorType);
            var mean      = await organizer.OrganizeMean(compositeMean.Content, translateRequest.FromLanguageExtension);

            return(new TranslateResult(true, mean));
        }
        public async Task <TranslateResult> Find(TranslateRequest translateRequest)
        {
            if (!_sesliSozlukConfiguration.CanSupport() || !_sesliSozlukConfiguration.IsActive())
            {
                return(new TranslateResult(false, new Maybe <string>()));
            }

            string parameter = $"sl=auto&text={Uri.EscapeUriString(translateRequest.CurrentText)}&tl={_applicationConfiguration.ToLanguage.Extension}";

            var response = await new RestClient(_sesliSozlukConfiguration.Url)
            {
                Encoding    = Encoding.UTF8,
                CachePolicy = new HttpRequestCachePolicy(HttpCacheAgeControl.MaxAge, TimeSpan.FromHours(1))
            }.ExecutePostTaskAsync(
                new RestRequest(Method.POST)
                .AddHeader(Headers.AcceptLanguage, AcceptLanguage)
                .AddHeader(Headers.AcceptEncoding, AcceptEncoding)
                .AddHeader(Headers.ContentType, ContentType)
                .AddHeader(Headers.UserAgent, UserAgent)
                .AddHeader(Headers.Accept, Accept)
                .AddParameter(ContentType, parameter, ParameterType.RequestBody));

            var mean = new Maybe <string>();

            if (response.Ok())
            {
                var meanOrganizer = _meanOrganizerFactory.GetMeanOrganizers().First(x => x.TranslatorType == TranslatorType);
                mean = await meanOrganizer.OrganizeMean(response.Content);
            }

            return(new TranslateResult(true, mean));
        }
        public async Task <TranslateResult> Find(TranslateRequest translateRequest)
        {
            if (!_turengConfiguration.CanSupport())
            {
                return(new TranslateResult(false, new Maybe <string>()));
            }

            if (!_turengConfiguration.IsActive())
            {
                return(new TranslateResult(false, new Maybe <string>()));
            }

            var uri = new Uri(_turengConfiguration.Url + translateRequest.CurrentText);

            IRestResponse response = await _restClient
                                     .Manipulate(client =>
            {
                client.BaseUrl     = uri;
                client.Encoding    = Encoding.UTF8;
                client.CachePolicy = new HttpRequestCachePolicy(HttpCacheAgeControl.MaxAge, TimeSpan.FromHours(1));
            }).ExecuteGetTaskAsync(
                new RestRequest(Method.GET)
                .AddHeader(Headers.UserAgent, UserAgent)
                .AddHeader(Headers.AcceptLanguage, AcceptLanguage));

            var mean = new Maybe <string>();

            if (response.Ok())
            {
                IMeanOrganizer organizer = _meanOrganizerFactory.GetMeanOrganizers().First(x => x.TranslatorType == TranslatorType);
                mean = await organizer.OrganizeMean(response.Content, translateRequest.FromLanguageExtension);
            }

            return(new TranslateResult(true, mean));
        }
Esempio n. 7
0
        public async Task <TranslateResult> Find(TranslateRequest translateRequest)
        {
            if (!configuration.IsAppropriateForTranslation(TranslatorType, translateRequest.FromLanguageExtension))
            {
                return(new TranslateResult(false, new Maybe <string>()));
            }

            var requestObject = new
            {
                from = configuration.FromLanguage.ToLower(),
                to   = configuration.ToLanguage.ToLower(),
                text = translateRequest.CurrentText
            };

            var response = await new RestClient(configuration.BingTranslatorUrl)
            {
                Encoding    = Encoding.UTF8,
                CachePolicy = new HttpRequestCachePolicy(HttpCacheAgeControl.MaxAge, TimeSpan.FromHours(1))
            }.ExecutePostTaskAsync(new RestRequest(Method.POST)
                                   .AddHeader("content-type", "application/json;Charset=UTF-8")
                                   .AddParameter("application/json;Charset=UTF-8",
                                                 JsonConvert.SerializeObject(requestObject),
                                                 ParameterType.RequestBody));

            var meanOrganizer = meanOrganizerFactory.GetMeanOrganizers().First(x => x.TranslatorType == TranslatorType);
            var mean          = await meanOrganizer.OrganizeMean(response.Content);

            return(new TranslateResult(true, mean));
        }
        public async Task <TranslateResult> Find(TranslateRequest translateRequest)
        {
            if (!_yandexConfiguration.CanSupport() || !_yandexConfiguration.IsActive())
            {
                return(new TranslateResult(false, new Maybe <string>()));
            }

            Uri           address;
            IRestResponse response;

            if (_yandexConfiguration.ShouldBeAnonymous)
            {
                address = new Uri(string.Format(_yandexConfiguration.Url +
                                                new StringBuilder()
                                                .Append($"id={_yandexConfiguration.SId}")
                                                .Append(Headers.Ampersand)
                                                .Append("srv=tr-text")
                                                .Append(Headers.Ampersand)
                                                .Append($"lang={translateRequest.FromLanguageExtension}-{_applicationConfiguration.ToLanguage.Extension}")
                                                .Append(Headers.Ampersand)
                                                .Append($"text={Uri.EscapeUriString(translateRequest.CurrentText)}")));

                response = await _restClient.Manipulate(client => { client.BaseUrl = address; })
                           .ExecutePostTaskAsync(new RestRequest(Method.POST)
                                                 .AddParameter(Headers.ContentTypeDefinition, $"text={translateRequest.CurrentText}"));
            }
            else
            {
                address = new Uri(string.Format(_yandexConfiguration.Url +
                                                new StringBuilder()
                                                .Append($"key={_yandexConfiguration.ApiKey}")
                                                .Append(Headers.Ampersand)
                                                .Append($"lang={translateRequest.FromLanguageExtension}-{_applicationConfiguration.ToLanguage.Extension}")
                                                .Append(Headers.Ampersand)
                                                .Append($"text={Uri.EscapeUriString(translateRequest.CurrentText)}")));

                response = await _restClient.Manipulate(client => { client.BaseUrl = address; }).ExecutePostTaskAsync(new RestRequest(Method.POST));
            }

            var mean = new Maybe <string>();

            if (response.Ok())
            {
                IMeanOrganizer organizer = _meanOrganizerFactory.GetMeanOrganizers().First(x => x.TranslatorType == TranslatorType);
                mean = await organizer.OrganizeMean(response.Content);
            }

            return(new TranslateResult(true, mean));
        }
        public async Task <TranslateResult> Find(TranslateRequest translateRequest)
        {
            if (!configuration.IsAppropriateForTranslation(TranslatorType, translateRequest.FromLanguageExtension))
            {
                return(new TranslateResult(false, new Maybe <string>()));
            }

            var address = new Uri(string.Format(configuration.YandexUrl +
                                                $"key={configuration.ApiKey}&lang={translateRequest.FromLanguageExtension}-{configuration.ToLanguageExtension}&text={Uri.EscapeUriString(translateRequest.CurrentText)}"));

            var compositeMean = await new RestClient(address).ExecutePostTaskAsync(new RestRequest(Method.POST));

            var organizer = meanOrganizerFactory.GetMeanOrganizers().First(x => x.TranslatorType == TranslatorType);
            var mean      = await organizer.OrganizeMean(compositeMean.Content);

            return(new TranslateResult(true, mean));
        }
Esempio n. 10
0
        public async Task <TranslateResult> Find(TranslateRequest translateRequest)
        {
            if (!_promptConfiguration.CanSupport() || !_promptConfiguration.IsActive())
            {
                return(new TranslateResult(false, new Maybe <string>()));
            }

            var requestObject = new
            {
                dirCode       = $"{translateRequest.FromLanguageExtension}-{_applicationConfiguration.ToLanguage.Extension}",
                template      = _promptConfiguration.Template,
                text          = translateRequest.CurrentText,
                lang          = translateRequest.FromLanguageExtension,
                limit         = _promptConfiguration.Limit,
                useAutoDetect = true,
                key           = string.Empty,
                ts            = _promptConfiguration.Ts,
                tid           = string.Empty,
                IsMobile      = false
            };

            IRestResponse response = await _restClient
                                     .Manipulate(client =>
            {
                client.BaseUrl = _promptConfiguration.Url.ToUri();
            }).ExecutePostTaskAsync(new RestRequest(Method.POST)
                                    .AddHeader(ContentTypeName, ContentType)
                                    .AddParameter(ContentType, requestObject.ToJsonString(false), ParameterType.RequestBody));

            var mean = new Maybe <string>();

            if (response.Ok())
            {
                IMeanOrganizer meanOrganizer = _meanOrganizerFactory.GetMeanOrganizers().First(x => x.TranslatorType == TranslatorType);
                mean = await meanOrganizer.OrganizeMean(response.Content);
            }

            return(new TranslateResult(true, mean));
        }
        public async Task <TranslateResult> Find(TranslateRequest translateRequest)
        {
            if (!configuration.IsAppropriateForTranslation(TranslatorType, translateRequest.FromLanguageExtension))
            {
                return(new TranslateResult(false, new Maybe <string>()));
            }

            var uri = new Uri(configuration.TurengUrl + translateRequest.CurrentText);

            var compositeMean = await new RestClient(uri)
            {
                Encoding    = Encoding.UTF8,
                CachePolicy = new HttpRequestCachePolicy(HttpCacheAgeControl.MaxAge, TimeSpan.FromHours(1))
            }.ExecuteGetTaskAsync(
                new RestRequest(Method.GET)
                .AddHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36")
                .AddHeader("Accept-Language", "en-US,en;q=0.8,tr;q=0.6"));

            var organizer = meanOrganizerFactory.GetMeanOrganizers().First(x => x.TranslatorType == TranslatorType);
            var mean      = await organizer.OrganizeMean(compositeMean.Content, translateRequest.FromLanguageExtension);

            return(new TranslateResult(true, mean));
        }