private void CpwContext_OnTradeExecuted(CoverPositionWindowViewModel context)
        {
            context.View.Close();


            if (context.IsCancel)
            {
                return;
            }

            var position = context.CoverPosition;

            if (null == position)
            {
                position = new CoverPosition();
            }

            position.Amount          = context.LotSize;
            position.Coveraccount_id = context.SelectedCoveringAccount;
            position.OrderType       = context.SelectedOrderType;
            position.OpenPrice       = context.OpenPrice;
            //position.Opentime = DateTime.Now; //do not set
            position.OpenedBy  = username;
            position.Commodity = context.SelectedCommodity;
            //position.Internalid = Guid.NewGuid(); //will be regenerated at server end..
            position.Remoteid = context.Orderid;

            DealerService.GetInstance().saveUpdateCloseCoverPosition(position, "createUpdateCoverPosition");
        }
        private void ExecuteCloseSelectedCoverPositionCommand()
        {
            if (null == OpenCoverTradesCollectionView.CurrentItem)
            {
                return;
            }

            CoverPosition position = OpenCoverTradesCollectionView.CurrentItem as CoverPosition;

            position.ClosedBy = username;

            DealerService.GetInstance().saveUpdateCloseCoverPosition(position, "closeCoverPosition");
        }
 private void ExecuteRejectSelectedTradeCommand()
 {
     lock (lockTrades)
     {
         TradePosition position = PendingTradesCollectionView.CurrentItem as TradePosition;
         if (position == null)
         {
             //todo show error
             return;
         }
         DealerService.GetInstance().approveRejectOrder(position.ClientName, position.OrderId, DealerService.COMMAND_VERB_REJECT);
     }
 }
 private void ExecuteBulkRejectSelectedTradeCommand()
 {
     lock (lockTrades)
     {
         foreach (var row in PendingTradesCollectionView)
         {
             TradePosition position = row as TradePosition;
             if (position.IsSelected)
             {
                 DealerService.GetInstance().approveRejectOrder(position.ClientName, position.OrderId, DealerService.COMMAND_VERB_REJECT);
             }
         }
     }
 }
 private void ExecuteRequoteSelectedOrders()
 {
     lock (lockTrades)
     {
         foreach (var row in PendingTradesCollectionView)
         {
             TradePosition position = row as TradePosition;
             if (position.IsSelected)
             {
                 DealerService.GetInstance().requoteOrder(
                     position.ClientName,
                     position.OrderId,
                     position.RequotePrice
                     );
             }
         }
     }
 }
        private async void ExecuteWindowLoaded()
        {
            ClientService.GetInstance().OnUpdateReceived += OnUpdateReceived;
            ClientService.GetInstance().OnCandleStickDataEventHandler          += MainWindowViewModel_OnCandleStickDataEventHandler;
            ClientService.GetInstance().OnConnectionClosedByServerEventHandler += MainWindowViewModel_OnConnectionClosedByServerEventHandler;

            DealerService.GetInstance().OnOfficePositionsUpdateReceived  += OnOfficePositionsUpdateReceived;
            DealerService.GetInstance().OnConnectionsInformationReceived += MainWindowViewModel_OnConnectionsInformationReceived;
            DealerService.GetInstance().OnNotificationReceived           += MainWindowViewModel_OnNotificationReceived;

            AuthService.GetInstance().OnGenericResponseReceived += MainWindow_OnGenericResponseReceived;

            LoginDialogData creds = await _dialogCoord.ShowLoginAsync(this, "Backoffice Login", "Login to continue using your account");

            if (creds != null && !string.IsNullOrEmpty(creds.Username) && !string.IsNullOrEmpty(creds.Password))
            {
                progressController = await _dialogCoord.ShowProgressAsync(this, "Please wait...", "Authenticating with server.");

                progressController.SetIndeterminate();

                if (!AuthService.GetInstance().init(creds.Username, creds.Password)
                    ||
                    !AuthService.GetInstance().ResolveUserEndpoints()
                    )
                {
                    await progressController.CloseAsync();

                    await _dialogCoord.ShowMessageAsync(this, "Authentication", "Incorrect username/password.");

                    App.Current.Shutdown();
                }
                else
                {
                    username = creds.Username;
                    password = creds.Password;
                }
            }
            else
            {
                await _dialogCoord.ShowMessageAsync(this, "Authentication", "Credentials are needed to continue.");

                App.Current.Shutdown();
            }
        }
        private void MainWindow_OnGenericResponseReceived(object sender, SharedData.events.GenericResponseEventArgs e)
        {
            officeExchangeName   = e.GenericResponse["officeExchangeName"];
            clientExchangeName   = e.GenericResponse["clientExchangeName"];
            responseQueueName    = e.GenericResponse["responseQueueName"];
            officeDealerInQName  = e.GenericResponse["officeDealerInQName"];
            officeDealerOutQName = e.GenericResponse["officeDealerOutQName"];

            ClientService.GetInstance().init(username, password, clientExchangeName, responseQueueName);
            DealerService.GetInstance().init(username, password, officeExchangeName, officeDealerOutQName, officeDealerInQName);

            System.Windows.Threading.
            Dispatcher.CurrentDispatcher.Invoke(async() => {
                await progressController.CloseAsync();

                MetroDialogSettings set = new MetroDialogSettings();
                await _dialogCoord.ShowMessageAsync(this, "Authentication", "Login successful.");

                //we are done here
                AuthService.Cleanup();
            });
        }
        private void ExecuteDisconnectSelectedUsersCommand()
        {
            ActiveConnections session = null;

            lock (lockActiveSessions)
            {
                int selIndex = ConnectionInfoCollectionView.CurrentPosition;

                if (selIndex >= 0 && selIndex < _connectionInfoCollection.Count)
                {
                    session = _connectionInfoCollection[selIndex];
                }
            }

            if (session != null)
            {
                DealerService.GetInstance().disconnectAndLockSession(
                    session.Username,
                    session.Connections.Select(x => x.MqName).ToArray()
                    );
            }
        }
 private void ExecuteWindowClosing()
 {
     ClientService.GetInstance().OnUpdateReceived -= OnUpdateReceived;
     DealerService.GetInstance().OnOfficePositionsUpdateReceived -= OnOfficePositionsUpdateReceived;
     ClientService.GetInstance().OnCandleStickDataEventHandler   -= MainWindowViewModel_OnCandleStickDataEventHandler;
 }