Пример #1
0
        public SpendSummary GetTotalSpend(int supplierId)
        {
            for (var i = 0; i < Constants.RetryCount; i++)
            {
                try
                {
                    var externalInvoicesData = ExternalInvoiceService.GetInvoices(supplierId.ToString()); //Get external invoices
                    break;
                }
                catch (TimeoutException)
                {
                    if (i == Constants.RetryCount - 1)
                    {
                        var failOverInvoiceData = _failoverInvoiceService.GetInvoices(supplierId);
                        if (failOverInvoiceData.Timestamp < DateTime.Now.AddMonths(-1))
                        {
                            throw new CustomException("GetTotalSpend Failed."); // intentionaly throwing new exception instead of just throw (stack trace not needed).
                        }

                        return(new SpendSummary("Failover supplier data", new List <SpendDetail> {
                            new SpendDetail(2017, 6000.00m)
                        }));                                                                                                          // Due to time restriction I am not writing the code to group based on year etc.
                    }
                }
            }

            return(new SpendSummary("External Supplier Without failover", new List <SpendDetail> {
                new SpendDetail(2017, 8000.00m)
            }));                                                                                                                      // Due to time restriction I am not writing the code to group based on year etc.
        }
Пример #2
0
        public List <SpendDetail> GetSpendDetail(int supplierId)
        {
            List <SpendDetail> result = null;

            int failedCount = 0;

            if (!IsOpenState && IsInClosedTime())
            {
                result = GetSpendDetail(failoverAction.GetInvoices(supplierId).Invoices);

                return(result);
            }

            for (; ;)
            {
                try
                {
                    result = GetSpendDetail(action.GetInvoices(supplierId.ToString()));

                    Reset();

                    return(result);
                }
                catch (WebTimeoutException ex)
                {
                    failedCount++;

                    if (failedCount == MaxTries)
                    {
                        IsOpenState     = false;
                        FailedTimestamp = DateTime.Now;

                        var resultFailover = failoverAction.GetInvoices(supplierId);
                        if (IsFailoverObsolete(resultFailover))
                        {
                            throw new ObsoleteDataException();
                        }

                        result = GetSpendDetail(resultFailover.Invoices);

                        return(result);
                    }
                }
            }
        }
Пример #3
0
        private ExternalInvoice[] getFailoverInvoiceCollection(int supplierId)
        {
            ExternalInvoice[] externalInvoices;
            var failoverInvoiceCollection = _failoverInvoiceService.GetInvoices(supplierId);

            externalInvoices = failoverInvoiceCollection.Invoices;
            if (failoverInvoiceCollection.IsOldData)
            {
                throw new Exception("Failover data is quite old");
            }

            return(externalInvoices);
        }