public async Task <string> PullJournalData() { Library library = new Library(); try { LogManager.SaveLog("PullDataMTN Start in JournalLibrary"); var ReconType = await repoReconTypeRepository.GetAsync(c => c.WSReconName == "ATM"); int ReconTypeId = ReconType.ReconTypeId; var AccountSources = await repoadmSourceAccountRepository.GetManyAsync(c => c.ReconTypeId == ReconTypeId); var listofAccountsource1 = AccountSources.Where(c => c.SourceName == "Source 1"); string acctlistSource1 = string.Empty; string acctlistSource2 = string.Empty; int dt1 = 0; // int dt2 = 0; foreach (var li in listofAccountsource1) { acctlistSource1 += "'" + li.AcctNo + "'" + ", "; dt1 = (int)li.DataSourceId; } int index = acctlistSource1.LastIndexOf(','); if (!string.IsNullOrEmpty(acctlistSource1)) { acctlistSource1 = (acctlistSource1.Remove(index, 1)); } var dtSouceCon1 = await repoadmReconDataSourcesRepository.GetAsync(c => c.ReconDSId == dt1); #region Source 2 var dtSouceCon2 = await repoadmSourceAccountRepository.GetAsync(c => c.ReconTypeId == ReconTypeId && c.SourceName == "Source 2"); #region //File Directory Below if (!string.IsNullOrWhiteSpace(dtSouceCon2.FileDirectory)) { try { string LastRecordId = string.Empty; var controlTable = await repoadmDataPoollingControlRepository.GetAsync(c => c.ReconTypeId == ReconType.ReconTypeId && c.TableName == "ATMTrans"); if (controlTable != null) { LastRecordId = controlTable.LastRecordId; } else { LastRecordId = "0"; } string FileDirectory = dtSouceCon2.FileDirectory; DataTable dTable = new DataTable(); DirectoryInfo d = new DirectoryInfo(FileDirectory); List <FileInfo> DLIST = null; DLIST = d.GetFiles("*" + ".jrn").ToList(); List <FileInfo> ggg = null; if (controlTable != null) { ggg = DLIST;//.Where(c => c.LastAccessTime > controlTable.LastRecordTimeStamp).ToList(); } else { ggg = DLIST; } string fileNamenAndType = string.Empty; string FileLastTime = string.Empty; int count = 0; foreach (var kl in ggg) { fileNamenAndType = (from f in DLIST orderby f.LastWriteTime ascending select kl).First().Name; FileLastTime = (from f in DLIST orderby f.LastAccessTimeUtc descending select kl).First().LastWriteTime.ToString(); string ipAddress = System.Configuration.ConfigurationManager.AppSettings["ipAddressJournal"].ToString(); string file = FileDirectory + "\\" + fileNamenAndType; string brandName = "WINCOR"; int brandid = 1; int x = gh.ProcessJournal(file, "", ipAddress, ipAddress, brandid, brandName); List <p_transaction> tranx = gh.ptranxs; var journal = new Journallog(); if (tranx.Count > 0) { var journalLogTBL = new Journallog(); foreach (var b in tranx) { try { journalLogTBL.terminalId = b.terminalId; journalLogTBL.atmip = b.atmip; journalLogTBL.brand = b.brand; journalLogTBL.trxn_date = b.trxn_date; journalLogTBL.trxn_time = b.trxn_time; journalLogTBL.tsn = b.tsn; journalLogTBL.pan = b.pan; journalLogTBL.eventType_id = b.eventType_id; journalLogTBL.currencyCode = b.currencyCode; journalLogTBL.amount = b.amount; journalLogTBL.availBal = b.availBal; journalLogTBL.ledger = b.ledger; journalLogTBL.surcharge = b.surcharge; journalLogTBL.accountfrm = b.accountfrm; journalLogTBL.accountTo = b.accountTo; journalLogTBL.trxn_status = b.trxn_status; journalLogTBL.comments = b.comments; journalLogTBL.detail = b.detail; journalLogTBL.cassette = b.cassette; journalLogTBL.errcode = b.errcode; journalLogTBL.rejectcount = b.rejectcount; journalLogTBL.dispensecount = b.dispensecount; journalLogTBL.requestcount = b.requestcount; journalLogTBL.remaincount = b.remaincount; journalLogTBL.pickupcount = b.pickupcount; journalLogTBL.denomination = b.denomination; journalLogTBL.jrn_filename = fileNamenAndType; journalLogTBL.mstate_id = b.mstate_id; journalLogTBL.device_stateId = b.device_stateId; journalLogTBL.file_down_load_id = b.file_down_load_id; journalLogTBL.TransTimeRange = b.TransTimeRange; journalLogTBL.opCode = b.opCode; journalLogTBL.takenAmount = b.takenAmount; var exist = await repoJournallogRepository.GetAsync(c => c.tsn == journalLogTBL.tsn); if (exist != null) { //Error Inserted here continue; } else { repoJournallogRepository.Add(journalLogTBL); var ret = await unitOfWork.Commit(0, null) > 0 ? true : false; if (ret) { count += 1; continue; } } } catch (Exception ex) { var exErr = ex == null ? ex.InnerException.Message : ex.Message; var stackTrace = new StackTrace(ex); var thisasm = Assembly.GetExecutingAssembly(); _methodname = stackTrace.GetFrames().Select(f => f.GetMethod()).First(m => m.Module.Assembly == thisasm).Name; _lineErrorNumber = ex.StackTrace.Substring(ex.StackTrace.Length - 7, 7); // library.SaveLog("An error occured in Journal in Line :" + _lineErrorNumber + " CLASSNAME: " + _classname + " METHOD NAME: [" + _methodname + "] ERROR: " + exErr); } } //Move from Temporal Table to JournalTrans Table below //var JourLogList = await repoJournallogRepository.GetManyAsync(c => c.MoveStatus != null); string currcy = string.Empty; var JourLogList = await repoJournallogRepository.GetManyAsync(c => c.ItbId > 0); if (JourLogList.Count() > 0) { var JournalTransTBL = new JournalTran(); var JournalTBLErr = new JournalTransError(); string appendtring = string.Empty; foreach (var b in JourLogList) { var gg = b.detail; if (gg != null) { var spldetails = gg.Split('\n'); if (spldetails[0].Contains("-> TRANSACTION START")) { foreach (var L in spldetails) { if (L.Contains("CURRENT")) { var g = string.Join(" ", L.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList().Select(w => w.Trim())); var cur = g.Split(' '); if (cur.Count() > 0) { currcy = cur[1].Substring(3); } } if (L.Contains("AVAILABL")) { var g = string.Join(" ", L.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList().Select(w => w.Trim())); string avail = g.Split(' ')[1]; } appendtring += L + " "; //I can be setting what will be entering the Table column from L if (L.Contains("<- TRANSACTION END")) { //Insert into the DB the break below break; //break as you find <- TRANSACTION END } } } JournalTransTBL.TerminalId = b.terminalId; JournalTransTBL.ATMIp = b.atmip; JournalTransTBL.Brand = b.brand; JournalTransTBL.TransDate = b.trxn_date; JournalTransTBL.TransTime = b.trxn_time; JournalTransTBL.TransRef = b.tsn; JournalTransTBL.Pan = b.pan; JournalTransTBL.EventTypeId = b.eventType_id; JournalTransTBL.CurrencyCode = b.currencyCode; JournalTransTBL.Amount = b.amount; decimal decValue = 0; JournalTransTBL.AvailBal = b.availBal == null?Math.Round(Convert.ToDecimal("0"), 2) : decimal.TryParse(b.availBal.ToString(), out decValue) ? decValue : Math.Round(Convert.ToDecimal("0"), 2); JournalTransTBL.Ledger = b.ledger == null?Math.Round(Convert.ToDecimal("0"), 2) : decimal.TryParse(b.ledger.ToString(), out decValue) ? decValue : Math.Round(Convert.ToDecimal("0"), 2); JournalTransTBL.CurrentAmount = currcy == null?Math.Round(Convert.ToDecimal("0"), 2) : decimal.TryParse(currcy, out decValue) ? decValue : Math.Round(Convert.ToDecimal("0"), 2); JournalTransTBL.Surcharge = b.surcharge; JournalTransTBL.AcctFrom = b.accountfrm; JournalTransTBL.AcctTo = b.accountTo; JournalTransTBL.TransStatus = b.trxn_status; JournalTransTBL.Cassette = b.cassette; JournalTransTBL.ErrorCode = b.errcode; JournalTransTBL.RejectCount = b.rejectcount; JournalTransTBL.DispenseCount = b.dispensecount; JournalTransTBL.RequestCount = b.requestcount; JournalTransTBL.RemainCount = b.remaincount; JournalTransTBL.PickUpCount = b.pickupcount; JournalTransTBL.Denomination = b.denomination; JournalTransTBL.JournalfileDirectory = fileNamenAndType; JournalTransTBL.MstateId = b.mstate_id; JournalTransTBL.DeviceStateId = b.device_stateId; JournalTransTBL.FileDownloadId = b.file_down_load_id; JournalTransTBL.TransTimeRange = b.TransTimeRange; JournalTransTBL.OpCode = b.opCode; JournalTransTBL.TakenAmount = b.takenAmount; JournalTransTBL.MatchingStatus = "N"; JournalTransTBL.ReconDate = DateTime.Now; JournalTransTBL.UserId = 1; JournalTransTBL.OrigRefNo = b.tsn; if (!string.IsNullOrWhiteSpace(b.tsn)) { var exist = await repoJournalTransRepository.GetAsync(c => c.TransRef == b.tsn); var existHis = await repoJournalTransHistoryRepository.GetAsync(c => c.TransRef == b.tsn); if (exist != null || existHis != null) { JournalTBLErr.TerminalId = JournalTransTBL.TerminalId; JournalTBLErr.ATMIp = JournalTransTBL.ATMIp; JournalTBLErr.Brand = JournalTransTBL.Brand; JournalTBLErr.TransDate = JournalTransTBL.TransDate; JournalTBLErr.TransTime = JournalTransTBL.TransTime; JournalTBLErr.TransRef = JournalTransTBL.TransRef; JournalTBLErr.Pan = JournalTransTBL.Pan; JournalTBLErr.EventTypeId = JournalTransTBL.EventTypeId; JournalTBLErr.CurrencyCode = JournalTransTBL.CurrencyCode; JournalTBLErr.Amount = JournalTransTBL.Amount; JournalTBLErr.AvailBal = JournalTransTBL.AvailBal; JournalTBLErr.Ledger = JournalTransTBL.Ledger; JournalTBLErr.Surcharge = JournalTransTBL.Surcharge; JournalTBLErr.AcctFrom = JournalTransTBL.AcctFrom; JournalTBLErr.AcctTo = JournalTransTBL.AcctTo; JournalTBLErr.TransStatus = JournalTransTBL.TransStatus; JournalTBLErr.Cassette = JournalTransTBL.Cassette; JournalTBLErr.ErrorCode = JournalTransTBL.ErrorCode; JournalTBLErr.RejectCount = JournalTransTBL.RejectCount; JournalTBLErr.DispenseCount = JournalTransTBL.DispenseCount; JournalTBLErr.RequestCount = JournalTransTBL.RequestCount; JournalTBLErr.RemainCount = JournalTransTBL.RemainCount; JournalTBLErr.PickUpCount = JournalTransTBL.PickUpCount; JournalTBLErr.Denomination = JournalTransTBL.Denomination; JournalTBLErr.JournalfileDirectory = fileNamenAndType; JournalTBLErr.MstateId = JournalTransTBL.MstateId; JournalTBLErr.DeviceStateId = JournalTransTBL.DeviceStateId; JournalTBLErr.FileDownloadId = JournalTransTBL.FileDownloadId; JournalTBLErr.TransTimeRange = JournalTransTBL.TransTimeRange; JournalTBLErr.OpCode = JournalTransTBL.OpCode; JournalTBLErr.TakenAmount = JournalTransTBL.TakenAmount; JournalTBLErr.MatchingStatus = JournalTransTBL.MatchingStatus; JournalTBLErr.MatchingType = JournalTransTBL.MatchingType; JournalTBLErr.ReconDate = JournalTransTBL.ReconDate; JournalTBLErr.UserId = JournalTransTBL.UserId; JournalTBLErr.ErrorMsg = "Duplicate transaction record"; JournalTBLErr.OrigRefNo = JournalTransTBL.OrigRefNo; repoJournalTransErrorRepository.Add(JournalTBLErr); var ret2 = await unitOfWork.Commit(0, null) > 0 ? true : false; if (ret2) { } } repoJournalTransRepository.Add(JournalTransTBL); var rey = await unitOfWork.Commit(0, null) > 0 ? true : false; if (rey) { } } else { JournalTBLErr.TerminalId = JournalTransTBL.TerminalId; JournalTBLErr.ATMIp = JournalTransTBL.ATMIp; JournalTBLErr.Brand = JournalTransTBL.Brand; JournalTBLErr.TransDate = JournalTransTBL.TransDate; JournalTBLErr.TransTime = JournalTransTBL.TransTime; JournalTBLErr.TransRef = JournalTransTBL.TransRef; JournalTBLErr.Pan = JournalTransTBL.Pan; JournalTBLErr.EventTypeId = JournalTransTBL.EventTypeId; JournalTBLErr.CurrencyCode = JournalTransTBL.CurrencyCode; JournalTBLErr.Amount = JournalTransTBL.Amount; JournalTBLErr.AvailBal = JournalTransTBL.AvailBal; JournalTBLErr.Ledger = JournalTransTBL.Ledger; JournalTBLErr.Surcharge = JournalTransTBL.Surcharge; JournalTBLErr.AcctFrom = JournalTransTBL.AcctFrom; JournalTBLErr.AcctTo = JournalTransTBL.AcctTo; JournalTBLErr.TransStatus = JournalTransTBL.TransStatus; JournalTBLErr.Cassette = JournalTransTBL.Cassette; JournalTBLErr.ErrorCode = JournalTransTBL.ErrorCode; JournalTBLErr.RejectCount = JournalTransTBL.RejectCount; JournalTBLErr.DispenseCount = JournalTransTBL.DispenseCount; JournalTBLErr.RequestCount = JournalTransTBL.RequestCount; JournalTBLErr.RemainCount = JournalTransTBL.RemainCount; JournalTBLErr.PickUpCount = JournalTransTBL.PickUpCount; JournalTBLErr.Denomination = JournalTransTBL.Denomination; JournalTBLErr.JournalfileDirectory = fileNamenAndType; JournalTBLErr.MstateId = JournalTransTBL.MstateId; JournalTBLErr.DeviceStateId = JournalTransTBL.DeviceStateId; JournalTBLErr.FileDownloadId = JournalTransTBL.FileDownloadId; JournalTBLErr.TransTimeRange = JournalTransTBL.TransTimeRange; JournalTBLErr.OpCode = JournalTransTBL.OpCode; JournalTBLErr.TakenAmount = JournalTransTBL.TakenAmount; JournalTBLErr.MatchingStatus = JournalTransTBL.MatchingStatus; JournalTBLErr.MatchingType = JournalTransTBL.MatchingType; JournalTBLErr.ReconDate = JournalTransTBL.ReconDate; JournalTBLErr.UserId = JournalTransTBL.UserId; JournalTBLErr.ErrorMsg = "No Ref No"; JournalTBLErr.OrigRefNo = JournalTransTBL.OrigRefNo; repoJournalTransErrorRepository.Add(JournalTBLErr); var ret2 = await unitOfWork.Commit(0, null) > 0 ? true : false; if (ret2) { } } } } //Truncate journal table after this as below string updatScript = "truncate table dbo.Journallog"; string connectionstring = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; SqlConnection con = new SqlConnection(connectionstring); con.Open(); SqlCommand commd = new SqlCommand(updatScript, con); commd.CommandType = CommandType.Text; commd.ExecuteNonQuery(); con.Close(); //Update and Move here var proceTBL = new FileProcessControl(); proceTBL.ReconTypeId = ReconTypeId; proceTBL.FileDirectory = FileDirectory; proceTBL.FileName = fileNamenAndType; proceTBL.NameConvention = ReconType.FileNamingConvention; proceTBL.DateProcessed = DateTime.Now; proceTBL.Status = "Processed"; proceTBL.DateCreated = DateTime.Now; proceTBL.UserId = 1; LogManager.SaveLog("Log File reading ReconTye :" + ReconType.ReconName + " FileDirectory: " + FileDirectory + "fileNamenAndType: " + fileNamenAndType + "getReconTypeInfo.FileNamingConvention: " + ReconType.FileNamingConvention); //repoadmFileProcessedRepository.Add(proceTBL); var ret1 = await unitOfWork.Commit(0, null) > 0 ? true : false; if (ret1) { string fnn = ReconType.ProcessedFileDirectory; string fn = @fnn + "\\" + fileNamenAndType; File.Move((FileDirectory + "\\" + fileNamenAndType), fn); } //Update control table if (controlTable != null) { controlTable.LastRecordTimeStamp = Convert.ToDateTime(FileLastTime); controlTable.LastTransDate = DateTime.Now; controlTable.RecordsCount = count; repoadmDataPoollingControlRepository.Update(controlTable); var ret = await unitOfWork.Commit(0, null) > 0 ? true : false; if (ret) { } } else { var admDataPoollingControlTBL = new admDataPullingControl(); admDataPoollingControlTBL.ReconTypeId = ReconType.ReconTypeId; admDataPoollingControlTBL.FileType = "File"; admDataPoollingControlTBL.TableName = "ATMTrans"; admDataPoollingControlTBL.DateCreated = DateTime.Now; admDataPoollingControlTBL.UserId = 1; admDataPoollingControlTBL.LastRecordTimeStamp = Convert.ToDateTime(FileLastTime); admDataPoollingControlTBL.ReconLevel = 1; admDataPoollingControlTBL.LastTransDate = DateTime.Now; admDataPoollingControlTBL.RecordsCount = count; repoadmDataPoollingControlRepository.Add(admDataPoollingControlTBL); var ret = await unitOfWork.Commit(0, null) > 0 ? true : false; if (ret) { } } } } } } catch (Exception ex) { var exErr = ex == null ? ex.InnerException.Message : ex.Message; var stackTrace = new StackTrace(ex); var thisasm = Assembly.GetExecutingAssembly(); _methodname = stackTrace.GetFrames().Select(f => f.GetMethod()).First(m => m.Module.Assembly == thisasm).Name; _lineErrorNumber = ex.StackTrace.Substring(ex.StackTrace.Length - 7, 7); LogManager.SaveLog("An error occured in Journal in Line :" + _lineErrorNumber + " CLASSNAME: " + _classname + " METHOD NAME: [" + _methodname + "] ERROR: " + exErr); // throw; } } #endregion #endregion #region Source 1 #endregion } catch (Exception ex) { var exErr = ex == null ? ex.InnerException.Message : ex.Message; var stackTrace = new StackTrace(ex); var thisasm = Assembly.GetExecutingAssembly(); _methodname = stackTrace.GetFrames().Select(f => f.GetMethod()).First(m => m.Module.Assembly == thisasm).Name; _lineErrorNumber = ex.StackTrace.Substring(ex.StackTrace.Length - 7, 7); LogManager.SaveLog("An error occured in Line JournalLibrary MTN sybase 6 File Source:" + _lineErrorNumber + " CLASSNAME: " + _classname + " METHOD NAME: [" + _methodname + "] ERROR: " + exErr); throw; } return(string.Empty); }
public async Task <string> PullNostroVostroData() { Library library = new Library(); try { LogManager.SaveLog("Task Start in NostroVostroLibrary"); var ReconType = await repoReconTypeRepository.GetAsync(c => c.WSReconName == "NostroVostro"); int ReconTypeId = ReconType.ReconTypeId; var AccountSources = await repoadmSourceAccountRepository.GetManyAsync(c => c.ReconTypeId == ReconTypeId); var listofAccountsource1 = AccountSources.Where(c => c.SourceName == "Source 1" && c.AcctNo != null); string acctlistSource1 = string.Empty; string acctlistSource2 = string.Empty; int dt1 = 0; // int dt2 = 0; foreach (var li in listofAccountsource1) { acctlistSource1 += "'" + li.AcctNo + "'" + ", "; dt1 = (int)li.DataSourceId; } int index = acctlistSource1.LastIndexOf(','); if (!string.IsNullOrEmpty(acctlistSource1)) { acctlistSource1 = (acctlistSource1.Remove(index, 1)); } var dtSouceCon1 = await repoadmReconDataSourcesRepository.GetAsync(c => c.ReconDSId == dt1); #region Source 1 #region // Sybase Server below if (dtSouceCon1.DatabaseType == "SYBASE") { try { LogManager.SaveLog("PullDataNostro for Sybase Start in NostroVostroLibrary"); var value1 = string.Empty; value1 = string.Empty; var value2 = string.Empty; value2 = string.Empty; int scriptExecTtype = 0; string FromDateParam = string.Empty; string ToDateParam = string.Empty; string LastRecordId = string.Empty; string CBSRecordCount = string.Empty; string MaxTransDate = string.Empty; string dateTest = string.Empty; string ReconDate = string.Empty; var controlTable = await repoadmDataPoollingControlRepository.GetAsync(c => c.ReconTypeId == ReconType.ReconTypeId && c.TableName == "CBSNostroTrans"); if (controlTable != null) { FromDateParam = controlTable.FromDateParam == null?DateTime.Now.ToString() : string.Format("{0:yyyyMMdd}", Convert.ToDateTime(controlTable.FromDateParam)); FromDateParam = "'" + FromDateParam + "'"; ToDateParam = controlTable.ToDateParam == null?DateTime.Now.ToString() : string.Format("{0:yyyyMMdd}", Convert.ToDateTime(controlTable.ToDateParam)); ToDateParam = "'" + ToDateParam + "'"; ReconDate = controlTable.LastTransDate == null?DateTime.Now.ToString() : string.Format("{0:yyyyMMdd}", Convert.ToDateTime(controlTable.LastTransDate)); ReconDate = "'" + ReconDate + "'"; LastRecordId = controlTable.LastRecordId; } else { LastRecordId = "0"; FromDateParam = "'20170901'"; ToDateParam = "'20170923'"; ReconDate = "'20170923'"; } string pdt = "";// parametername.Split(' ')[1]; List <AseParameter> parameterPasses = new List <AseParameter>() { new AseParameter() { ParameterName = pdt, AseDbType = AseDbType.VarChar, Value = value1 }, new AseParameter() { ParameterName = pdt, AseDbType = AseDbType.VarChar, Value = value2 } }; string connstring = System.Configuration.ConfigurationManager.AppSettings["sybconnection"].ToString(); connstring = connstring.Replace("{{Data Source}}", dtSouceCon1.ipAddress); connstring = connstring.Replace("{{port}}", dtSouceCon1.PortNumber); connstring = connstring.Replace("{{database}}", dtSouceCon1.DatabaseName); connstring = connstring.Replace("{{uid}}", dtSouceCon1.UserName); connstring = connstring.Replace("{{pwd}}", library.Decrypt(dtSouceCon1.Password)); DataSet dsGetData = new DataSet(); using (AseConnection theCons = new AseConnection(connstring)) { DataSet ds = new DataSet(); try { theCons.Open(); if (theCons.State.ToString() == "Open") { LogManager.SaveLog("Sybase Connection open for Ip " + dtSouceCon1.ipAddress); } else { LogManager.SaveLog("Sybase Connection not Open for Ip " + dtSouceCon1.ipAddress); } } catch (Exception ex) { var exErr = ex == null ? ex.InnerException.Message : ex.Message; var stackTrace = new StackTrace(ex); var thisasm = Assembly.GetExecutingAssembly(); _methodname = stackTrace.GetFrames().Select(f => f.GetMethod()).First(m => m.Module.Assembly == thisasm).Name; _lineErrorNumber = ex.StackTrace.Substring(ex.StackTrace.Length - 7, 7); LogManager.SaveLog("An error occured NostroVostroLibrary Line: " + _lineErrorNumber + " CLASSNAME: " + _classname + " METHOD NAME: [" + _methodname + "] ERROR: " + exErr); } try { var CurrencyList = AccountSources.Where(c => c.SourceName == "Source 1" && c.Currency != null && c.Currency != string.Empty); int gocount = 0; foreach (var cur in CurrencyList) { //87572420 string currency = "'" + cur.Currency + "'";; string Account = "'" + cur.AcctNo + "'";; string SqlString = ReconType.Source1Script.Replace("{Account}", Account) .Replace("{Currency}", currency) .Replace("{LastRecordId}", LastRecordId) .Replace("{ReconDate}", ReconDate); AseCommand cmd = new AseCommand(SqlString, theCons); cmd.Connection = theCons; cmd.CommandText = SqlString; cmd.CommandTimeout = 0; //i.e check if the parameters are not null, if the are null, that means scriptExecTtype = 1, // would be using CommandText not store procdure if (!string.IsNullOrWhiteSpace(value1) && !string.IsNullOrWhiteSpace(value1)) { if (parameterPasses != null) { cmd.Parameters.AddRange(parameterPasses.ToArray()); var gggg = (parameterPasses.ToArray()); } } else { scriptExecTtype = 1; } cmd.CommandType = scriptExecTtype == 0 ? CommandType.StoredProcedure : CommandType.Text; AseDataReader reader = cmd.ExecuteReader(); ds.EnforceConstraints = false; ds.Load(reader, LoadOption.OverwriteChanges, "Results"); var returndata = ds.Tables["Results"]; LogManager.SaveLog("PullDataCBSNostroTrans for Sybase returndata.Rows.Count " + returndata.Rows.Count); if (returndata.Rows.Count > 0) { var CBSNostroTransTBL = new CBSNostroTran(); var CBSNostroTransTBLErr = new CBSNostroTransError(); int count = 0; int countTrans = 0; for (int col = 0; col < returndata.Rows.Count; col++) { try { CBSNostroTransTBL.AcctNo = returndata.Rows[col][0] == null ? null : returndata.Rows[col][0].ToString(); CBSNostroTransTBL.AcctType = returndata.Rows[col][1] == null ? null : returndata.Rows[col][1].ToString(); CBSNostroTransTBL.TransDate = returndata.Rows[col][2] == null ? (DateTime?)null : Convert.ToDateTime(returndata.Rows[col][2]);; dateTest = CBSNostroTransTBL.TransDate.ToString(); if (countTrans > 1) { MaxTransDate = CBSNostroTransTBL.TransDate.ToString(); if (Convert.ToDateTime(dateTest) > Convert.ToDateTime(MaxTransDate)) { MaxTransDate = dateTest; } else { MaxTransDate = MaxTransDate; } } CBSNostroTransTBL.Amount = returndata.Rows[col][3] == null ? 0 : Math.Round(Convert.ToDecimal(returndata.Rows[col][3]), 2); CBSNostroTransTBL.Description = returndata.Rows[col][4] == null ? null : returndata.Rows[col][4].ToString(); CBSNostroTransTBL.Reference = returndata.Rows[col][5] == null ? null : returndata.Rows[col][5].ToString(); CBSNostroTransTBL.OrigRefNo = CBSNostroTransTBL.Reference; CBSNostroTransTBL.DebitCredit = returndata.Rows[col][6] == null ? null : returndata.Rows[col][6].ToString(); CBSNostroTransTBL.OriginatingBranch = returndata.Rows[col][7] == null ? null : returndata.Rows[col][7].ToString(); CBSNostroTransTBL.PostedBy = returndata.Rows[col][8] == null ? null : returndata.Rows[col][8].ToString(); CBSNostroTransTBL.Currency = returndata.Rows[col][9] == null ? null : returndata.Rows[col][9].ToString(); CBSNostroTransTBL.PtId = returndata.Rows[col][10] == null ? null : returndata.Rows[col][10].ToString(); int revcode; CBSNostroTransTBL.ReversalCode = returndata.Rows[col][11] == null ? (int?)null : int.TryParse(returndata.Rows[col][11].ToString(), out revcode) ? revcode : (int?)null; LastRecordId = CBSNostroTransTBL.PtId; CBSNostroTransTBL.MatchingStatus = "N"; CBSNostroTransTBL.PullDate = DateTime.Now; CBSNostroTransTBL.UserId = 1; countTrans += 1; if (!string.IsNullOrWhiteSpace(CBSNostroTransTBL.Reference)) { var exist = await repoCBSNostroVostroTransRepository.GetAsync(c => (c.Reference == CBSNostroTransTBL.Reference && c.Amount == CBSNostroTransTBL.Amount)); var existHis = await repoCBSNostroVostroTransHistoryRepository.GetAsync(c => c.Reference == CBSNostroTransTBL.Reference && c.Amount == CBSNostroTransTBL.Amount); if (exist != null || existHis != null) { CBSNostroTransTBLErr.AcctNo = CBSNostroTransTBL.AcctNo; CBSNostroTransTBLErr.AcctType = CBSNostroTransTBL.AcctType; CBSNostroTransTBLErr.TransDate = CBSNostroTransTBL.TransDate; CBSNostroTransTBLErr.Amount = CBSNostroTransTBL.Amount; CBSNostroTransTBLErr.Description = CBSNostroTransTBL.Description; CBSNostroTransTBLErr.Reference = CBSNostroTransTBL.Reference; CBSNostroTransTBLErr.OrigRefNo = CBSNostroTransTBL.Reference; CBSNostroTransTBLErr.DebitCredit = CBSNostroTransTBL.DebitCredit; CBSNostroTransTBLErr.OriginatingBranch = CBSNostroTransTBL.OriginatingBranch; CBSNostroTransTBLErr.PostedBy = CBSNostroTransTBL.PostedBy; CBSNostroTransTBLErr.Currency = CBSNostroTransTBL.Currency; CBSNostroTransTBLErr.PtId = CBSNostroTransTBL.PtId; LastRecordId = CBSNostroTransTBLErr.PtId; CBSNostroTransTBLErr.MatchingStatus = CBSNostroTransTBL.MatchingStatus; CBSNostroTransTBLErr.PullDate = CBSNostroTransTBL.PullDate; CBSNostroTransTBLErr.ReversalCode = CBSNostroTransTBL.ReversalCode; CBSNostroTransTBLErr.UserId = 1; CBSNostroTransTBLErr.ErrorMsg = "Duplicate transaction record"; repoCBSNostroVostroTransErrorRepository.Add(CBSNostroTransTBLErr); var ret1 = await unitOfWork.Commit(0, null) > 0 ? true : false; if (ret1) { continue; } continue; } else { repoCBSNostroVostroTransRepository.Add(CBSNostroTransTBL); var ret = await unitOfWork.Commit(0, null) > 0 ? true : false; if (ret) { count += 1; CBSRecordCount = count.ToString(); continue; } } } else { CBSNostroTransTBLErr.AcctNo = CBSNostroTransTBL.AcctNo; CBSNostroTransTBLErr.AcctType = CBSNostroTransTBL.AcctType; CBSNostroTransTBLErr.TransDate = CBSNostroTransTBL.TransDate; CBSNostroTransTBLErr.Amount = CBSNostroTransTBL.Amount; CBSNostroTransTBLErr.Description = CBSNostroTransTBL.Description; CBSNostroTransTBLErr.Reference = CBSNostroTransTBL.Reference; CBSNostroTransTBLErr.OrigRefNo = CBSNostroTransTBL.Reference; CBSNostroTransTBLErr.DebitCredit = CBSNostroTransTBL.DebitCredit; CBSNostroTransTBLErr.OriginatingBranch = CBSNostroTransTBL.OriginatingBranch; CBSNostroTransTBLErr.PostedBy = CBSNostroTransTBL.PostedBy; CBSNostroTransTBLErr.Currency = CBSNostroTransTBL.Currency; CBSNostroTransTBLErr.PtId = CBSNostroTransTBL.PtId; LastRecordId = CBSNostroTransTBLErr.PtId; CBSNostroTransTBLErr.MatchingStatus = CBSNostroTransTBL.MatchingStatus; CBSNostroTransTBLErr.PullDate = CBSNostroTransTBL.PullDate; CBSNostroTransTBLErr.ReversalCode = CBSNostroTransTBL.ReversalCode; CBSNostroTransTBLErr.UserId = 1; CBSNostroTransTBLErr.ErrorMsg = "No ref No."; repoCBSNostroVostroTransErrorRepository.Add(CBSNostroTransTBLErr); var ret1 = await unitOfWork.Commit(0, null) > 0 ? true : false; if (ret1) { continue; } } } catch (Exception ex) { var exErr = ex == null ? ex.InnerException.Message : ex.Message; var stackTrace = new StackTrace(ex); var thisasm = Assembly.GetExecutingAssembly(); _methodname = stackTrace.GetFrames().Select(f => f.GetMethod()).First(m => m.Module.Assembly == thisasm).Name; _lineErrorNumber = ex.StackTrace.Substring(ex.StackTrace.Length - 7, 7); LogManager.SaveLog("An error occured NostroVostroLibrary in Line: " + _lineErrorNumber + " CLASSNAME: " + _classname + " METHOD NAME: [" + _methodname + "] ERROR: " + exErr); try { CBSNostroTransTBLErr.AcctNo = CBSNostroTransTBL.AcctNo; CBSNostroTransTBLErr.AcctType = CBSNostroTransTBL.AcctType; CBSNostroTransTBLErr.TransDate = CBSNostroTransTBL.TransDate; CBSNostroTransTBLErr.Amount = CBSNostroTransTBL.Amount; CBSNostroTransTBLErr.Description = CBSNostroTransTBL.Description; CBSNostroTransTBLErr.Reference = CBSNostroTransTBL.Reference; CBSNostroTransTBLErr.OrigRefNo = CBSNostroTransTBL.Reference; CBSNostroTransTBLErr.DebitCredit = CBSNostroTransTBL.DebitCredit; CBSNostroTransTBLErr.OriginatingBranch = CBSNostroTransTBL.OriginatingBranch; CBSNostroTransTBLErr.PostedBy = CBSNostroTransTBL.PostedBy; CBSNostroTransTBLErr.Currency = CBSNostroTransTBL.Currency; CBSNostroTransTBLErr.PtId = CBSNostroTransTBL.PtId; LastRecordId = CBSNostroTransTBLErr.PtId; CBSNostroTransTBLErr.MatchingStatus = CBSNostroTransTBL.MatchingStatus; CBSNostroTransTBLErr.PullDate = CBSNostroTransTBL.PullDate; CBSNostroTransTBLErr.UserId = 1; CBSNostroTransTBLErr.ErrorMsg = ex == null ? ex.InnerException.Message : ex.Message; repoCBSNostroVostroTransErrorRepository.Add(CBSNostroTransTBLErr); var ret1 = unitOfWork.CommitNonAsync(0, null) > 0 ? true : false; if (ret1) { continue; } } catch (Exception ex1) { var exErr2 = ex1 == null ? ex.InnerException.Message : ex.Message; var stackTrace2 = new StackTrace(ex); var thisas = Assembly.GetExecutingAssembly(); _methodname = stackTrace.GetFrames().Select(f => f.GetMethod()).First(m => m.Module.Assembly == thisas).Name; _lineErrorNumber = ex.StackTrace.Substring(ex.StackTrace.Length - 7, 7); LogManager.SaveLog("An error occured NostroVostroLibrary in Line: " + _lineErrorNumber + " CLASSNAME: " + _classname + " METHOD NAME: [" + _methodname + "] ERROR: " + exErr); continue; } continue; } } if (controlTable != null) { //Update with below string updatScript = "update CBSNostroTrans set VostroAcctNo = b.VostroAcctNo " + " from CBSNostroTrans a,admSourceAccount b " + " where a.AcctNo = b.AcctNo " + " and b.ReconTypeId = " + ReconType.ReconTypeId; string connectionstring = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; SqlConnection con = new SqlConnection(connectionstring); con.Open(); SqlCommand commd = new SqlCommand(updatScript, con); commd.CommandType = CommandType.Text; commd.ExecuteNonQuery(); con.Close(); controlTable.LastRecordId = LastRecordId; controlTable.LastRecordTimeStamp = DateTime.Now; DateTime dt = new DateTime(); controlTable.LastTransDate = MaxTransDate == null ? DateTime.Now : DateTime.TryParse(MaxTransDate, out dt) ? dt : DateTime.Now; controlTable.PullDate = DateTime.Now; int recTrack; controlTable.RecordsCount = CBSRecordCount == null ? (int?)null : int.TryParse(CBSRecordCount, out recTrack) ? recTrack : (int?)null; repoadmDataPoollingControlRepository.Update(controlTable); var ret = await unitOfWork.Commit(0, null) > 0 ? true : false; if (ret) { } } else { string updatScript = "update CBSNostroTrans set VostroAcctNo = b.VostroAcctNo " + " from CBSNostroTrans a,admSourceAccount b " + " where a.AcctNo = b.AcctNo " + " and b.ReconTypeId = " + ReconType.ReconTypeId; string connectionstring = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; SqlConnection con = new SqlConnection(connectionstring); con.Open(); SqlCommand commd = new SqlCommand(updatScript, con); commd.CommandType = CommandType.Text; commd.ExecuteNonQuery(); con.Close(); var admDataPoollingControlTBL = new admDataPullingControl(); admDataPoollingControlTBL.ReconTypeId = ReconType.ReconTypeId; admDataPoollingControlTBL.FileType = "Table"; admDataPoollingControlTBL.TableName = "CBSNostroTrans"; admDataPoollingControlTBL.DateCreated = DateTime.Now; admDataPoollingControlTBL.UserId = 1; admDataPoollingControlTBL.LastRecordTimeStamp = DateTime.Now; admDataPoollingControlTBL.LastRecordId = LastRecordId; admDataPoollingControlTBL.ReconLevel = 1; DateTime dt = new DateTime(); admDataPoollingControlTBL.LastTransDate = MaxTransDate == null ? DateTime.Now : DateTime.TryParse(MaxTransDate, out dt) ? dt : DateTime.Now; admDataPoollingControlTBL.PullDate = DateTime.Now; int recTrack; admDataPoollingControlTBL.RecordsCount = CBSRecordCount == null ? (int?)null : int.TryParse(CBSRecordCount, out recTrack) ? recTrack : (int?)null; repoadmDataPoollingControlRepository.Add(admDataPoollingControlTBL); var ret = await unitOfWork.Commit(0, null) > 0 ? true : false; if (ret) { } } } var lstRec = await repoadmDataPoollingControlRepository.GetAsync(c => c.ReconTypeId == ReconType.ReconTypeId && c.TableName == "CBSNostroTrans"); LastRecordId = lstRec.LastRecordId; } // reader.Close(); theCons.Close(); } catch (Exception ex) { var exErr = ex == null ? ex.InnerException.Message : ex.Message; var stackTrace = new StackTrace(ex); var thisasm = Assembly.GetExecutingAssembly(); _methodname = stackTrace.GetFrames().Select(f => f.GetMethod()).First(m => m.Module.Assembly == thisasm).Name; _lineErrorNumber = ex.StackTrace.Substring(ex.StackTrace.Length - 7, 7); LogManager.SaveLog("An error occured NostroVostroLibrary in Line: " + _lineErrorNumber + " CLASSNAME: " + _classname + " METHOD NAME: [" + _methodname + "] ERROR: " + exErr); } } } catch (Exception ex) { var exErr = ex == null ? ex.InnerException.Message : ex.Message; var stackTrace = new StackTrace(ex); var thisasm = Assembly.GetExecutingAssembly(); _methodname = stackTrace.GetFrames().Select(f => f.GetMethod()).First(m => m.Module.Assembly == thisasm).Name; _lineErrorNumber = ex.StackTrace.Substring(ex.StackTrace.Length - 7, 7); LogManager.SaveLog("An error occured in CBSNostroVostroTrans Line: " + _lineErrorNumber + " CLASSNAME: " + _classname + " METHOD NAME: [" + _methodname + "] ERROR: " + exErr); } } #endregion #endregion #region Source 2 var dtSouceCon2 = await repoadmSourceAccountRepository.GetAsync(c => c.ReconTypeId == ReconTypeId && c.SourceName == "Source 2"); #region //File Directory Below if (!string.IsNullOrWhiteSpace(dtSouceCon2.FileDirectory)) { try { string LastRecordId = string.Empty; var controlTable = await repoadmDataPoollingControlRepository.GetAsync(c => c.ReconTypeId == ReconType.ReconTypeId && c.TableName == "VostroMT940950Trans"); if (controlTable != null) { LastRecordId = controlTable.LastRecordId; } else { LastRecordId = "0"; } string FileDirectory = dtSouceCon2.FileDirectory; DataTable dTable = new DataTable(); DirectoryInfo d = new DirectoryInfo(FileDirectory); List <FileInfo> DLIST = null; DLIST = d.GetFiles("*" + ".out").ToList(); List <FileInfo> ggg = null; if (controlTable != null) { ggg = DLIST;//.Where(c => c.LastWriteTime > controlTable.LastRecordTimeStamp).ToList(); } else { ggg = DLIST; } string fileNamenAndType = string.Empty; string FileLastTime = string.Empty; int count = 0; string returnValue = string.Empty; foreach (var kl in ggg) { fileNamenAndType = (from f in DLIST orderby f.LastWriteTime ascending select kl).First().Name; FileLastTime = (from f in DLIST orderby f.LastAccessTimeUtc descending select kl).First().LastWriteTime.ToString(); int read = await readMT940.Generate940950Message(dtSouceCon2.FileDirectory + "\\" + fileNamenAndType, ReconTypeId, dtSouceCon2.FileDirectory, fileNamenAndType, FileLastTime); returnValue = read.ToString(); if (!string.IsNullOrWhiteSpace(returnValue)) { // Move here var proceTBL = new FileProcessControl(); proceTBL.ReconTypeId = ReconTypeId; proceTBL.FileDirectory = FileDirectory; proceTBL.FileName = fileNamenAndType; proceTBL.NameConvention = ReconType.FileNamingConvention; proceTBL.DateProcessed = DateTime.Now; proceTBL.Status = "Processed"; proceTBL.DateCreated = DateTime.Now; proceTBL.UserId = 1; repoadmFileProcessedRepository.Add(proceTBL); var ret1 = await unitOfWork.Commit(0, null) > 0 ? true : false; if (ret1) { LogManager.SaveLog("Move File Start Nostro Vostro"); string MvFile = library.MoveFile(FileDirectory + "\\" + fileNamenAndType, ReconType.ProcessedFileDirectory, fileNamenAndType); LogManager.SaveLog("Move File in Nostro Vostro status: " + MvFile); } } } } catch (Exception ex) { var exErr = ex == null ? ex.InnerException.Message : ex.Message; var stackTrace = new StackTrace(ex); var thisasm = Assembly.GetExecutingAssembly(); _methodname = stackTrace.GetFrames().Select(f => f.GetMethod()).First(m => m.Module.Assembly == thisasm).Name; _lineErrorNumber = ex.StackTrace.Substring(ex.StackTrace.Length - 7, 7); LogManager.SaveLog("An error occured in NostroVostroLibrary Line : " + _lineErrorNumber + " CLASSNAME: " + _classname + " METHOD NAME: [" + _methodname + "] ERROR: " + exErr); } } #endregion #endregion } catch (Exception ex) { var exErr = ex == null ? ex.InnerException.Message : ex.Message; var stackTrace = new StackTrace(ex); var thisasm = Assembly.GetExecutingAssembly(); _methodname = stackTrace.GetFrames().Select(f => f.GetMethod()).First(m => m.Module.Assembly == thisasm).Name; _lineErrorNumber = ex.StackTrace.Substring(ex.StackTrace.Length - 7, 7); LogManager.SaveLog("An error occured in NostroVostroLogManager Line: " + _lineErrorNumber + " CLASSNAME: " + _classname + " METHOD NAME: [" + _methodname + "] ERROR: " + exErr); throw; } return(string.Empty); }