Exemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="context"></param>
        /// 
        public override void Invoke(ExchangeRuntime runtime)
        {
            if (runtime.Abort)
            {
                // runtime.Status = ExchangeEngine.
                runtime.Continue();
                return;
            }

            Stopwatch timer = new Stopwatch();
            timer.Start();

            PricingEvent @event = new PricingEvent(this.GetType().Name);
            string debtamount = runtime.GetDebtLead().CreditCardDebtAmount;
            string daysbehind = runtime.GetDebtLead().PaymentStatus;
            Console.WriteLine("amount={0}, days={1}.", debtamount, daysbehind);
            List<long> prospects = runtime.GetData(ExchangeRuntime.PROSPECTS) as List<long>;

            EntityCollection<Allocation> allocations = ExchangeService.GetAllocationPlan(prospects, debtamount, daysbehind);
            if (allocations == null)
            {
                runtime.Status = ExchangeRuntime.PENDING_MATCH;
                timer.Stop();
                @event.ElapsedTime = timer.ElapsedMilliseconds;
                runtime.AllocationCount = 0;
                runtime.AddStrategyEvent(@event);
                runtime.Continue();
                return;
            }

            List<long> distributions = new List<long>();

            foreach (Allocation prospect in allocations)
            {
                OutboundDuplicate outDupe = new OutboundDuplicate();
                outDupe.Aid = Convert.ToString(prospect.Aid);
                outDupe.Oid = Convert.ToString(prospect.OrderId);
                outDupe.Email = runtime.GetLead().Email;
                outDupe.Created = runtime.GetLead().Created;
                ExchangeService.SaveOutboundDuplicate(outDupe);

                distributions.Add(prospect.Aid);
                @event.Bids.Add(new Bid(prospect.Aid, prospect.OrderId));
            }

            if (allocations.Count() > 0)
            {
                runtime.Status = ExchangeRuntime.ACCEPTED;
            }

            timer.Stop();
            @event.ElapsedTime = timer.ElapsedMilliseconds;
            runtime.StoreData(ExchangeRuntime.DISTRIBUTIONS, distributions);
            runtime.AllocationCount = allocations.Count();
            runtime.AddStrategyEvent(@event);
            runtime.Continue();
        }