protected static void RegisterState(TranslationState state)
 {
     Thread.SetData(
         Thread.GetNamedDataSlot("TranslationState"),
         state);
 }
Beispiel #2
0
        public Result Translate(string phrase, LanguagePair languagesPair, string subject, NetworkSetting networkSetting, TranslationState state)
        {
            if (!SupportedSubjects.Contains(subject))
            {
                throw new ArgumentException("Subject : " + subject + " not supported");
            }

            RegisterState(state);

            Result result = ResultsCache.GetCachedResult(this, phrase, languagesPair, subject);

            lock (result)
            {
                if (result.IsHasData())
                {
                    UnregisterState();
                    return(result);
                }

                long start = DateTime.Now.Ticks;
                try
                {
                    CheckIsTerminated();
                    string error;
                    if (CheckPhrase(phrase, out error))
                    {
                        DoTranslate(phrase, languagesPair, subject, result, networkSetting);
                    }
                    else
                    {
                        result.Error = new TranslationException(error);
                    }
                }
                catch (System.Exception e)
                {
                    result.Error = e;
                }
                result.QueryTicks = DateTime.Now.Ticks - start;
            }
            UnregisterState();
            return(result);
        }
 protected static void RegisterState(TranslationState state)
 {
     Thread.SetData(
         Thread.GetNamedDataSlot("TranslationState"),
         state);
 }