示例#1
0
        private void AppointmentsBooked(AppointmentsBookedListModelFilter filter, string destinationPath)
        {
            var       pageNumber = 1;
            const int pageSize   = 100;

            var list = new List <AppointmentsBookedModel>();

            while (true)
            {
                int totalRecords;
                var model = _eventCustomerReportingService.GetAppointmentsBooked(pageNumber, pageSize, filter, out totalRecords);
                if (model == null || model.Collection == null || !model.Collection.Any())
                {
                    break;
                }

                list.AddRange(model.Collection);
                _logger.Info(String.Format("\n\nPageNumber:{0} Totalrecords: {1}  Current Length: {2}", pageNumber, totalRecords, list.Count));

                pageNumber++;

                if (list.Count >= totalRecords)
                {
                    break;
                }
            }

            if (list.Any())
            {
                _appointmentBookedExportCsvHelper.WriteCsv(list, destinationPath, _logger);
            }
        }
示例#2
0
        public void PollForAppointmentBookExport()
        {
            try
            {
                if (_accountIds.IsNullOrEmpty())
                {
                    return;
                }

                var accounts = (_corporateAccountRepository).GetByIds(_accountIds);

                if (accounts.IsNullOrEmpty())
                {
                    _logger.Info("Accounts can't be null");
                    return;
                }

                foreach (var account in accounts)
                {
                    _logger.Info("Running for account " + account.Tag);
                    var list = new List <AppointmentsBookedModel>();

                    var toDate          = DateTime.Today.GetLastDateOfYear();
                    var destinationPath = string.Format(_destinationAppointmentBookedReportPath, toDate.Year);
                    destinationPath = Path.Combine(destinationPath, account.FolderName);

                    var sourcePath = destinationPath + string.Format(@"\WCR_AppointmentBookedReport_{0}.csv", DateTime.Today.ToString("yyyyMMdd"));

                    var appointmentSettings = string.Format(_appointmentSettings, "WellCareToWellmed");
                    var customSettings      = _customSettingManager.Deserialize(appointmentSettings);
                    customSettings = customSettings ?? new CustomSettings();

                    var fromDate = (customSettings.LastTransactionDate == null) ? _cutOfDate : DateTime.Today.GetFirstDateOfYear();

                    _logger.Info(string.Format("Generating AppointmentBooked for accountId {0} and account tag {1}. ", account.Id, account.Tag));

                    CreateDistinationDirectory(destinationPath);

                    list.AddRange(AppointmentsBooked(new AppointmentsBookedListModelFilter {
                        EventFrom = fromDate, EventTo = toDate.Date, AccountId = account.Id, Tag = account.Tag
                    }));

                    if (File.Exists(sourcePath))
                    {
                        sourcePath = _pgpFileEncryptionHelper.EncryptFile(account, sourcePath);
                    }

                    customSettings.LastTransactionDate = toDate;
                    _customSettingManager.SerializeandSave(appointmentSettings, customSettings);

                    if (list.Any())
                    {
                        _appointmentBookedExportCsvHelper.WriteCsv(list, sourcePath, _logger);

                        if (_sendReportToSftp)
                        {
                            var sftpFolderAppointmentBookedReportDirectory = string.Format(_destinationSftpFolderAppointmentBookedReportPath, toDate.Year);

                            sftpFolderAppointmentBookedReportDirectory = sftpFolderAppointmentBookedReportDirectory + "\\" + account.FolderName;

                            _logger.Info("source path:" + sourcePath);

                            var processFtp = new ProcessFtp(_logger, _sftpHost, _sftpUserName, _sftpPassword);
                            processFtp.UploadSingleFile(sourcePath, sftpFolderAppointmentBookedReportDirectory, "");

                            _logger.Info("destination :" + sftpFolderAppointmentBookedReportDirectory);
                        }
                    }
                    else
                    {
                        _logger.Info("No Records Found for account " + account.Tag);
                    }

                    _logger.Info("********** Completed for Account " + account.Tag + " *****************");
                }
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Main App: \n Error {0} \n Trace: {1} \n\n\n", ex.Message, ex.StackTrace));
            }
        }