Example #1
0
 private void btnTest_Click(object sender, EventArgs e)
 {
     try
     {
         string url = WDWebService.GetServiceURL(((WDURLItem)cboConnEnv.SelectedItem).Key, txtTenant.Text, txtUsername.Text, txtPassword.Text);
         if (url.Length > 4 && url.Substring(0, 4) == "http")
         {
             lnkConnURL.Text = String.Concat(url, "/", txtTenant.Text, "/");
             MessageBox.Show("Success", "Connection Test", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else
         {
             if (url.Length > 30)
             {
                 url = url.Substring(0, 30) + "...";
             }
             throw new Exception("Data returned: " + url);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Test failed. " + ex.Message, "Connection Test", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Example #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtName.Text.Length == 0)
                {
                    throw new Exception("Name is required.");
                }
                if (cboConnEnv.SelectedIndex == ListBox.NoMatches)
                {
                    throw new Exception("An environment URL must be selected.");
                }

                txtName.Enabled = false;
                string conn         = txtName.Text;
                string tenant       = txtTenant.Text;
                string username     = txtUsername.Text;
                string password     = Crypto.Protect(txtPassword.Text);
                string envText      = ((WDURLItem)cboConnEnv.SelectedItem).Value;
                string envURL       = ((WDURLItem)cboConnEnv.SelectedItem).Key;
                bool   savePassword = chkSavePassword.Checked;
                this.Password = password;
                string url = "";

                // New Item
                if (lstConnections.FindStringExact(txtName.Text) == ListBox.NoMatches)
                {
                    if (lstConnections.ValuesToString(txtName.Text).Length + conn.Length <= 500)
                    {
                        lstConnections.Items.Add(txtName.Text);
                        string conns = lstConnections.ValuesToString();
                        Settings.Set(IniSection.Connections, IniKey.Names, conns);
                    }
                    else
                    {
                        throw new Exception("List of all names cannot exceed 500 characters.");
                    }
                }
                Settings.Set(IniSection.Connection, conn, IniKey.Environment, envText);

                Settings.Set(IniSection.Connection, conn, IniKey.Tenant, tenant);
                Settings.Set(IniSection.Connection, conn, IniKey.Username, username);
                Settings.Set(IniSection.Connection, conn, IniKey.SavePassword, savePassword.ToString());

                if (cboConnEnv.SelectedIndex != ListBox.NoMatches && txtTenant.Text.Length > 0 &&
                    txtUsername.Text.Length > 0 && txtPassword.Text.Length > 0)
                {
                    url = WDWebService.GetServiceURL(((WDURLItem)cboConnEnv.SelectedItem).Key, txtTenant.Text, txtUsername.Text, txtPassword.Text);
                    url = String.Concat(url, "/", tenant, "/");
                    Settings.Set(IniSection.Connection, conn, IniKey.URL, url);
                    lnkConnURL.Text = url;
                }

                if (chkSavePassword.Checked)
                {
                    Settings.Set(IniSection.Connection, conn, IniKey.Password, password);
                }
                else
                {
                    if (txtPassword.Text.Length == 0)
                    {
                        Settings.Set(IniSection.Connection, conn, IniKey.Password, "");
                    }
                }
                MessageBox.Show("Saved", "Connection Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
                DirtySet(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error saving connection. " + Environment.NewLine + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }