Пример #1
0
        public static ResourceDatabase Load(string databaseFile)
        {
            string connection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
                                databaseFile + ";";

            using (var myConnection = new OleDbConnection(connection)) {
                myConnection.Open();
                ResourceDatabase db = new ResourceDatabase();
                using (OleDbCommand myOleDbCommand = new OleDbCommand("SELECT * FROM Localization", myConnection)) {
                    using (OleDbDataReader reader = myOleDbCommand.ExecuteReader()) {
                        string[] fieldNames = Enumerable.Range(0, reader.FieldCount).Select(i => reader.GetName(i)).ToArray();
                        db.Languages.Add(new LanguageTable("en"));
                        foreach (string fieldName in fieldNames)
                        {
                            if (fieldName.StartsWith("lang-"))
                            {
                                db.Languages.Add(new LanguageTable(fieldName.Substring(5)));
                            }
                        }
                        while (reader.Read())
                        {
                            ResourceEntry primaryEntry = new ResourceEntry {
                                Key         = reader["ResourceName"].ToString(),
                                Description = reader["PrimaryPurpose"].ToString(),
                                Value       = reader["PrimaryResLangValue"].ToString()
                            };
                            db.Languages[0].Entries.Add(primaryEntry.Key, primaryEntry);
                            for (int i = 1; i < db.Languages.Count; i++)
                            {
                                string val = reader["lang-" + db.Languages[i].LanguageName].ToString();
                                if (!string.IsNullOrEmpty(val))
                                {
                                    ResourceEntry entry = new ResourceEntry {
                                        Key         = primaryEntry.Key,
                                        Description = primaryEntry.Description,
                                        Value       = val
                                    };
                                    db.Languages[i].Entries.Add(entry.Key, entry);
                                }
                            }
                        }
                    }
                }
                return(db);
            }
        }
Пример #2
0
		public static ResourceDatabase Load(string databaseFile)
		{
			string connection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
				databaseFile + ";";
			using (var myConnection = new OleDbConnection(connection)) {
				myConnection.Open();
				ResourceDatabase db = new ResourceDatabase();
				using (OleDbCommand myOleDbCommand = new OleDbCommand("SELECT * FROM Localization", myConnection)) {
					using (OleDbDataReader reader = myOleDbCommand.ExecuteReader()) {
						string[] fieldNames = Enumerable.Range(0, reader.FieldCount).Select(i => reader.GetName(i)).ToArray();
						db.Languages.Add(new LanguageTable("en"));
						foreach (string fieldName in fieldNames) {
							if (fieldName.StartsWith("lang-"))
								db.Languages.Add(new LanguageTable(fieldName.Substring(5)));
						}
						while (reader.Read()) {
							ResourceEntry primaryEntry = new ResourceEntry {
								Key = reader["ResourceName"].ToString(),
								Description = reader["PrimaryPurpose"].ToString(),
								Value = reader["PrimaryResLangValue"].ToString()
							};
							db.Languages[0].Entries.Add(primaryEntry.Key, primaryEntry);
							for (int i = 1; i < db.Languages.Count; i++) {
								string val = reader["lang-" + db.Languages[i].LanguageName].ToString();
								if (!string.IsNullOrEmpty(val)) {
									ResourceEntry entry = new ResourceEntry {
										Key = primaryEntry.Key,
										Description = primaryEntry.Description,
										Value = val
									};
									db.Languages[i].Entries.Add(entry.Key, entry);
								}
							}
						}
					}
				}
				return db;
			}
		}