예제 #1
0
        private void OnSettingAuthor(object sender, EventArgs e)
        {
            DoubleInput conform = new DoubleInput();

            conform.Text          = "Git author setting";
            conform.label1.Text   = "Username";
            conform.label2.Text   = "E-mail";
            conform.ConfirmEvent += (sd, author, email) => {
                if (author == "")
                {
                    MessageBox.Show("Username can't be empty.");
                    return;
                }
                if (email == "")
                {
                    MessageBox.Show("E-mail can't be empty.");
                    return;
                }
                string reg = @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
                Regex  r   = new Regex(reg);
                if (!r.IsMatch(email))
                {
                    MessageBox.Show("E-mail is not a email.");
                    return;
                }

                GH_SettingsServer sserver = new GH_SettingsServer("ggit");
                sserver.SetValue("author", author);
                sserver.SetValue("email", email);
                sserver.WritePersistentSettings();

                conform.Close();
            };
            conform.Show(ActiveCanvas.FindForm());
        }
예제 #2
0
        private void OnClone(object sender, EventArgs e)
        {
            DoubleInput cloneForm = new DoubleInput();

            cloneForm.Text = "Clone remote repository";

            cloneForm.label1.Text = "Remote Url";
            cloneForm.label2.Text = "Local Path";

            cloneForm.input2.Cursor   = Cursors.Hand;
            cloneForm.input2.Text     = "Click me !";
            cloneForm.input2.ReadOnly = true;
            cloneForm.input2.Click   += (ed, eg) =>
            {
                if (cloneForm.input1.Text == "")
                {
                    MessageBox.Show("No remote url found");
                    return;
                }
                FolderBrowserDialog folder = new FolderBrowserDialog();
                DialogResult        res    = folder.ShowDialog();
                if (res == DialogResult.OK || res == DialogResult.Yes)
                {
                    Uri    uri  = new Uri(cloneForm.input1.Text);
                    string name = uri.Segments[uri.Segments.Length - 1].TrimEnd('/').Split('.')[0];
                    cloneForm.input2.Text = Path.Combine(@folder.SelectedPath, name);
                }
            };

            cloneForm.Show();

            cloneForm.ConfirmEvent += async(sd, url, path) =>
            {
                LoadingForm loadingForm = new LoadingForm();
                loadingForm.Show(ActiveCanvas.FindForm());
                await Task.Run(() => CloneRepository(url, path));

                loadingForm.Close();
                cloneForm.Close();
                Uri    uri  = new Uri(url);
                string name = uri.Segments[uri.Segments.Length - 1].TrimEnd('/').Split('.')[0];
                MessageBox.Show(string.Format("{0} is Cloned to {1}", name, path));
            };
        }
예제 #3
0
        private void DocumentPush()
        {
            // TO DO nothing to push tip
            if (ActiveCanvas.Document == null)
            {
                return;
            }
            try
            {
                string docPath = ActiveCanvas.Document.FilePath;
                using (var repo = new Repository(getWorkDir(docPath)))
                {
                    GH_SettingsServer sserver = new GH_SettingsServer("ggit");
                    if (repo.Network.Remotes["origin"] == null)
                    {
                        MessageBox.Show("Remote origin is not exist, create a repository remotely, something like github, and paste the url into next window form.");
                        SingleInput inputer = new SingleInput();
                        inputer.Text             = "Remote Url";
                        inputer.singleLabel.Text = "Remote Url";
                        inputer.ConfirmEvent    += (sender, content) => {
                            repo.Network.Remotes.Add("origin", content);
                            inputer.Close();
                        };
                        inputer.ShowDialog();
                        return;
                    }

                    Remote remote = repo.Network.Remotes["origin"];
                    string token  = sserver.GetValue("AccessToken", "");

                    if (token == "")
                    {
                        DialogResult choose = MessageBox.Show("Do you want to set a Personal Access Token to avoid input username and password for each push ?", "Access Token didn't exist", MessageBoxButtons.YesNoCancel);
                        if (choose == DialogResult.OK)
                        {
                            MessageBox.Show("Remote origin is not exist, create a repository remotely, something like github, and paste the url into next window form.");
                            SingleInput inputer = new SingleInput();
                            inputer.Text             = "Access Token";
                            inputer.singleLabel.Text = "Token";
                            inputer.ConfirmEvent    += (sender, accessToken) => {
                                sserver.SetValue("AccessToken", accessToken);
                                inputer.Close();
                            };
                            inputer.ShowDialog();
                        }
                        else if (choose == DialogResult.No)
                        {
                            DoubleInput loginForm = new DoubleInput();
                            loginForm.Text                = "Git login";
                            loginForm.label1.Text         = "Username";
                            loginForm.input2.PasswordChar = '*';
                            loginForm.label2.Text         = "Passowrd";
                            loginForm.ConfirmEvent       += (sd, username, password) => {
                                if (username == "")
                                {
                                    MessageBox.Show("Username can't be empty.");
                                    return;
                                }
                                if (password == "")
                                {
                                    MessageBox.Show("E-mail can't be empty.");
                                    return;
                                }

                                PushOptions options1 = new PushOptions();
                                options1.CredentialsProvider = (_url, _user, _cred) =>
                                                               new UsernamePasswordCredentials
                                {
                                    // TO DO Set AccessToken From
                                    Username = username,
                                    Password = password
                                };

                                repo.Network.Push(remote, @"refs/heads/master", options1);

                                loginForm.Close();
                            };
                            loginForm.ShowDialog();
                        }
                        return;
                    }

                    PushOptions options = new PushOptions();
                    options.CredentialsProvider = (_url, _user, _cred) =>
                                                  new UsernamePasswordCredentials
                    {
                        // TO DO Set AccessToken From
                        Username = token,
                        Password = string.Empty
                    };

                    repo.Network.Push(remote, @"refs/heads/master", options);
                    DocumentEditor.SetStatusBarEvent(new GH_RuntimeMessage("Push done !"));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }