예제 #1
0
        private void comboEntryName_TextChanged(object sender, EventArgs e)
        {
            if (accounts.ContainsKey(comboEntryName.Text))
            {
                JiraAccount a = accounts[comboEntryName.Text];
                textServerUrl.Text = a.url;
                textLogin.Text     = a.login;
                textPassword.Text  = a.password;

                saveLastUsed();
            }

            updateButtons();
        }
예제 #2
0
        public void Login(IUser tempUser, LoginCallback callback)
        {
            var account = new JiraAccount(Properties.Settings.Default.jiraurl, tempUser.Username, tempUser.Password);

            jiraClient = new JiraClient(account);
            var mergedCredentials  = $"{tempUser.Username}:{tempUser.Password}";
            var byteCredentials    = Encoding.UTF8.GetBytes(mergedCredentials);
            var encodedCredentials = Convert.ToBase64String(byteCredentials);

            OnLoginCallback = callback;

            using (var webClient = new WebClient())
            {
                webClient.Headers.Set("Authorization", "Basic " + encodedCredentials);
                webClient.DownloadStringAsync(new Uri(Properties.Settings.Default.jiraurl));
                webClient.DownloadStringCompleted += WebClient_DownloadStringCompleted;
            }
        }
        private void InitializeJiraClient()
        {
            if (client == null)
            {
                //Replace these 4 lines of code with your Jira creds and url
                JiraInstance credentialsReader = new JiraInstance();
                string       userName          = credentialsReader.Username;
                string       password          = credentialsReader.Password;
                this.jiraURL = credentialsReader.Url;

                JiraAccount account = new JiraAccount()
                {
                    Password  = password,
                    ServerUrl = jiraURL,
                    User      = userName
                };

                client = new JiraClient(account);
            }
        }
예제 #4
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            List <JiraAccount> accounts = jiraAccounts.ItemsSource as List <JiraAccount>;

            // ensure only one active account
            if (accounts.FindAll(ac => ac.active).Count != 1)
            {
                MessageBox.Show("You need to select only one active account!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            // check guid field id for active account
            JiraAccount activeAccount = accounts.Find(ac => ac.active);

            if (string.IsNullOrWhiteSpace(activeAccount.username))
            {
                // for setting BCF username only
                DialogResult = true;
                return;
            }
            var client = new RestClient(activeAccount.jiraserver);

            client.CookieContainer = new System.Net.CookieContainer();
            var request = new RestRequest("/rest/auth/1/session", Method.POST);

            request.AddHeader("content-type", "application/json");
            string requestBody = "{\"username\": \"" + activeAccount.username + "\",\"password\": \"" + activeAccount.password + "\"}";

            request.AddParameter("application/json", requestBody, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var request2 = new RestRequest("/rest/api/2/field", Method.GET);
                IRestResponse <List <JiraCustomField> > response2 = null;
                try
                {
                    response2 = client.Execute <List <JiraCustomField> >(request2);
                    JiraCustomField guidField = response2.Data.Find(field => field.name == "GUID");
                    if (guidField != null)
                    {
                        activeAccount.guidfield = guidField.id;
                        MessageBox.Show(string.Format("The GUID field Id on {0} is {1}. Now you can create an issue with the plug-ins of Revit and Navisworks!", activeAccount.jiraserver, guidField.id), "Success", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show(string.Format("There's no custom field named GUID on {0}. Creating an issue might fail. Please check with your Jira administrator!", activeAccount.jiraserver), "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
                catch (Exception ex)
                {
                    RestCallback.LogRequest(client, request2, response2, ex);
                    MessageBox.Show(string.Format("Cannot connect to {0}. Please check with your Jira administrator!\nStatus Code: " + response2.StatusCode.ToString(), activeAccount.jiraserver), "Warning", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                RestCallback.LogRequest(client, request, response);
                MessageBox.Show("Login failed. Please check your username/password!\nStatus Code: " + response.StatusCode.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            DialogResult = true;
        }
예제 #5
0
        private void setupFromCommandLine(NameValueCollection cmdline)
        {
            if (cmdline == null)
            {
                return;
            }

            string type = cmdline["type"];

            if (type == null || !type.Equals("jira"))
            {
                return;
            }

            string user = cmdline["user"];
            string host = cmdline["host"];

            if (host == null)
            {
                return;
            }

            issueKey = cmdline["issueKey"];

            issueId    = cmdline["id"];
            jSessionId = cmdline["JSESSIONID"] ?? cmdline["jsessionid"];
            token      = cmdline["soaptoken"] ?? cmdline["soaptoken"];

            bool found = false;

            foreach (string a in accounts.Keys)
            {
                if (!accounts[a].url.Equals(host))
                {
                    continue;
                }

                found = true;
                comboEntryName.SelectedItem = a;
                break;
            }

            if (!found)
            {
                accounts[FROM_WEB] = new JiraAccount(host, user, null);
                comboEntryName.Items.Add(FROM_WEB);
                comboEntryName.SelectedItem = FROM_WEB;
                textPassword.Focus();
            }

            textIssueNumber.Text = issueKey;

            StartPosition = FormStartPosition.CenterParent;

            if ((issueId != null && jSessionId != null) || (token != null && issueKey != null))
            {
                textIssueNumber.Enabled    = false;
                textLogin.Enabled          = false;
                textPassword.Enabled       = false;
                textServerUrl.Enabled      = false;
                comboEntryName.Enabled     = false;
                btnSave.Enabled            = false;
                btnDelete.Enabled          = false;
                checkStorePassword.Enabled = false;
                checkStorePassword.Checked = false;
                commentBox.Enabled         = false;

                ClientSize = new Size(ClientSize.Width / 2, ClientSize.Height - commentBox.Height - groupBoxAccounts.Height - 60);

                commentBox.Visible         = false;
                groupBoxComment.Visible    = false;
                groupBoxAccounts.Visible   = false;
                comboEntryName.Visible     = false;
                textServerUrl.Visible      = false;
                btnDelete.Visible          = false;
                btnSave.Visible            = false;
                labelUserName.Visible      = false;
                labelPassword.Visible      = false;
                labelEntryName.Visible     = false;
                labelIssueNumber.Visible   = false;
                labelServerUrl.Visible     = false;
                checkStorePassword.Visible = false;
                textIssueNumber.Visible    = false;
                textLogin.Visible          = false;
                textPassword.Visible       = false;
                buttonUpload.Visible       = false;
            }
        }