/// <summary> /// Invokes the appropriate partner transaction reporter based on the provider deal id /// </summary> /// <param name="deal">Deal being reported</param> /// <param name="partnerTransactionReportingCargo">Transaction reporting cargo</param> private void InvokeTransactionReporter(Deal deal, PartnerTransactionReportingCargo partnerTransactionReportingCargo) { string errorMessage; if (!string.IsNullOrEmpty(deal.ProviderDealId) && deal.ProviderDealId.IndexOf(':') != -1) { string dealProvider = deal.ProviderDealId.Substring(0, deal.ProviderDealId.IndexOf(':')); Partners partners; if (Enum.TryParse(dealProvider.Trim(), true, out partners)) { switch (partners) { case Partners.Deem: InvokeDeemReporter(deal, partnerTransactionReportingCargo); break; } } else { errorMessage = string.Format( "Cannot report the transaction for the deal {0}. Transaction JobProcessor does not have a reporter registered for provider {1}", partnerTransactionReportingCargo.DealId, dealProvider); Log.Info(errorMessage); } } else { errorMessage = string.Format( "Cannot report the transaction for the deal {0}. ProviderDealId is not in expected format {1}", partnerTransactionReportingCargo.DealId, deal.ProviderDealId); Log.Error(errorMessage); } }
/// <summary> /// Invokes the Deem transaction reporter /// </summary> /// <param name="deal">Deal being reported</param> /// <param name="partnerTransactionReportingCargo">Transaction reporting cargo</param> private void InvokeDeemReporter(Deal deal, PartnerTransactionReportingCargo partnerTransactionReportingCargo) { //replace the deal id in the cargo with the deem provider deal id partnerTransactionReportingCargo.DealId = deal.ProviderDealId.Substring(deal.ProviderDealId.IndexOf(':') + 1); //Keep our deal id as the transaction reference partnerTransactionReportingCargo.TransactionReference = deal.Id; _partnerToReporter[Partners.Deem].Report(partnerTransactionReportingCargo); }
/// <summary> /// Dequeues an item from the specified queue and processes the message /// </summary> private void ProcessNextRequest() { PartnerTransactionReportingCargo partnerTransactionReportingCargo = null; try { if (this._jobsQueue.TryDequeue(out partnerTransactionReportingCargo)) { Log.Info("Dequeued transaction job from partner-transactions queue. Cargo : {0}", partnerTransactionReportingCargo.ToString()); //Get the deal id from the cargo and query the deals server for the deal info List <Guid> dealsGuid = new List <Guid> { new Guid(partnerTransactionReportingCargo.DealId) }; Log.Info("Querying the deal server for deal id : {0}", partnerTransactionReportingCargo.DealId); Task <IEnumerable <Deal> > dealsByGuidTask = _dealsClient.GetDealsById(dealsGuid, format: "all"); IEnumerable <Deal> deals = dealsByGuidTask.Result.ToList(); if (deals.Any()) { Deal deal = deals.First(); InvokeTransactionReporter(deal, partnerTransactionReportingCargo); } else { Log.Warn(string.Format("Deal {0} not found in deals server", partnerTransactionReportingCargo.DealId)); } } else { // No jobs in the queue. Log.Verbose("No jobs in the partner-transaction jobs queue. Agent Id: {0} is going to sleep for {1} seconds", this._agentId, SleepTimeWhenQueueEmpty.TotalSeconds); Thread.Sleep(SleepTimeWhenQueueEmpty); } } catch (Exception exp) { this.HandleError(EventCode.EmailAgentUnexpectedError, exp, "Unexpected Error", this._agentId, partnerTransactionReportingCargo); } }