Ejemplo n.º 1
0
        private ItemSummary GetItemSummary(string username, List <long> customerItems)
        {
            var di = new DisplayItemInfo();

            object[] oa;
            try
            {
                oa = di.displayItemSummariesWithoutItemData(UserContext);
            }
            catch (Exception e)
            {
                Log.ErrorFormat("Failure getting yodlee item. Error:{0}", e);
                return(null);
            }

            if (oa == null || oa.Length == 0)
            {
                // No items were found for the user.
                Log.InfoFormat("No items were found for the user '{0}'", username);
                return(null);
            }

            foreach (ItemSummary item in oa)
            {
                if (customerItems != null && customerItems.Contains(item.itemId))
                {
                    continue;
                }
                Log.DebugFormat("item {0} {1} added {2} status {3}", item.itemId, item.itemDisplayName, item.refreshInfo.itemCreateDate, item.refreshInfo.statusCode);
                if (item.refreshInfo.statusCode == 801)
                {
                    Log.WarnFormat("Item status code is not '0' but '{0}' for user {1}", item.refreshInfo.statusCode, username);
                    numOfRetriesForGetItemSummary--;
                    if (numOfRetriesForGetItemSummary > 0)
                    {
                        Log.InfoFormat("Will retry {0} more time\\s", numOfRetriesForGetItemSummary);
                        Thread.Sleep(5000);
                        return(GetItemSummary(username, customerItems));
                    }

                    if (item.refreshInfo.statusCode == 801)                     //REFRESH_NEVER_DONE
                    {
                        return(item);
                    }
                }
                else if (item.refreshInfo.statusCode == 0)                //STATUS_OK
                {
                    return(item);
                }
                else
                {
                    Log.WarnFormat("Item status code is not '0' but '{0}' for user {1}", item.refreshInfo.statusCode, username);
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Displays the item information and item data information
        /// for the given bank itemSummary.
        /// </summary>
        /// <param name="userContext"></param>
        /// <param name="itemId"></param>
        /// <param name="itemSummaryInfo"></param>
        /// <param name="error"></param>
        /// <param name="bankTransactionDataList"></param>
        public void GetBankDataForItem(UserContext userContext, long itemId, out string itemSummaryInfo, out string error, out Dictionary <BankData, List <BankTransactionData> > bankTransactionDataList)
        {
            Log.Debug(string.Format("GetBankDataForItem: userContex valid {0}, itemId {1}", userContext.valid, itemId));
            var dataExtent = new DataExtent
            {
                startLevel          = 0,
                endLevel            = int.MaxValue,
                startLevelSpecified = true,
                endLevelSpecified   = true
            };

            ItemSummary itemSummary = dataService.getItemSummaryForItem1(userContext, itemId, true, dataExtent);

            if (itemSummary == null)
            {
                throw new Exception(string.Format("Item for item id {0} not found", itemId));
            }

            error = "";
            bankTransactionDataList = new Dictionary <BankData, List <BankTransactionData> >();

            String containerType = itemSummary.contentServiceInfo.containerInfo.containerName;

            if (!containerType.Equals("bank"))
            {
                throw new Exception("displayBankDataForItem called with invalid container type" + containerType);
            }

            var displayItemInfo = new DisplayItemInfo();

            itemSummaryInfo = displayItemInfo.getItemSummaryInfo(itemSummary);
            Log.Debug(itemSummaryInfo);
            // Get ItemData
            ItemData1 itemData = itemSummary.itemData;

            if (itemData == null)
            {
                error += "\tItemData is null";
            }
            else
            {
                object[] accounts = itemData.accounts;
                if (accounts == null || accounts.Length == 0)
                {
                    Log.Warn("Yodlee get bank data: No accounts");
                }
                else
                {
                    foreach (object account in accounts)
                    {
                        var bankData = (BankData)account;
                        bankTransactionDataList.Add(bankData, new List <BankTransactionData>());
                        object[] bankTransactions = bankData.bankTransactions;
                        if (bankTransactions == null || bankTransactions.Length == 0)
                        {
                            Log.Warn("Yodlee get bank data: No bank transactions");
                        }
                        else
                        {
                            foreach (object bankTransaction in bankTransactions)
                            {
                                var transactionData =
                                    (BankTransactionData)bankTransaction;
                                bankTransactionDataList[bankData].Add(transactionData);
                            }
                        }
                    }
                }
            }
            // Get AccountHistory

            if (itemData != null)
            {
                object[] acctHistories = itemData.accountHistory;
                if (acctHistories == null || acctHistories.Length == 0)
                {
                    //error += "\tNo Account History";
                }
                else
                {
                    foreach (object accountHistory in acctHistories)
                    {
                        var acctHistory = (AccountHistory)accountHistory;

                        Log.Debug(string.Format("\tHistory For Account ID: {0}", acctHistory.accountId));

                        // Get History
                        object[] histories = acctHistory.history;
                        if (histories == null || histories.Length == 0)
                        {
                            Log.Warn("Yodlee get bank data: No History");
                        }
                        else
                        {
                            foreach (object history in histories)
                            {
                                var bankData = (BankData)history;
                                Log.Debug(
                                    string.Format(
                                        "Account History: Bank Account Name: {0}, Bank Account Cust Description: {1} Bank Account Identifier: {2} Bank Account Balance: {3} Bank Current Balance: {4} Bank Current Acct Type: {5} Bank Current As of Date: {6} Last Updated: {7}",
                                        bankData.accountName, bankData.customDescription, bankData.bankAccountId, bankData.availableBalance.amount,
                                        bankData.currentBalance.amount, bankData.acctType, bankData.asOfDate.date,
                                        UtcToDateTime(bankData.lastUpdated.HasValue ? bankData.lastUpdated.Value : 0)));
                            }
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(error))
            {
                Log.Warn(error);
            }
        }