Esempio n. 1
0
        /// <summary>
        /// 英語から日本語へ翻訳
        /// </summary>
        /// <param name="englishText"></param>
        /// <returns></returns>
        public string TranslateEnglishToJapanese(string englishText)
        {
#if DEBUG
            return("Debug - " + englishText);
#else
            try
            {
                //アクセストークン取得
                //アクセストークンは10分間有効であるため、余裕を見て9分以上経過している場合に再度取得する
                if (AdmToken == null ||
                    this.StopWatch.ElapsedMilliseconds > (this.AccessTokenExpiresIn * 1000))
                {
                    this.StopWatch.Reset();
                    this.StopWatch.Start();
                    this.AdmToken = this.AdmAuth.GetAccessToken();

                    // アクセストークンの有効期限(秒)を記憶
                    // 余裕を見て95%にする
                    this.AccessTokenExpiresIn = ( int )(int.Parse(this.AdmToken.expires_in) * 0.95);
                }

                //Create a header with the access_token property of the returned token
                string headerValue = "Bearer " + this.AdmToken.access_token;

                //翻訳実施
                string japaneseText = this.TranslateMethod(headerValue,
                                                           englishText,
                                                           "en",
                                                           "ja");
                System.Threading.Thread.Sleep(100);   //wait

                return(japaneseText);
            }
            catch (WebException ex)
            {
                throw new ApplicationException(this.GetErrorMessage(ex), ex);
            }
#endif
        }
Esempio n. 2
0
        /// <summary>
        /// 英語から日本語へ翻訳
        /// </summary>
        /// <param name="englishText"></param>
        /// <returns></returns>
        public string TranslateEnglishToJapanese( string englishText )
        {
            #if DEBUG
            return "Debug - " + englishText;
            #else
            try
            {
                //アクセストークン取得
                //アクセストークンは10分間有効であるため、余裕を見て9分以上経過している場合に再度取得する
                if ( AdmToken == null
                        || this.StopWatch.ElapsedMilliseconds > ( this.AccessTokenExpiresIn * 1000 ) )
                {
                    this.StopWatch.Reset();
                    this.StopWatch.Start();
                    this.AdmToken = this.AdmAuth.GetAccessToken();

                    // アクセストークンの有効期限(秒)を記憶
                    // 余裕を見て95%にする
                    this.AccessTokenExpiresIn = ( int ) ( int.Parse( this.AdmToken.expires_in ) * 0.95 );
                }

                //Create a header with the access_token property of the returned token
                string headerValue = "Bearer " + this.AdmToken.access_token;

                //翻訳実施
                string japaneseText = this.TranslateMethod(headerValue,
                                                           englishText,
                                                           "en",
                                                           "ja");
                System.Threading.Thread.Sleep( 100 ); //wait

                return japaneseText;
            }
            catch ( WebException ex )
            {
                throw new ApplicationException( this.GetErrorMessage( ex ) , ex );
            }
            #endif
        }