Esempio n. 1
0
File: QifDom.cs Progetto: rolek/qif
        /// <summary>
        /// Imports a stream in a QIF format and replaces the current instance properties with details found in the import stream.
        /// </summary>
        /// <param name="reader">The import reader stream.</param>
        /// <param name="append">If set to <c>true</c> the import will append records rather than overwrite. Defaults to legacy behavior, which overwrites.</param>
        public void Import(StreamReader reader, bool append = false)
        {
            QifDom import = ImportFile(reader, Configuration);

            if (append)
            {
                AccountListTransactions.AddRange(import.AccountListTransactions);
                AssetTransactions.AddRange(import.AssetTransactions);
                BankTransactions.AddRange(import.BankTransactions);
                CashTransactions.AddRange(import.CashTransactions);
                CategoryListTransactions.AddRange(import.CategoryListTransactions);
                ClassListTransactions.AddRange(import.ClassListTransactions);
                CreditCardTransactions.AddRange(import.CreditCardTransactions);
                InvestmentTransactions.AddRange(import.InvestmentTransactions);
                LiabilityTransactions.AddRange(import.LiabilityTransactions);
                MemorizedTransactionListTransactions.AddRange(import.MemorizedTransactionListTransactions);
            }
            else
            {
                AccountListTransactions              = import.AccountListTransactions;
                AssetTransactions                    = import.AssetTransactions;
                BankTransactions                     = import.BankTransactions;
                CashTransactions                     = import.CashTransactions;
                CategoryListTransactions             = import.CategoryListTransactions;
                ClassListTransactions                = import.ClassListTransactions;
                CreditCardTransactions               = import.CreditCardTransactions;
                InvestmentTransactions               = import.InvestmentTransactions;
                LiabilityTransactions                = import.LiabilityTransactions;
                MemorizedTransactionListTransactions = import.MemorizedTransactionListTransactions;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a transaction to the appropriate transaction list.
        /// </summary>
        /// <param name="parserName">The GetType().Name of the parser that is adding a transaction.</param>
        /// <param name="transaction">The transaction to add.</param>
        public void AddTransaction(string parserName, object transaction)
        {
            bool isAutoAcct = false;

            // first, see if we are associating transactions with an account via !Option:AutoSwitch
            if (isAutoSwitch)
            {
                isAutoAcct = AutoSwitchAccountList.AddTransaction(parserName, transaction);
            }
            if (!isAutoAcct)
            {
                // this transaction does not associate with a particular account

                if (parserName == typeof(AccountListParser).Name)
                {
                    AccountList.Add((AccountListTransaction)transaction);
                }

                else if (parserName == typeof(AssetParser).Name)
                {
                    AssetTransactions.Add((BasicTransaction)transaction);
                }

                else if (parserName == typeof(BankParser).Name)
                {
                    BankTransactions.Add((BasicTransaction)transaction);
                }

                else if (parserName == typeof(CashParser).Name)
                {
                    CashTransactions.Add((BasicTransaction)transaction);
                }

                else if (parserName == typeof(CategoryListParser).Name)
                {
                    CategoryListTransactions.Add((CategoryListTransaction)transaction);
                }

                else if (parserName == typeof(ClassListParser).Name)
                {
                    ClassListTransactions.Add((ClassListTransaction)transaction);
                }

                else if (parserName == typeof(CreditCardParser).Name)
                {
                    CreditCardTransactions.Add((BasicTransaction)transaction);
                }

                else if (parserName == typeof(InvestmentParser).Name)
                {
                    InvestmentTransactions.Add((InvestmentTransaction)transaction);
                }

                else if (parserName == typeof(LiabilityParser).Name)
                {
                    LiabilityTransactions.Add((BasicTransaction)transaction);
                }

                else if (parserName == typeof(MemorizedTransactionListParser).Name)
                {
                    MemorizedTransactionListTransactions.Add((MemorizedTransactionListTransaction)transaction);
                }

                else if (parserName == typeof(PriceParser).Name)
                {
                    PriceTransactions.Add((PriceRecord)transaction);
                }

                else if (parserName == typeof(SecurityParser).Name)
                {
                    SecurityTransactions.Add((SecurityTransaction)transaction);
                }

                else if (parserName == typeof(TagParser).Name)
                {
                    TagTransactions.Add((TagTransaction)transaction);
                }

                else if (parserName == typeof(UnhandledTypeParser).Name)
                {
                    UnhandledTypeTransactions.Add((UnhandledTypeTransaction)transaction);
                }
            }
        }