예제 #1
0
 /// <summary>
 /// Create a new Transaction object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="dateTime">Initial value of the DateTime property.</param>
 /// <param name="value">Initial value of the Value property.</param>
 public static Transaction CreateTransaction(global::System.Int32 id, global::System.DateTime dateTime, global::System.Double value)
 {
     Transaction transaction = new Transaction();
     transaction.Id = id;
     transaction.DateTime = dateTime;
     transaction.Value = value;
     return transaction;
 }
예제 #2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Transactions EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToTransactions(Transaction transaction)
 {
     base.AddObject("Transactions", transaction);
 }
예제 #3
0
        private void GenerateTransactions(string cfgName, ProgressWindow progress)
        {
            using(var ctx = new CityContainer())
            {
                var selectionMethodName = ctx.Configurations.Single(c => c.Name == cfgName).SelectionMethod.Name;
                Logger.LogInfo("Using POI selection method: {0}", selectionMethodName);

                var demandsInConfiguration = ctx.Demands.Where(d => d.Person.Address.District.Configuration.Name == cfgName);
                var totalTransactions = demandsInConfiguration.Count();
                foreach (var demand in demandsInConfiguration)
                {
                    if (progress.Worker.CancellationPending)
                    {
                        progress.Args.Cancel = true;
                        _simulationCancelled = true;
                        return;
                    }

                    var demandType = demand.PoiType.Code;
                    var matchingPois = ctx.Pois.Where(p => p.Type.Select(k => k.Code).Contains(demandType));

                    var selectedPoi = SelectPoi(matchingPois, demand.Person.Address.MapPoint, selectionMethodName);

                    if (selectedPoi == null) continue;

                    var transactionValue = StatisticalData.TransactionValue;
                    var creditCard = demand.Person.CreditCard;

                    var balanceAfterTransaction = creditCard.Balance - transactionValue;

                    if (balanceAfterTransaction < creditCard.Limit) continue;
                    creditCard.Balance -= transactionValue;
                    creditCard.Balance = Math.Round(creditCard.Balance, 2);

                    var transactionDateTime = demand.DateTime
                        .AddHours(Random.Next(0,24))
                        .AddMinutes(Random.Next(0,60))
                        .AddSeconds(Random.Next(0,60));

                    var transaction = new Transaction
                                          {
                                              Demand = demand,
                                              CreditCard = creditCard,
                                              Poi = selectedPoi,
                                              Value = transactionValue,
                                              DateTime = transactionDateTime
                                          };

                    ctx.Transactions.AddObject(transaction);
                    demand.Fulfilled = true;

                    ++progress.Current;
                    progress.InvokeUpdate(totalTransactions, GeneratingTransactionsMsg);
                }
                progress.InvokeUpdate(totalTransactions, GeneratingTransactionsMsg + PersistingMsg);
                ctx.SaveChanges();
            }
        }