protected void Connect <T>(string name, string token) where T : AccountConnection { var a = this._context.Current; var c = this._accountConnectionService.GetConnection <T>(name); if (this._context.Current == null || (c != null && c.AccountId == a.ID)) { return; } if (c != null && c.AccountId != a.ID) { throw new CooperknownException(string.Format(this.Lang().sorry_already_connect_another, name)); } if (typeof(T) == typeof(GoogleConnection)) { this._accountConnectionService.Create(c = new GoogleConnection(name, token, a)); } else if (typeof(T) == typeof(GitHubConnection)) { this._accountConnectionService.Create(c = new GitHubConnection(name, token, a)); } //HACK:连接账号时自动关联一切可以关联的信息 this.AssociateEverything(c); }
private async void Button_ClickAsync(object sender, RoutedEventArgs e) { // Get user inputs tok = token.Password; // Start async to get user Task <User> getUser = GitHubConnection.LoginAsync(tok); // Pop up splash screen in the meantime SplashWindow verificationSplash = new SplashWindow(GlobalSettings.validationUri); // Await for user User user = await getUser; // Close splash screen verificationSplash.CloseSplash(); // Pop up splash screen in the meantime SplashWindow verifiedSplash = new SplashWindow(GlobalSettings.validatedUri); // Wait x seconds showing message System.Threading.Thread.Sleep(2000); // Close splash screen verifiedSplash.CloseSplash(); // Greet user GitHubConnection.GreetUser(user); // If you go to this point, it was successful GlobalSettings.logged = true; // And close the log in form Close(); }
private async void Login_ClickAsync(object sender, RoutedEventArgs e) { // Get user inputs GHtok = token.Password; GHemail = email.Text; GHpassword = Password.Password; User user = null; // Check it's different from default values if (GHtok != "") { user = await GitHubConnection.LoginAsync(GHtok); } else if (GHemail != "email address" && GHpassword != "password") { user = await GitHubConnection.LoginAsync(GHemail, GHpassword); } // Pop up splash screen in the meantime SplashWindow verificationSplash = new SplashWindow(GlobalSettings.validationUri); // Close splash screen verificationSplash.CloseSplash(); if (user != null) { // Pop up splash screen in the meantime SplashWindow verifiedSplash = new SplashWindow(GlobalSettings.validatedUri); // Wait x seconds showing message System.Threading.Thread.Sleep(2000); // Close splash screen verifiedSplash.CloseSplash(); // Greet user GitHubConnection.GreetUser(user); // If you go to this point, it was successful GlobalSettings.logged = true; GitHubConnection.ChangeLoginGreet(); } else { Helpers.ErrorMessage("It seems like you've input the wrong credentials/token"); GlobalSettings.logged = false; } // And close the log in form Close(); }
public async Task TestGetUserRepoInformation_For_sohail92_repos_urlAsync() { // arrange GitHubConnection gitHubConnection = new GitHubConnection(); // act var result = await gitHubConnection.GetUserInformation("sohail92"); // assert Assert.IsNotNull(result); Assert.IsTrue(result.ReposUrl == "https://api.github.com/users/Sohail92/repos"); }
public async Task TestGetUserRepoInformation_For_robconery_locationAsync() { // arrange GitHubConnection gitHubConnection = new GitHubConnection(); // act var result = await gitHubConnection.GetUserInformation("robconery"); // assert Assert.IsNotNull(result); Assert.IsTrue(result.Location == "Honolulu, HI"); }
public async Task TestGetUserRepoInformation_For_sohail92_locationAsync() { // arrange GitHubConnection gitHubConnection = new GitHubConnection(); // act var result = await gitHubConnection.GetUserInformation("sohail92"); // assert Assert.IsNotNull(result); Assert.IsTrue(result.Location == "Middlesbrough, UK"); }
public async Task TestGetUserRepoInformation_For_UserNotFoundAsync() { // arrange GitHubConnection gitHubConnection = new GitHubConnection(); // act var result = await gitHubConnection.GetUserInformation("ABC123USERNOTFOUND_ABC_DEF_GHI"); // assert Assert.IsNotNull(result); Assert.IsNull(result.Name); // we shouldnt have got details back for this user as they dont exist. }
public async Task TestGetUserRepoInformation_For_robconery_As_Username() { // arrange GitHubConnection gitHubConnection = new GitHubConnection(); // act var result = await gitHubConnection.GetUserInformation("robconery"); // assert Assert.IsNotNull(result); Assert.IsTrue(result.Name == "Rob Conery"); }
public async Task TestGetUserRepoInformation_For_robconery_repos_returned_is_lessThenOrEqualTo_5Async() { // arrange GitHubConnection gitHubConnection = new GitHubConnection(); // act var result = await gitHubConnection.GetUserRepoInformation("robconery"); // assert Assert.IsNotNull(result); Assert.IsTrue(result.Count <= 5); }
public async Task TestGetUserRepoInformation_For_Sohail92_As_UsernameAsync() { // arrange GitHubConnection gitHubConnection = new GitHubConnection(); // act var result = await gitHubConnection.GetUserInformation("sohail92"); // assert Assert.IsNotNull(result); Assert.IsTrue(result.Name == "Sohail Rahman"); }
public async Task TestGetUserRepoInformation_For_robconery_avatar_urlAsync() { // arrange GitHubConnection gitHubConnection = new GitHubConnection(); // act var result = await gitHubConnection.GetUserInformation("robconery"); // assert Assert.IsNotNull(result); Assert.IsTrue(result.AvatarUrl == "https://avatars0.githubusercontent.com/u/78586?v=4"); }
public void CreateGit() { var u = this.RandomString(); var c = new GitHubConnection(u, _token, this.CreateAccount()); this._accountConnectionService.Create(c); Assert.Greater(c.ID, 0); var c2 = this._accountConnectionService.GetConnection <GitHubConnection>(u); Assert.IsNotNull(c2); Assert.AreEqual(c2.ID, c.ID); Assert.AreEqual(c2.Name, c.Name); }
private async void EmailPassB_ClickAsync(object sender, RoutedEventArgs e) { GHemail = email.Text; GHpassword = password.Password; // Start async to get user Task <User> getUser = GitHubConnection.LoginAsync(GHemail, GHpassword); // Pop up splash screen in the meantime SplashWindow splash = new SplashWindow(GlobalSettings.validationUri); // Await for user User user = await getUser; // Close splash screen splash.CloseSplash(); if (user != null) { // Pop up splash screen in the meantime SplashWindow verifiedSplash = new SplashWindow(GlobalSettings.validatedUri); // Wait x seconds showing message System.Threading.Thread.Sleep(2000); // Close splash screen verifiedSplash.CloseSplash(); // Greet user GitHubConnection.GreetUser(user); // If you go to this point, it was successful GlobalSettings.logged = true; } else { Helpers.ErrorMessage("It seems like you've input the wrong credentials/token"); GlobalSettings.logged = false; } // And close the log in form Close(); }
/// <summary> /// Method that is called when Dynamo has finished loading and the UI is ready to be interacted with. /// </summary> /// <param name="vlp"> /// Parameters that provide references to Dynamo commands, settings, events and /// Dynamo UI items like menus or the background preview. This object is supplied by Dynamo itself. /// </param> public void Loaded(ViewLoadedParams vlp) { // let's now create a completely top-level new menu item MenuItem extensionMenu = new MenuItem { Header = "DynaHub" }; // and now we add a new sub-menu item that says hello when clicked loginMenuItem = new MenuItem { Header = "Login to GitHub" }; var browseMenuItem = new MenuItem { Header = "Browse GitHub" }; var packagesMenuItem = new MenuItem { Header = "Get packages" }; var logoutMenuItem = new MenuItem { Header = "Logout" }; var VM = vlp.DynamoWindow.DataContext as DynamoViewModel; // Define Login menu option loginMenuItem.Click += (sender, args) => { if (!GlobalSettings.logged) { // Create data tree to represent repo structure Views.Login l = new Views.Login(); l.ShowDialog(); } else { Helpers.ErrorMessage("You are already logged in."); } }; // Define Browse menu option browseMenuItem.Click += (sender, args) => { if (GlobalSettings.logged) { // Create data tree to represent repo structure Views.Browser b = new Views.Browser(); b.ShowDialog(); // Open downloaded file - path received from Browser VM.OpenCommand.Execute(Views.Browser.toOpen); } else { Helpers.ErrorMessage("You'll need to login before trying to access your files!"); } }; // Define Get Packages menu option packagesMenuItem.Click += (sender, args) => { if (GlobalSettings.logged) { // Download packages to Dynamo's packages folder Views.Packages p = new Views.Packages(vlp); p.ShowDialog(); } else { Helpers.ErrorMessage("You'll need to login before downloading the packages!"); } }; // Define Get Packages menu option logoutMenuItem.Click += (sender, args) => { if (GlobalSettings.logged) { // Logout of current GitHub login GitHubConnection.Logout(); //Views.Packages o = new Views.Packages(vlp); //o.ShowDialog(); } else { Helpers.ErrorMessage("You can't logout if you're not logged in"); } }; // Add main menu to Dynamo vlp.dynamoMenu.Items.Add(extensionMenu); // Add sub-menus to main menu extensionMenu.Items.Add(loginMenuItem); extensionMenu.Items.Add(browseMenuItem); extensionMenu.Items.Add(packagesMenuItem); extensionMenu.Items.Add(logoutMenuItem); }