示例#1
0
 // get the regular expression string that finds a match to the description string
 private static RegExString GetRegExString(IRegExStringRepository regExStringRepository, string description)
 {
     foreach (var r in regExStringRepository.GetAll())
     {
         if (!String.IsNullOrEmpty(r.SearchString) && Regex.Match(description, r.SearchString).Success)
         {
             return(r);
         }
     }
     return(regExStringRepository.GetAll().First(m => m.SearchString == ""));
 }
示例#2
0
        public HomeController(ITransactionRepository transactionRepository, IRegExStringRepository regExStringRepository)
        {
            this.transactionRepository = transactionRepository;
            this.regExStringRepository = regExStringRepository;

            // load transaction data file into the database if needed
            if (transactionRepository.GetAll().Count == 0)
            {
                // after testing is done use the AppSettings' version for the inputFile
                //var inputFile = (string)ConfigurationManager.AppSettings["InputFile"];
                var inputFile = System.Web.HttpContext.Current.Server.MapPath(@"\TestData.txt");

                Helper.LoadInputFile(inputFile, transactionRepository, regExStringRepository);
            }
        }
示例#3
0
 // loads transactions from input file into the database
 public static void LoadInputFile(string inputFile, ITransactionRepository transactionRepository, IRegExStringRepository regExStringRepository)
 {
     using (var reader = new StreamReader(inputFile))
     {
         while (!reader.EndOfStream)
         {
             var tokens      = reader.ReadLine().Replace("\\", "").Replace("\"", "").Split(',');
             var transaction = new Transaction()
             {
                 Date        = DateTime.Parse(tokens[0]),
                 Amount      = Decimal.Parse(tokens[1]),
                 Description = tokens[4],
                 RegExString = GetRegExString(regExStringRepository, tokens[4]),
             };
             transactionRepository.Create(transaction);
         }
     }
 }