Exemple #1
0
        public void TestParserCount()
        {
            string       location            = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            StreamReader reader              = new StreamReader(Path.Combine(location, "sample2.txt"));
            AlbiladBankStatmentParser parser = new AlbiladBankStatmentParser();
            var transactions = parser.Parse(reader);

            Assert.IsTrue(transactions.Count() == 2);
        }
Exemple #2
0
        public void TestParser()
        {
            string filename = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), @"sample2.txt");
            var    stream   = new StreamReader(filename);

            AlbiladBankStatmentParser parser = new AlbiladBankStatmentParser();

            using (stream)
            {
                var transactions = parser.Parse(stream);
                var s            = transactions.First();
                Assert.IsTrue(s.Balance == (decimal)1000.00);
                Assert.IsTrue(s.Credit == 0);
                Assert.IsTrue(s.BeneficiaryId == "0000000000000");
                Assert.IsTrue(s.Beneficiary == "BIG STORE");
                Assert.IsTrue(s.Debt == (decimal) - 10);
                Assert.IsTrue(s.Date == new DateTime(2000, 1, 1, 0, 00, 0));
                Assert.IsTrue(s.Type == "مشتريات نقطة بيع");
                Assert.IsTrue(s.ReferenceNumber == "FT0000000000000");
            }
        }
        static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("Missing Arguments.");
                Console.WriteLine(@"extract transactions from Alibald bank statment pdf file into csv format.
                Usage: program.exe  password  pdffile  csvfile \n\n
                password : the password for encrypted pdf file \n
                pdffile  : the input pdf bankstatment file \n
                csvfile : the output csv file.");
            }

            string password = args[0];
            string input    = args[1];
            string output   = args[2];

            Process process = new Process();

            process.StartInfo.FileName               = "pdftotext.exe";
            process.StartInfo.Arguments              = $" -opw {password} -table -marginl 50 -margint 260 -marginb 80 -enc UTF-8 {input} -";
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;

            process.Start();
            var stream = process.StandardOutput;
            AlbiladBankStatmentParser bankStatmentParser = new AlbiladBankStatmentParser();
            var transactions = bankStatmentParser.Parse(stream);

            using (var writer = new StreamWriter(output))
            {
                using (var csv = new CsvWriter(writer, CultureInfo.CurrentCulture))
                {
                    csv.Configuration.RegisterClassMap <TransactionMap>();
                    csv.WriteRecords(transactions);
                }
            }
        }