コード例 #1
0
ファイル: LoginForm.cs プロジェクト: tariqhamid/FXCMHDD
        private void loginLogoutButton_Click(object sender, EventArgs e)
        {
            //Validate username and password
            if (usernameDropdownList.Text.Trim().Equals(""))
            {
                MessageBox.Show("Please enter a valid username!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            else if (passwordTextbox.Text.Trim().Equals(""))
            {
                MessageBox.Show("Please enter a valid password!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }



            //Instantiate trading session and try to login
            tss = new TradingSession();
            tss.login(usernameDropdownList.Text, passwordTextbox.Text, "http://www.fxcorporate.com/Hosts.jsp", accountTypeDropdownList.Text);
            //Log.logMessageToFile("Login","Login method called");
            logger.Debug("Login method was called");


            //Wait for 5000 milliseconds to make sure the application logged in
            Stopwatch timer = new Stopwatch();

            timer.Start();
            while (tss.ConnectionStatus != O2GSessionStatusCode.Connected)
            {
                Thread.Sleep(1000);
                if (tss.ConnectionStatus == O2GSessionStatusCode.Unknown)
                {
                    logger.Error("Connection Status is unknown");
                    MessageBox.Show("Please check user credentials", "Error logging in");
                    return;
                }

                if (timer.Elapsed.TotalSeconds > 90 && tss.ConnectionStatus != O2GSessionStatusCode.Connected)
                {
                    logger.Error("Login is taking longer than 20 seconds!");
                    MessageBox.Show("Please check user credentials", "Error logging in");
                    return;
                }
            }

            timer.Stop();


            //Check if any login errors occurred, if exist return and throw error.
            if (tss.Error.Length != 0)
            {
                MessageBox.Show("Please check user credentials", "Error logging in");
                return;
            }


            //this.Invoke((MethodInvoker)delegate () {

            //});

            this.Hide();
            fillRatesGrid();

            logger.Debug("Starting HDD Basic");
            HddMainFormBasic.setPassword(passwordTextbox.Text);
            HddMainFormBasic.setUsername(usernameDropdownList.Text);
            HddMainFormBasic.setAccountType(accountTypeDropdownList.Text);
            HddMainFormBasic.setTradingSession(tss);
            HddMainFormBasic.setStatusLabel("Connected");
            HddMainFormBasic.setCurrencyList(temp, templist);
            HddMainFormBasic.setVersionLabel(mVersionLabel.Text);
            hddBasic = new HddMainFormBasic();
            hddBasic.Show();


            if (saveLoginButton.Checked)
            {
                set.username   = usernameDropdownList.Text;
                set.connection = accountTypeDropdownList.Text;
                set.saveMe     = saveLoginButton.Checked;
                set.Save();
            }


            //Save the user information into SQL lite
            fillTable(usernameDropdownList.Text.Trim(), accountTypeDropdownList.SelectedItem.ToString());
        }