예제 #1
0
        /// <summary>
        /// 处理英文单词
        /// </summary>
        /// <param name="w"></param>
        /// <returns></returns>
        private static Word[] DealWordEn(string result)
        {
            WordEn word = new WordEn();

            string value      = result.Class("word-text");
            string sample     = result.Class("simple");
            string pronounces = result.Class("pronounces");
            string audio      = pronounces.Class(Tag.span, "word-audio");

            string detail      = result.Class("word-details-item detail");
            string detailEnEn  = result.Class("word-details-item enen");
            string synant      = result.Class("word-details-item synant");
            string inflections = result.Class("word-details-item inflections");
            string phrase      = result.Class("word-details-item phrase");

            word.Value      = value.FilterHTML_();
            word.Sample     = sample.FilterHTML();
            word.Pronounces = pronounces.FilterHTML();
            word.Audio      = audio.Attr("data-src");

            word.PronouncesEn = Regex.Replace(word.Pronounces, "美(.\\[.*?\\])?", "").Trim();
            word.PronouncesUs = Regex.Replace(word.Pronounces, "英.\\[.*?\\]", "").Trim();

            word.Detail      = detail.FilterHTML_();
            word.DetailEnEn  = detailEnEn.FilterHTML_();
            word.Synant      = synant.FilterHTML_();
            word.Inflections = inflections.FilterHTML();
            word.Phrase      = phrase.FilterHTML_();

            return(new Word[] { word });
        }
예제 #2
0
        /// <summary>
        /// 写入数据库
        /// </summary>
        private static void WriteWotd2DB(object o)
        {
            Word word = (Word)o;

            if (word.Value == null || word.Value.Equals(""))
            {
                return;
            }
            string sql = "";

            try
            {
                if (word.GetType() == typeof(WordEn))
                {
                    WordEn w = word as WordEn;
                    w   = (WordEn)w.FilterDB();
                    sql = @"UPDATE WORD_EN 
                            SET PronouncesUs = N'{1}', 
                                Sample = N'{2}', 
                                Phrase = N'{3}', 
                                Detail = N'{4}', 
                                PronouncesEn = N'{5}', 
                                DetailEnEn = N'{6}', 
                                Synant = N'{7}', 
                                Inflections = N'{8}', 
                                AudioUrl = N'{9}', 
                                UpdateCount = UpdateCount + 1, 
                                UpdateTime = GETDATE() WHERE VALUE = N'{0}';
                            IF @@ROWCOUNT = 0 
                            INSERT INTO WORD_EN(
                                Value, PronouncesUs, Sample, Phrase, Detail, PronouncesEn, 
                                DetailEnEn, Synant, Inflections, AudioUrl, Audio, Mark,
                                UpdateCount, UpdateTime
                            ) VALUES (
                                N'{0}',N'{1}',N'{2}',N'{3}',N'{4}',N'{5}',N'{6}',N'{7}',N'{8}',N'{9}',NULL, 0, 0, GETDATE()
                            )";
                    sql = string.Format(sql, w.Value, w.PronouncesUs, w.Sample, w.Phrase, w.Detail, w.PronouncesEn, w.DetailEnEn, w.Synant, w.Inflections, w.Audio);
                }
                else if (word.GetType() == typeof(WordJp))
                {
                    WordJp w = word as WordJp;
                    w   = (WordJp)w.FilterDB();
                    sql = @"UPDATE WORD_JP 
                            SET Sample = N'{2}', 
                                Detail = N'{3}',
                                Synant = N'{4}', 
                                AudioUrl = N'{5}', 
                                UpdateCount = UpdateCount + 1, 
                                UpdateTime = GETDATE() WHERE VALUE = N'{0}' AND Pronounces = N'{1}';
                            IF @@ROWCOUNT = 0 
                            INSERT INTO WORD_JP(
                                Value, Pronounces, Sample, Detail, Synant, AudioUrl, Audio, UpdateCount, UpdateTime
                            ) VALUES (N'{0}',N'{1}',N'{2}',N'{3}',N'{4}',N'{5}', NULL, 0, GETDATE())";
                    sql = string.Format(sql, w.Value, w.Pronounces, w.Sample, w.Detail, w.Synant, w.Audio);
                }

                using (DbManager db = new DbManager())
                {
                    db.ExeceteQuery(sql);
                }
            }
            catch (Exception ex)
            {
                if (ex.GetType() == typeof(SqlException) && ((SqlException)ex).Number == 2627)
                {
                    //sql = "UPDATE WORD_JP";
                }
                else
                {
                    Log.Write("WriteWotd2DB Filed [{0}]\t{1}", word.Value, ex.Message);
                    Log.Write("SQL【{0}】", sql);
                }
            }
        }