Beispiel #1
0
        private FileInfo[] GetFilesToLoad(issuer config, DirectoryInfo dirInfo)
        {
            try
            {
                FileInfo[] filesToLoad = FilesToImport(dirInfo);

                if (filesToLoad.Count() == 0)
                {
                    //build app log comment
                    applogcomment += "No files to load";

                    return(null);
                }

                //build app log comment
                applogcomment += " Total=" + filesToLoad.Count();

                return(filesToLoad);
            }
            catch (Exception ex)
            {
                //build app log comment
                applogcomment += "Invalid directory: " + dirInfo.FullName;
                //write to error log
                LogFileWriter.WriteFileLoaderError(config.issuer_code + ": Cannot find import directory: " +
                                                   dirInfo.FullName + ToString(), ex);

                return(null);
            }
        }
Beispiel #2
0
        private void RegisterNonExistanceBranch(string record, string brachCode, issuer config)
        {
            try
            {
                //if (!Directory.Exists(config.cards_file_location + "\\missingBranches"))
                //{
                //    Directory.CreateDirectory(config.cards_file_location + "\\missingBranches");
                //}

                StreamWriter sr = new StreamWriter(//config.cards_file_location +
                    "\\missingBranches\\" + config.issuer_code + "_" + brachCode + ".OUT", true);

                sr.WriteLine(record);
                sr.Flush();
                sr.Close();

                LogFileWriter.WriteFileLoaderError(
                    config.issuer_code + ": " + fullFileName + " contains records of a non existant branch", new Exception("INVALID ISSUER BRANCH"));

                fileLoadComments += " | file contains data for a non existant branch in this issuer, please ensure branches are created prior loading";
                fileStatus        = FileStatus.PARTIAL_LOAD;
            }
            catch (Exception ex)
            {
                LogFileWriter.WriteFileLoaderError(ToString(), ex);
            }
        }
Beispiel #3
0
        internal void InsertPinBatchRecord(string batchReference, string loadedDT, int mailerCount, int issuerID,
                                           string branchCode)
        {
            //writes a load batch record to the load_batch table

            Console.WriteLine("Writing batch to DB");

            var sqlStatement = new StringBuilder("");

            sqlStatement.Append("INSERT INTO pin_batch VALUES (");
            sqlStatement.Append("'" + batchReference + "', ");
            sqlStatement.Append("'" + loadedDT + "', ");
            sqlStatement.Append("'" + mailerCount + "', ");
            sqlStatement.Append("'" + issuerID + "', ");
            sqlStatement.Append("'', "); //manager comment
            sqlStatement.Append("'LOADED',");
            sqlStatement.Append("'', "); //operator comment
            sqlStatement.Append("'" + branchCode + "')");
            try
            {
                using (SqlConnection con = dbObject.SQLConnection)
                {
                    string sql     = sqlStatement.ToString();
                    var    command = new SqlCommand(sql, con);
                    command.ExecuteNonQuery();
                    Console.WriteLine("Batch written to DB OK");
                }
            }
            catch (Exception ex)
            {
                LogFileWriter.WriteFileLoaderError(ToString(), ex);
            }
        }
Beispiel #4
0
        //public bool ValidateCardLoaded(string cardNumber)
        //{
        //    //check if the card has been loaded into the DB
        //    try
        //    {
        //        using (SqlConnection con = dbObject.SQLConnection)
        //        {
        //            string sql =
        //                "OPEN SYMMETRIC KEY Indigo_Symmetric_Key " +
        //                "DECRYPTION BY CERTIFICATE Indigo_Certificate; " +
        //                "SELECT card_number FROM load_card WHERE " +
        //                "DECRYPTBYKEY(card_number) =  '" + cardNumber + "' " +
        //                "CLOSE SYMMETRIC KEY Indigo_Symmetric_Key;";

        //            var command = new SqlCommand(sql, con);
        //            SqlDataReader dataReader = command.ExecuteReader();

        //            if (dataReader.HasRows)
        //                return true;
        //            else
        //                return false;
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        LogFileWriter.WriteFileLoaderError(ToString(), ex);
        //        return false;
        //    }
        //}

        public bool CheckPinMailerLoaded(string cardNumber, string encryptedPinBlock)
        {
            //check if the PIN MAILER has been loaded into the DB
            try
            {
                using (SqlConnection con = dbObject.SQLConnection)
                {
                    string sql = " SELECT * FROM pin_mailer WHERE card_number ='" + cardNumber +
                                 "' AND encrypted_pin = '" + encryptedPinBlock + "'";

                    var           command    = new SqlCommand(sql, con);
                    SqlDataReader dataReader = command.ExecuteReader();

                    if (dataReader.HasRows)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                LogFileWriter.WriteFileLoaderError(ToString(), ex);
                return(false);
            }
        }
Beispiel #5
0
 private FileInfo[] FilesToImport(DirectoryInfo dirInfo)
 {
     try
     {
         return(dirInfo.GetFiles());
     }
     catch (FileNotFoundException e)
     {
         //invalid Dir structure
         LogFileWriter.WriteFileLoaderError(ToString(), e);
         return(null);
     }
 }
Beispiel #6
0
 private void CreatePinBatchReference_SmartVista(string fileName)
 {
     try
     {
         fileName = fileName.Substring(3, (fileName.Length - 3));
         fileName = fileName.Substring(0, fileName.LastIndexOf('_'));
     }
     catch (Exception ex)
     {
         //file name incorrectly formatted
         LogFileWriter.WriteFileLoaderError(fileName + " file name formatted incorrectly: " + ToString(), ex);
         fileLoadComments += "| file name formatted incorrectly";
         fileStatus        = FileStatus.INVALID_NAME;
     }
 }
Beispiel #7
0
        private void ArchiveFiles(FileStatus fileStatus, issuer config, FileInfo fileInfo, string strDateTime)
        {
            string archivefilename = fileInfo.Name + "_" + strDateTime;

            try
            {
                if (true /*config.delete_card_file_YN*/)
                {
                    File.Delete(fileInfo.FullName);
                }
                else
                {
                    if (fileStatus.Equals(FileStatus.PROCESSED))
                    {
                        if (!new DirectoryInfo(fileInfo.DirectoryName + "\\completed").Exists)
                        {
                            new DirectoryInfo(fileInfo.DirectoryName + "\\completed").Create();
                        }
                        fileInfo.MoveTo(fileInfo.DirectoryName + "\\completed\\" + archivefilename);
                    }
                    else if (fileStatus.Equals(FileStatus.PARTIAL_LOAD))
                    {
                        if (!new DirectoryInfo(fileInfo.DirectoryName + "\\partialload").Exists)
                        {
                            new DirectoryInfo(fileInfo.DirectoryName + "\\partialload").Create();
                        }
                        fileInfo.MoveTo(fileInfo.DirectoryName + "\\partialload\\" + archivefilename);
                    }
                    else
                    {
                        if (!new DirectoryInfo(fileInfo.DirectoryName + "\\failed").Exists)
                        {
                            new DirectoryInfo(fileInfo.DirectoryName + "\\failed").Create();
                        }
                        fileInfo.MoveTo(fileInfo.DirectoryName + "\\failed\\" + archivefilename);
                    }
                }
            }
            catch (Exception e)
            {
                //error in writing to DB / moving file
                LogFileWriter.WriteFileLoaderError(ToString(), e);
                fileLoadComments += " | Could not move file to archive directory";
            }
        }
Beispiel #8
0
        private string CreateCardBatchReference_Tieto(string fileName)
        {
            try
            {
                //Mpho will need to put more logic in here
                return(fileName.Substring(0, fileName.Length));
            }
            catch (Exception ex)
            {
                //file name incorrectly formatted
                LogFileWriter.WriteFileLoaderError(fileName + " file name formatted incorrectly: " + ToString(), ex);
                fileLoadComments += " | file name formatted incorrectly";
                fileStatus        = FileStatus.INVALID_NAME;
                invalidformatfile++;
            }

            return(null);
        }
Beispiel #9
0
        /// <summary>
        /// Returns all active issuers.
        /// </summary>
        /// <returns></returns>
        internal List <issuer> GetIssuerConfiguration()
        {
            var rtnList = new List <issuer>();

            try
            {
                using (var context = new indigo_databaseEntities(dbObject.EFSQLConnectionString))
                {
                    ObjectResult <issuer> results = context.usp_find_issuer_by_status((int)IssuerStatus.ACTIVE);

                    foreach (issuer result in results)
                    {
                        rtnList.Add(result);
                    }
                }
            }
            catch (Exception ex)
            {
                LogFileWriter.WriteFileLoaderComment("Unable to access the database, cannot run the file loader");
                LogFileWriter.WriteFileLoaderError(ToString(), ex);
            }
            return(rtnList);
        }
Beispiel #10
0
        /// <summary>
        /// Reads all card info from file, checks for duplicates in the file, in the DB and verifies the branch is valid, returns a list of valid card number with their branch code.
        /// </summary>
        /// <param name="fullFileName"></param>
        /// <param name="config"></param>
        /// <param name="fileHistory"></param>
        /// <returns></returns>
        private Dictionary <string, ValidCard> ProcessCardFile_Tieto(string fullFileName, issuer config, file_history fileHistory)
        {
            //<PAN, validCard>
            Dictionary <string, ValidCard> validCards = new Dictionary <string, ValidCard>();
            var cardsFile = new TextFile(fullFileName, false, false);

            try
            {
                //<BranchCode, BranchLookup>
                Dictionary <string, BranchLookup> validBranches = new Dictionary <string, BranchLookup>();

                CardRecords = cardsFile.ReadFile();

                string duplicatesInFileMessage     = "";
                string duplicatesInDB              = "";
                string unlicensesCardsErrorMessage = "";//temporary until license management is fully implemented

                #region basic records processing and fields settings
                for (int i = 0; i < CardRecords.Count; i++)
                {
                    string line = CardRecords[i][0];
                    //text file, so each record only contains 1 string which then needs to be sub-stringed.

                    string[] fields = line.Split(new string[] {
                        " ".PadLeft(1), " ".PadLeft(2), " ".PadLeft(3),
                        " ".PadLeft(4), " ".PadLeft(5), " ".PadLeft(6),
                        " ".PadLeft(7), " ".PadLeft(8), " ".PadLeft(9),
                        " ".PadLeft(10), " ".PadLeft(11), " ".PadLeft(12),
                        " ".PadLeft(13), " ".PadLeft(14), " ".PadLeft(15)
                    }, StringSplitOptions.RemoveEmptyEntries);

                    ValidCard validCard = new ValidCard();
                    validCard.PAN            = fields[0].Substring(1, 16);
                    validCard.BranchCode     = validCard.PAN.Substring(6, 2);
                    validCard.PsuedoPAN      = fields[1] + fields[2];
                    validCard.SequenceNumber = fields[PostilionDetailedRecordColumns.SEQ_NR];

                    BranchLookup branchLookup;
                    //See if we've already checked the DB for the branch. If it's not in the dictionary then do a read from the DB.
                    if (!validBranches.TryGetValue(validCard.BranchCode, out branchLookup))
                    {
                        //check if branch exist
                        branch Branch = CheckDBForBranch(config.issuer_id, validCard.BranchCode);
                        branchLookup = new BranchLookup(validCard.BranchCode, 0, false);

                        if (Branch != null)
                        {
                            branchLookup = new BranchLookup(Branch.branch_code, Branch.branch_id, true);
                        }

                        validBranches.Add(validCard.BranchCode, branchLookup);
                    }


                    //check if branch exist
                    //if not, add a record to rejected file
                    if (!branchLookup.IsValid)
                    {
                        RegisterNonExistanceBranch(line, validCard.BranchCode, config);
                    }
                    else
                    {
                        //CardRecords[i] = new[] { validCard.PsuedoPAN, validCard.BranchCode }; //, custNames, pinBlock };

                        //Check if the card has been added to the dictionary already, if it has dont add it again.
                        if (validCards.ContainsKey(validCard.PsuedoPAN))
                        {
                            duplicaterecords++;
                            duplicatesInFileMessage += validCard.PsuedoPAN + ", ";
                        }
                        else
                        {
                            //check if card is within licensed ecobank bins -- temp solution
                            //TODO: RAB Remove hard coding here.... yuck yuck yuck
                            if (CheckIfIsLicenseCardRecord(validCard.PsuedoPAN))
                            {
                                validCard.BranchId = branchLookup.BranchId;
                                validCards.Add(validCard.PsuedoPAN, validCard);
                            }
                        }
                    }
                }
                #endregion

                #region check card records for duplication in indigo
                //check if card record is in the DB
                List <string> results = fileLoaderDAL.ValidateCardsLoaded(new List <string>(validCards.Keys));

                foreach (string result in results)
                {
                    //Because the results coming back are based on the keys, the dictionary should have this key, but checking just incase
                    if (validCards.ContainsKey(result))
                    {
                        //recored is already in DB
                        validCards.Remove(result);
                        duplicaterecords++;
                        duplicatesInDB   += string.Format("Card Record is a duplicate in Indigo {0},", result);
                        fileLoadComments += Environment.NewLine + string.Format("Card Record {0} is a duplicate to a previously loaded record. Record will be excluded".ToUpper() + Environment.NewLine, result);
                    }
                }
                #endregion

                processedrecords = validCards.Count;

                //update file status
                UpdateFileStatusAfterRead();

                //add comments for duplicates
                if (duplicatesInFileMessage.Trim().Length > 0)
                {
                    fileLoadComments += " Duplicate records in file: ".ToUpper() + duplicatesInFileMessage + ". ";
                }

                if (duplicatesInDB.Trim().Length > 0)
                {
                    fileLoadComments += " Records already exist in DB: ".ToUpper() + duplicatesInDB + ". ";
                }

                //add comments for unlicense records
                if (unlicensesCardsErrorMessage.Trim().Length > 0)
                {
                    fileLoadComments += " - Unlicensed cards processing is disabled. Unlicensed records: ".ToUpper() +
                                        unlicensedrecords + ". ";
                }
            }
            catch (Exception ex)
            {
                //invalid file structure
                LogFileWriter.WriteFileLoaderError(
                    config.issuer_code + ": " + fullFileName + " contains invalid data, or is not formatted correctly" +
                    ToString(), ex);
                fileLoadComments += " | file contains invalid data, or is not formatted correctly";
                fileStatus        = FileStatus.INVALID_FORMAT;
                invalidformatfile++;
            }

            fileHistory.file_statuses.file_status_id = (int)fileStatus;
            fileHistory.number_successful_records    = processedrecords;
            fileHistory.number_failed_records        = duplicaterecords;
            fileHistory.file_load_comments           = fileLoadComments;

            return(validCards);
        }