public void CreateNewConfiguration(string repositoryName, string repositoryId, string projectName, string projectId, string personalAccessToken) { var vstsProject = new VstsProject { Name = projectName, Id = projectId, Repositories = new List <RepositoryRegistration> { new RepositoryRegistration { Name = repositoryName, Id = repositoryId, Directory = _gitConfiguration.GitDirectory } } }; //check to see if this account is in the configuration var configuration = Accounts.FirstOrDefault(x => x.AccountName.Equals(GitHost, StringComparison.OrdinalIgnoreCase)); if (configuration == null) { configuration = new VstsAccount { AccountName = _gitConfiguration.Host, PersonalAccessToken = personalAccessToken, Projects = new List <VstsProject> { vstsProject } }; Accounts.Add(configuration); } else { var existingProject = configuration.Projects.FirstOrDefault(x => x.Name.Equals(projectName, StringComparison.OrdinalIgnoreCase)); if (existingProject == null) { configuration.Projects.Add(vstsProject); } else { existingProject.Repositories.Add(new RepositoryRegistration { Directory = _gitConfiguration.GitDirectory, Id = repositoryId, Name = repositoryName }); } } var json = JsonConvert.SerializeObject(Accounts, Formatting.Indented); File.WriteAllText(VstsCliConfigPath, json); }
public void SetAccountInfo(string personalAccessToken, string fullName) { //check to see if this account is in the configuration var configuration = Accounts.FirstOrDefault(x => x.AccountName.Equals(GitHost, StringComparison.OrdinalIgnoreCase)); // Don't stomp on the existing account if (configuration != null) { return; } configuration = new VstsAccount { AccountName = _gitConfiguration.Host, PersonalAccessToken = personalAccessToken, FullName = fullName, Projects = new List <VstsProject>() }; Accounts.Add(configuration); var json = JsonConvert.SerializeObject(Accounts, Formatting.Indented); File.WriteAllText(VstsCliConfigPath, json); }