Esempio n. 1
0
        public RequestManager(DBUtil dbUtils)
        {
            this._dbUtils = dbUtils;

            WeiConfiguration weiConfig = (WeiConfiguration)ConfigurationManager.GetSection("Wei");

            _brequiresReview = weiConfig.requiresReview;
            _searchString    = weiConfig.searchString;
            _replaceString   = weiConfig.replaceString;

            int threadPoolSize = 0;

            try
            {
                threadPoolSize = Convert.ToInt32(weiConfig.ThreadPoolSize);
            }
            catch (Exception e)
            {
                LogUtil.log("Cannot parse ThreadPoolSize attribute. ThreadPoolSize is configured as:" + weiConfig.ThreadPoolSize, e);
                throw new Exception("Invalid ThreadPoolSize attribute specified in the configuration file");
            }

            System.Threading.ThreadPool.SetMaxThreads(threadPoolSize, threadPoolSize);

            try
            {
                _maxTranslateRetryCount = Int32.Parse(weiConfig.TranslatorSetting.NoOfRetries);
            }
            catch (Exception e)
            {
                LogUtil.log("Cannot parse NoOfRetries attribute. NoOfRetries is configured as:" + weiConfig.TranslatorSetting.NoOfRetries, e);
                throw new Exception("Invalid NoOfRetries attribute in the configuration file");
            }
            translator = new Translator(weiConfig);

            _fallBackParser = new DefaultParser(translator);
            _parsers.Add("SWIFT", new SwiftParser(translator, weiConfig.SwiftSetting));
            foreach (ParserConfigElement parserConfig in weiConfig.Parsers)
            {
                Type type;
                if (parserConfig.DllName != null && parserConfig.DllName.Trim().Length > 0)
                {
                    type = TypeUtil.getType(parserConfig.DllName, parserConfig.ClassName, typeof(IConfigurableMessageParser));
                }
                else
                {
                    type = TypeUtil.getType(null, parserConfig.ClassName, typeof(IConfigurableMessageParser));
                }
                IConfigurableMessageParser configurableParser = (IConfigurableMessageParser)Activator.CreateInstance(type);
                configurableParser.configure(translator, parserConfig.Param1, parserConfig.Param2, parserConfig.Param3, parserConfig.Param4, parserConfig.Param5);
                _parsers.Add(parserConfig.Name, configurableParser);
            }
        }
Esempio n. 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            WeiConfiguration weiConfig = (WeiConfiguration)ConfigurationManager.GetSection("Wei");

            translator = new Translator(weiConfig);

            foreach (MapFileConfigElement mapFileConfig in weiConfig.TranslatorSetting.MapFiles)
            {
                srcLanguage.Items.Add(mapFileConfig.Language);
            }



            providers.SelectedIndex = 0;
        }
        public void initialize(string key, Int32 maxLength, WeiConfiguration config)
        {
            this.key       = key;
            this.maxLength = maxLength;

            if (config.Proxy != null && config.Proxy.Uri != null && config.Proxy.Uri.Trim().Length > 0)
            {
                proxy                    = new WebProxy();
                proxy.Address            = new Uri(config.Proxy.Uri);
                proxy.BypassProxyOnLocal = Convert.ToBoolean(config.Proxy.BypassLocal);

                foreach (BypassConfigElement bypass in config.Proxy.Bypass)
                {
                    proxy.BypassArrayList.Add(bypass.Name);
                }

                if (config.Proxy.Credential.Count > 0)
                {
                    String username = null;
                    String password = null;

                    foreach (CredentialConfigElement cred in config.Proxy.Credential)
                    {
                        if (cred.Key.Equals("username"))
                        {
                            username = cred.Value;
                        }
                        if (cred.Key.Equals("password"))
                        {
                            password = cred.Value;
                        }
                    }
                    if (username != null && password != null)
                    {
                        ICredentials credential = new NetworkCredential(username, password);
                        proxy.Credentials = credential;
                    }
                    else
                    {
                        LogUtil.logInfo("Ignoring credential as either username/password is not configured. Username:"******" password:" + password);
                    }
                }
            }
        }
Esempio n. 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                WeiConfiguration weiConfig    = (WeiConfiguration)ConfigurationManager.GetSection("Wei");
                string           _sDisclaimer = "Disclaimer: Translation service is powered by ";

                if (weiConfig != null)
                {
                    foreach (ProviderConfigElement provider in weiConfig.TranslatorSetting.Providers)
                    {
                        if (provider.Name == weiConfig.TranslatorSetting.CurrentTranslationProvider)
                        {
                            lblText.Text         = _sDisclaimer + provider.Name;
                            lblVersionValue.Text = provider.Version;
                        }
                    }
                }
            }
            btnClose.Attributes.Add("onclick", "popup_close();return false;");
        }
Esempio n. 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string _translate;
            string _CTCode;
            string _sEnglish;
            string _sChinese = "";
            int    _istart;
            int    _iend;

            if (!Page.IsPostBack)
            {
                string from = Request.QueryString["from"];
                string text = Request.QueryString["text"];
                DbUtil _dataAccess;
                _dataAccess = EnterpriseLibraryContainer.Current.GetInstance <DbUtil>();

                //from = "CTC";
                //text = "1159 5646 7456 2609 2139 4098 2345";
                DataTable _dataTable;

                if (text != "")
                {
                    _dDataset  = _dataAccess.getTranslationsByCTC(text);
                    _dataTable = _dDataset.Tables[0];
                    if (_dataTable.Rows.Count > 0)
                    {
                        for (int iRow = 0; iRow < _dataTable.Rows.Count; iRow++)
                        {
                            lblChineseValue.Text  = _dataTable.Rows[iRow]["ChineseChar"].ToString();
                            lblOldTransValue.Text = _dataTable.Rows[iRow]["OldTrans"].ToString();
                            lblNewTransValue.Text = _dataTable.Rows[iRow]["NewTrans"].ToString();
                        }
                        lblCTCValue.Text = text;
                    }
                    else
                    {
                        WeiConfiguration weiConfig = (WeiConfiguration)ConfigurationManager.GetSection("Wei");

                        if (weiConfig != null)
                        {
                            translator = new Translator(weiConfig);
                            if (translator != null)
                            {
                                _translate = translator.convertAndTranslate(text, true);


                                if (_translate != null)
                                {
                                    _istart = _translate.IndexOf("[");
                                    _iend   = _translate.IndexOf("]");
                                    if (_istart > 0)
                                    {
                                        _CTCode = _translate.Substring(0, _istart);
                                        //Check if this is a valid CTC Code


                                        lblCTCValue.Text = _CTCode.ToString();

                                        _sEnglish        = _translate.Substring(_istart + 1, _iend - (_istart + 1));
                                        lblOldTrans.Text = _sEnglish.Trim().ToString();
                                        lblNewTrans.Text = _sEnglish.Trim().ToString();

                                        _sChinese = translator.convert(text, false, null);

                                        if (_sChinese != null)
                                        {
                                            lblChineseValue.Text = _sChinese.Trim().ToString();
                                        }
                                        LblError.Visible    = false;
                                        lblChinese.Visible  = true;
                                        lblCTC.Visible      = true;
                                        lblOldTrans.Visible = true;
                                        lblNewTrans.Visible = true;
                                    }
                                    else
                                    {
                                        LblError.Text       = "The text is not valid for translation.";
                                        LblError.Visible    = true;
                                        lblChinese.Visible  = false;
                                        lblCTC.Visible      = false;
                                        lblOldTrans.Visible = false;
                                        lblNewTrans.Visible = false;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }