Beispiel #1
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Addresses EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToAddresses(Address address)
 {
     base.AddObject("Addresses", address);
 }
Beispiel #2
0
 /// <summary>
 /// Create a new Address object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 public static Address CreateAddress(global::System.Int32 id)
 {
     Address address = new Address();
     address.Id = id;
     return address;
 }
Beispiel #3
0
        private static void GeneratePeopleData(string cfgName, ProgressWindow progress)
        {
            using (var ctx = new CityContainer())
            {
                var cfgDistricts = ctx.Districts.Where(d => d.Configuration.Name == cfgName);
                var totalAddresses = cfgDistricts.Select(d => d.Population).Sum();
                foreach (var district in cfgDistricts)
                {
                    Logger.LogInfo("generating people for district.");

                    var locations = GeoUtilities.MapPointsToLocations(district.MapPoints);

                    for (var i = 0; i < district.Population; i++)
                    {
                        if (progress.Worker.CancellationPending)
                        {
                            progress.Args.Cancel = true;
                            _simulationCancelled = true;
                            return;
                        }

                        Logger.LogInfo("generating person {0} / {1}", i + 1, district.Population);

                        var bankId = Random.Next(1, ctx.Banks.Count() + 1);
                        var currencyId = Random.Next(1, ctx.Currencies.Count() + 1);
                        var ccNumber = StatisticalData.CreditCardNumber;
                        var personCreditCard = new CreditCard
                                                   {
                                                       Balance = StatisticalData.CreditCardBalance,
                                                       Limit = StatisticalData.CreditCardLimit,
                                                       Bank = ctx.Banks.Single(b => b.Id == bankId),
                                                       Currency = ctx.Currencies.Single(c => c.Id == currencyId),
                                                       Number = ccNumber
                                                   };

                        var templateId = Random.Next(1, ctx.PersonTemplates.Count() + 1);
                        var person = new Person
                                         {
                                             Template = ctx.PersonTemplates.Single(t => t.Id == templateId),
                                             CreditCard = personCreditCard
                                         };

                        var addressGeo = GeoUtilities.RandomLocationWithinPolygon(locations);
                        var address = new Address
                                          {
                                              District = district,
                                              MapPoint = new MapPoint
                                                             {
                                                                 Lat = addressGeo.Latitude,
                                                                 Lng = addressGeo.Longitude
                                                             }
                                          };
                        address.Residents.Add(person);

                        ctx.Addresses.AddObject(address);

                        ++progress.Current;
                        progress.InvokeUpdate(totalAddresses, GeneratingPeopleMsg);
                    }
                }
                progress.InvokeUpdate(totalAddresses, GeneratingPeopleMsg + PersistingMsg);
                ctx.SaveChanges();
            }
        }