Ejemplo n.º 1
0
        public override void Execute(Task task)
        {
            try
            {
                if (_settings.IsDemo == false)
                {
                    base.Execute(task);
                    return;
                }

                foreach (Client client in _clientDataService.GetAllClients())
                {
                    List <Transaction> transactions = _transactionsDataService.GetTransactions(client.ID);
                    foreach (Transaction transaction in transactions)
                    {
                        if (transaction.Owner == "User")
                        {
                            _transactionsDataService.DeleteTransaction(transaction.ID, client.ID);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Serilog.Log.Logger?.Error(ex, "Demo Clean Down Failed with error: {ex.Message}");
            }

            base.Execute(task);
        }
Ejemplo n.º 2
0
        public override void Execute(Task task)
        {
            Task = task;
            var args = Task.Data;

            _datafeedDataService    = new FinanceAPIMongoDataService.DataService.DatafeedDataService(Settings.MongoDB_ConnectionString);
            _accountDataService     = new FinanceAPIMongoDataService.DataService.AccountDataService(Settings.MongoDB_ConnectionString);
            _transactionDataService = new FinanceAPIMongoDataService.DataService.TransactionsDataService(Settings.MongoDB_ConnectionString);

            if (string.IsNullOrEmpty(args["AccountID"].ToString()))
            {
                base.Execute(Task);
                return;
            }

            string accountID = args["AccountID"].ToString();

            if (!_accountDataService.GetAccounts(Task.ClientID).Any(a => a.ID == accountID))
            {
                base.Execute(Task);
                return;
            }

            List <ExternalAccount> externalAccounts = _datafeedDataService.GetExternalAccounts(Task.ClientID, accountID);
            Account      account     = _accountDataService.GetAccountById(accountID, Task.ClientID);
            IDatafeedAPI datafeedApi = new TrueLayerAPI(Settings.MongoDB_ConnectionString, Settings.TrueLayer_ClientID, Settings.TrueLayer_ClientSecret, Settings.TrueLayer_Mode);

            if (account == null || externalAccounts.Count == 0)
            {
                base.Execute(Task);
                return;
            }

            AccountSettings accountSettings = _accountDataService.GetAccountSettings(accountID);

            decimal totalAccountBalance          = 0;
            decimal totalAvailableAccountBalance = 0;

            foreach (var externalAccount in externalAccounts)
            {
                totalAccountBalance          += ProcessExternalAccount(externalAccount, datafeedApi, account, out decimal availableBalance);
                totalAvailableAccountBalance += availableBalance;
            }

            // Reload account to get new balance
            account = _accountDataService.GetAccountById(accountID, Task.ClientID);

            if (accountSettings != null && accountSettings.GenerateAdjustments)
            {
                BalanceAccount(account, totalAccountBalance);
            }

            // Enqueue task to calculate logos on new transactions
            Task logoTask = new Task($"Logo Calculator [{account.AccountName}]", Task.ClientID, TaskType.LogoCalculator, DateTime.Now);

            logoTask.Data = new Dictionary <string, object> {
                { "ClientID", Task.ClientID }, { "AccountID", accountID }
            };

            // Set Account Last Refreshed Date
            _accountDataService.UpdateLastRefreshedDate(accountID, DateTime.Now);

            BackgroundJob.Enqueue <LogoCalculatorTask>(t => t.Execute(logoTask));
            base.Execute(Task);
        }