This repository was archived by the owner on Feb 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathProjects.cs
More file actions
112 lines (93 loc) · 3.69 KB
/
Projects.cs
File metadata and controls
112 lines (93 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System.Collections.Generic;
using EasyHttp.Http;
using TeamCitySharp.Connection;
using TeamCitySharp.DomainEntities;
namespace TeamCitySharp.ActionTypes
{
using System.Net;
using EasyHttp.Infrastructure;
internal class Projects : IProjects
{
private readonly TeamCityCaller _caller;
internal Projects(TeamCityCaller caller)
{
_caller = caller;
}
public List<Project> All()
{
var projectWrapper = _caller.Get<ProjectWrapper>("/app/rest/projects");
return projectWrapper.Project;
}
public Project ByName(string projectLocatorName)
{
return GetProject(string.Format("name:{0}", projectLocatorName));
}
public Project ById(string projectLocatorId)
{
return GetProject(projectLocatorId);
}
public Project Details(Project project)
{
return ById(project.Id);
}
public Project Create(string projectName)
{
return _caller.Post<Project>(projectName, HttpContentTypes.TextPlain, "/app/rest/projects/", HttpContentTypes.ApplicationJson);
}
public bool SetName(string projectCode, string name)
{
try
{
var response = _caller.Put(name, HttpContentTypes.TextPlain, string.Format("/app/rest/projects/{0}/name", projectCode), null);
return response.StatusCode == HttpStatusCode.OK;
}
catch (HttpException ex)
{
if (ex.StatusCode == HttpStatusCode.NotFound)
{
return false;
}
throw;
}
}
public Project Create(string projectName, string projectId)
{
var content = string.Format
(@"<newProjectDescription name='{0}' id='{1}' copyAllAssociatedSettings='true'> </newProjectDescription>"
, projectName, projectId);
/* extended xml version:
* <newProjectDescription name='New Project Name' id='newProjectId' copyAllAssociatedSettings='true'><parentProject locator='id:project1'/><sourceProject locator='id:project2'/></newProjectDescription>
* more details could be found in documentation: https://confluence.jetbrains.com/display/TCD9/REST+API#RESTAPI-ProjectSettings
*/
return _caller.Post<Project>(content, HttpContentTypes.ApplicationXml, "/app/rest/projects/", HttpContentTypes.ApplicationJson);
}
public void Delete(string projectName)
{
_caller.DeleteFormat("/app/rest/projects/name:{0}", projectName);
}
public void DeleteProjectParameter(string projectName, string parameterName)
{
_caller.DeleteFormat("/app/rest/projects/name:{0}/parameters/{1}", projectName, parameterName);
}
public void SetProjectParameter(string projectName, string settingName, string settingValue)
{
_caller.PutFormat(settingValue, "/app/rest/projects/name:{0}/parameters/{1}", projectName, settingName);
}
private Project GetProject(string locator)
{
try
{
var project = _caller.GetFormat<Project>("/app/rest/projects/{0}", locator);
return project;
}
catch (HttpException ex)
{
if (ex.StatusCode == HttpStatusCode.NotFound)
{
return null;
}
throw;
}
}
}
}