Ejemplo n.º 1
0
        /// <summary>
        /// This handler handles the event when the <see cref="ITransactionRepository.GetTransactionsCompleted"/>
        /// event is raised by <see cref="_transactionRepository"/>.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TransactionRepositoryGetTransactionsCompleted(object sender, GetTransactionFinishedEventArg e)
        {
            // var graphData = GetGraphData(e.TransactionList);//Graph data is calculated in the background thread.
            double income  = 0;
            double expense = 0;

            if (e.TransactionList != null)
            {
                income  = e.TransactionList.Where(t => t.FlowType == TransactionFlowType.Income).Sum(t => t.Amount);
                expense = e.TransactionList.Where(t => t.FlowType == TransactionFlowType.Expenditure).Sum(t => t.Amount);
            }
            ThreadSafeInvoke(() =>
            {
                GraphItems = null;
                _messagingService.CloseProgressMessage();
                if (e.HasError)
                {
                    _messagingService.ShowMessage(UIText.ERROR_OCCURED_MSG);
                    return;
                }
                if (e.TransactionList == null || !e.TransactionList.Any())
                {
                    _messagingService.ShowMessage(UIText.NO_DATA_EXISTS_MSG);
                    return;
                }
                TotalExpenditure    = expense;
                TotalIncome         = income;
                var transactionList = e.TransactionList.Select(t => new TransactionViewModel(t));
                // GraphItems = graphData;
                Transactions.AddRange(transactionList);
            });
        }
Ejemplo n.º 2
0
        private async void GetTransactionListInitial()
        {
            Transactions.Clear();
            var transactions = await WalletService.GetWalletTransactions();

            Transactions.AddRange(transactions);
        }
Ejemplo n.º 3
0
        public LKPageViewModel()
        {
            AtmContext context = new AtmContext();

            Transactions.AddRange(from t in context.Transactions where t.Account.AccountId == PublcElements.AccountId select t);
            CurrentAccount = (from a in context.Accounts where a.AccountId == PublcElements.AccountId select a).First();
        }
Ejemplo n.º 4
0
        private async void RefreshTxs()
        {
            var txs = await MempoolMgr.GetTxsJsonFromMempool();

            this.TxCount = txs.Count;
            Transactions.Clear();
            Transactions.AddRange(txs);
        }
Ejemplo n.º 5
0
 public Block(string minerAddress, Block previousBlock, IList <Transaction> transactions, int difficulty)
 {
     PreviousHash = previousBlock.Hash;
     Height       = previousBlock.Height + 1;
     Difficulty   = difficulty;
     Transactions.Add(Transaction.CreateRewardTransaction(minerAddress));
     Transactions.AddRange(transactions);
 }
Ejemplo n.º 6
0
        private async Task GetTransactionList()
        {
            IsBusy = true;
            Transactions.Clear();
            var transactions = await WalletService.GetWalletTransactions();

            Transactions.AddRange(transactions);
            IsBusy = false;
        }
Ejemplo n.º 7
0
 internal void AddEvent(int requestId, short eventId, EpcisEvent currentEvent)
 {
     Events.Add(EventDto.Create(currentEvent, eventId, requestId));
     Epcs.AddRange(currentEvent.Epcs.Select(x => EpcDto.Create(x, eventId, requestId)));
     SourceDests.AddRange(currentEvent.SourceDestinationList.Select(x => SourceDestDto.Create(x, eventId, requestId)));
     Transactions.AddRange(currentEvent.BusinessTransactions.Select(x => TransactionDto.Create(x, eventId, requestId)));
     CorrectiveIds.AddRange(currentEvent.CorrectiveEventIds?.Select(x => CorrectiveIdDto.Create(x, eventId, requestId)));
     CustomFields.AddRange(currentEvent.CustomFields.ToFlattenedDtos(eventId, requestId));
 }
Ejemplo n.º 8
0
 public DebugUndoRedoViewModel(IViewModelServiceProvider serviceProvider, IUndoRedoService undoRedo)
     : base(serviceProvider)
 {
     this.undoRedo = undoRedo;
     ClearDiscardedItemsCommand = new AnonymousCommand(ServiceProvider, () => DiscardedTransactions.Clear());
     undoRedo.Done += TransactionAdded;
     undoRedo.TransactionDiscarded -= TransactionDiscarded;
     undoRedo.Cleared += UndoStackCleared;
     Transactions.AddRange(undoRedo.RetrieveAllTransactions().Select(x => new OperationViewModel(ServiceProvider, undoRedo, (Operation)x)));
 }
Ejemplo n.º 9
0
 public Block(DateTime date, Block previousBlock, IList <Transaction> transactions)
 {
     Index        = (previousBlock?.Index ?? -1) + 1;
     Date         = date;
     PreviousHash = previousBlock?.Hash;
     if (transactions != null)
     {
         Transactions.AddRange(transactions);
     }
     Nonce = 0;
     Hash  = CalculateHash();
 }
Ejemplo n.º 10
0
        public Block(long pIndex, long pTimestamp, long pProof, IEnumerable <Transaction> pTransactions,
                     string pPreviousBlockHash)
        {
            Index     = pIndex;
            Timestamp = pTimestamp;
            Proof     = pProof;
            if (pTransactions != null && pTransactions.Any())
            {
                Transactions.AddRange(pTransactions);
            }

            PreviousBlockHash = pPreviousBlockHash;
        }
Ejemplo n.º 11
0
 public void LoadDataFromFile(string dataFilePath)
 {
     try
     {
         DataFilePath = dataFilePath;
         var transactions = _transactionLoader.Load(dataFilePath);
         Transactions.AddRange(transactions);
         StartDate = Transactions.StartDate;
         EndDate   = Transactions.EndDate;
     }
     catch (Exception ex)
     {
         Logger.Logs.Instance.Log(ex);
     }
 }
Ejemplo n.º 12
0
        public void Seed(bool isDevelopment)
        {
            if (!TransactionCategories.Any())
            {
                TransactionCategories.AddRange(new[]
                {
                    new TransactionCategory {
                        TransactionType = (int)TransactionTypes.Income, Title = "Salary"
                    },
                    new TransactionCategory {
                        TransactionType = (int)TransactionTypes.Income, Title = "Refund"
                    },
                    new TransactionCategory {
                        TransactionType = (int)TransactionTypes.Income, Title = "Investment"
                    },
                    new TransactionCategory {
                        TransactionType = (int)TransactionTypes.Income, Title = "Allowance"
                    },
                    new TransactionCategory {
                        TransactionType = (int)TransactionTypes.Income, Title = "Bonus"
                    },
                    new TransactionCategory {
                        TransactionType = (int)TransactionTypes.Income, Title = "Other"
                    },

                    new TransactionCategory {
                        TransactionType = (int)TransactionTypes.Expense, Title = "Food"
                    },
                    new TransactionCategory {
                        TransactionType = (int)TransactionTypes.Expense, Title = "Bill"
                    },
                    new TransactionCategory {
                        TransactionType = (int)TransactionTypes.Expense, Title = "Transportation"
                    },
                    new TransactionCategory {
                        TransactionType = (int)TransactionTypes.Expense, Title = "Car"
                    },
                    new TransactionCategory {
                        TransactionType = (int)TransactionTypes.Expense, Title = "Shopping"
                    },
                    new TransactionCategory {
                        TransactionType = (int)TransactionTypes.Expense, Title = "Clothing"
                    },
                    new TransactionCategory {
                        TransactionType = (int)TransactionTypes.Expense, Title = "Smoking"
                    },
                    new TransactionCategory {
                        TransactionType = (int)TransactionTypes.Expense, Title = "Electronics"
                    },
                    new TransactionCategory {
                        TransactionType = (int)TransactionTypes.Expense, Title = "Travel"
                    },
                    new TransactionCategory {
                        TransactionType = (int)TransactionTypes.Expense, Title = "Education"
                    },
                    new TransactionCategory {
                        TransactionType = (int)TransactionTypes.Expense, Title = "Gifts"
                    },
                    new TransactionCategory {
                        TransactionType = (int)TransactionTypes.Expense, Title = "Sports"
                    },
                    new TransactionCategory {
                        TransactionType = (int)TransactionTypes.Expense, Title = "Entertainment"
                    },
                    new TransactionCategory {
                        TransactionType = (int)TransactionTypes.Expense, Title = "Other"
                    },
                });
                SaveChanges();
            }

            if (isDevelopment)
            {
                if (!Transactions.Any())
                {
                    Transactions.AddRange(new[]
                    {
                        new Transaction
                        {
                            Id                    = Guid.NewGuid(),
                            AccountId             = 1,
                            AccountTitle          = "Default cash",
                            Amount                = 200,
                            Date                  = DateTime.UtcNow,
                            Notes                 = "Default transaction",
                            TransactionCategoryId = 1,
                            Type                  = "Income",
                            TypeId                = (int)TransactionTypes.Income,
                            TransactionTags       = new List <TransactionTag> {
                                new TransactionTag {
                                    Tag = "Default"
                                }
                            },
                            UserId        = 1,
                            CurrencyTitle = "US Dollar",
                            CurrencyId    = 1,
                            CurrencyCode  = "USD",
                        },
                        new Transaction
                        {
                            Id                    = Guid.NewGuid(),
                            AccountId             = 1,
                            AccountTitle          = "Default cash",
                            Amount                = 75,
                            Date                  = DateTime.UtcNow,
                            Notes                 = "Default transaction",
                            TransactionCategoryId = 2,
                            Type                  = "Expense",
                            TypeId                = (int)TransactionTypes.Expense,
                            TransactionTags       = new List <TransactionTag> {
                                new TransactionTag {
                                    Tag = "Default"
                                }
                            },
                            UserId        = 1,
                            CurrencyTitle = "US Dollar",
                            CurrencyId    = 1,
                            CurrencyCode  = "USD",
                        }
                    });

                    SaveChanges();
                }

                if (!Accounts.Any())
                {
                    Accounts.AddRange(new Account[]
                    {
                        new Account
                        {
                            Title     = "Cash default",
                            AccountId = 1,
                            UserId    = 1
                        }
                    });
                    SaveChanges();
                }
            }
        }
Ejemplo n.º 13
0
        private void StateUpdateLoop()
        {
            decimal        quantity          = 0;
            decimal        cost              = 0;
            var            txs               = new List <CryptoTransaction>();
            DateTimeOffset?oldestOpen        = null;
            var            positionInstances = new List <PositionInstance>();
            DateTimeOffset lastTransaction   = DateTimeOffset.UtcNow;

            bool PurchaseProcessing(ICryptoTransaction st)
            {
                lastTransaction = st.When;

                if (quantity == 0)
                {
                    oldestOpen = st.When;
                    positionInstances.Add(new PositionInstance(Token));
                }

                quantity += st.Quantity;
                cost     += st.DollarAmount;

                txs.Add(
                    CryptoTransaction.DebitTx(
                        Id,
                        st.Id,
                        Token,
                        $"Purchased {st.Quantity} for ${st.DollarAmount}",
                        st.DollarAmount,
                        st.When
                        )
                    );

                positionInstances[positionInstances.Count - 1].Buy(st.Quantity, st.DollarAmount, st.When);

                return(true);
            }

            bool SellProcessing(ICryptoTransaction st)
            {
                // TODO: this should never happen but in prod I see sell get
                // triggered before purchase... something is amiss
                if (positionInstances.Count > 0)
                {
                    positionInstances[positionInstances.Count - 1].Sell(st.Quantity, st.DollarAmount, st.When);
                }

                lastTransaction = st.When;

                txs.Add(
                    CryptoTransaction.CreditTx(
                        Id,
                        st.Id,
                        Token,
                        $"Sold {st.Quantity} for ${st.DollarAmount}",
                        st.DollarAmount,
                        st.When
                        )
                    );

                quantity -= st.Quantity;
                cost     -= st.DollarAmount;

                return(true);
            }

            foreach (var st in BuyOrSell.OrderBy(e => e.When).ThenBy(i => BuyOrSell.IndexOf(i)))
            {
                if (Deletes.Contains(st.Id))
                {
                    continue;
                }

                if (st is CryptoPurchased sp)
                {
                    PurchaseProcessing(sp);
                }
                else if (st is CryptoSold ss)
                {
                    SellProcessing(ss);
                }

                if (quantity == 0)
                {
                    cost       = 0;
                    oldestOpen = null;
                }
            }

            foreach (var a in Awards)
            {
                if (Deletes.Contains(a.Id))
                {
                    continue;
                }

                if (quantity == 0)
                {
                    oldestOpen = a.When;
                }

                quantity += a.Quantity;
            }

            foreach (var y in Yields)
            {
                if (Deletes.Contains(y.Id))
                {
                    continue;
                }

                quantity += y.Quantity;
            }

            Quantity = quantity;
            Cost     = cost;
            Transactions.Clear();
            Transactions.AddRange(txs);
            PositionInstances.Clear();
            PositionInstances.AddRange(positionInstances);

            DaysHeld = oldestOpen.HasValue ?
                       (int)Math.Floor(DateTimeOffset.UtcNow.Subtract(oldestOpen.Value).TotalDays) : 0;

            DaysSinceLastTransaction = (int)DateTimeOffset.UtcNow.Subtract(lastTransaction).TotalDays;
        }
Ejemplo n.º 14
0
        private void StateUpdateLoop()
        {
            decimal        avgCost           = 0;
            decimal        owned             = 0;
            decimal        cost              = 0;
            var            txs               = new List <Transaction>();
            DateTimeOffset?oldestOpen        = null;
            var            positionInstances = new List <PositionInstance>();
            DateTimeOffset lastTransaction   = DateTimeOffset.UtcNow;

            bool PurchaseProcessing(IStockTransaction st)
            {
                lastTransaction = st.When;

                if (owned == 0)
                {
                    oldestOpen = st.When;
                    positionInstances.Add(new PositionInstance(Ticker));
                }

                avgCost = (avgCost * owned + st.Price * st.NumberOfShares)
                          / (owned + st.NumberOfShares);
                owned += st.NumberOfShares;
                cost  += st.Price * st.NumberOfShares;

                txs.Add(
                    Transaction.DebitTx(
                        Id,
                        st.Id,
                        Ticker,
                        $"Purchased {st.NumberOfShares} shares @ ${st.Price}/share",
                        st.Price * st.NumberOfShares,
                        st.When,
                        isOption: false
                        )
                    );

                positionInstances[positionInstances.Count - 1].Buy(st.NumberOfShares, st.Price, st.When);

                return(true);
            }

            bool SellProcessing(IStockTransaction st)
            {
                // TODO: this should never happen but in prod I see sell get
                // triggered before purchase... something is amiss
                if (positionInstances.Count > 0)
                {
                    positionInstances[positionInstances.Count - 1].Sell(st.NumberOfShares, st.Price, st.When);
                }

                lastTransaction = st.When;

                txs.Add(
                    Transaction.CreditTx(
                        Id,
                        st.Id,
                        Ticker,
                        $"Sold {st.NumberOfShares} shares @ ${st.Price}/share",
                        st.Price * st.NumberOfShares,
                        st.When,
                        isOption: false
                        )
                    );

                txs.Add(
                    Transaction.PLTx(
                        Id,
                        Ticker,
                        $"Sold {st.NumberOfShares} shares @ ${st.Price}/share",
                        avgCost * st.NumberOfShares,
                        st.Price * st.NumberOfShares,
                        st.When,
                        isOption: false
                        )
                    );

                owned -= st.NumberOfShares;
                cost  -= avgCost * st.NumberOfShares;

                return(true);
            }

            foreach (var st in BuyOrSell.OrderBy(e => e.When).ThenBy(i => BuyOrSell.IndexOf(i)))
            {
                if (Deletes.Contains(st.Id))
                {
                    continue;
                }

                if (st is StockPurchased sp)
                {
                    PurchaseProcessing(sp);
                }
                else if (st is StockSold ss)
                {
                    SellProcessing(ss);
                }

                if (owned == 0)
                {
                    avgCost    = 0;
                    cost       = 0;
                    oldestOpen = null;
                }
            }

            AverageCost = avgCost;
            Owned       = owned;
            Cost        = cost;
            Transactions.Clear();
            Transactions.AddRange(txs);
            PositionInstances.Clear();
            PositionInstances.AddRange(positionInstances);

            DaysHeld = oldestOpen.HasValue ? (int)Math.Floor(DateTimeOffset.UtcNow.Subtract(oldestOpen.Value).TotalDays)
                : 0;

            DaysSinceLastTransaction = (int)DateTimeOffset.UtcNow.Subtract(lastTransaction).TotalDays;
        }