예제 #1
0
        // function that gets the new diginote digged and the new time needed to dig another diginote
        internal void GetDiginoteDigged()
        {
            try
            {
                if (user != null) // if not already logged out
                {
                    // add new diginote
                    Diginotes.Add(diginoteSystem.DigDiginote(user));

                    // notify update because we have a new diginote
                    NotificationMessenger.sendNotification(this, new NotificationType(NotifType.Diginotes, null), "");

                    // get new time needed to dig
                    DigTime = diginoteSystem.GetDigtime();
                }
            }
            catch
            {
                // couldn't reach server
                NotificationMessenger.sendNotification(this, new NotificationType(NotifType.NoServer, null), "");
            }
        }
예제 #2
0
        // handler for incoming messenger notifications
        private void ChangeHandler(ChangeArgs args)
        {
            if (args.User1 == null || args.User1 == user.Username || args.User2 == user.Username) // if the logged user can receive the message
            {
                if (args.Type == ChangeType.QuotationUp || args.Type == ChangeType.QuotationDown) // quotation changed
                {
                    App.Current.Dispatcher.Invoke((System.Action)(() =>
                    {
                        // set new quotation value
                        Quotation = args.QuotationValue;

                        // notify change
                        NotificationMessenger.sendNotification(this, new NotificationType(NotifType.Quotation, null), "");

                        // add new stat
                        QuotationEvolution.Add(new DataPoint(DateTimeAxis.ToDouble(args.QuotationStat.first), args.QuotationStat.second));

                        if (Orders.Count > 0 && Orders[0].State == OrderState.Pending) // if last order is pending
                        {
                            if (args.User2 != user.Username &&
                                ((args.Type == ChangeType.QuotationUp && Orders[0].Type == OrderType.Buy) ||
                                 (args.Type == ChangeType.QuotationDown && Orders[0].Type == OrderType.Sell)))
                            // if the new quotation needs to be appproved by the user
                            {
                                // get last order
                                Order lastOrder = Orders[0];

                                // remove and set new state
                                Orders.Remove(lastOrder);
                                lastOrder.State = OrderState.WaitApproval;

                                // add to the list, we need to remove and add to cast the listview update
                                Orders.Insert(0, lastOrder);

                                // notify main window to show approve dialog
                                NotificationMessenger.sendNotification(this, new NotificationType(NotifType.AskApprove, null), "");
                            }
                        }
                    }));
                }
                else if (args.Type == ChangeType.Transaction) // transaction occurred
                {
                    App.Current.Dispatcher.Invoke((System.Action)(() =>
                    {
                        // get last order
                        Order lastOrder = Orders[0];

                        // remove order
                        Orders.Remove(lastOrder);

                        if (args.User1 == user.Username) // if the user logged sold the diginotes
                        {
                            // insert the changed order, we need to remove and add to cast the listview update
                            Orders.Insert(0, args.Order1);

                            // look for and remove the diginotes traded
                            List <DiginoteInfo> toRemove = new List <DiginoteInfo>();
                            foreach (DiginoteInfo dInfo in Diginotes)
                            {
                                if (args.DiginotesTraded.Exists(d => d.Serial == dInfo.Serial))
                                {
                                    toRemove.Add(dInfo);
                                }
                            }
                            foreach (DiginoteInfo dInfo in toRemove)
                            {
                                Diginotes.Remove(dInfo);
                            }
                        }
                        else if (args.User2 == user.Username) // if the user logged bought the diginotes
                        {
                            // insert the changed order, we need to remove and add to cast the listview update
                            Orders.Insert(0, args.Order2);

                            // add the diginotes traded
                            args.DiginotesTraded.ForEach(Diginotes.Add);
                        }

                        // update transaction statistics
                        if (TransactionsPerMin.Count > 0)
                        {
                            DataPoint lastStatItem = TransactionsPerMin[TransactionsPerMin.Count - 1];
                            if (lastStatItem.X == DateTimeAxis.ToDouble(args.TransactionStat.first))
                            {
                                TransactionsPerMin.Remove(lastStatItem);
                                lastStatItem.Y++;
                                TransactionsPerMin.Add(lastStatItem);
                            }
                            else
                            {
                                TransactionsPerMin.Add(new DataPoint(DateTimeAxis.ToDouble(args.TransactionStat.first), args.TransactionStat.second));
                            }
                        }
                        else
                        {
                            TransactionsPerMin.Add(new DataPoint(DateTimeAxis.ToDouble(args.TransactionStat.first), args.TransactionStat.second));
                        }

                        // notify changes
                        NotificationMessenger.sendNotification(this, new NotificationType(NotifType.Transaction, null), "");
                        NotificationMessenger.sendNotification(this, new NotificationType(NotifType.Diginotes, null), "");

                        // if the order of the logged user wasn't totally satifiest, notify main window to show the dialog to ask for a new quotation
                        if (Orders[0].Quantity != 0)
                        {
                            if (Orders[0].Type == OrderType.Buy)
                            {
                                NotificationMessenger.sendNotification(this, new NotificationType(NotifType.AskQuotation, null), "+" + Quotation);
                            }
                            else
                            {
                                NotificationMessenger.sendNotification(this, new NotificationType(NotifType.AskQuotation, null), "-" + Quotation);
                            }
                        }
                    }));
                }
                else if (args.Type == ChangeType.Login) // login occurred
                {
                    // set data
                    NumUsers        = args.NumUsers;
                    NumLoggedUsers  = args.NumLoggedUsers;
                    NumSysDiginotes = args.NumSysDiginotes;

                    // notify update
                    NotificationMessenger.sendNotification(this, new NotificationType(NotifType.SystemInfo, null), "");
                }
                else if (args.Type == ChangeType.Logout) // logout occurred
                {
                    // set data
                    NumLoggedUsers = args.NumLoggedUsers;

                    // notify update
                    NotificationMessenger.sendNotification(this, new NotificationType(NotifType.SystemInfo, null), "");
                }
                else if (args.Type == ChangeType.SysDiginotes) // update on number of diginotes in system
                {
                    // set data
                    NumSysDiginotes = args.NumSysDiginotes;

                    // notify update
                    NotificationMessenger.sendNotification(this, new NotificationType(NotifType.SystemInfo, null), "");
                }
                else if (args.Type == ChangeType.OfferDemand) // update in number of diginotes to buy or sell
                {
                    // set data
                    DiginotesOffer  = args.DiginotesOffer;
                    DiginotesDemand = args.DiginotesDemand;

                    // notify update
                    NotificationMessenger.sendNotification(this, new NotificationType(NotifType.SystemInfo, null), "");
                }
            }
        }