Exemple #1
0
        public void Reconnect()
        {
            try
            {
                _log.Info("Disconnecting...");
                _client.DisConnect();

                _client = new PLMPackServiceClient();

                // try to connect using user credentials
                _client.ClientCredentials.UserName.UserName = Properties.Settings.Default.CredentialUserName;
                _client.ClientCredentials.UserName.Password = Properties.Settings.Default.CredentialPassword;
                _user = _client.Connect();
                _log.Info(string.Format("Reconnected as {0}", _user.Name));
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
            }
        }
Exemple #2
0
        protected override void OnClosing(CancelEventArgs e)
        {
            if (DialogResult != DialogResult.Cancel)
            {
                try
                {
                    System.Net.ServicePointManager.ServerCertificateValidationCallback =
                        ((sender, certificate, chain, sslPolicyErrors) => true);

                    PLMPackServiceClient client = WCFClientSingleton.ClientGuest;
                    if (null != client.Connect())
                    {
                        e.Cancel = true;
                    }

                    string userName = client.EmailToUserName(Email);
                    string email    = client.UserNameToEmail(UserName);

                    if (!string.IsNullOrEmpty(userName))
                    {
                        MessageBox.Show(string.Format(Properties.Resources.ID_EMAILALREADYUSED, Email));
                        e.Cancel = true;
                    }
                    else if (!string.IsNullOrEmpty(email))
                    {
                        MessageBox.Show(string.Format(Properties.Resources.ID_USERNAMEALREADYUSED, UserName));
                        e.Cancel = true;
                    }
                    else if (client.CreateUser(UserName, UserPassword, FirstName, LastName, Email, Country, City, PhoneNumber, Company, WebSiteURL))
                    {
                        MessageBox.Show(string.Format(Properties.Resources.ID_USERSUCCESSFULLYCREATED, UserName));
                        e.Cancel = false;
                    }
                }
                catch (Exception ex)
                {
                    _log.Error(ex.Message);
                }
            }
            base.OnClosing(e);
        }
Exemple #3
0
        public bool Connect(string userName, string password)
        {
            // check for empty userName or password
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
            {
                return(false);
            }
            // show wait cursor
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                const int maxRetry   = 5;
                int       retryCount = 0;
                bool      success    = false;
                // this loop to handle timeout exception
                // that usually occurs when calling the software for the first time in a period of time
                while (!success && retryCount < maxRetry)
                {
                    try
                    {
                        System.Net.ServicePointManager.ServerCertificateValidationCallback =
                            ((sender, certificate, chain, sslPolicyErrors) => true);
                        // try to connect using user credentials
                        _client = new PLMPackServiceClient();
                        _client.ClientCredentials.UserName.UserName = userName;
                        _client.ClientCredentials.UserName.Password = password;
                        _user   = _client.Connect();
                        success = true;
                    }
                    catch (System.TimeoutException ex)
                    {
                        ++retryCount;
                        _log.Warn(ex.Message);
                        if (maxRetry == retryCount)
                        {
                            if (DialogResult.Yes == MessageBox.Show("Had a timeout exception. Retry?", Application.ProductName, MessageBoxButtons.YesNo))
                            {
                                retryCount = 0;
                            }
                        }
                    }
                    catch (System.ServiceModel.Security.MessageSecurityException ex)
                    {
                        ++retryCount;
                        _log.Error(ex.InnerException.ToString());
                        MessageBox.Show(ex.InnerException.Message);
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connection failed!");
                _log.Error(ex.ToString());
                return(false);
            }
            // hide wait cursor
            Cursor.Current = Cursors.WaitCursor;

            // login successful -> save user credentials
            Properties.Settings.Default.CredentialUserName = userName;
            Properties.Settings.Default.CredentialPassword = password;
            Properties.Settings.Default.Save();

            if (null != _user)
            {
                _log.Info(string.Format("User connected as {0}", _user.Name));
            }

            if (null != Connected)
            {
                Connected();
            }

            return(true);
        }