/*In this method we will get all the files for the lead adapter and we will download the file to our machine * in to the local folder of the lead adapter and we will get all the data that is embeded in the file * and we will validate each record and also checking the duplicate status and adding the particular recrod * and finally we will upload all the contacts and the joblogs and then we will move the file from local folder * to archive folder and we will delete the file from the ftp location. */ public virtual void Process() { try { leadAdapterAndAccountMap = repository.GetLeadAdapterByID(LeadAdapterAccountMapID); ServiceProvider ServiceProviders = serviceProviderRepository .GetServiceProviders(1, CommunicationType.Mail, MailType.TransactionalEmail); #region Read FTP var ftpManager = new FtpService(); ftpManager.OnServiceFailure += ftpManager_OnServiceFailure; var filesList = ftpManager.GetFiles(leadAdapterAndAccountMap.RequestGuid, string.Empty, ServiceProviders.LoginToken, leadAdapterAndAccountMap.LeadAdapterTypeID.ToString(), leadAdapterAndAccountMap.AccountName); foreach (var fileName in filesList) { /* * Read XML file from local path for Builder Number * Get accounts related to builder number * Copy file to all those accounts * **/ try { var localFilePath = Path.Combine(leadAdapterAndAccountMap.LocalFilePath, fileName); ftpManager.Download(leadAdapterAndAccountMap.RequestGuid, string.Empty, fileName, localFilePath); List <LeadAdapterAndAccountMap> leadData = new List <LeadAdapterAndAccountMap>(); leadData.Add(leadAdapterAndAccountMap); var nodes = GetNodes(localFilePath); foreach (var node in nodes) { var attributes = node.GetAllAttributesAndElements(); var builderNumber = attributes[_fieldMappings.GetOrDefault("BuilderNumber")].Value; IEnumerable <Guid> matchedGuids = ftpManager.FindMatchGuids(leadAdapterAndAccountMap.RequestGuid); leadData.AddRange(repository.GetEmptyCommunities(builderNumber, leadAdapterAndAccountMap.LeadAdapterTypeID, matchedGuids)); } if (File.Exists(localFilePath)) { File.Delete(localFilePath); } foreach (LeadAdapterAndAccountMap leadAdapter in leadData.GroupBy(g => g.Id).Select(s => s.First())) { Logger.Current.Informational("Inserting joblog for account id : " + leadAdapter.AccountID); var jobLog = new LeadAdapterJobLogs(); jobLog.LeadAdapterAndAccountMapID = leadAdapter.Id; jobLog.LeadAdapterJobStatusID = LeadAdapterJobStatus.Undefined; jobLog.Remarks = string.Empty; jobLog.FileName = fileName; List <LeadAdapterJobLogDetails> details = new List <LeadAdapterJobLogDetails>(); jobLog.LeadAdapterJobLogDetails = details; var leadAdapterJobLogID = importDataRepository.InsertLeadAdapterjob(jobLog, new Guid(), false, false, leadAdapter.AccountID, leadAdapter.CreatedBy, 1, leadAdapter.CreatedBy, true, 0); var filePath = Path.Combine(leadAdapter.LocalFilePath, fileName); var fileName_rename = Path.GetFileNameWithoutExtension(filePath) + "~" + leadAdapterJobLogID + Path.GetExtension(filePath); localFilePath = Path.Combine(leadAdapter.LocalFilePath, fileName_rename); ftpManager.Download(leadAdapter.RequestGuid, string.Empty, fileName, localFilePath); } } catch (Exception ex) { Logger.Current.Error("An error occured while accessing file downloading it to matched accounts, filename : " + fileName, ex); continue; } } ; #endregion #region Read Local Files readLocalFiles(ftpManager); #endregion } catch (IndexOutOfRangeException indexEx) { Logger.Current.Error("Index out of range exception, account name : " + leadAdapterAndAccountMap.AccountName, indexEx); } catch (Exception ex) { Logger.Current.Error("An error occured when uploading the contacts in the lead adapter, account name : " + leadAdapterAndAccountMap.AccountName, ex); SendEmail("Exception details" + ex, "Exception while processing data from " + leadAdapterAndAccountMap.LeadAdapterTypeID.ToString() + " LeadAdapter"); } finally { repository.UpdateProcessedDate(LeadAdapterAccountMapID); } }