Esempio n. 1
0
        internal static void CheckReferenceData()
        {
            // csv...
            string data = ResourceHelper.GetString("AmxMobile.Services.Resources.Countries.csv");
            using (StringReader reader = new StringReader(data))
            {
                CsvDataReader csv = new CsvDataReader(reader, true);

                // txn...
                using (TransactionState txn = Database.StartTransaction())
                {
                    try
                    {
                        while (csv.Read())
                        {
                            // get...
                            string name = csv.GetString("Common Name");
                            if (name == null)
                                throw new InvalidOperationException("'name' is null.");
                            if (name.Length == 0)
                                throw new InvalidOperationException("'name' is zero-length.");

                            // get...
                            Country country = Country.GetByName(name);
                            if (country == null)
                            {
                                country = new Country();
                                country.Name = name;
                                if (string.Compare(name, "United Kingdom", true, Cultures.System) == 0)
                                    country.Ordinal = 1000;
                                if (string.Compare(name, "United States", true, Cultures.System) == 0)
                                    country.Ordinal = 1001;
                                else
                                    country.Ordinal = 9999;

                                // save...
                                country.SaveChanges();
                            }
                        }

                        // ok...
                        txn.Commit();
                    }
                    catch (Exception ex)
                    {
                        txn.Rollback(ex);
                        throw new InvalidOperationException("The operation failed", ex);
                    }
                }

            }
        }
 /// <summary>
 /// Adds a range of <see cref="Country"/> instances to the collection.
 /// </summary>
 public void AddRange(Country[] items)
 {
     base.AddRange(items);
 }
 /// <summary>
 /// Adds a <see cref="Country"/> instance to the collection.
 /// </summary>
 public int Add(Country item)
 {
     return base.Add(item);
 }