/// <summary> /// http://drupal.stackexchange.com/questions/101872/attach-file-to-post-using-c-restsharp-and-drupal-services/143727#143727?newreg=0d4ecba4b7234432831af804a232fdb9 /// </summary> public void uploadArtifact3() //Caused by: java.lang.IllegalStateException: Form too large 832324>200000 { RestRequest request = new RestRequest("artifact/maven/content/", Method.POST); request.RequestFormat = RestSharp.DataFormat.Json; request.AddParameter("r", "releases"); request.AddParameter("hasPom", "false"); request.AddParameter("p", "zip"); request.AddParameter("e", "zip"); request.AddParameter("g", "otpp.devops"); request.AddParameter("a", "githubSuspsendInactiveADAccounts"); request.AddParameter("v", "1.0.1"); //request.AddParameter("file", "@C:\\Temp\\Nexus\\githubSuspsendInactiveADAccounts-1.0.1.zip"); string filename = "githubSuspsendInactiveADAccounts-1.0.1.zip"; string filevalue = System.Convert.ToBase64String(RestSharpAPI.file_get_byte_contents(filename)); request.AddParameter("file", filevalue); request.AddParameter("filename", filename); IRestResponse response = client.Execute <DFile>(request); Console.WriteLine("Response received: {0}", response.ResponseStatus); }
List<string> urls = new List<string>(); // foler URL to be deleted #endregion Fields #region Constructors /// <summary> /// Initializes a new instance of the <see cref="GitHubAPI"/> class. /// </summary> /// <param name="client">The RestClient.</param> public NexusAPI(RestSharpAPI restSharpAPI, RestClient client) { this.restSharpAPI = restSharpAPI; this.client = client; }
static void Main(string[] args) { try { RestSharpAPI restSharpAPI = new RestSharpAPI(baseUrl); //RestClient client = restSharpAPI.getClient(); //works RestClient client = restSharpAPI.getClient(user, password); // works if (restSharpAPI == null || client == null) { Console.WriteLine("restSharpAPI or client is null"); Environment.Exit(1); } NexusAPI nexusAPI = new NexusAPI(restSharpAPI, client); //nexusAPI.testDelete(); //Console.ReadKey(true); List<NexusContent> contents = new List<NexusContent>(); string repository = "otpp-snapshots"; //string repository = "releases"; string pattern = ".zip"; int days = 0; contents = nexusAPI.getContent(repository, "/"); nexusAPI.findArtifacts(repository, contents, days, pattern); Console.WriteLine("Size of artifacts: {0}", nexusAPI.urls.Count); nexusAPI.removeLastFromList(repository); for (int i = nexusAPI.urls.Count - 1; i >= 0; i--) { nexusAPI.urls[i].TrimEnd('/'); int local = nexusAPI.urls[i].IndexOf("/local/"); nexusAPI.urls[i] = nexusAPI.urls[i].Substring(local + 6); Console.WriteLine("URL to be deleted: {0}", nexusAPI.urls[i]); } //nexusAPI.deleteArtifact(nexusAPI.urls, repository); Console.ReadKey(true); List<NexusRepo> repos = new List<NexusRepo>(); repos = nexusAPI.GetAllRepos(); if (repos == null) { Console.WriteLine("repos is null"); Console.ReadKey(true); Environment.Exit(1); } else { Console.WriteLine("Size of repos: {0}", repos.Count); } foreach (NexusRepo repo in repos) { // Console.WriteLine("Repo info: {0}", repo.ToString()); } //nexusAPI.uploadArtifact(); //nexusAPI.uploadArtifact1(); //nexusAPI.uploadArtifact2(); //nexusAPI.uploadArtifact3(); //List<NexusArtifact> artifacts = new List<NexusArtifact>(); //artifacts = nexusAPI.searchMetadata(); //if (artifacts == null) //{ // Console.WriteLine("artifacts is null"); // Console.ReadKey(true); // Environment.Exit(1); //} //else { // Console.WriteLine("Size of repos: {0}", artifacts.Count); //} Console.ReadKey(true); } catch (Exception ex) { Console.WriteLine("Exception caught: {0}", ex); Console.ReadKey(true); } }
/// <summary> /// Initializes a new instance of the <see cref="GitHubAPI"/> class. /// </summary> /// <param name="client">The RestClient.</param> public GitHubAPI(RestSharpAPI restSharpAPI, RestClient client) { this.restSharpAPI = restSharpAPI; this.client = client; }
static void Main(string[] args) { try { RestSharpAPI restSharpAPI = new RestSharpAPI(baseUrl); //RestClient client = restSharpAPI.getClient(myUser, myPassword); RestClient client = restSharpAPI.getClient2(myUser, myToken); GitHubAPI gitHubAPI = new GitHubAPI(restSharpAPI, client); List<GitHubRepo> repos = new List<GitHubRepo>(); List<GitHubTeam> teams = new List<GitHubTeam>(); List<GitHubUser> users = new List<GitHubUser>(); List<GitHubCommit> commits = new List<GitHubCommit>(); string since = "2016-01-01T00:00:00Z"; string path = "GitHubAuditReport_" + System.DateTime.Now.ToString("dd-MM-yyyy") + ".txt"; string org = "Trade-Efficiencies-CRD"; //string org = "DevOps"; string createText = "Audit Report for GitHub Organization: " + org + "\n"; createText = createText + "===============================================\n"; //string repo = "Sample"; repos = gitHubAPI.GetOrgRepos(org); foreach (GitHubRepo repo in repos) // Loop through List with foreach. { Console.WriteLine("repo info: {0} \n", repo.name); createText = createText + "\nRepository : " + repo.name + "\n"; createText = createText + "------------------------------------------\n"; commits = gitHubAPI.GetCommits(org, repo.name, since); if (commits.Count == 0) { createText = createText + "No new change in this repo.\n"; continue; } foreach (GitHubCommit item in commits) // Loop through List with foreach. { Console.WriteLine("commit info: {0} \n", item.sha); createText = createText + "\nChange: " + item.commit.message + "\n"; GitHubCommit commit = gitHubAPI.GetCommit(org, repo.name, item.sha); createText = createText + commit.ToString(); } } // Write to a file createText = createText + Environment.NewLine; File.WriteAllText(path, createText); Console.WriteLine("File " + path +" created"); /// print single commit //string sha = "60cf9d282af07d138504c0af987dd0fcdfe45ec6"; //GitHubCommit commit = gitHubAPI.GetCommit(org, repo, sha); //Console.WriteLine("Commit info: {0}", commit.ToString()); // Write to a file //string path = "GitHubAuditReport_" + System.DateTime.Now.ToString("dd-MM-yyyy") + ".txt"; //string createText = commit.ToString() + Environment.NewLine; //File.WriteAllText(path, createText); //Console.WriteLine("file created"); //repos = gitHubAPI.GetOrgRepos(org); //foreach (GitHubRepo repo in repos) // Loop through List with foreach. //{ // Console.WriteLine("Repo info: {0}", repo.ToString()); //} //string userId = "huj"; //repos = gitHubAPI.GetUserRepos(userId); //teams = gitHubAPI.GetOrgTeams(org); //foreach (GitHubTeam team in teams) // Loop through List with foreach. //{ // Console.WriteLine("Team info: {0}", team.ToString()); // users = gitHubAPI.GetTeamMembers(team.id); // foreach (GitHubUser user in users) // Loop through List with foreach. // { // Console.WriteLine("User info: {0}", user.ToString()); // } //} /// User Operations //GitHubUser gitHubUser = gitHubAPI.GetGitHubUser(); //Console.WriteLine("User1 info: {0}", gitHubUser.ToString()); //GitHubUser gitHubUser2 = gitHubAPI.GetGitHubUser2(); //Console.WriteLine("User2 info: {0}", gitHubUser2.ToString()); //GitHubUser gitHubUser3 = gitHubAPI.GetGitHubUser3(); //Console.WriteLine("User3 info: {0}", gitHubUser3.ToString()); //List<GitHubUser> users = new List<GitHubUser>(); //users = gitHubAPI.GetAllUsers(); //foreach (GitHubUser user in users) // Loop through List with foreach. //{ // Console.WriteLine("User info: {0}", user.ldap_dn); //} Console.ReadKey(true); } catch (Exception ex) { Console.WriteLine("Exception caught: {0}", ex); Console.ReadKey(true); } }
static void Main(string[] args) { try { RestSharpAPI restSharpAPI = new RestSharpAPI(baseUrl); //RestClient client = restSharpAPI.getClient(); //works RestClient client = restSharpAPI.getClient(user, password); // works if (restSharpAPI == null || client == null) { Console.WriteLine("restSharpAPI or client is null"); Environment.Exit(1); } NexusAPI nexusAPI = new NexusAPI(restSharpAPI, client); //nexusAPI.testDelete(); //Console.ReadKey(true); List <NexusContent> contents = new List <NexusContent>(); string repository = "otpp-snapshots"; //string repository = "releases"; string pattern = ".zip"; int days = 0; contents = nexusAPI.getContent(repository, "/"); nexusAPI.findArtifacts(repository, contents, days, pattern); Console.WriteLine("Size of artifacts: {0}", nexusAPI.urls.Count); nexusAPI.removeLastFromList(repository); for (int i = nexusAPI.urls.Count - 1; i >= 0; i--) { nexusAPI.urls[i].TrimEnd('/'); int local = nexusAPI.urls[i].IndexOf("/local/"); nexusAPI.urls[i] = nexusAPI.urls[i].Substring(local + 6); Console.WriteLine("URL to be deleted: {0}", nexusAPI.urls[i]); } //nexusAPI.deleteArtifact(nexusAPI.urls, repository); Console.ReadKey(true); List <NexusRepo> repos = new List <NexusRepo>(); repos = nexusAPI.GetAllRepos(); if (repos == null) { Console.WriteLine("repos is null"); Console.ReadKey(true); Environment.Exit(1); } else { Console.WriteLine("Size of repos: {0}", repos.Count); } foreach (NexusRepo repo in repos) { // Console.WriteLine("Repo info: {0}", repo.ToString()); } //nexusAPI.uploadArtifact(); //nexusAPI.uploadArtifact1(); //nexusAPI.uploadArtifact2(); //nexusAPI.uploadArtifact3(); //List<NexusArtifact> artifacts = new List<NexusArtifact>(); //artifacts = nexusAPI.searchMetadata(); //if (artifacts == null) //{ // Console.WriteLine("artifacts is null"); // Console.ReadKey(true); // Environment.Exit(1); //} //else { // Console.WriteLine("Size of repos: {0}", artifacts.Count); //} Console.ReadKey(true); } catch (Exception ex) { Console.WriteLine("Exception caught: {0}", ex); Console.ReadKey(true); } }
List <string> urls = new List <string>(); // foler URL to be deleted /// <summary> /// Initializes a new instance of the <see cref="GitHubAPI"/> class. /// </summary> /// <param name="client">The RestClient.</param> public NexusAPI(RestSharpAPI restSharpAPI, RestClient client) { this.restSharpAPI = restSharpAPI; this.client = client; }