private string searchInServer(String sourceString)
        {
            if (_neurotolgeConnector == null)
            {
                // Use basic connection settings
                string serverAddress = _options.serverAddress;
                int    serverPort    = int.Parse(_options.port);

                // Use features
                string        client   = _options.client;
                string        subject  = _options.subject;
                List <string> features = new List <string>();

                if (!String.IsNullOrEmpty(client))
                {
                    features.Add(client);
                }

                if (!String.IsNullOrEmpty(subject))
                {
                    features.Add(subject);
                }

                if (!String.IsNullOrEmpty(_options.otherFeatures))
                {
                    features.AddRange(_options.otherFeatures.Split(';'));
                }

                _neurotolgeConnector = new NeurotolgeConnector(serverAddress, serverPort, features);
            }

            var translatedText = _neurotolgeConnector.getTranslation(_languageDirection, sourceString);

            return(translatedText);
        }
        private async Task <List <PreTranslateSegment> > PrepareTempData(List <PreTranslateSegment> preTranslateSegments)
        {
            try
            {
                string sourceString = String.Empty;
                for (var i = 0; i < preTranslateSegments.Count; i++)
                {
                    var    newSeg     = preTranslateSegments[i].TranslationUnit.SourceSegment.Duplicate();
                    string sourceText = newSeg.ToPlain();

                    preTranslateSegments[i].SourceText = sourceText;

                    if (i == preTranslateSegments.Count - 1)
                    {
                        sourceString += sourceText;
                    }
                    else
                    {
                        sourceString += sourceText + "|";
                    }
                }

                // Use basic connection settings
                string serverAddress = _options.serverAddress;
                int    serverPort    = int.Parse(_options.port);

                // Use features
                string        client   = _options.client;
                string        subject  = _options.subject;
                List <string> features = new List <string>();

                if (!String.IsNullOrEmpty(client))
                {
                    features.Add(client);
                }

                if (!String.IsNullOrEmpty(subject))
                {
                    features.Add(subject);
                }

                if (!String.IsNullOrEmpty(_options.otherFeatures))
                {
                    features.AddRange(_options.otherFeatures.Split(';'));
                }
                var translator = new NeurotolgeConnector(serverAddress, serverPort, features);

                //await Task.Run(() => Parallel.ForEach(preTranslateSegments, segment =>
                //{
                //    var translation = HttpUtility.UrlDecode(translator.getTranslation(_languageDirection, segment.SourceText));
                //    segment.PlainTranslation = HttpUtility.HtmlDecode(translation);
                //})).ConfigureAwait(true);

                //await Task.Run(() =>
                //{
                //    var translations = translator.getTranslation(_languageDirection, sourceString);
                //    string[] substrings = translations.Split('|');

                //}).ConfigureAwait(true);
                var      translations      = translator.getTranslation(_languageDirection, sourceString);
                string[] translationsSplit = translations.Split('|');
                if (translationsSplit.Length == preTranslateSegments.Count)
                {
                    for (var i = 0; i < preTranslateSegments.Count; i++)
                    {
                        preTranslateSegments[i].PlainTranslation = translationsSplit[i];
                    }
                }
                else
                {
                    Console.Write("error in searchtranslationunits. The lengths are not the same.");
                }

                return(preTranslateSegments);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(preTranslateSegments);
        }
        public SearchResults[] SearchTranslationUnitsMasked(SearchSettings settings, TranslationUnit[] translationUnits, bool[] mask)
        {
            List <SearchResults> results = new List <SearchResults>();
            string sourceString          = String.Empty;
            int    stringLength          = 0;

            // Use basic connection settings
            string serverAddress = _options.serverAddress;
            int    serverPort    = int.Parse(_options.port);

            // Use features
            string        client   = _options.client;
            string        subject  = _options.subject;
            List <string> features = new List <string>();

            if (!String.IsNullOrEmpty(client))
            {
                features.Add(client);
            }

            if (!String.IsNullOrEmpty(subject))
            {
                features.Add(subject);
            }

            if (!String.IsNullOrEmpty(_options.otherFeatures))
            {
                features.AddRange(_options.otherFeatures.Split(';'));
            }

            if (_neurotolgeConnector == null)
            {
                var translator = new NeurotolgeConnector(serverAddress, serverPort, features);
                _neurotolgeConnector = translator;
            }

            var sourceStrings = new List <String>();

            for (var i = 0; i < translationUnits.Length; i++)
            {
                var tu = translationUnits[i];
                if (mask == null || mask[i])
                {
                    // There are problems if the text is too long
                    if (stringLength < 700)
                    {
                        if (i == translationUnits.Length - 1)
                        {
                            sourceString += tu.SourceSegment.ToPlain();
                            stringLength  = sourceString.Length;
                            sourceStrings.Add(sourceString);
                        }
                        else
                        {
                            sourceString += tu.SourceSegment.ToPlain() + "|";
                            stringLength  = sourceString.Length;
                        }
                    }
                    else
                    {
                        sourceString = sourceString.Remove(sourceString.Length - 1);
                        sourceStrings.Add(sourceString);
                        sourceString = String.Empty;

                        if (i == translationUnits.Length - 1)
                        {
                            sourceString += tu.SourceSegment.ToPlain();
                            stringLength  = sourceString.Length;
                            sourceStrings.Add(sourceString);
                        }
                        else
                        {
                            sourceString += tu.SourceSegment.ToPlain() + "|";
                            stringLength  = sourceString.Length;
                        }
                    }
                }
                else
                {
                    results.Add(null);
                }
            }

            foreach (var source in sourceStrings)
            {
                var      translations      = _neurotolgeConnector.getTranslation(_languageDirection, source);
                string[] translationsSplit = translations.Split('|');
                for (var j = 0; j < translationsSplit.Length; j++)
                {
                    var translation = new Segment(_languageDirection.TargetCulture);
                    var newSeg      = translationUnits[j].SourceSegment.Duplicate();

                    translation.Add(translationsSplit[j]);

                    var searchResult  = CreateSearchResult(newSeg, translation);
                    var results_small = new SearchResults
                    {
                        SourceSegment = newSeg
                    };
                    results_small.Add(searchResult);
                    results.Add(results_small);
                }
            }

            return(results.ToArray());
        }