Exemplo n.º 1
0
        private DataRow CreateRow(DataTable dt, ImportedRow ir, ImportDefinition id)
        {
            var dr = dt.NewRow();

            foreach (var c in ir.Columns)
            {
                CastValueToType(c.Key, c.Value, id.Columns.Single(x => x.PropertyName == c.Key).DataType, dr);
            }

            foreach (var dp in id.DestinationProperties)
            {
                if (dp.Substitute)
                {
                    CastValueToType(dp.PropertyName,
                                    this.substitutions[dp.SubstitutionName],
                                    dp.DataType, dr);
                }
                else
                {
                    CastValueToType(dp.PropertyName, dp.GetValueToSet(), dp.DataType, dr);
                }
            }


            return(dr);
        }
Exemplo n.º 2
0
        protected static ImportResult ImportPaypal(string contents)
        {
            string[]           lines  = contents.Split('\n');
            ImportResult       result = new ImportResult();
            List <ImportedRow> rows   = new List <ImportedRow>();

            foreach (string line in lines)
            {
                string[] parts = line.Split('\t');

                if (parts.Length < 30)
                {
                    continue;
                }

                if (StripQuotes(parts[6]) != "SEK")
                {
                    continue; // HACK: Need to fix currency support at some time
                }

                // Get current balance from the first line in the file

                if (result.CurrentBalance == 0.0)
                {
                    result.CurrentBalance = Double.Parse(StripQuotes(parts[34]), CultureInfo.InvariantCulture);
                }

                ImportedRow row = new ImportedRow();

                // DEBUG -- REMOVE WHEN DEPLOYING

                if (Debugger.IsAttached)
                {
                    Console.WriteLine("New Row -----");

                    Console.WriteLine("- SuppliedTxId: {0}", parts[12]);
                    Console.WriteLine("- Comment:      {0}", parts[4]);
                    Console.WriteLine("- DateTime:     {0} {1}", parts[0], parts[1]);
                    Console.WriteLine("- AmountGross:  {0}", parts[7]);
                    Console.WriteLine("- Fee:          {0}", parts[8]);
                    Console.WriteLine("- AmountNet:    {0}", parts[9]);
                }

                row.SuppliedTransactionId = StripQuotes(parts[12]);
                row.Comment  = StripQuotes(parts[4]);
                row.DateTime = DateTime.Parse(StripQuotes(parts[0]) + " " + StripQuotes(parts[1]),
                                              CultureInfo.InvariantCulture);
                row.AmountCentsGross = Int64.Parse(StripQuotes(parts[7]).Replace(".", "").Replace(",", ""));
                row.FeeCents         = Int64.Parse(StripQuotes(parts[8]).Replace(".", "").Replace(",", ""));
                row.AmountCentsNet   = Int64.Parse(StripQuotes(parts[9]).Replace(".", "").Replace(",", ""));

                rows.Add(row);
            }

            result.Rows = rows;
            return(result);
        }
    protected ImportResult ImportSebText(string contents)
    {
        string patternRows =
            @"^\s(?<datetime>[0-9]{4}\-[0-9]{2}\-[0-9]{2})\s\t[0-9]{4}\-[0-9]{2}\-[0-9]{2}\s\t(?<transactionid>[^\s]+)\s\t(?<comment>[^\t]+)\t(?<amount>[\-,.0-9]+)\s\t(?<balance>[\-,.0-9]+)";
        string patternBalance =
            @"^[0-9\s]+\t[\-0-9\.\,]+\s\t(?<balance>[\-0-9\.\,]+)\s\t[\-0-9\.\,]+";

        List <ImportedRow> rows   = new List <ImportedRow>();
        ImportResult       result = new ImportResult();

        Regex regexBalance = new Regex(patternBalance, RegexOptions.Multiline | RegexOptions.Compiled);
        Regex regexRows    = new Regex(patternRows, RegexOptions.Multiline | RegexOptions.Compiled);

        Match matchBalance = regexBalance.Match(contents);

        if (!matchBalance.Success)
        {
            throw new ArgumentException("Unable to find balance");
        }

        string stringBalance = matchBalance.Groups["balance"].Value.Replace(".", "").Replace(",", ".");

        result.CurrentBalance = Double.Parse(stringBalance, CultureInfo.InvariantCulture);

        Match matchRow = regexRows.Match(contents);

        while (matchRow.Success)
        {
            string amountString = matchRow.Groups["amount"].Value;
            amountString = amountString.Replace(".", "").Replace(",", "");

            ImportedRow row = new ImportedRow();
            row.DateTime       = DateTime.Parse(matchRow.Groups["datetime"].Value);
            row.Comment        = matchRow.Groups["comment"].Value.Trim();
            row.CurrentBalance = Double.Parse(matchRow.Groups["balance"].Value.Replace(".", "").Replace(",", "."), CultureInfo.InvariantCulture);
            row.AmountCentsNet = Int64.Parse(amountString);
            row.HashBase       = matchRow.Groups["transactionid"].Value;

            rows.Add(row);

            matchRow = matchRow.NextMatch();
        }

        result.Rows = rows;

        if (rows.Count < 100 && rows.Count > 0)
        {
            // A serious error has occurred. Dev assistance is necessary.

            Person.FromIdentity(1).SendNotice("Contents for bank parsing (I see " + rows.Count.ToString() + " rows)\r\n\r\n", contents, 1);

            Person.FromIdentity(1).SendPhoneMessage("Bank import failed - " + rows.Count.ToString() + " rows parsed - see mail");

            throw new ArgumentException("PirateWeb is unable to parse the page. Developer assistance has been called in.");
        }
        return(result);
    }
    protected ImportResult ImportSeb(string contents)
    {
        string patternRows =
            @"<tr class=""[a-z]+?"">\s*<td style=""white-space: nowrap;"">(?<datetime>[0-9\-]+)</td>\s*<td style=""white-space: nowrap;"">[0-9\-]+</td>\s*<td>(?<transactionid>.+?)</td>\s*<td>(?<comment>.*?)</td>\s*<td class=""numeric"">(?<linkdummy><a href="".*?"">)?.*?(?<amount>[0-9\.,\-]+).*?</td>\s*<td class=""numeric"">(?<balance>[0-9\.,\-]+)</td>\s*</tr>";
        string patternBalance =
            @"<tbody>\s*<tr class=""[a-z]+"">\s*<td>[0-9\s]+</td>\s*<td class=""numeric"">(?<balance>[0-9\.\-,]+)</td>\s*<td class=""numeric"">[0-9\.\-,]+</td>\s*<td class=""numeric"">[0-9\.\-,]+</td>\s*</tr>\s*</tbody>";

        List <ImportedRow> rows   = new List <ImportedRow>();
        ImportResult       result = new ImportResult();

        Regex regexBalance = new Regex(patternBalance, RegexOptions.Singleline);
        Regex regexRows    = new Regex(patternRows, RegexOptions.Singleline | RegexOptions.Compiled);

        Match matchBalance = regexBalance.Match(contents);

        if (!matchBalance.Success)
        {
            throw new ArgumentException("Unable to find balance");
        }

        string stringBalance = matchBalance.Groups["balance"].Value.Replace(".", "").Replace(",", ".");

        result.CurrentBalance = Double.Parse(stringBalance, CultureInfo.InvariantCulture);

        Match matchRow = regexRows.Match(contents);

        while (matchRow.Success)
        {
            string amountString = matchRow.Groups["amount"].Value;
            amountString = amountString.Replace(".", "").Replace(",", "");

            ImportedRow row = new ImportedRow();
            row.DateTime       = DateTime.Parse(matchRow.Groups["datetime"].Value);
            row.Comment        = StripHtml(matchRow.Groups["comment"].Value);
            row.CurrentBalance = Double.Parse(matchRow.Groups["balance"].Value.Replace(".", "").Replace(",", "."), CultureInfo.InvariantCulture);
            row.AmountCentsNet = Int64.Parse(amountString);
            row.HashBase       = matchRow.Groups["transactionid"].Value;

            rows.Add(row);

            matchRow = matchRow.NextMatch();
        }

        result.Rows = rows;

        if (rows.Count < 20 && rows.Count > 0)
        {
            // A serious error has occurred. Dev assistance is necessary.

            Person.FromIdentity(1).SendNotice("Contents for bank parsing (I see " + rows.Count.ToString() + " rows)", contents, 1);

            Person.FromIdentity(1).SendPhoneMessage("Bank import failed - " + rows.Count.ToString() + " rows parsed - see mail");

            throw new ArgumentException("PirateWeb is unable to parse the page. Developer assistance has been called in.");
        }
        return(result);
    }
Exemplo n.º 5
0
        protected static ImportResult ImportPaypal(string contents)
        {
            string[] lines = contents.Split('\n');
            ImportResult result = new ImportResult();
            List<ImportedRow> rows = new List<ImportedRow>();

            foreach (string line in lines)
            {
                string[] parts = line.Split('\t');

                if (parts.Length < 30)
                {
                    continue;
                }

                if (StripQuotes(parts[6]) != "SEK")
                {
                    continue; // HACK: Need to fix currency support at some time
                }

                // Get current balance from the first line in the file

                if (result.CurrentBalance == 0.0)
                {
                    result.CurrentBalance = Double.Parse(StripQuotes(parts[34]), CultureInfo.InvariantCulture);
                }

                ImportedRow row = new ImportedRow();

                // DEBUG -- REMOVE WHEN DEPLOYING

                if (System.Diagnostics.Debugger.IsAttached)
                {
                    Console.WriteLine("New Row -----");

                    Console.WriteLine("- SuppliedTxId: {0}", parts[12]);
                    Console.WriteLine("- Comment:      {0}", parts[4]);
                    Console.WriteLine("- DateTime:     {0} {1}", parts[0], parts[1]);
                    Console.WriteLine("- AmountGross:  {0}", parts[7]);
                    Console.WriteLine("- Fee:          {0}", parts[8]);
                    Console.WriteLine("- AmountNet:    {0}", parts[9]);
                }

                row.SuppliedTransactionId = StripQuotes(parts[12]);
                row.Comment = StripQuotes(parts[4]);
                row.DateTime = DateTime.Parse(StripQuotes(parts[0]) + " " + StripQuotes(parts[1]), CultureInfo.InvariantCulture);
                row.AmountCentsGross = Int64.Parse(StripQuotes(parts[7]).Replace(".", "").Replace(",",""));
                row.FeeCents = Int64.Parse(StripQuotes(parts[8]).Replace(".", "").Replace(",", ""));
                row.AmountCentsNet = Int64.Parse(StripQuotes(parts[9]).Replace(".", "").Replace(",", ""));

                rows.Add(row);
            }

            result.Rows = rows;
            return result;
        }
Exemplo n.º 6
0
        public void ValuesDoNotMatchDataType()
        {
            // Arrange
            var id     = CreateImportDefinition();
            var values = CreateInvalidImportRecordArray();

            // Act
            var row = new ImportedRow(0, values, id);

            // Assert
            Assert.AreEqual(10, row.ErrorMessages.Count);
        }
Exemplo n.º 7
0
        public static ImportResult CreateImportResult()
        {
            var ir          = new ImportResult();
            var importedRow = new ImportedRow();

            importedRow.Columns.Add("ABoolean", "true");
            importedRow.Columns.Add("AByte", "1");
            importedRow.Columns.Add("ACharacter", "z");
            importedRow.Columns.Add("ADateTime", "1929-06-12T11:30:15Z");
            importedRow.Columns.Add("ADecimal", "654.321");
            importedRow.Columns.Add("ADouble", "-123.456");
            importedRow.Columns.Add("AGuid", "C506A057-9EAD-422D-BADE-C5E3E1A97F62");
            importedRow.Columns.Add("AnInt16", "-32768");
            importedRow.Columns.Add("AnInt32", "-2147483648");
            importedRow.Columns.Add("AnInt64", "-9223372036854775808");
            importedRow.Columns.Add("AString", "This is an imported string.");
            ir.Rows.Add(importedRow);
            return(ir);
        }
    protected ImportResult ImportPaypal(string contents)
    {
        string[]           lines  = contents.Split('\n');
        ImportResult       result = new ImportResult();
        List <ImportedRow> rows   = new List <ImportedRow>();

        foreach (string line in lines)
        {
            string[] parts = line.Split('\t');

            if (parts.Length < 30)
            {
                continue;
            }

            if (StripQuotes(parts[6]) != "SEK")
            {
                continue; // HACK: Need to fix currency support at some time
            }

            // Get current balance from the first line in the file

            if (result.CurrentBalance == 0.0)
            {
                result.CurrentBalance = Double.Parse(StripQuotes(parts[34]), CultureInfo.InvariantCulture);
            }

            ImportedRow row = new ImportedRow();

            row.SuppliedTransactionId = StripQuotes(parts[12]);
            row.Comment          = StripQuotes(parts[4]);
            row.DateTime         = DateTime.Parse(StripQuotes(parts[0]) + " " + StripQuotes(parts[1]), CultureInfo.InvariantCulture);
            row.AmountCentsGross = Int64.Parse(StripQuotes(parts[7]).Replace(".", ""));
            row.Fee            = Double.Parse(StripQuotes(parts[8]), CultureInfo.InvariantCulture);
            row.AmountCentsNet = Int64.Parse(StripQuotes(parts[9]).Replace(".", ""));

            rows.Add(row);
        }

        result.Rows = rows;
        return(result);
    }
Exemplo n.º 9
0
        public void ImportedRowPopulatesCorrectly()
        {
            // Arrange
            var id     = CreateImportDefinition();
            var values = CreateImportRecordArray();

            // Act
            var row = new ImportedRow(0, values, id);

            // Assert
            Assert.AreEqual(0, row.RowNumber);
            Assert.AreEqual(0, row.ErrorMessages.Count);
            Assert.AreEqual(11, row.Columns.Count);

            for (var i = 0; i < values.Length; i++)
            {
                Assert.AreEqual(values[i],
                                row.Columns[id.Columns[i].PropertyName]);
            }
        }
Exemplo n.º 10
0
        private T CreateObject(ImportDefinition id, ImportedRow ir)
        {
            var obj = (T)Activator.CreateInstance(typeof(T));

            foreach (var c in ir.Columns)
            {
                PopulateProperty(obj, c.Key, id.Columns.Single(x => x.PropertyName == c.Key).DataType, c.Value);
            }

            foreach (var dp in id.DestinationProperties)
            {
                if (dp.Substitute)
                {
                    PopulateProperty(obj, dp.PropertyName, dp.DataType, substitutions[dp.SubstitutionName]);
                }
                else
                {
                    PopulateProperty(obj, dp.PropertyName, dp.DataType, dp.GetValueToSet());
                }
            }

            return((T)obj);
        }
Exemplo n.º 11
0
        protected static ImportResult ImportPayson(string contents)
        {
            string regexPattern = @"<tr>\s+<td>\s*(?<datetime>[0-9]{4}-[0-9]{2}-[0-9]{2}\s[0-9]{2}:[0-9]{2}:[0-9]{2})\s*</td><td>(?<comment1>[^<]*)</td><td>[^>]*</td><td>(?<txid>[0-9]+)</td>\s*<td>(?<from>[^<]+)</td>\s*<td>(?<to>[^<]+)</td><td class=\""tal\"">(?<gross>[\-0-9,]+)</td><td class=\""tal\"">(?<fee>[\-0-9,]+)</td><td class=\""tal\"">(?<vat>[\-0-9,]+)</td><td class=\""tal\"">(?<net>[\-0-9,]+)</td><td class=\""tal\"">(?<balance>[\-0-9,]+)</td><td>(?<currency>[^<]+)</td><td>(?<reference>[^<]+)</td><td[^>]+?>(?<comment2>[^<]+)</td>";

            Regex regex = new Regex(regexPattern, RegexOptions.Singleline);
            Match match = regex.Match(contents);

            ImportResult       result = new ImportResult();
            List <ImportedRow> rows   = new List <ImportedRow>();

            while (match.Success)
            {
                if (match.Groups["currency"].Value != "SEK")
                {
                    continue; // HACK: Need to fix currency support at some time
                }

                // Get current balance from the first line in the file

                if (result.CurrentBalance == 0.0)
                {
                    result.CurrentBalance = Int64.Parse(match.Groups["balance"].Value.Replace(",", "")) / 10000.0;
                }

                ImportedRow row = new ImportedRow();

                // DEBUG -- REMOVE WHEN DEPLOYING

                if (System.Diagnostics.Debugger.IsAttached)
                {
                    Console.WriteLine("New Row -----");

                    Console.WriteLine("- SuppliedTxId: {0}", match.Groups["txid"].Value);
                    Console.WriteLine("- Comment:      {0}", HttpUtility.HtmlDecode(match.Groups["comment2"].Value));
                    Console.WriteLine("- DateTime:     {0}", match.Groups["datetime"].Value);
                    Console.WriteLine("- AmountGross:  {0}", match.Groups["gross"].Value);
                    Console.WriteLine("- Fee:          {0}", match.Groups["fee"].Value);
                    Console.WriteLine("- AmountNet:    {0}", match.Groups["net"].Value);
                }

                string comment = HttpUtility.HtmlDecode(match.Groups["comment2"].Value.Trim());
                if (String.IsNullOrEmpty(comment))
                {
                    comment = match.Groups["comment1"].Value.Trim();
                }

                row.SuppliedTransactionId = "Payson-" + match.Groups["txid"].Value;
                row.Comment          = comment;
                row.DateTime         = DateTime.Parse(match.Groups["datetime"].Value, CultureInfo.InvariantCulture);
                row.AmountCentsGross = Int64.Parse(match.Groups["gross"].Value.Replace(".", "").Replace(",", "")) / 100;
                row.FeeCents         = Int64.Parse(match.Groups["fee"].Value.Replace(".", "").Replace(",", "")) / 100;
                row.AmountCentsNet   = Int64.Parse(match.Groups["net"].Value.Replace(".", "").Replace(",", "")) / 100;

                rows.Add(row);

                match = match.NextMatch();
            }

            result.Rows = rows;
            return(result);
        }
    protected ImportResult ImportPaypal (string contents)
    {
        string[] lines = contents.Split('\n');
        ImportResult result = new ImportResult();
        List<ImportedRow> rows = new List<ImportedRow>();

        foreach (string line in lines)
        {
            string[] parts = line.Split('\t');

            if (parts.Length < 30)
            {
                continue;
            }

            if (StripQuotes(parts[6]) != "SEK")
            {
                continue; // HACK: Need to fix currency support at some time
            }

            // Get current balance from the first line in the file

            if (result.CurrentBalance == 0.0)
            {
                result.CurrentBalance = Double.Parse(StripQuotes(parts[34]), CultureInfo.InvariantCulture);
            }

            ImportedRow row = new ImportedRow();

            row.SuppliedTransactionId = StripQuotes(parts[12]);
            row.Comment = StripQuotes(parts[4]);
            row.DateTime = DateTime.Parse(StripQuotes(parts[0]) + " " + StripQuotes(parts[1]), CultureInfo.InvariantCulture);
            row.AmountCentsGross = Int64.Parse(StripQuotes(parts[7]).Replace(".", ""));
            row.Fee = Double.Parse(StripQuotes(parts[8]), CultureInfo.InvariantCulture);
            row.AmountCentsNet = Int64.Parse(StripQuotes(parts[9]).Replace(".", ""));

            rows.Add(row);
        }

        result.Rows = rows;
        return result;
    }
    protected ImportResult ImportSebText(string contents)
    {
        string patternRows =
            @"^\s(?<datetime>[0-9]{4}\-[0-9]{2}\-[0-9]{2})\s\t[0-9]{4}\-[0-9]{2}\-[0-9]{2}\s\t(?<transactionid>[^\s]+)\s\t(?<comment>[^\t]+)\t(?<amount>[\-,.0-9]+)\s\t(?<balance>[\-,.0-9]+)";
        string patternBalance =
            @"^[0-9\s]+\t[\-0-9\.\,]+\s\t(?<balance>[\-0-9\.\,]+)\s\t[\-0-9\.\,]+";

        List<ImportedRow> rows = new List<ImportedRow>();
        ImportResult result = new ImportResult();

        Regex regexBalance = new Regex(patternBalance, RegexOptions.Multiline | RegexOptions.Compiled);
        Regex regexRows = new Regex(patternRows, RegexOptions.Multiline | RegexOptions.Compiled);

        Match matchBalance = regexBalance.Match(contents);
        if (!matchBalance.Success)
        {
            throw new ArgumentException("Unable to find balance");
        }

        string stringBalance = matchBalance.Groups["balance"].Value.Replace(".", "").Replace(",", ".");
        result.CurrentBalance = Double.Parse(stringBalance, CultureInfo.InvariantCulture);

        Match matchRow = regexRows.Match(contents);
        while (matchRow.Success)
        {
            string amountString = matchRow.Groups["amount"].Value;
            amountString = amountString.Replace(".", "").Replace(",", "");

            ImportedRow row = new ImportedRow();
            row.DateTime = DateTime.Parse(matchRow.Groups["datetime"].Value);
            row.Comment = matchRow.Groups["comment"].Value.Trim();
            row.CurrentBalance = Double.Parse(matchRow.Groups["balance"].Value.Replace(".", "").Replace(",", "."), CultureInfo.InvariantCulture);
            row.AmountCentsNet = Int64.Parse(amountString);
            row.HashBase = matchRow.Groups["transactionid"].Value;

            rows.Add(row);

            matchRow = matchRow.NextMatch();
        }

        result.Rows = rows;

        if (rows.Count < 100 && rows.Count > 0)
        {
            // A serious error has occurred. Dev assistance is necessary.

            Person.FromIdentity(1).SendNotice("Contents for bank parsing (I see " + rows.Count.ToString() + " rows)\r\n\r\n", contents, 1);

            Person.FromIdentity(1).SendPhoneMessage("Bank import failed - " + rows.Count.ToString() + " rows parsed - see mail");

            throw new ArgumentException("PirateWeb is unable to parse the page. Developer assistance has been called in.");
        }
        return result;
    }
    protected ImportResult ImportSeb (string contents)
    {
        string patternRows =
            @"<tr class=""[a-z]+?"">\s*<td style=""white-space: nowrap;"">(?<datetime>[0-9\-]+)</td>\s*<td style=""white-space: nowrap;"">[0-9\-]+</td>\s*<td>(?<transactionid>.+?)</td>\s*<td>(?<comment>.*?)</td>\s*<td class=""numeric"">(?<linkdummy><a href="".*?"">)?.*?(?<amount>[0-9\.,\-]+).*?</td>\s*<td class=""numeric"">(?<balance>[0-9\.,\-]+)</td>\s*</tr>";
        string patternBalance =
            @"<tbody>\s*<tr class=""[a-z]+"">\s*<td>[0-9\s]+</td>\s*<td class=""numeric"">(?<balance>[0-9\.\-,]+)</td>\s*<td class=""numeric"">[0-9\.\-,]+</td>\s*<td class=""numeric"">[0-9\.\-,]+</td>\s*</tr>\s*</tbody>";

        List<ImportedRow> rows = new List<ImportedRow>();
        ImportResult result = new ImportResult();

        Regex regexBalance = new Regex(patternBalance, RegexOptions.Singleline);
        Regex regexRows = new Regex(patternRows, RegexOptions.Singleline | RegexOptions.Compiled);

        Match matchBalance = regexBalance.Match(contents);
        if (!matchBalance.Success)
        {
            throw new ArgumentException("Unable to find balance");
        }

        string stringBalance = matchBalance.Groups["balance"].Value.Replace(".", "").Replace(",", ".");
        result.CurrentBalance = Double.Parse(stringBalance, CultureInfo.InvariantCulture);

        Match matchRow = regexRows.Match(contents);
        while (matchRow.Success)
        {
            string amountString = matchRow.Groups["amount"].Value;
            amountString = amountString.Replace(".", "").Replace(",", "");

            ImportedRow row = new ImportedRow();
            row.DateTime = DateTime.Parse(matchRow.Groups["datetime"].Value);
            row.Comment = StripHtml(matchRow.Groups["comment"].Value);
            row.CurrentBalance = Double.Parse(matchRow.Groups["balance"].Value.Replace(".", "").Replace(",", "."), CultureInfo.InvariantCulture);
            row.AmountCentsNet = Int64.Parse(amountString);
            row.HashBase = matchRow.Groups["transactionid"].Value;

            rows.Add(row);

            matchRow = matchRow.NextMatch();
        }

        result.Rows = rows;

        if (rows.Count < 20 && rows.Count > 0)
        {
            // A serious error has occurred. Dev assistance is necessary.

            Person.FromIdentity(1).SendNotice("Contents for bank parsing (I see " + rows.Count.ToString() + " rows)", contents, 1);

            Person.FromIdentity(1).SendPhoneMessage("Bank import failed - " + rows.Count.ToString() + " rows parsed - see mail");

            throw new ArgumentException("PirateWeb is unable to parse the page. Developer assistance has been called in.");
        }
        return result;
    }
Exemplo n.º 15
0
        protected static ImportResult ImportPayson(string contents)
        {
            string regexPattern = @"<tr>\s+<td>\s*(?<datetime>[0-9]{4}-[0-9]{2}-[0-9]{2}\s[0-9]{2}:[0-9]{2}:[0-9]{2})\s*</td><td>(?<comment1>[^<]*)</td><td>[^>]*</td><td>(?<txid>[0-9]+)</td>\s*<td>(?<from>[^<]+)</td>\s*<td>(?<to>[^<]+)</td><td class=\""tal\"">(?<gross>[\-0-9,]+)</td><td class=\""tal\"">(?<fee>[\-0-9,]+)</td><td class=\""tal\"">(?<vat>[\-0-9,]+)</td><td class=\""tal\"">(?<net>[\-0-9,]+)</td><td class=\""tal\"">(?<balance>[\-0-9,]+)</td><td>(?<currency>[^<]+)</td><td>(?<reference>[^<]+)</td><td[^>]+?>(?<comment2>[^<]+)</td>";

            Regex regex = new Regex(regexPattern, RegexOptions.Singleline);
            Match match = regex.Match(contents);

            ImportResult result = new ImportResult();
            List<ImportedRow> rows = new List<ImportedRow>();

            while (match.Success)
            {
                if (match.Groups["currency"].Value != "SEK")
                {
                    continue; // HACK: Need to fix currency support at some time
                }

                // Get current balance from the first line in the file

                if (result.CurrentBalance == 0.0)
                {
                    result.CurrentBalance = Int64.Parse(match.Groups["balance"].Value.Replace(",", ""))/10000.0;
                }

                ImportedRow row = new ImportedRow();

                // DEBUG -- REMOVE WHEN DEPLOYING

                if (System.Diagnostics.Debugger.IsAttached)
                {
                    Console.WriteLine("New Row -----");

                    Console.WriteLine("- SuppliedTxId: {0}", match.Groups["txid"].Value);
                    Console.WriteLine("- Comment:      {0}", HttpUtility.HtmlDecode(match.Groups["comment2"].Value));
                    Console.WriteLine("- DateTime:     {0}", match.Groups["datetime"].Value);
                    Console.WriteLine("- AmountGross:  {0}", match.Groups["gross"].Value);
                    Console.WriteLine("- Fee:          {0}", match.Groups["fee"].Value);
                    Console.WriteLine("- AmountNet:    {0}", match.Groups["net"].Value);
                }

                string comment = HttpUtility.HtmlDecode(match.Groups["comment2"].Value.Trim());
                if (String.IsNullOrEmpty(comment))
                {
                    comment = match.Groups["comment1"].Value.Trim();
                }

                row.SuppliedTransactionId = "Payson-" + match.Groups["txid"].Value;
                row.Comment = comment;
                row.DateTime = DateTime.Parse(match.Groups["datetime"].Value, CultureInfo.InvariantCulture);
                row.AmountCentsGross = Int64.Parse(match.Groups["gross"].Value.Replace(".", "").Replace(",", ""))/100;
                row.FeeCents = Int64.Parse(match.Groups["fee"].Value.Replace(".", "").Replace(",", ""))/100;
                row.AmountCentsNet = Int64.Parse(match.Groups["net"].Value.Replace(".", "").Replace(",", ""))/100;

                rows.Add(row);

                match = match.NextMatch();
            }

            result.Rows = rows;
            return result;
        }