Example #1
0
 //Closing event. Uninitialize dll, disconnect, close all windows.
 public void OnWindowClosing(object sender, CancelEventArgs e)
 {
     //if (Status == "Status: Disconnected")
     //{
     //
     //    return;
     //}
     //e.Cancel = true;if (_isConnected)
     IsShuttingDown = true;
     Connection.Stop(new TimeSpan(0, 0, 0, 100));
     SecVm = null;
     foreach (Window window in Application.Current.Windows)
     {
         if (window.GetType() != typeof(MainWindow) && window.GetType().Namespace.Split('.')[0] != "Microsoft")
         {
             //var context = window.DataContext as IWindow;
             //if (context != null)
             //    context.IsManuallyClosed = false
             if (window is IRememberPlacement)
             {
                 ((IRememberPlacement)window).IsManuallyClosed = false;
             }
             window.Close();
         }
     }
     TXmlConnector.ConnectorSendCommand("<command id=\"disconnect\"/>");
     Application.Current.Shutdown();
     //TXmlConnector.ConnectorUnInitialize();
 }
Example #2
0
        private void XmlConnector_OnSendNewStatus(string data)
        {
            var status = (ServerStatus)_statusXml.Deserialize(new StringReader(data));

            if (status.Recover == "true")
            {
                Status         = "Status: Reconnecting...";
                IsReconnecting = true;
                Animate        = false;
                return;
            }
            if (status.Connected != "true")
            {
                if (IsShuttingDown)
                {
                    //TXmlConnector.ConnectorUnInitialize();
                    //Application.Current.Shutdown();
                    return;
                }
                MenuItemConnectCommand = new Command(arg => Show_LoginForm()); //set command to open LoginForm
                MenuItemConnectText    = "Connect";                            //change text
                Status = "Status: Disconnected";                               //change status string

                //_dialogCoordinator.ShowMessageAsync(this, "Connection status", "Connection lost");
                //disable menu buttons
                InfoEnabled           = false;
                TradeEnabled          = false;
                Animate               = false;
                SecVm                 = new SecuritiesViewModel();
                ClientTradesViewModel = new ClientTradesViewModel();
                ClientOrdersViewModel = new ClientOrdersViewModel();
                //close windows
                Application.Current.Dispatcher.Invoke(() => {
                    foreach (Window window in Application.Current.Windows)
                    {
                        if (window.GetType() != typeof(MainWindow) && window.GetType().Namespace.Split('.')[0] != "Microsoft")
                        {
                            window.Close();
                        }
                    }
                });
                //clear clients
                ClientsViewModel.Clients.Clear();
                //clear subs
                Level2DataHandler.UnsubAll();
                TickDataHandler.UnsubAll();
            }
            else
            {
                MenuItemConnectCommand = new Command(arg => Disconnect()); //set command to disconnect
                Status = "Status: Connected";                              //change text
                MenuItemConnectText = "Disconnect";                        //change status string
                //enable menu buttons
                InfoEnabled  = true;
                TradeEnabled = true;
                Animate      = true;
                //Application.Current.Dispatcher.Invoke(() => {
                //    if (!CheckIfWindowIsOpened(typeof(Clients)))
                //        {
                //            _clientsViewModel.Timer.Start();
                //            new Clients { DataContext = _clientsViewModel }.Show();
                //        }
                //    });
                //if reconnecting, do not restore windows
                if (!IsReconnecting)
                {
                    OpenSavedWindows();
                }
                ClientsViewModel.GetInfo();
                IsReconnecting = false; //reconnected at this point
            }

            IsConnected            = status.Connected == "true";
            MenuItemConnectEnabled = true; //enable it after status change
            IsActive = false;
        }