Exemplo n.º 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());
        }
Exemplo n.º 2
0
        private GH_SettingsServer server; //GH_SettingsServer handles writing and reading from the preferences xml file.

        #endregion Fields

        #region Constructors

        //class constructor extending GH_Component - this is where the component name, nickname, description, category, and subcategory are defined.
        public GoogleAuthenticator()
            : base("Google Authenticator", "GAuth", "Use this component to authenticate with Google to gain access to your spreadsheets", Properties.Resources.AssemblyName, "Spreadsheets")
        {
            //on component creation, set up the settings server and initialize variables
             server = new GH_SettingsServer(PREFS_FILENAME);

             accessCode = "";
             accessToken = server.GetValue(PREFS_TOKEN, "");
             refreshToken = server.GetValue(PREFS_REFTOKEN, "");
             loggedIn = !String.IsNullOrEmpty(accessToken) && !String.IsNullOrEmpty(refreshToken);
             UpdateMenu();
        }
Exemplo n.º 3
0
        public static Signature getSignature()
        {
            GH_SettingsServer sserver  = new GH_SettingsServer("ggit");
            string            username = sserver.GetValue("author", "");
            string            email    = sserver.GetValue("email", "");

            if (username == "" || email == "")
            {
                return(null);
            }
            Signature author = new Signature(username, email, DateTime.Now);

            return(author);
        }
Exemplo n.º 4
0
        private void PullRepository()
        {
            if (ActiveCanvas.Document == null)
            {
                return;
            }
            string docPath = ActiveCanvas.Document.FilePath;

            try
            {
                using (var repo = new Repository(getWorkDir(docPath)))
                {
                    GH_SettingsServer sserver = new GH_SettingsServer("ggit");
                    string            token   = sserver.GetValue("AccessToken", "");
                    // Credential information to fetch
                    PullOptions options = new PullOptions();
                    options.FetchOptions = new FetchOptions();
                    options.FetchOptions.CredentialsProvider = (_url, _user, _cred) =>
                                                               new UsernamePasswordCredentials
                    {
                        // TO DO Set AccessToken From
                        Username = token,
                        Password = string.Empty
                    };

                    // User information to create a merge commit
                    var signature = getSignature();

                    // Pull
                    Commands.Pull(repo, signature, options);
                }
            } catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
0
 //this method saves the token information to the settings XML file.
 private void SaveAuth(GH_SettingsServer server, string token, string reftoken)
 {
     server.SetValue(PREFS_TOKEN, token);
     server.SetValue(PREFS_REFTOKEN, reftoken);
     server.WritePersistentSettings();
 }