Beispiel #1
0
 /// <summary>
 /// Writes a single row to a CSV file.
 /// </summary>
 /// <param name="row">The row to be written</param>
 public void WriteRow(ProcessorRow row)
 {
     StringBuilder builder = new StringBuilder();
         bool firstColumn = true;
         foreach (string value in row)
         {
             // Add separator if this isn't the first value
             if (!firstColumn)
             {
                 builder.Append(',');
             }
             // Implement special handling for values that contain comma or quote
             // Enclose in quotes and double up any double quotes
             if (value.IndexOfAny(new char[] { '"', ',' }) != -1)
             {
                 builder.AppendFormat("\"{0}\"", value.Replace("\"", "\"\""));
             }
             else
             {
                 builder.Append(value);
             }
             firstColumn = false;
         }
         row.LineText = builder.ToString();
         WriteLine(row.LineText);
 }
Beispiel #2
0
        private void CreateWSF()
        {
            string dateTime = DateTime.Now.ToString("yyyyMMdd");
            string requestedDate = DateTime.Now.ToString("yyMMdd");
            //_filePath = System.Configuration.ConfigurationManager.AppSettings["ftpPathWriteProcessorWSF"].ToString();
            string folderPath = System.Configuration.ConfigurationManager.AppSettings["ftpPathWriteProcessorWSF"].ToString();
            double totalBalance = 0d;
            string processorCode = string.Empty;
            Int64 rowCount = 0;

            //Get the list of datasource to be processed
            DataSet ds = new DataLayer().RetrieveWSFInformation();
            logger.Log(NLog.LogLevel.Info, "<br/><font color=red>Creation  of the WSF files starts........." + DateTime.Now.ToString());
            //Get the list of processors to process the data file
            if (ds.Tables[1].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[1].Rows.Count; i++)
                {

                    processorCode = ds.Tables[1].Rows[i]["processorId"].ToString();

                    #region Process the files
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        rowCount = ds.Tables[0].Rows.Count;
                        //_filePath = string.Concat(processorCode.Substring(0, 2), requestedDate.Substring(0, 6), ".wsf");
                        string fileName= string.Concat(processorCode.Substring(0, 2), requestedDate.Substring(0, 6), ".wsf");

                    //    using (MRFWriter writer = new MRFWriter(_filePath))
                        using (MRFWriter writer = new MRFWriter(Path.Combine(folderPath, fileName)))
                        {
                            ProcessorRow rowHeader = new ProcessorRow();
                            rowHeader.Add(String.Format("HEADER"));
                            rowHeader.Add(String.Format(dateTime));
                            rowHeader.Add(String.Format(processorCode));
                            writer.WriteRow(rowHeader);
                            for (int count = 0; count <= rowCount - 1; count++)
                            {
                                /// Need to add logic to create the file based on the values from the file/db
                                ProcessorRow row = new ProcessorRow();
                                row.Add(String.Format(dateTime));
                                row.Add(String.Format(processorCode));
                                row.Add(String.Format(ds.Tables[0].Rows[count]["merchantId"].ToString()));
                                row.Add(String.Format(ds.Tables[0].Rows[count]["processorNumber"].ToString()));
                                row.Add(String.Format(ds.Tables[0].Rows[count]["balance"].ToString()));
                                row.Add(String.Format(ds.Tables[0].Rows[count]["rate"].ToString()));
                               totalBalance+=Convert.ToDouble(ds.Tables[0].Rows[count]["balance"].ToString());
                                writer.WriteRow(row);
                            }
                            ProcessorRow rowTrailer = new ProcessorRow();
                            rowTrailer.Add(String.Format("TRAILER"));
                            rowTrailer.Add(String.Format(dateTime));
                            rowTrailer.Add(String.Format(processorCode));
                            rowTrailer.Add(String.Format(rowCount.ToString()));
                            rowTrailer.Add(String.Format(totalBalance.ToString()));
                            writer.WriteRow(rowTrailer);

                        }
                    }

                }
                    #endregion
                logger.Log(NLog.LogLevel.Info, "<br/><font color=red>Reading of the files Ends........." + DateTime.Now.ToString());
            }
        }
Beispiel #3
0
        /// <summary>
        /// Reads a processor file
        /// </summary>
        private void ReadPAF()
        {
            // Read sample data from CSV file

            string pathtoRead = System.Configuration.ConfigurationManager.AppSettings["ftpPathReadProcessorActivity"].ToString();
            logger.Log(NLog.LogLevel.Info, "Reading of the files starts........."+ pathtoRead);
            string[] files = System.IO.Directory.GetFiles(pathtoRead, "*.paf");
            logger.Log(NLog.LogLevel.Info, "<br/>Number of files  to be read ..." +files.Count());
            foreach (var item in files)
            {
                #region Read files from a location
                using (SPFReader reader = new SPFReader(item))
                {
                    int count = 0;
                    //   double mccvBaseValue = 0D;
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Indent = true;
                    settings.CloseOutput = true;
                    settings.OmitXmlDeclaration = false;
                    StringBuilder sbXml = new StringBuilder();
                    XmlWriter writer = XmlWriter.Create(sbXml, settings);
                    ProcessorRow row = new ProcessorRow();
                    writer.WriteStartElement("processor");
                    while (reader.ReadRow(row))
                    {
                        if (count > 0)
                        {
                            /*
                                 * [0]- Processor Processed date,* [1]-AMI Processor Code* [2]- Processor Merchant Number,* [3]-Retrieval source
                                 * [4]-Total Amount,* [5]-Withdrawal Amount,* [6]-Activity type,* [7]-(Specified Percentage) Rate,* [8]-Start date
                                 * [9]-End date,* [10]-Processor Processed Date,* [11]-Processor Merchant Category
                                 * [12]-Processor Merchant Status, * [13]-Processor Merchant Business Start Date
                                 * [14]-Legal Company Name,* [15]-RNC,* [16]-Bank Account Number,* [17]-Authorized Owner Name
                                 * */
                            if (count==0)
                            {
                                string header = Convert.ToString(row[0]);
                                string processorDate = Convert.ToString(row[1]);
                                string amiprocessorcode = Convert.ToString(row[2]);
                                if (string.IsNullOrEmpty(header) || string.IsNullOrEmpty(processorDate) || string.IsNullOrEmpty(amiprocessorcode))
                                {
                                    logger.Log(NLog.LogLevel.Info, "Missing required paramters");
                                    break;
                                }

                            }

                            if (row.Count > 6)
                            {

                                try
                                {
                                    DateTime processedDate;
                                    processedDate = DateTime.ParseExact(Convert.ToString(row[0]), "yyyyMMdd", CultureInfo.InvariantCulture);
                                    writer.WriteStartElement("processoractivity");
                                    writer.WriteAttributeString("processedDate", Convert.ToString(row[0]));
                                    writer.WriteAttributeString("processorCode", row[1]);
                                    writer.WriteAttributeString("pMerchantNumber", Convert.ToString(row[2]));
                                    writer.WriteAttributeString("retrievalSource", Convert.ToString(row[3]));
                                    writer.WriteAttributeString("totalAmount", Convert.ToString(row[4]));
                                    writer.WriteAttributeString("withdrawalAmount", Convert.ToString(row[5]));
                                    //Activity type 70 Withdrawal and 20 Adjustment
                                    writer.WriteAttributeString("activityType", Convert.ToString(row[6]));
                                    //Percent withheld. (1.00 means 100%, 0.50 means 50% and so on)
                                    writer.WriteAttributeString("specifiedRate", Convert.ToString(row[7]));
                                    writer.WriteAttributeString("startDate", Convert.ToString(row[8]));
                                    writer.WriteAttributeString("endDate", Convert.ToString(row[9]));
                                    writer.WriteEndElement();
                                }
                                catch (Exception ex)
                                {
                                    logger.Log(NLog.LogLevel.Info, "Exception " + ex.ToString() + "<br />" + ex.StackTrace + "<br/>" + Convert.ToString(row[0]));
                                    break;
                                }
                                logger.Log(NLog.LogLevel.Info, "Finished reading row");
                            }
                        }
                        count++;
                    }
                    writer.WriteEndElement();
                    writer.Flush();
                   new DataLayer().InsertProcessorActivities(sbXml.ToString());
                }
                #endregion
                MovetoArchive(item);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Reads a processor file
        /// </summary>
        private void ReadSPF()
        {
            try
            {

            string pathtoRead = string.Empty;
            string[] files;
            // Read sample data from CSV file
               /* if (System.Configuration.ConfigurationManager.AppSettings["isftp"].ToString() == "1")
            {
                logger.Log(NLog.LogLevel.Info, "<br/><font color=red>Reading of the files from ftp starts........." + DateTime.Now.ToString());
                files = GetFilesfromFTP();
                logger.Log(NLog.LogLevel.Info, "<br/><font color=red>Read  files from ftp server........." + files.Count() + "to be downloaded");
                foreach (string item in files)
                {
                    logger.Log(NLog.LogLevel.Info, "<br/><font color=red>Downloading  files from ftp server........." + item + "");
                    DownloadFilesfromFTP(item);
                }
            }*/
            pathtoRead = System.Configuration.ConfigurationManager.AppSettings["systemPathRead"].ToString();
            files = System.IO.Directory.GetFiles(pathtoRead, "*.spf");

            logger.Log(NLog.LogLevel.Info, "<br/><font color=red>Reading of the files starts........." + DateTime.Now.ToString());

            logger.Log(NLog.LogLevel.Info, "<br/>Total # of files........." + files.Count());
            foreach (var item in files)
            {
                #region Read files from a location
                using (SPFReader reader = new SPFReader(item))
                {

                    int count = 0;
                    //   double mccvBaseValue = 0D;
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Indent = true;
                    settings.CloseOutput = true;
                    settings.OmitXmlDeclaration = false;
                    StringBuilder sbXml = new StringBuilder();
                    XmlWriter writer = XmlWriter.Create(sbXml, settings);

                    ProcessorRow row = new ProcessorRow();
                    writer.WriteStartElement("profiles");
                    while (reader.ReadRow(row))
                    {
                        if (count > 0)
                        {
                            /*
                                 * [0]- Merchant Number,* [1]-Processor Merchant Number* [2]- Processor Code,* [3]-Activity type
                                 * [4]-Retrieval source,* [5]-Currency,* [6]-Total Amount,* [7]-Total Tickets,* [8]-Start date
                                 * [9]-End date,* [10]-Processor Processed Date,* [11]-Processor Merchant Category
                                 * [12]-Processor Merchant Status, * [13]-Processor Merchant Business Start Date
                                 * [14]-Legal Company Name,* [15]-RNC,* [16]-Bank Account Number,* [17]-Authorized Owner Name
                                 * */

                            if (row.Count > 4)
                            {

                                try
                                {
                                    DateTime processedDate;
                                    processedDate = DateTime.ParseExact(Convert.ToString(row[10]), "yyyyMMdd", CultureInfo.InvariantCulture);

                                    writer.WriteStartElement("monthlyprofile");
                                    writer.WriteAttributeString("merchantId", Convert.ToString(row[0]));
                                    writer.WriteAttributeString("pMerchantNumber", Convert.ToString(row[1]));
                                    writer.WriteAttributeString("processorCode", row[2]);
                                    writer.WriteAttributeString("activityType", Convert.ToString(row[3]));
                                    writer.WriteAttributeString("retrievalSource", Convert.ToString(row[4]));
                                    writer.WriteAttributeString("currencyId", Convert.ToString(row[5]));
                                    writer.WriteAttributeString("totalAmount", Convert.ToString(row[6]));
                                    writer.WriteAttributeString("totalTickets", Convert.ToString(row[7]));
                                    writer.WriteAttributeString("startDate", Convert.ToString(row[8]));
                                    writer.WriteAttributeString("endDate", Convert.ToString(row[9]));
                                    writer.WriteAttributeString("processedDate", Convert.ToString(row[10]));
                                    writer.WriteAttributeString("month", Convert.ToString(processedDate.Month));
                                    writer.WriteAttributeString("year", Convert.ToString(processedDate.Year));

                                    writer.WriteAttributeString("processorMerchantCategory", Convert.ToString(row[11]) ?? string.Empty);
                                    if (Convert.ToString(row[12]) == "A")
                                    {
                                        writer.WriteAttributeString("processorMerchantStatus", "1");
                                    }
                                    else
                                    {
                                        writer.WriteAttributeString("processorMerchantStatus", "0");
                                    }

                                    writer.WriteAttributeString("processorMerchantBusinessStartDate", Convert.ToString(row[13]));
                                    writer.WriteAttributeString("legalName", row.ElementAtOrDefault(14));
                                    writer.WriteAttributeString("rnc", row.ElementAtOrDefault(15));
                                    writer.WriteAttributeString("bankAccountNumber", row.ElementAtOrDefault(16));
                                    writer.WriteAttributeString("authorizedOwnerName", row.ElementAtOrDefault(17));
                                    writer.WriteEndElement();
                                }
                                catch (Exception ex)
                                {

                                    logger.Log(NLog.LogLevel.Error, ex.StackTrace);
                                    break;
                                }
                            }
                        }
                        count++;
                    }
                    writer.WriteEndElement();
                    writer.Flush();

                   new DataLayer().InsertCreditProfiles(sbXml.ToString());

                }

                #endregion
                logger.Log(NLog.LogLevel.Info, "<br/>Completed insertion of the data to the system</font>");
                MovetoArchive(item);
            }
            }
            catch (Exception ex)
            {

                logger.Log(NLog.LogLevel.Error, ex.StackTrace);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Writes a processor file
        /// </summary>
        private void CreateMRF()
        {
            try
            {
            string dateTime = DateTime.Now.ToString("yyyyMMdd");
            string requestedDate = DateTime.Now.ToString("yyMMdd");

            string fileLocation = System.Configuration.ConfigurationManager.AppSettings["systemPathWrite"].ToString();
            string fileName = string.Empty;
            //fileLocation;
            string processorCode = string.Empty;
            string processorName = string.Empty;
            Int64 rowCount = 0;
            Int64 individualRows = 0;
            #region Load File

            //Get the list of datasource to be processed
            DataSet ds = new DataLayer().RetrieveProcessorQueue();
            logger.Log(NLog.LogLevel.Info, "<br/><font color=red>Creation  of the MRF files starts........." + DateTime.Now.ToString());
            //Get the list of processors to process the data file
            if (ds.Tables[1].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[1].Rows.Count; i++)
                {
                    processorCode = ds.Tables[1].Rows[i]["processorId"].ToString();
                    processorName = ds.Tables[1].Rows[i]["name"].ToString();
                    #region Process the files
                    logger.Log(NLog.LogLevel.Info, "<br/><font color=red>Total Rows Count in MRF files Creation........." + ds.Tables[0].Rows.Count.ToString());
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        fileName = string.Concat(processorCode.Substring(0, 2), requestedDate.Substring(0, 6), ".mrf");
                        rowCount = ds.Tables[0].Rows.Count;
                        _filePath = Path.Combine(fileLocation, fileName);
                        logger.Log(NLog.LogLevel.Info, "<br/><font color=red>File Path:   " + _filePath);
                        individualRows = 0;
                        using (MRFWriter writer = new MRFWriter(_filePath))
                        {
                            logger.Log(NLog.LogLevel.Info, "<br/><font color=red> Processor Code:   " + processorCode);
                            ProcessorRow rowHeader = new ProcessorRow();
                            rowHeader.Add(String.Format("HEADER"));
                            rowHeader.Add(String.Format(dateTime));
                            rowHeader.Add(String.Format(processorCode));
                            writer.WriteRow(rowHeader);
                            for (int count = 0; count <= rowCount - 1; count++)
                            {

                                if (processorCode == String.Format(ds.Tables[0].Rows[count]["ProcessorId"].ToString()))
                                {
                                    /// Need to add logic to create the file based on the values from the file/db
                                    ProcessorRow row = new ProcessorRow();
                                    row.Add(String.Format(dateTime));
                                    row.Add(String.Format(ds.Tables[0].Rows[count]["ProcessorId"].ToString()));
                                    row.Add(String.Format(ds.Tables[0].Rows[count]["merchantId"].ToString()));
                                    logger.Log(NLog.LogLevel.Info, "<br/><font color=red> Merchant Id :   " + String.Format(ds.Tables[0].Rows[count]["merchantId"].ToString()));
                                    row.Add(String.Format(ds.Tables[0].Rows[count]["processorNumber"].ToString()));

                                    writer.WriteRow(row);
                                    new DataLayer().UpdateProcessorQueue(Convert.ToInt64(ds.Tables[0].Rows[count]["merchantId"].ToString()), ds.Tables[0].Rows[count]["processorNumber"].ToString());
                                    individualRows++;
                                }
                            }
                            ProcessorRow rowTrailer = new ProcessorRow();
                            rowTrailer.Add(String.Format("TRAILER"));
                            rowTrailer.Add(String.Format(dateTime));
                            rowTrailer.Add(String.Format(processorCode));
                            rowTrailer.Add(String.Format(individualRows.ToString()));
                            writer.WriteRow(rowTrailer);

                        }

                        /* if (System.Configuration.ConfigurationManager.AppSettings["isftp"].ToString() == "1")
                         {
                             FtpWebRequest ftp = (FtpWebRequest)WebRequest.Create(Path.Combine(System.Configuration.ConfigurationManager.AppSettings["ftpPathWrite"].ToString(), fileName));
                             ftp.Credentials = new NetworkCredential(System.Configuration.ConfigurationManager.AppSettings["username"].ToString(), System.Configuration.ConfigurationManager.AppSettings["password"].ToString());
                             ftp.Method = WebRequestMethods.Ftp.UploadFile;
                             FileStream fs = File.OpenRead(_filePath);
                             byte[] buffer = new byte[fs.Length];
                             fs.Read(buffer, 0, buffer.Length);
                             fs.Close();

                             Stream ftpstream = ftp.GetRequestStream();
                             ftpstream.Write(buffer, 0, buffer.Length);
                             ftpstream.Close();
                         }*/
                    }
                }

                    #endregion

                }

            }
            catch(Exception ex)
            {

                logger.Log(NLog.LogLevel.Info, "<br/><font color=red>Error while creating MRF........." + ex.InnerException.ToString());
            }
            logger.Log(NLog.LogLevel.Info, "<br/><font color=red>Creation  of the MRF Ends........." + DateTime.Now.ToString());
            #endregion
        }
Beispiel #6
0
        /// <summary>
        /// Reads a row of data from a CSV file
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public bool ReadRow(ProcessorRow row)
        {
            row.LineText = ReadLine();
                if (String.IsNullOrEmpty(row.LineText))
                    return false;

                int pos = 0;
                int rows = 0;

                while (pos < row.LineText.Length)
                {
                    string value;

                    // Special handling for quoted field
                    if (row.LineText[pos] == '"')
                    #region quotedtext
                    {
                        // Skip initial quote
                        pos++;

                        // Parse quoted value
                        int start = pos;
                        while (pos < row.LineText.Length)
                        {
                            // Test for quote character
                            if (row.LineText[pos] == '"')
                            {
                                // Found one
                                pos++;

                                // If two quotes together, keep one
                                // Otherwise, indicates end of value
                                if (pos >= row.LineText.Length || row.LineText[pos] != '"')
                                {
                                    pos--;
                                    break;
                                }
                            }
                            pos++;
                        }
                        value = row.LineText.Substring(start, pos - start);
                        value = value.Replace("\"\"", "\"");
                    }
                    #endregion
                    else
                    {
                        // Parse unquoted value
                        int start = pos;
                        while (pos < row.LineText.Length && row.LineText[pos] != ',')
                            pos++;
                        value = row.LineText.Substring(start, pos - start);

                    }

                    // Add field to list
                    if (rows < row.Count)
                        row[rows] = value;
                    else
                        row.Add(value);
                    rows++;

                    // Eat up to and including next comma
                    while (pos < row.LineText.Length && row.LineText[pos] != ',')
                        pos++;
                    if (pos < row.LineText.Length)
                        pos++;
                }
                // Delete any unused items
                while (row.Count > rows)
                    row.RemoveAt(rows);

                // Return true if any columns read
                return (row.Count > 0);
        }
Beispiel #7
0
        /// <summary>
        /// Reads a processor file
        /// </summary>
        private void ReadRSF()
        {
            // Read sample data from CSV file

            string pathtoRead = System.Configuration.ConfigurationManager.AppSettings["ftpPathReadProcessorRSF"].ToString();
            logger.Log(NLog.LogLevel.Info, "Reading of the files starts........."+ pathtoRead);
            string[] files = System.IO.Directory.GetFiles(pathtoRead, "*.paf");
            logger.Log(NLog.LogLevel.Info, "<br/>Number of files  to be read ..." +files.Count());
            foreach (var item in files)
            {
                #region Read files from a location
                using (SPFReader reader = new SPFReader(item))
                {
                    int count = 0;
                    //   double mccvBaseValue = 0D;
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Indent = true;
                    settings.CloseOutput = true;
                    settings.OmitXmlDeclaration = false;
                    StringBuilder sbXml = new StringBuilder();
                    XmlWriter writer = XmlWriter.Create(sbXml, settings);

                    ProcessorRow row = new ProcessorRow();
                    writer.WriteStartElement("processor");
                    while (reader.ReadRow(row))
                    {
                        if (count > 0)
                        {

                            if (count==0)
                            {
                                string header = Convert.ToString(row[0]);
                                string processorDate = Convert.ToString(row[1]);
                                string amiprocessorcode = Convert.ToString(row[2]);
                                if (string.IsNullOrEmpty(header) || string.IsNullOrEmpty(processorDate) || string.IsNullOrEmpty(amiprocessorcode))
                                {
                                    logger.Log(NLog.LogLevel.Info, "Missing required paramters");
                                    break;
                                }
                            }

                            if (row.Count > 4)
                            {

                                try
                                {
                                    DateTime processedDate;
                                    processedDate = DateTime.ParseExact(Convert.ToString(row[0]), "yyyyMMdd", CultureInfo.InvariantCulture);

                                    writer.WriteStartElement("processoractivity");
                                    writer.WriteAttributeString("processedDate", Convert.ToString(row[0]));
                                    writer.WriteAttributeString("processorCode", row[1]);
                                    writer.WriteAttributeString("pMerchantId", Convert.ToString(row[2]));
                                    writer.WriteAttributeString("pMerchantNumber", Convert.ToString(row[2]));
                                    writer.WriteAttributeString("balance", Convert.ToString(row[3]));
                                    writer.WriteAttributeString("rate", Convert.ToString(row[4]));
                                    writer.WriteAttributeString("terminal", Convert.ToString(row[5]));
                                    //Set up status 0 Suucessfull,1- failed,2-No change
                                    writer.WriteAttributeString("setupstatus", Convert.ToString(row[6]));
                                    //Percent withheld. (1.00 means 100%, 0.50 means 50% and so on)
                                    writer.WriteAttributeString("info", Convert.ToString(row[7]));

                                    writer.WriteEndElement();
                                    logger.Log(NLog.LogLevel.Info, "Finished reading row");
                                }
                                catch (Exception ex)
                                {
                                    logger.Log(NLog.LogLevel.Info, "Exception "  + ex.ToString());
                                    break;
                                }
                            }
                        }
                        count++;
                    }
                    writer.WriteEndElement();
                    writer.Flush();
                   new DataLayer().InsertProcessorResponsesetup(sbXml.ToString());
                }
                #endregion
            }
        }