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); }
private int ImportBackfillTransactions(Stream dataStream, string filename, DateTime importDate) { try { // speed up bulk insertion _dbContext.Configuration.AutoDetectChangesEnabled = false; _dbContext.Configuration.ValidateOnSaveEnabled = false; // TODO: need to implement this import var dataProvider = new AirbnbImportService(_dbContext); return(dataProvider.BackfillCompletedAirbnbTransactions(dataStream, filename, importDate)); } catch { throw; } }
static void Main(string[] args) { var transactionType = FtpTransactionType.Root; // assume to process both completed and future transactions if (args.Length > 0) { int type; if (Int32.TryParse(args[0], out type) == true && Enum.IsDefined(typeof(FtpTransactionType), type)) { transactionType = (FtpTransactionType)type; } } try { AirbnbImportService airbnbService = new AirbnbImportService(); if (transactionType == FtpTransactionType.Root || transactionType == FtpTransactionType.Completed) { airbnbService.ImportTransactions(FtpTransactionType.Completed); } if (transactionType == FtpTransactionType.Root || transactionType == FtpTransactionType.Future) { airbnbService.ImportTransactions(FtpTransactionType.Future); } if (transactionType == FtpTransactionType.Root || transactionType == FtpTransactionType.Gross) { airbnbService.ImportTransactions(FtpTransactionType.Gross); } // TODO: import other transaction types } catch (Exception ex) { string innerMsg = (ex.InnerException == null ? "" : (ex.InnerException.Message == null ? "" : ex.InnerException.Message)); Console.WriteLine(ex.Message + "\r\n" + innerMsg); } return; }
static void Main(string[] args) { var transactionType = FtpTransactionType.Root; // assume to process both completed and future transactions DateTime startDate = DateTime.Today.Date; DateTime endDate = DateTime.Today.Date; if (args.Length > 0) { int type; if (Int32.TryParse(args[0], out type) == true && Enum.IsDefined(typeof(FtpTransactionType), type)) { transactionType = (FtpTransactionType)type; } DateTime.TryParseExact(args[1], "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out startDate); DateTime.TryParseExact(args[2], "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out endDate); } try { AirbnbImportService airbnbService = new AirbnbImportService(); if (transactionType == FtpTransactionType.Completed) { airbnbService.ValidateTransactions(FtpTransactionType.Completed, startDate, endDate); } //if (transactionType == FtpTransactionType.Future) // airbnbService.ImportTransactions(FtpTransactionType.Future); //if (transactionType == FtpTransactionType.Gross) // airbnbService.ImportTransactions(FtpTransactionType.Gross); } catch (Exception ex) { string innerMsg = (ex.InnerException == null ? "" : (ex.InnerException.Message == null ? "" : ex.InnerException.Message)); Console.WriteLine(ex.Message + "\r\n" + innerMsg); } return; }
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); }