Beispiel #1
0
        public static List <Operation> Import()
        {
            var ignored = ConfigurationManager.IgnoredTransaction();

            var importFactory = ImportFactory.GetFactory(ConfigurationManager.BankName());
            var importer      = importFactory.CreateImporter();
            var transactions  = new List <Transaction>();
            var path          = ConfigurationManager.PathToImportFiles();

            foreach (string file in Directory.EnumerateFiles(path, "*.csv"))
            {
                transactions.AddRange(importer.ReadTransactions(file));
                File.Move(file, file + ".taken");

                foreach (var ignoredItem in ignored)
                {
                    if (ignoredItem.DescriptionRegex == "")
                    {
                        ignoredItem.DescriptionRegex = ".*";
                    }

                    if (ignoredItem.TitleRegex == "")
                    {
                        ignoredItem.TitleRegex = ".*";
                    }

                    transactions = transactions.Where(t => !Regex.Match(t.ContractorData, ignoredItem.DescriptionRegex).Success || !Regex.Match(t.Title, ignoredItem.TitleRegex).Success).ToList();
                    transactions.Reverse();
                }
            }

            return(new TransactionToOperationMapper().ConvertToEntitiesCollection(transactions, User, Importances, Frequencies, Tags, TransactionTypes, TransferTypes).ToList());
        }
        private List <ApiOperation> Import(int bankId, List <string> lines)
        {
            var ignored = Schematics.Where(t => t.Type.Id == 1);

            var importFactory = ImportFactory.GetFactory(GetBanks(bankId).Name);
            var importer      = importFactory.CreateImporter();
            var transactions  = new List <Transaction>();

            transactions.AddRange(importer.ReadTransactions(lines));

            foreach (var ignoredItem in ignored)
            {
                if (ignoredItem.Context.DescriptionRegex == "")
                {
                    ignoredItem.Context.DescriptionRegex = ".*";
                }

                if (ignoredItem.Context.TitleRegex == "")
                {
                    ignoredItem.Context.TitleRegex = ".*";
                }

                transactions = transactions.Where(t => !Regex.Match(t.ContractorData, ignoredItem.Context.DescriptionRegex).Success || !Regex.Match(t.Title, ignoredItem.Context.TitleRegex).Success).ToList();
            }

            transactions.Reverse();
            var mapper = new TransactionsToApiOperationsMapper();

            mapper.setSchematics(Schematics.Where(t => t.Type.Id == 2));
            var a = mapper.ConvertToEntitiesCollection(transactions, User, Importances, Frequencies, Tags, TransactionTypes, TransferTypes).ToList();

            return(a);
        }