コード例 #1
0
        /// <summary>
        /// Retrieves language information from https://www.loc.gov/standards/iso639-2/php/code_list.php
        /// and stores it in the specified languageDb
        /// </summary>
        /// <param name="languageDb"></param>
        /// <param name="onSaved"></param>
        /// <param name="onExists"></param>
        /// <param name="onOtherNameSaved"></param>
        /// <param name="onOtherNameExists"></param>
        public static bool?EnsureLanguages(Database languageDb, Action <Language> onSaved = null, Action <Language> onExists = null, Action <OtherName> onOtherNameSaved = null, Action <OtherName> onOtherNameExists = null)
        {
            return(_retrieveLock.DoubleCheckLock(ref _languagesRetrieved, () =>
            {
                CQ cq = CQ.Create(Http.Get("https://www.loc.gov/standards/iso639-2/php/code_list.php"));
                cq = cq.Remove("script");

                bool first = true;
                cq["tr", cq["table[width='100%'][cellspacing='0'][cellpadding='4'][border='1']"]].Each((Action <IDomObject>)(row =>
                {
                    if (!first)
                    {
                        string isoCode = cq["td", row][0].InnerText.DelimitSplit(" ")[0];
                        Language language = Language.OneWhere(c => c.ISO6392 == isoCode, languageDb);
                        if (language == null)
                        {
                            language = new Language();
                            language.Uuid = Guid.NewGuid().ToString();
                            language.ISO6392 = isoCode;
                            language.ISO6391 = cq["td", row][1].InnerText;
                            string[] englishNames = cq["td", row][2].InnerText.DelimitSplit(";");
                            string[] frenchNames = cq["td", row][3].InnerText.DelimitSplit(";");
                            string[] germanNames = cq["td", row][4].InnerText.DelimitSplit(";");
                            language.EnglishName = englishNames.Length > 0 ? englishNames[0] : "";
                            language.FrenchName = frenchNames.Length > 0 ? frenchNames[0].Or("&nbsp;") : "";
                            language.GermanName = germanNames.Length > 0 ? germanNames[0].Or("&nbsp;") : "";
                            language.Save(languageDb);

                            if (onSaved != null)
                            {
                                onSaved(language);
                            }

                            if (englishNames.Length > 1)
                            {
                                SetOtherNames(languageDb, language, englishNames, "English");
                            }
                            if (frenchNames.Length > 1)
                            {
                                SetOtherNames(languageDb, language, frenchNames, "French");
                            }
                            if (germanNames.Length > 1)
                            {
                                SetOtherNames(languageDb, language, germanNames, "German");
                            }
                        }
                        else
                        {
                            if (onExists != null)
                            {
                                onExists(language);
                            }
                        }
                    }
                    first = false;
                }));
                return true;
            }));
        }
コード例 #2
0
ファイル: Language.cs プロジェクト: dekkerb115/Bam.Net
 public ActionResult Update(Bam.Net.Translation.Language dao)
 {
     try
     {
         dao.Save();
         return(Json(new { Success = true, Message = "", Dao = dao.ToJsonSafe() }));
     }
     catch (Exception ex)
     {
         return(GetErrorResult(ex));
     }
 }
コード例 #3
0
ファイル: Language.cs プロジェクト: ThreeHeadz/Bam.Net
        private static Language CreateFromFilter(IQueryFilter filter, Database database = null)
        {
            Database db  = database ?? Db.For <Language>();
            var      dao = new Language();

            filter.Parameters.Each(p =>
            {
                dao.Property(p.ColumnName, p.Value);
            });
            dao.Save(db);
            return(dao);
        }