/// <summary>
        /// Internal method for ExportFinancialBatches().
        /// </summary>
        /// <param name="modifiedSince">The modified since.</param>
        private void ExportFinancialBatches_Internal(DateTime modifiedSince)
        {
            using (var dtBatches = GetTableData(SqlQueries.BATCHES))
            {
                foreach (DataRow row in dtBatches.Rows)
                {
                    var importBatch = F1FinancialBatch.Translate(row);

                    if (importBatch != null)
                    {
                        ImportPackage.WriteToPackage(importBatch);
                    }
                }

                // Cleanup - Remember not to Clear() any cached tables.
                dtBatches.Clear();
                GC.Collect();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Exports the batches.
        /// </summary>
        /// <param name="modifiedSince">The modified since.</param>
        public override void ExportFinancialBatches(DateTime modifiedSince)
        {
            try
            {
                using (var dtBatches = GetTableData(SQL_BATCHES))
                {
                    foreach (DataRow row in dtBatches.Rows)
                    {
                        var importBatch = F1FinancialBatch.Translate(row);

                        if (importBatch != null)
                        {
                            ImportPackage.WriteToPackage(importBatch);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Internal method for ExportFinancialBatches().
        /// </summary>
        /// <param name="modifiedSince">The modified since.</param>
        private void ExportFinancialBatches_Internal(DateTime modifiedSince)
        {
            var batches = _db.Table("Batch").Data.AsEnumerable()
                          .Select(b => new BatchDTO {
                BatchId     = b.Field <int>("BatchId"),
                BatchName   = b.Field <string>("BatchName"),
                BatchDate   = b.Field <DateTime>("BatchDate"),
                BatchAmount = b.Field <decimal>("BatchAmount")
            }).ToList();

            var batchesFromContribution = _db.Table("Contribution").Data.AsEnumerable()
                                          .Where(c => c.Field <int?>("BatchId") == null)
                                          .Select(c => new {
                BatchId     = 90000000 + Int32.Parse(c.Field <DateTime>("Received_Date").ToString("yyyyMMdd")),
                BatchName   = "Batch: " + c.Field <DateTime>("Received_Date").ToString("MMM dd, yyyy"),
                BatchDate   = c.Field <DateTime>("Received_Date"),
                BatchAmount = c.Field <decimal>("Amount")
            })
                                          .GroupBy(c => c.BatchId)
                                          .Select(x => new BatchDTO
            {
                BatchId     = x.First().BatchId,
                BatchName   = x.First().BatchName,
                BatchDate   = x.Min(z => z.BatchDate),
                BatchAmount = x.Sum(z => z.BatchAmount)
            }).ToList();

            batches = batches.Concat(batchesFromContribution).ToList();

            foreach (var batch in batches)
            {
                var importBatch = F1FinancialBatch.Translate(batch);

                if (importBatch != null)
                {
                    ImportPackage.WriteToPackage(importBatch);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Exports the batches.
        /// </summary>
        /// <param name="modifiedSince">The modified since.</param>
        public override void ExportFinancialBatches(DateTime modifiedSince)
        {
            try
            {
                // first, we need to find out what batch types are available
                _client.Authenticator = OAuth1Authenticator.ForProtectedResource(ApiConsumerKey, ApiConsumerSecret, OAuthToken, OAuthSecret);
                _request = new RestRequest(API_BATCH_TYPES, Method.GET);
                _request.AddHeader("content-type", "application/xml");
                var batchTypeResponse = _client.Execute(_request);
                ApiCounter++;

                XDocument xBatchTypeDoc = XDocument.Parse(batchTypeResponse.Content);
                var       batchTypes    = xBatchTypeDoc.Elements("batchTypes");

                // process all batches for each batch type
                foreach (var batchType in batchTypes.Elements())
                {
                    int  batchCurrentPage = 1;
                    int  batchLoopCounter = 0;
                    bool moreBatchesExist = true;

                    while (moreBatchesExist)
                    {
                        _request = new RestRequest(API_BATCHES, Method.GET);
                        _request.AddQueryParameter("lastUpdatedDate", modifiedSince.ToShortDateString());
                        _request.AddQueryParameter("batchTypeID", batchType.Attribute("id").Value);
                        _request.AddQueryParameter("recordsPerPage", "1000");
                        _request.AddQueryParameter("page", batchCurrentPage.ToString());
                        _request.AddHeader("content-type", "application/xml");

                        var batchRepsonse = _client.Execute(_request);
                        ApiCounter++;

                        XDocument xBatchDoc = XDocument.Parse(batchRepsonse.Content);

                        if (F1Api.DumpResponseToXmlFile)
                        {
                            xBatchDoc.Save(Path.Combine(ImportPackage.PackageDirectory, $"API_FINANCIAL_BATCHES_ResponseLog_{batchLoopCounter++}.xml"));
                        }

                        var batches = xBatchDoc.Element("results");

                        if (batches != null)
                        {
                            var batchReturnCount     = batches.Attribute("count")?.Value.AsIntegerOrNull();
                            var batchAdditionalPages = batches.Attribute("additionalPages").Value.AsInteger();

                            if (batchReturnCount.HasValue)
                            {
                                // process all batches
                                foreach (var batchNode in batches.Elements())
                                {
                                    var importBatch = F1FinancialBatch.Translate(batchNode);

                                    if (importBatch != null)
                                    {
                                        ImportPackage.WriteToPackage(importBatch);
                                    }
                                }

                                if (batchAdditionalPages <= 0)
                                {
                                    moreBatchesExist = false;
                                }
                                else
                                {
                                    batchCurrentPage++;
                                }
                            }
                        }
                        else
                        {
                            moreBatchesExist = false;
                        }

                        // developer safety blanket (prevents eating all the api calls for the day)
                        if (batchLoopCounter > loopThreshold)
                        {
                            break;
                        }
                        batchLoopCounter++;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
            }
        }