Пример #1
0
        private ProcessResult LogMissingAirbnbTrasactions(List <ImportFile> importFiles, DateTime logDate, FtpTransactionType fileTransactionType)
        {
            var    result    = new ProcessResult();
            string localFile = string.Empty;

            try
            {
                // speed up bulk insertion
                _dbContext.Configuration.AutoDetectChangesEnabled = false;
                _dbContext.Configuration.ValidateOnSaveEnabled    = false;

                string tempFolder    = GetDownloadFolder();
                var    ftpService    = new AirbnbFtpService();
                var    importService = new AirbnbImportService();

                var payoutProvider = new OwnerPayoutService(_dbContext);
                foreach (var importFile in importFiles)
                {
                    result.Count++;

                    // download file from ftp site
                    string csvFileUrl = importFile.Id;
                    localFile = Path.Combine(tempFolder, importFile.Name);
                    ftpService.Download(csvFileUrl, localFile);
                    //DojoLogger.Info(string.Format("Download file {0} completed.", localFile));

                    // process only those data that is later than the most recent imported payout date in db
                    DateTime?startPayoutDate = payoutProvider.GetMostRecentPayoutDate(importFile.Name);
                    var      count           = importService.LogMissingCompletedAirbnbTransactions(
                        localFile, logDate.ToString("yyyy-MM-dd"), startPayoutDate);

                    if (count == -1)
                    {
                        result.Skip++;
                    }
                    else
                    {
                        result.Bad += count;
                    }

                    importService.DeleteFileIfAllowed(localFile);
                }
            }
            catch (Exception ex)
            {
                DojoLogger.Error(string.Format("Import file {0} fails. Exception: {1}", localFile, ex.Message));
                // fall through
            }

            result.Good = result.Count - result.Bad - result.Skip;
            return(result);
        }
Пример #2
0
        private ProcessResult ImportAirbnbTrasactions(List <ImportFile> importFiles, DateTime importDate, FtpTransactionType fileTransactionType)
        {
            var    result    = new ProcessResult();
            string localFile = string.Empty;

            try
            {
                // speed up bulk insertion
                _dbContext.Configuration.AutoDetectChangesEnabled = false;
                _dbContext.Configuration.ValidateOnSaveEnabled    = false;

                string tempFolder    = GetDownloadFolder();
                var    ftpService    = new AirbnbFtpService();
                var    importService = new AirbnbImportService();

                DojoLogger.Info(string.Format("Temporary download folder is {0} for {1} files from FTP server.", tempFolder, importFiles.Count.ToString()));

                if (fileTransactionType == FtpTransactionType.Completed)
                {
                    var payoutProvider = new OwnerPayoutService(_dbContext);
                    foreach (var importFile in importFiles)
                    {
                        result.Count++;

                        // download file from ftp site
                        string csvFileUrl = importFile.Id;
                        localFile = Path.Combine(tempFolder, importFile.Name);
                        ftpService.Download(csvFileUrl, localFile);
                        //DojoLogger.Info(string.Format("Download file {0} completed.", localFile));

                        // process only those data that is later than the most recent imported payout date in db
                        DateTime?startPayoutDate = payoutProvider.GetMostRecentPayoutDate(importFile.Name);
                        var      count           = importService.ImportCompletedAirbnbTransactions(
                            localFile, importDate.ToString("yyyy-MM-dd"), startPayoutDate);

                        if (count == -1)
                        {
                            result.Skip++;
                        }
                        else
                        {
                            result.Bad += count;
                        }

                        importService.DeleteFileIfAllowed(localFile);
                    }
                }
                else if (fileTransactionType == FtpTransactionType.Future)
                {
                    var    reservationProvider  = new ReservationService(_dbContext);
                    string mostRecentDateString = reservationProvider.GetMostRecentFutureDate();

                    foreach (var importFile in importFiles)
                    {
                        result.Count++;

                        //string sortableDate = importService.ParseDateFromTransactionFileUrl(importFile.Id);
                        //if (string.Compare(sortableDate, mostRecentDateString) > 0)
                        //{
                        // download file from ftp site
                        string csvFileUrl = importFile.Id;
                        localFile = Path.Combine(tempFolder, importFile.Name);
                        ftpService.Download(csvFileUrl, localFile);
                        var count = importService.ImportFutureAirbnbTransactions(localFile, importDate.ToString("yyyy-MM-dd"));

                        if (count == -1)
                        {
                            result.Skip++;
                        }
                        else
                        {
                            result.Bad += count;
                        }

                        importService.DeleteFileIfAllowed(localFile);

                        //}
                        //else
                        //    result.Skip++;
                    }
                }
                else
                {
                    var    reservationProvider  = new ReservationService(_dbContext);
                    string mostRecentDateString = reservationProvider.GetMostRecentGrossDate();

                    foreach (var importFile in importFiles)
                    {
                        result.Count++;

                        //string sortableDate = importService.ParseDateFromTransactionFileUrl(importFile.Id);
                        //if (string.Compare(sortableDate, mostRecentDateString) > 0)
                        //{
                        // download file from ftp site
                        string csvFileUrl = importFile.Id;
                        localFile = Path.Combine(tempFolder, importFile.Name);
                        ftpService.Download(csvFileUrl, localFile);
                        var count = importService.ImportGrossEarningTransactions(localFile, importDate.ToString("yyyy-MM-dd"));

                        if (count == -1)
                        {
                            result.Skip++;
                        }
                        else
                        {
                            result.Bad += count;
                        }

                        importService.DeleteFileIfAllowed(localFile);
                    }
                }
            }
            catch (Exception ex)
            {
                DojoLogger.Error(string.Format("Import file {0} fails. Exception: {1}", localFile, ex.Message));
                // fall through
            }

            result.Good = result.Count - result.Bad - result.Skip;
            return(result);
        }