Esempio n. 1
0
        private List <WordDomain> ConvertExcelDomainToWordDomain(ExcelDomain excelDomain)
        {
            var result = new List <WordDomain>();

            excelDomain.BodyDomain.DataList.ForEach(p =>
            {
                var wordDomain = new WordDomain
                {
                    Id         = Guid.NewGuid(),
                    CreateTime = DateTime.Now.Ticks
                };
                p.ColumnList.ForEach(pro =>
                {
                    switch (pro.ColumnNumber)
                    {
                    case 1:
                        wordDomain.Word = pro.Value;
                        break;

                    case 2:
                        wordDomain.Trascation = pro.Value;
                        break;

                    case 3:
                        wordDomain.Phonetic = pro.Value;
                        break;

                    case 4:
                        wordDomain.Voice = pro.Value;
                        break;

                    default:
                        break;
                    }
                });
                result.Add(wordDomain);
            });
            return(result);
        }
Esempio n. 2
0
        //private void Input_MouseEnter(object sender, MouseEventArgs e)
        //{
        //    if (e.LeftButton == MouseButtonState.Pressed)
        //    {
        //        this.Yes.Visibility = Visibility.Hidden;
        //        this.No.Visibility = Visibility.Hidden;
        //    }
        //}

        private void GoNext(object sender, EventArgs e)
        {
            this.TipsContent.Content = string.Empty;
            this.Yes.Visibility      = Visibility.Hidden;
            this.No.Visibility       = Visibility.Hidden;
            this.VoiceError.Content  = string.Empty;
            this.Input.Text          = string.Empty;
            this.Input.Focus();

            var newOne = this.SelectedModelDomain.Model.Equals(ModelEnum.Revised) || this.SelectedModelDomain.Model.Equals(ModelEnum.RevisedChange) ? this.wordRepository.GetReadedOne() : this.wordRepository.GetOneExcludeById(this.CurrentWordDomain.Id);

            if (newOne != null)
            {
                //ThreadPool.QueueUserWorkItem((p => { this.Voice_Click(null, null); }));
                this.LastWrodDomain    = this.CurrentWordDomain;
                this.CurrentWordDomain = newOne;
                this.Voice_Click(null, null);
                this.InitWordData(newOne);
            }
            else
            {
                MessageBox.Show("resource is null, please import resource.");
            }
        }
Esempio n. 3
0
        private void InitWordData(WordDomain wordInfo = null)
        {
            var currentModel = this.SelectedModelDomain.Model;

            switch (currentModel)
            {
            case ModelEnum.Default:
                wordInfo = wordInfo == null?this.wordRepository.GetOne() : wordInfo;

                if (wordInfo == null)
                {
                    MessageBox.Show("resource is null, please import resource.");
                    return;
                }
                this.Word.Content       = wordInfo.Word;
                wordInfo.TrascationFlag = false;
                break;

            case ModelEnum.Changed:
                wordInfo = wordInfo == null?this.wordRepository.GetOne() : wordInfo;

                if (wordInfo == null)
                {
                    MessageBox.Show("resource is null, please import resource.");
                    return;
                }
                this.Word.Content       = wordInfo.Trascation;
                wordInfo.TrascationFlag = false;
                break;

            case ModelEnum.Mixed:
                wordInfo = wordInfo == null?this.wordRepository.GetOne() : wordInfo;

                if (wordInfo == null)
                {
                    MessageBox.Show("resource is null, please import resource.");
                    return;
                }
                Random rd     = new Random();
                var    number = rd.Next(1000, 10000);
                if (number % 2 == 0)
                {
                    this.Word.Content       = wordInfo.Word;
                    wordInfo.TrascationFlag = false;
                }
                else
                {
                    this.Word.Content       = wordInfo.Trascation;
                    wordInfo.TrascationFlag = true;
                }
                break;

            case ModelEnum.Revised:
                wordInfo = wordInfo == null?this.wordRepository.GetReadedOne() : wordInfo;

                if (wordInfo == null)
                {
                    MessageBox.Show("resource is null, please import resource.");
                    return;
                }
                this.Word.Content       = wordInfo.Word;
                wordInfo.TrascationFlag = false;
                break;

            case ModelEnum.RevisedChange:
                wordInfo = wordInfo == null?this.wordRepository.GetReadedOne() : wordInfo;

                if (wordInfo == null)
                {
                    MessageBox.Show("resource is null, please import resource.");
                    return;
                }
                this.Word.Content       = wordInfo.Trascation;
                wordInfo.TrascationFlag = false;
                break;

            default:
                break;
            }
            this.CurrentWordDomain = wordInfo;
        }
Esempio n. 4
0
        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.wordRepository == null)
            {
                var seletedOne = this.DropDownList.SelectedValue as LanguageDomain;
                this.TableName      = mappingDic[seletedOne.Name];
                this.wordRepository = new WordRepository(this.TableName);
            }
            var textBox = this.Word as TextBox;

            if (textBox != null && !string.IsNullOrEmpty(textBox.Text))
            {
                this.TranslatedInformation.Content = string.Empty;
                if (!this.CheckIfInvalidInput(textBox.Text))
                {
                    TranslationResult result        = null;
                    JinShanDomain     jinshanDomain = null;
                    if (!textBox.Text.Any(p => !Regex.IsMatch(p.ToString(), ChineseRule)))
                    {
                        //result = TranslationMethod.TranslatedWithBaidu(textBox.Text, LanguageEnum.ZH, LanguageEnum.EN);
                        jinshanDomain = JinShanUtil.Translate(textBox.Text);
                    }
                    else if (!textBox.Text.Any(p => !Regex.IsMatch(p.ToString(), JapaneseRule)))
                    {
                        result = TranslationMethod.TranslatedWithBaidu(textBox.Text, LanguageEnum.JP, LanguageEnum.ZH);
                    }
                    else
                    {
                        result = TranslationMethod.TranslatedWithBaidu(textBox.Text, LanguageEnum.Auto, LanguageEnum.ZH);
                    }
                    //|| (!string.IsNullOrEmpty(result.Error_code) && result.Error_code != "52000")
                    if (result == null && jinshanDomain == null)
                    {
                        this.TranslatedInformation.Content    = string.Format("Error code: {0}, {1}", result.Error_code, result.Error_msg);
                        this.TranslatedInformation.Foreground = Brushes.Red;
                    }
                    else
                    {
                        if (jinshanDomain != null)
                        {
                            var wordInfo = new WordDomain
                            {
                                Id         = Guid.NewGuid(),
                                Word       = jinshanDomain.word_name,
                                Flag       = 0,
                                CreateTime = DateTime.Now.Ticks
                            };
                            var defaultOne = jinshanDomain.symbols.FirstOrDefault();
                            wordInfo.Phonetic = defaultOne.ph_en;
                            wordInfo.Voice    = this.ConvertVoice(defaultOne);
                            //var translationStr = string.Empty;
                            //foreach (var part in defaultOne.parts)
                            //{
                            //    var meanStr = string.Empty;
                            //    foreach (var mean in part.means)
                            //    {
                            //        meanStr += mean;
                            //        meanStr += ";";
                            //    }
                            //    translationStr += "{";
                            //    translationStr += part.part;
                            //    translationStr += ":";
                            //    translationStr += meanStr;
                            //    translationStr += "}";
                            //}
                            wordInfo.Trascation = defaultOne.parts.FirstOrDefault().means[0];
                            this.wordRepository = new WordRepository("Language_Custom");
                            this.wordRepository.InsertAll(new List <WordDomain> {
                                wordInfo
                            }, !string.IsNullOrEmpty(wordInfo.Voice));
                            // 删除缓存中最旧的data
                            this.UpdateHistoryResource(wordInfo.Word, string.Join(",", defaultOne.parts.FirstOrDefault().means.FirstOrDefault()));
                        }
                        else
                        {
                            var contentStr = string.Empty;
                            for (var i = 0; i < result.Trans_result.Length; i++)
                            {
                                if (i > 0)
                                {
                                    contentStr += "/r/n";
                                }
                                var line = string.Format("{0}:  {1}", result.Trans_result[i].Src, result.Trans_result[i].Dst);
                                contentStr += line;
                                // 添加到OtherResource
                                //ResourceAction.RemoveAndAddNewResEntry(historyResourceUrl, "Key_" + result.Trans_result[i].Src, result.Trans_result[i].Dst);
                                var wordInfo = new WordDomain()
                                {
                                    Id         = Guid.NewGuid(),
                                    Word       = result.Trans_result[i].Src,
                                    Trascation = result.Trans_result[i].Dst,
                                    Phonetic   = result.Trans_result[i].Src,
                                    Flag       = 0,
                                    CreateTime = DateTime.Now.Ticks
                                };
                                this.wordRepository.InsertAll(new List <WordDomain> {
                                    wordInfo
                                });

                                // 删除缓存中最旧的data
                                this.UpdateHistoryResource(result.Trans_result[i].Src, result.Trans_result[i].Dst);
                            }
                            this.TranslatedInformation.Content = contentStr;
                        }

                        this.TranslatedInformation.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999933"));
                        this.InitHistoryContent();
                    }
                }
                else
                {
                    this.TranslatedInformation.Content    = string.Format("Error: invalid word, please input again.");
                    this.TranslatedInformation.Foreground = Brushes.Red;
                    this.Word.Focus();
                }
            }
        }