Esempio n. 1
0
        private FileStatus ProcessPinFile_SmartVista(issuer config)
        {
            //branchCode = batchReference.Substring(0, batchReference.IndexOf('_'));

            //read file
            //IndigoFileLoader.objects.root.ACardsFile cardsFile = null;
            var             cardsFile = new CSVFile(fullFileName, false, false);
            List <string[]> records   = cardsFile.ReadFile();

            //note --- check if ref is null

            //parse records, format contents
            for (int i = 0; i < records.Count; i++)
            {
                var    newRecord = new string[3];
                string record    = records[i][0];
                newRecord[0] = record.Substring(0, 4) + record.Substring(5, 4) + record.Substring(10, 4) +
                               record.Substring(15, 4);
                newRecord[1] =
                    IndigoFileLoader.utility.UtilityClass.HandleUnexpectedCharacters(
                        record.Substring(record.IndexOf('^') + 1, record.LastIndexOf('^') - record.IndexOf('^') - 1)
                        .Replace('/', ' '));
                newRecord[2] = record.Substring(record.LastIndexOf('#') + 1, 16);
                records[i]   = newRecord;
            }

            return(FileStatus.READ);
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
0
        public void LoadFilesForIssuer(issuer config)
        {
            //check what functions are being used
            if (config.instant_card_issue_YN)
            {
                //load card file for instant issue
                LoadCardFile(config);
            }

            //if (config.pin_mailer_printing_YN)
            //{
            //    //load pin file for instant issue
            //    LoadPinFile(config);
            //}
        }
Esempio n. 5
0
        public void LoadPinCardFile(issuer issuer)
        {
            ////build app log comment
            //string applogcomment = DateTime.Now.ToLongTimeString() + " " + issuer.issuer_code + " CARD FILES: ";

            //var dirInfo = new DirectoryInfo(issuer.cards_file_location);
            //FileInfo[] filesToLoad = dirInfo.GetFiles();

            //if (filesToLoad != null)
            //{
            //    //process each file in array
            //    foreach (FileInfo fileInfo in filesToLoad)
            //    {
            //        file_history fileHistory = new file_history();
            //        fileHistory.file_types = new file_types();
            //        fileHistory.file_statuses = new file_statuses();
            //        fileHistory.name_of_file = fileInfo.Name;
            //        fileHistory.file_directory = fileInfo.Directory.ToString();
            //        fileHistory.file_size = (int)fileInfo.Length;
            //        fileHistory.file_types.file_type_id = (int)FileType.CARD_IMPORT;
            //        fileHistory.file_created_date = fileInfo.CreationTime;

            //        //check if the file has already been loaded
            //        if (!CheckIfDuplicateFile(fileInfo.Name))
            //        {
            //            IndigoFileReaderModule fileReader = new IndigoFileReaderModule();
            //            string loadBatchReference = fileReader.cardFileReader.generateBatchReference(fileInfo);

            //            List<CardFileRecord> cardFileRecords = fileReader.cardFileReader.getCardRecords(fileInfo);

            //            Dictionary<string, CardFileRecord> validCards = new Dictionary<string, CardFileRecord>();
            //            validCards = validateCardRecords(cardFileRecords, issuer.issuer_id);

            //            //write batch and cards to DB
            //            if (fileHistory.file_statuses.file_status_id == (int)FileStatus.PROCESSED ||
            //                    fileHistory.file_statuses.file_status_id == (int)FileStatus.PARTIAL_LOAD)
            //            {
            //                if (validCards != null && validCards.Count > 0)
            //                {
            //                    if (fileLoaderDAL.CreateLoadBatch(validCards, loadBatchReference, issuer.issuer_id, fileHistory))
            //                    {
            //                    }
            //                }
            //            }
            //        }
            //    }
            //}
        }
Esempio n. 6
0
        /// <summary>
        /// Builds the issuers list menu for migrations
        /// </summary>
        /// <returns></returns>
        private static issuer BuildSelectIssuerMenu()
        {
            issuer selectIssuer = null;

            var migratedIssuers     = NewIndigoRepo.GetIssuersIDs();
            var issuersForMigration = OriginalIndigoRepo.GetOtherIssuers(migratedIssuers);

            var menu = "\n\n                          Issuers List\n" +
                       "                    ______________________\n\n";

            for (int i = 0; i < issuersForMigration.Count; i++)
            {
                var menuItem = string.Format("{0}   {1:25} ({2})\n",
                                             i + 1, issuersForMigration[i].issuer_name, issuersForMigration[i].issuer_code);
                menu += menuItem;
            }// end for (int i = 0; i < issuersForMigration.Count; i++)

            Console.WriteLine(menu);

prompt:
            Console.Write("\nPlease select an Issuer to migrate: ");
            var input = Console.ReadLine();

            try
            {
                int selectedIndex;
                if (int.TryParse(input, out selectedIndex))
                {
                    selectIssuer = issuersForMigration[(selectedIndex - 1)];
                }
            }
            catch
            {
            }// end catch

            if (selectIssuer == null)
            {
                var msg = "Invalid selection. Please try again. :{";
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("\n{0}\n", msg);
                ErrorLogger.LogError(msg);
                Console.ForegroundColor = ConsoleColor.Gray;
                goto prompt;
            }

            return(selectIssuer);
        }// end method static issuer BuildSelectIssuerMenu()
Esempio n. 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";
            }
        }
Esempio n. 8
0
        private bool CheckIfDuplicateFile(issuer config, string fileName)
        {
            //TO DO: configure the issuer setup to determine if this check should be done
            bool checkforduplicates = true;

            if (checkforduplicates)
            {
                if (fileLoaderDAL.CheckIfFileExists(fileName))
                {
                    //file with same name has already been processed
                    fileLoadComments += Environment.NewLine + string.Format("CMS Records File: {0} is a duplicate to a previously loaded batch. loading will is aborted".ToUpper() + Environment.NewLine, fileName);
                    fileStatus        = FileStatus.DUPLICATE_FILE;
                    duplicatefile++;
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 9
0
        /// <summary>
        /// Fetch an issuer based on bin code and branch code.
        /// Should produce one eunique issuer.
        /// </summary>
        /// <param name="binCode"></param>
        /// <param name="branchCode"></param>
        /// <returns></returns>
        internal bool FetchIssuerByProductAndBinCode(string binCode, string branchCode, out issuer cardFileIssuer)
        {
            cardFileIssuer = new issuer();
            using (var context = new indigo_databaseEntities(dbObject.EFSQLConnectionString))
            {
                var results = context.usp_get_issuer_by_product_and_branchcode(binCode, branchCode);

                List <issuer> issuers = results.ToList();

                if (issuers.Count() > 1)
                {
                    //throw new Exception("BIN code and branch code linked to more than, one issuer. Check configuaration.");
                    return(false);
                }
                else if (issuers.Count == 0)
                {
                    return(false);
                }

                cardFileIssuer = issuers.First();
                return(true);
            }
        }
Esempio n. 10
0
        private void LoadPinFile(issuer config)
        {
            ////build app log comment
            //applogcomment = DateTime.Now.ToLongTimeString() + " " + config.issuer_code + " PIN FILES:";

            //var dirInfo = new DirectoryInfo(config.pin_file_location);

            ////check there are files to load
            //FileInfo[] filesToLoad = GetFilesToLoad(config, dirInfo);

            //if (filesToLoad != null)
            //{
            //    //process each file in array
            //    foreach (FileInfo fileInfo in filesToLoad)
            //    {
            //        //setup variables
            //        SetupVariables(fileInfo);

            //        //check if the file has already been loaded
            //        if (!CheckIfDuplicateFile(config, fileInfo.Name))
            //        {
            //            //TO DO: get this value from the database (hard coded for MSB)
            //            var cmsType = CMS.SMART_VISTA;
            //            string batchReference = "";

            //            switch (cmsType)
            //            {
            //                case CMS.SMART_VISTA:
            //                    //MSB
            //                    CreatePinBatchReference_SmartVista(fileInfo.Name);
            //                    ProcessPinFile_SmartVista(config);
            //                    break;

            //                case CMS.POSTILION:
            //                    //RSwitch
            //                    CreatePinBatchReference_Postilion(config.issuer_id, config.issuer_code, strDateTime);
            //                    ProcessPinFile_Postilion(fullFileName, config, strDateTime);
            //                    break;
            //            }

            //            //write batch and pins to DB
            //            if (fileStatus.Equals(FileStatus.READ) || fileStatus.Equals(FileStatus.PARTIAL_LOAD))
            //            {
            //                string branchCode = batchReference.Substring(0, batchReference.IndexOf('_'));
            //                fileLoaderDAL.InsertPinBatchRecord(batchReference, strDateTime, PINMailerRecords.Count(),
            //                                                   config.issuer_id, branchCode);
            //                fileLoaderDAL.InsertPinRecords(batchReference, PINMailerRecords);
            //            }
            //        }
            //        //write history
            //        CreateFileHistory(fileInfo.Name, fileInfo.Directory.ToString(), fileInfo.Length, FileType.PIN_MAILER,
            //                          fileInfo.CreationTime.ToString(), fileStatus, strDateTime, config.issuer_id,
            //                          processedrecords,
            //                          duplicaterecords, fileLoadComments);
            //        //archive
            //        ArchiveFiles(fileStatus, config, fileInfo, strDateTime);
            //    }
            //    //build app log comment
            //    applogcomment += " Success=" + successfileload + ", Partial=" + partialfileload + " Failed=" +
            //                     failedfileload +
            //                     ", Duplicate=" + duplicatefile + ", Invalid format=" + invalidformatfile;
            //}
            ////write to application log
            //LogFileWriter.WriteFileLoaderComment(applogcomment);
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
        private void ProcessPinFile_Postilion(string fullFileName, issuer config, string processedDT)
        {
            //try
            //{
            //    //read file
            //    ACardsFile cardsFile = null;
            //    cardsFile = new CSVFile(fullFileName, false, false);
            //    List<string[]> records = cardsFile.ReadFile();


            //    var batchReferences = new List<string>();

            //    //PINMailerRecords = new List<PINMailer>();

            //    //parse records, format contents
            //    //start at pos 1 and end at count -1 (ignore header & footer)
            //    for (int i = 1; i < records.Count - 1; i++)
            //    {
            //        string cardNumber = records[i][0];
            //        string batchReference = records[i][1]; //validate what i am getting here!!
            //        string customerName = records[i][7] + " " + records[i][8] + " " + records[i][10];
            //        string encryptedPIN = records[i][19];
            //        string customerAddress = records[i][24] + ";" + records[i][25] + ";" + records[i][26];

            //        //RL fix this
            //        //int index = batchNames.IndexOf(batchReference);
            //        int index = 1;

            //        if (index == null)
            //        {
            //            //new branch, need to add a new List for that branch to the split batches
            //            //splitBatches.Add(new List<string[]>());

            //            //add the PIN mailer to the the List for the correct branch

            //            //we now need to create a batch and insert into DB
            //            // batchReference = CreatePinBatchReference_Postilion(config.IssuerID, config.IssuerCode, processedDT);

            //            // batchReferences.Add(batchReference);

            //            PINMailerRecords.Add(new PINMailer(config.issuer_id,
            //                                               batchReference,
            //                                               "", //pin mailer ref
            //                                               PINMailerStatus.NOT_PRINTED,
            //                                               cardNumber,
            //                                               "", //pvv offset
            //                                               encryptedPIN,
            //                                               customerName,
            //                                               customerAddress,
            //                                               DateTime.MinValue,
            //                                               DateTime.MinValue));
            //        }
            //    }
            //}
            //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;
            //}
        }
Esempio n. 13
0
        /// <summary>
        /// THIS IS NOW REDUNDENT CODE - DONT USE
        /// </summary>
        /// <param name="config"></param>
        private void LoadCardFile(issuer config)
        {
            //build app log comment
            applogcomment = DateTime.Now.ToLongTimeString() + " " + config.issuer_code + " CARD FILES: ";

            var dirInfo = new DirectoryInfo("" /*config.cards_file_location*/);

            //check there are files to load
            FileInfo[] filesToLoad = GetFilesToLoad(config, dirInfo);

            if (filesToLoad != null)
            {
                //process each file in array
                foreach (FileInfo fileInfo in filesToLoad)
                {
                    file_history fileHistory = new file_history();
                    fileHistory.file_types              = new file_types();
                    fileHistory.file_statuses           = new file_statuses();
                    fileHistory.name_of_file            = fileInfo.Name;
                    fileHistory.file_directory          = fileInfo.Directory.ToString();
                    fileHistory.file_size               = (int)fileInfo.Length;
                    fileHistory.file_types.file_type_id = (int)FileType.CARD_IMPORT;
                    fileHistory.file_created_date       = fileInfo.CreationTime;

                    //setup variables
                    SetupVariables(fileInfo);

                    //check if the file has already been loaded
                    if (!CheckIfDuplicateFile(config, fileInfo.Name))
                    {
                        //TO DO: get this value from the database (hard coded for Ecobank)
                        var    cmsType            = CMS.TIETO;
                        string loadBatchReference = "";
                        //<PAN, ValidCard>
                        Dictionary <string, ValidCard> validCards = new Dictionary <string, ValidCard>();

                        //card issuing
                        switch (cmsType)
                        {
                        case CMS.TIETO:
                            //Ecobank
                            loadBatchReference = CreateCardBatchReference_Tieto(fileInfo.Name);
                            if (fileStatus.Equals(FileStatus.READ))
                            {
                                validCards = ProcessCardFile_Tieto(fullFileName, config, fileHistory);
                            }
                            break;
                        }

                        //write batch and cards to DB
                        if (fileStatus.Equals(FileStatus.PROCESSED) || fileStatus.Equals(FileStatus.PARTIAL_LOAD))
                        {
                            if (validCards.Count > 0)
                            {
                                if (true /*fileLoaderDAL.CreateLoadBatch(validCards, loadBatchReference, config.issuer_id, fileHistory)*/)
                                {
                                    Veneka.Indigo.CardManagement.LoadBatchMangementService loadBatchMgm = new Veneka.Indigo.CardManagement.LoadBatchMangementService();

                                    //SELF APPROVES LOAD BATCH
                                    Veneka.Indigo.CardManagement.objects.DatabaseResponse response = null;//loadBatchMgm.UpdateLoadBatchStatus(loadBatchReference, "SYSTEM",
                                    //     indigoCardManagement.LoadBatchStatus.APPROVED.ToString());


                                    if (response.responseSuccess)
                                    {
                                        //CREATES A DISTRIBUTION BATCH
                                        List <string> cardsList  = new List <string>();
                                        string        branchCode = String.Empty;
                                        foreach (var item in this.CardRecords)
                                        {
                                            cardsList.Add(item[0]);
                                            branchCode = item[1];
                                        }

                                        var batch = new Veneka.Indigo.CardManagement.objects.DistributionBatch
                                                    (
                                            0, String.Empty, string.Empty, config.issuer_id, null,
                                            DateTime.Now, Veneka.Indigo.CardManagement.DistributionBatchStatus.CREATED,
                                            cardsList, branchCode, string.Empty,
                                            new List <string>());

                                        Veneka.Indigo.CardManagement.DistBatchManagementService distBatchMgm = new Veneka.Indigo.CardManagement.DistBatchManagementService();


                                        if (cardsList.Count > 0)
                                        {
                                            response = null;//distBatchMgm.CreateDistributionBatch(batch, "SYSTEM", cardsList);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    //write history
                    CreateFileHistory(fileInfo.Name, fileInfo.Directory.ToString(), fileInfo.Length,
                                      FileType.CARD_IMPORT,
                                      fileInfo.CreationTime.ToString(), fileStatus, strDateTime, config.issuer_id,
                                      processedrecords,
                                      duplicaterecords, fileLoadComments);
                    //archive

                    ArchiveFiles(fileStatus, config, fileInfo, strDateTime);
                }

                //build app log comment
                applogcomment += " Success=" + successfileload + ", Partial=" + partialfileload + " Failed=" +
                                 failedfileload +
                                 ", Duplicate=" + duplicatefile + ", Invalid format=" + invalidformatfile;
            }

            //write to application log
            LogFileWriter.WriteFileLoaderComment(applogcomment);
        }
Esempio n. 14
0
        public BetFileResponse SaveATGFile(BetFileRequest request)
        {
            var raceDay = request.RaceDay;

            var coupons = new List <string[]> ();

            foreach (var row in request.Rows)
            {
                var horses = row.Split(',').Select(x => Int32.Parse(x));
                var legs   = new List <string>();
                foreach (var horse in horses)
                {
                    var marks = "000000000000000".ToArray();
                    marks [horse - 1] = '1';
                    legs.Add(new string(marks));
                }
                coupons.Add(legs.ToArray());
            }

            //var coupons = new List<string[]>() { request.Rows };

            var atgXMLFile = new issuer();

            atgXMLFile.company       = "none";
            atgXMLFile.createddate   = DateTime.Now;
            atgXMLFile.product       = "TrabLab";
            atgXMLFile.version       = "0.1";
            atgXMLFile.schemaversion = "ATG File Betting XSD ver 1.8";

            var betcoupons = new betcouponsType();

            atgXMLFile.betcoupons = betcoupons;

            if (request.RaceDay.BetType == "V75")
            {
                int couponId    = 1;
                var couponTypes = new List <v75CouponType>();
                foreach (var kupong in coupons)
                {
                    var couponType = new v75CouponType();
                    couponType.date     = new DateTime(raceDay.Year, raceDay.Month, raceDay.Date);
                    couponType.couponid = Convert.ToString(couponId++);

                    var legTypes = new List <legType>();
                    int legId    = 1;
                    foreach (var leg in kupong)
                    {
                        legType legType = new legType();
                        legType.marks = leg;
                        legType.legno = Convert.ToString(legId++);
                        legTypes.Add(legType);
                    }
                    couponType.leg = legTypes.ToArray();
                    couponTypes.Add(couponType);
                }
                betcoupons.v75Coupon = couponTypes.ToArray();
            }
            else if (raceDay.BetType == "V65")
            {
                int couponId    = 1;
                var couponTypes = new List <v65CouponType>();
                foreach (var kupong in coupons)
                {
                    var couponType = new v65CouponType();
                    couponType.date     = new DateTime(raceDay.Year, raceDay.Month, raceDay.Date);
                    couponType.couponid = Convert.ToString(couponId++);

                    var legTypes = new List <legType>();
                    int legId    = 1;
                    foreach (var leg in kupong)
                    {
                        legType legType = new legType();
                        legType.marks = leg;
                        legType.legno = Convert.ToString(legId++);
                        legTypes.Add(legType);
                    }
                    couponType.leg = legTypes.ToArray();
                    couponTypes.Add(couponType);
                }
                betcoupons.v65Coupon = couponTypes.ToArray();
            }
            else if (raceDay.BetType == "V86")
            {
                int couponId    = 1;
                var couponTypes = new List <v86CouponType>();
                foreach (var kupong in coupons)
                {
                    var couponType = new v86CouponType();
                    couponType.date      = new DateTime(raceDay.Year, raceDay.Month, raceDay.Date);
                    couponType.couponid  = Convert.ToString(couponId++);
                    couponType.trackcode = raceDay.TrackId.ToString();
                    var legTypes = new List <legType>();
                    int legId    = 1;
                    foreach (var leg in kupong)
                    {
                        legType legType = new legType();
                        legType.marks = leg;
                        legType.legno = Convert.ToString(legId++);
                        legTypes.Add(legType);
                    }
                    couponType.leg = legTypes.ToArray();
                    couponTypes.Add(couponType);
                }
                betcoupons.v86Coupon = couponTypes.ToArray();
            }
            else if (raceDay.BetType == "V64")
            {
                int couponId    = 1;
                var couponTypes = new List <v64CouponType>();
                foreach (var kupong in coupons)
                {
                    var couponType = new v64CouponType();
                    couponType.date     = new DateTime(raceDay.Year, raceDay.Month, raceDay.Date);
                    couponType.couponid = Convert.ToString(couponId++);

                    var legTypes = new List <legType>();
                    int legId    = 1;
                    foreach (var leg in kupong)
                    {
                        legType legType = new legType();
                        legType.marks = leg;
                        legType.legno = Convert.ToString(legId++);
                        legTypes.Add(legType);
                    }
                    couponType.leg = legTypes.ToArray();
                    couponTypes.Add(couponType);
                }
                betcoupons.v64Coupon = couponTypes.ToArray();
            }
            else if (raceDay.BetType == "V5")
            {
                int couponId    = 1;
                var couponTypes = new List <v5CouponType>();
                foreach (var kupong in coupons)
                {
                    var couponType = new v5CouponType();
                    couponType.date      = new DateTime(raceDay.Year, raceDay.Month, raceDay.Date);
                    couponType.couponid  = Convert.ToString(couponId++);
                    couponType.trackcode = raceDay.TrackId.ToString();
                    var legTypes = new List <legType>();
                    int legId    = 1;
                    foreach (var leg in kupong)
                    {
                        legType legType = new legType();
                        legType.marks = leg;
                        legType.legno = Convert.ToString(legId++);
                        legTypes.Add(legType);
                    }
                    couponType.leg = legTypes.ToArray();
                    couponTypes.Add(couponType);
                }
                betcoupons.v5Coupon = couponTypes.ToArray();
            }
            else if (raceDay.BetType == "V4")
            {
                int couponId    = 1;
                var couponTypes = new List <v4CouponType>();
                foreach (var kupong in coupons)
                {
                    var couponType = new v4CouponType();
                    couponType.date      = new DateTime(raceDay.Year, raceDay.Month, raceDay.Date);
                    couponType.couponid  = Convert.ToString(couponId++);
                    couponType.trackcode = raceDay.TrackId.ToString();
                    var legTypes = new List <legType>();
                    int legId    = 1;
                    foreach (var leg in kupong)
                    {
                        legType legType = new legType();
                        legType.marks = leg;
                        legType.legno = Convert.ToString(legId++);
                        legTypes.Add(legType);
                    }
                    couponType.leg = legTypes.ToArray();
                    couponTypes.Add(couponType);
                }
                betcoupons.v4Coupon = couponTypes.ToArray();
            }

            //var systemSize = Coupon.CountRows(legs);
            //var reducedSize = coupon.Sum(x => Coupon.CountRows(x));

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(issuer));
            MemoryStream  memoryStream  = new MemoryStream();
            XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);

            xmlSerializer.Serialize(xmlTextWriter, atgXMLFile);
            xmlTextWriter.BaseStream.Position = 0;
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(request.Filename);

            Crc16  crc16 = new Crc16();
            string checkSumAsHexString = crc16.GetCheckSumAsHexString(xmlTextWriter.BaseStream);
            var    fileName            = string.Format("{0}_{1}_{2}_{3}.xml", fileNameWithoutExtension, request.ReducedSize, request.SystemSize, checkSumAsHexString);

            xmlTextWriter.BaseStream.Position = 0;
            StreamReader streamReader = new StreamReader(xmlTextWriter.BaseStream);

            return(new BetFileResponse()
            {
                XML = streamReader.ReadToEnd(), Filename = fileName
            });
            //string end = streamReader.ReadToEnd();
            //StreamWriter streamWriter = new StreamWriter(fileName, false);
            //streamWriter.Write(end);
            //streamWriter.Flush();
            //streamWriter.Close();
            //xmlTextWriter.Close();
            //return fileName;
        }