public GithubProfile Add(GithubProfile entity, long createdBy = 0) { entity.SetCreateDateTime(); return(_context.Set <GithubProfile>() .Add(entity) .Entity); }
public object Post(AddGithubSSHKeyToCurrentUser request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); WebGithubProfile result; try { context.Open(); context.LogInfo(this, string.Format("/github/sshkey POST")); GithubProfile user = GithubProfile.FromId(context, context.UserId); UserTep userTep = UserTep.FromId(context, context.UserId); userTep.LoadSSHPubKey(); user.PublicSSHKey = userTep.SshPubKey; GithubClient githubClient = new GithubClient(context); if (!user.IsAuthorizationTokenValid()) { throw new UnauthorizedAccessException("Invalid token"); } if (user.PublicSSHKey == null) { throw new UnauthorizedAccessException("No available public ssh key"); } githubClient.AddSshKey("Terradue ssh key", user.PublicSSHKey, user.Name, user.Token); context.LogDebug(this, string.Format("User {0} added Terradue ssh key to his github account", userTep.Username)); result = new WebGithubProfile(user); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public GithubProfile Update(GithubProfile entity) { entity.SetUpdateDateTime(); return(_context.Set <GithubProfile>() .Update(entity) .Entity); }
public object Put(UpdateGithubUser request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); WebGithubProfile result; try { context.Open(); context.LogInfo(this, string.Format("/github/user PUT Id='{0}'", request.Id)); GithubProfile user = GithubProfile.FromId(context, request.Id); user = request.ToEntity(context, user); user.Store(); user.Load(); //to get information from Github UserTep userTep = UserTep.FromId(context, context.UserId); userTep.LoadSSHPubKey(); user.PublicSSHKey = userTep.SshPubKey; context.LogDebug(this, string.Format("Github account of user {0} has been updated", userTep.Username)); result = new WebGithubProfile(user); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public object Put(GetNewGithubToken request) { if (request.Code == null) { throw new Exception("Code is empty"); } var context = TepWebContext.GetWebContext(PagePrivileges.UserView); WebGithubProfile result; try { context.Open(); context.LogInfo(this, string.Format("/github/token PUT")); GithubProfile user = GithubProfile.FromId(context, context.UserId); //user.GetNewAuthorizationToken(request.Password, "write:public_key", "Terradue Sandboxes Application"); user.GetNewAuthorizationToken(request.Code); context.LogDebug(this, string.Format("User {0} requested a new github token", user.Identifier)); result = new WebGithubProfile(user); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public async Task <ActionResult <GithubProfile> > PostGithubProfile(GithubProfile githubProfile) { _context.GithubProfile.Add(githubProfile); await _context.SaveChangesAsync(); return(CreatedAtAction("GetGithubProfile", new { id = githubProfile.Id }, githubProfile)); }
public async Task <IActionResult> PutGithubProfile(int id, GithubProfile githubProfile) { if (id != githubProfile.Id) { return(BadRequest()); } _context.Entry(githubProfile).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GithubProfileExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IEnumerable <GithubProfile> > GetGithubProfiles() { GithubProfile githubProfile = null; List <GithubProfile> githubProfiles = new List <GithubProfile>(); string sqlcomandstring = "select * from Monitoring.dbo.GithubProfile"; using (SqlConnection sqlconnection = new SqlConnection(connectionString)) { await sqlconnection.OpenAsync(); SqlCommand sqlCommand = new SqlCommand(sqlcomandstring, sqlconnection); using (SqlDataReader Reader = sqlCommand.ExecuteReader()) { foreach (var item in Reader) { githubProfile = new GithubProfile { Id = (int)Reader["id"], UserName = Reader["UserName"] as string, Company = Reader["Company"] as string, Name = Reader["Name"] as string, Bio = Reader["Bio"] as string, Location = Reader["Location"] as string, Email = Reader["Email"] as string }; githubProfiles.Add(githubProfile); } } return(githubProfiles); } }
protected override SocialProfile GetNewProfile(Dictionary <string, object> dictionary) { dictionary.Add("id", "dummy"); var data = new GithubProfile(dictionary); data.id = data.email; return(data); }
public IActionResult Index() { UserRepos userRepos = new UserRepos(); userRepos.user = GithubProfile.GetInfo(); userRepos.starredRepos = GithubProfile.GetStarredRepos(); return(View(userRepos)); }
public async Task <bool> Handle(CreateProfileCommand request, CancellationToken cancellationToken) { // create a client for github var github = new GitHubClient(new ProductHeaderValue("MyAmazingApp")); var user = await github.User.Get(request.GithubAccount); //if user not register in github we wont continue if (user == null) { return(false); } // check if user register before var existProfile = await _profileRepository.GetByEmail(request.Email); //if user register in our db before, we just updated the saved info and check if repos changed then update info in our db if (existProfile != null) { existProfile.Email = request.Email; existProfile.Name = request.Name; existProfile.Organization = request.Organization; existProfile.GithubAccount = request.GithubAccount; existProfile.PhoneNumber = request.PhoneNumber; _profileRepository.Update(existProfile); var updateResult = (await _profileRepository.UnitOfWork.SaveChangesAsync(cancellationToken)) > 0; await _mediator.Send(new CreateRepoCommand { AccountName = request.GithubAccount, ProfileId = existProfile.Id }, cancellationToken); return(updateResult); } //if user not register in our db before , we submitted as new account and then get all the repos of user var createDto = new GithubProfile { Email = request.Email, Name = request.Name, Organization = request.Organization, GithubAccount = request.GithubAccount, PhoneNumber = request.PhoneNumber }; _profileRepository.Add(createDto); var result = await _profileRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken); await _mediator.Send(new CreateRepoCommand { AccountName = request.GithubAccount, ProfileId = createDto.Id }, cancellationToken); return(result); }
private void ProfileUpdate(GithubProfile profile, string url, MonitoringEntities db) { try { var profileInDb = db.GithubProfiles.FirstOrDefault(x => x.Url == url); if (profileInDb == null) { return; } if (!string.IsNullOrEmpty(profile.Bio)) { profileInDb.Bio = profile.Bio; } if (!string.IsNullOrEmpty(profile.BlogOrWebsite)) { profileInDb.BlogOrWebsite = profile.BlogOrWebsite; } if (!string.IsNullOrEmpty(profile.Company)) { profileInDb.Company = profile.Company; } if (!string.IsNullOrEmpty(profile.Email)) { profileInDb.Email = profile.Email; } if (!string.IsNullOrEmpty(profile.Name)) { profileInDb.Name = profile.Name; } if (!string.IsNullOrEmpty(profile.Location)) { profileInDb.Location = profile.Location; } if (!string.IsNullOrEmpty(profile.ImageUrl)) { profileInDb.ImageUrl = profile.ImageUrl; } if (profileInDb.StarsCount != 0) { profileInDb.StarsCount = profile.StarsCount; } profileInDb.LastUpdate = DateTime.Now; db.GithubProfiles.AddOrUpdate(profileInDb); } catch (Exception e) { Logger.Error(e, MethodBase.GetCurrentMethod().Name); } }
// Get a Github profile by id public GithubProfileModel GetAGithubProfile(int id) { GithubProfile dbProfile = monitoringContext.GithubProfile.Find(id); if (dbProfile == null) { GithubProfileModel nullModel = new GithubProfileModel(); nullModel = null; return(nullModel); } else { return(Helper.FromDbToModelForGithubProfileModel(dbProfile)); } }
public static GithubProfileModel FromDbToModelForGithubProfileModel(GithubProfile dbGithubProfile) { GithubProfileModel profileModel = new GithubProfileModel(); profileModel.UserName = dbGithubProfile.UserName; profileModel.Url = dbGithubProfile.Url; profileModel.Company = dbGithubProfile.Company; profileModel.Name = dbGithubProfile.Name; profileModel.Bio = dbGithubProfile.Bio; profileModel.Location = dbGithubProfile.Location; profileModel.Email = dbGithubProfile.Email; profileModel.BlogOrWebsite = dbGithubProfile.BlogOrWebsite; profileModel.StarsCount = dbGithubProfile.StarsCount; profileModel.LastUpdate = dbGithubProfile.LastUpdate; return(profileModel); }
/// <summary> /// Get Github profile general information /// </summary> /// <param name="content">Github general page HTML content </param> /// <param name="link">Github general page url</param> /// <returns>General information from profile </returns> public static GithubProfile GetGithubProfileSelenium(string content, string link) { if (content.Contains("org-name lh-condensed")) { return(null); } var document = new HtmlDocument(); document.LoadHtml(content); try { var imageUrl = document.DocumentNode.SelectSingleNode(".//img[@class='avatar width-full rounded-2']").GetAttributeValue("src", ""); var email = document.DocumentNode.SelectSingleNode(".//a[@class='u-email']")?.GetAttributeValue("href", "")?.Split(new[] { "mailto:" }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault(); var name = document.DocumentNode.SelectSingleNode(".//span[@class='p-name vcard-fullname d-block overflow-hidden']")?.InnerText; var userName = document.DocumentNode.SelectSingleNode(".//span[@class='p-nickname vcard-username d-block']")?.InnerText; var company = document.DocumentNode.SelectSingleNode(".//a[@class='user-mention']")?.InnerText; var location = document.DocumentNode.SelectSingleNode(".//span[@class='p-label']")?.InnerText; var social = document.DocumentNode.SelectSingleNode(".//a[@class='u-url']")?.InnerText; var bio = document.DocumentNode.SelectSingleNode(".//div[@class='p-note user-profile-bio']")?.InnerText; var starCount = document.DocumentNode.SelectSingleNode(".//span[@class='Counter']")?.InnerText?.Replace(" ", "").Replace("\n", "").Replace("\r", " ").Trim() ?? "-1"; var profile = new GithubProfile { Url = link, Bio = bio, BlogOrWebsite = social, Company = company, Email = email, ImageUrl = imageUrl, Location = location, Name = name, UserName = userName, StarsCount = int.Parse(starCount) }; return(profile); } catch (Exception e) { Logger.Error(e, MethodBase.GetCurrentMethod().Name); return(null); } }
public object Get(GetGithubUser request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); WebGithubProfile result; try { context.Open(); context.LogInfo(this, string.Format("/github/user/current GET")); GithubProfile user = GithubProfile.FromId(context, context.UserId); UserTep userTep = UserTep.FromId(context, context.UserId); userTep.LoadSSHPubKey(); user.PublicSSHKey = userTep.SshPubKey; result = new WebGithubProfile(user); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public IActionResult GetGithubRepos() { var userRepos = GithubProfile.GetGithubRepos(); return(View(userRepos)); }
public IActionResult GetGithubProfile() { var userProfile = GithubProfile.GetGithubProfile(); return(View(userProfile)); }
public object Post(CreateOneUser request) { WebOneUser result; var context = TepWebContext.GetWebContext(PagePrivileges.UserView); try { context.Open(); int provId = (request.ProviderId != 0 ? request.ProviderId : context.GetConfigIntegerValue("One-default-provider")); User user = User.FromId(context, context.UserId); string username = user.Email; try{ CloudUser usercloud = CloudUser.FromIdAndProvider(context, context.UserId, provId); if (!String.IsNullOrEmpty(usercloud.CloudUsername)) { username = usercloud.CloudUsername; } }catch (Exception) {} OneCloudProvider oneCloud = (OneCloudProvider)CloudProvider.FromId(context, provId); //create user int id = oneCloud.XmlRpc.UserAllocate(username, request.Password, (String.IsNullOrEmpty(request.AuthDriver) ? "x509" : request.AuthDriver)); USER oneuser = oneCloud.XmlRpc.UserGetInfo(id); context.LogInfo(this, string.Format("/one/user POST ProviderId='{0}',Id='{1}'", request.ProviderId, id)); List <KeyValuePair <string, string> > templatePairs = new List <KeyValuePair <string, string> >(); templatePairs.Add(new KeyValuePair <string, string>("USERNAME", username)); templatePairs.Add(new KeyValuePair <string, string>("VM_USERNAME", user.Username)); try{ GithubProfile github = GithubProfile.FromId(context, user.Id); if (!String.IsNullOrEmpty(github.Name)) { templatePairs.Add(new KeyValuePair <string, string>("GITHUB_USERNAME", github.Name)); } if (!String.IsNullOrEmpty(github.Email)) { templatePairs.Add(new KeyValuePair <string, string>("GITHUB_EMAIL", github.Email)); } if (!String.IsNullOrEmpty(github.Token)) { templatePairs.Add(new KeyValuePair <string, string>("GITHUB_TOKEN", github.Token)); } }catch (Exception) {} //update user template string templateUser = CreateTemplate((XmlNode[])oneuser.TEMPLATE, templatePairs); if (!oneCloud.XmlRpc.UserUpdate(id, templateUser)) { throw new Exception("Error during update of user"); } //add user to group GEP oneCloud.XmlRpc.UserUpdateGroup(id, context.GetConfigIntegerValue("One-GEP-grpID")); result = new WebOneUser { Id = oneuser.ID, Name = oneuser.NAME, Password = oneuser.PASSWORD, AuthDriver = oneuser.AUTH_DRIVER }; context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public void UpdateGithubProfilesInDb() { using (MonitoringEntities db = new MonitoringEntities()) { var githubProfiles = db.GithubProfiles.ToList(); var allFromApi = GetAllFromApiAsync(); for (var i = 0; i < allFromApi.Count; i++) { var githubApiModel = allFromApi[i]; try { var userJson = SendGetRequest(githubApiModel.url); var userModel = JsonConvert.DeserializeObject <GithubApiUserModel>(userJson); var updateProfile = githubProfiles.FirstOrDefault(x => x.UserName == userModel.login); if (updateProfile is null) { var newGithubMember = new GithubProfile { UserName = userModel.login, Email = userModel.email as string, Company = userModel.company as string, Location = userModel.location, ImageUrl = userModel.avatar_url, BlogOrWebsite = userModel.blog, Name = userModel.name, Bio = userModel.bio as string, Url = userModel.html_url, LastUpdate = DateTime.Now }; db.GithubProfiles.Add(newGithubMember); } else { if (userModel.email != null) { updateProfile.Email = userModel.email as string; } if (userModel.company != null) { updateProfile.Company = userModel.company as string; } if (userModel.location != null) { updateProfile.Location = userModel.location; } if (userModel.avatar_url != null) { updateProfile.ImageUrl = userModel.avatar_url; } if (userModel.blog != null) { updateProfile.BlogOrWebsite = userModel.blog; } if (userModel.name != null) { updateProfile.Name = userModel.name; } if (userModel.bio != null) { updateProfile.Bio = userModel.bio as string; } updateProfile.LastUpdate = DateTime.Now; db.GithubProfiles.AddOrUpdate(updateProfile); } db.SaveChanges(); //Thread.Sleep(1500); } catch { Console.WriteLine(i); } } } }