예제 #1
0
        private object ResolveUsers(ApiCall apiCall)
        {
            if (apiCall.Method == HttpMethod.Get)
            {
                if (!apiCall.HasLocatorSegment)
                {
                    // [Headers("Accept: application/json")]
                    // [Get("/app/rest/users")]
                    // Task<UserListDto> Users();
                    return(this.Users.All());
                }
                else if (apiCall.HasLocator("username"))
                {
                    // [Headers("Accept: application/json")]
                    // [Get("/app/rest/users/{locator}")]
                    // Task<UserDto> Users([AliasAs("locator")] string userLocator);
                    return(this.Users.ByUsername(apiCall.GetLocator("username")));
                }
                else
                {
                    // [Headers("Accept: application/json")]
                    // [Get("/app/rest/users/{locator}")]
                    // Task<UserDto> Users([AliasAs("locator")] string userLocator);
                    return(this.Users.ById(apiCall.GetLocator()));
                }
            }

            throw new NotImplementedException($"End-point {apiCall.Method} : {apiCall.RequestPath} not implemented.");
        }
예제 #2
0
        private object ResolveProjects(ApiCall apiCall)
        {
            if (apiCall.Method == HttpMethod.Post)
            {
                // [Headers("Accept: application/json", "Content-Type: application/xml")]
                // [Post("/app/rest/projects")]
                // Task<ProjectDto> CreateProject([Body] string projectDescriptionXml);
                return(this.Projects.Create(apiCall.Content));
            }
            else if (apiCall.Method == HttpMethod.Get)
            {
                if (!apiCall.HasLocatorSegment)
                {
                    // [Headers("Accept: application/json")]
                    // [Get("/app/rest/projects")]
                    // Task<ProjectListDto> Projects();
                    return(this.Projects.All());
                }
                else
                {
                    // [Headers("Accept: application/json")]
                    // [Get("/app/rest/projects/{id}")]
                    // Task<ProjectDto> Project(string id);
                    return(this.Projects.ById(apiCall.GetLocator()));
                }
            }
            else if (apiCall.Method == HttpMethod.Put)
            {
                if (apiCall.PropertySegment == "parameters")
                {
                    // [Put("/app/rest/projects/{id}/parameters/{name}")]
                    // Task SetProjectParameter([AliasAs("id")] string projectId, string name, [Body] string value);
                    var id    = apiCall.GetLocator();
                    var name  = apiCall.DescriptorSegment;
                    var value = apiCall.Content;
                    return(this.Projects.SetParameter(id, name, value));
                }
            }
            else if (apiCall.Method == HttpMethod.Delete)
            {
                // [Headers("Accept: application/json")]
                // [Delete("/app/rest/projects/{locator}")]
                // Task DeleteProject([AliasAs("locator")] string projectLocator);
                return(this.Projects.Delete(apiCall.GetLocator()));
            }

            throw new NotImplementedException($"End-point {apiCall.Method} : {apiCall.RequestPath} not implemented.");
        }
예제 #3
0
        private object ResolveAgents(ApiCall apiCall)
        {
            if (apiCall.Method == HttpMethod.Put)
            {
                // [Headers("Accept: text/plain", "Content-Type: text/plain")]
                // [Put("/app/rest/agents/{locator}/enabled")]
                // Task EnableAgent([AliasAs("locator")] string agentlocator, [Body(BodySerializationMethod.Serialized)] bool enable);
                var id = apiCall.GetLocator();
                if (apiCall.Content == "false")
                {
                    return(BuildAgents.Disable(id));
                }
                else if (apiCall.Content == "true")
                {
                    return(BuildAgents.Enable(id));
                }
            }
            else
            {
                // [Headers("Accept: application/json")]
                // [Get("/app/rest/agents")]
                // Task<BuildAgentListDto> Agents();

                // [Headers("Accept: application/json")]
                // [Get("/app/rest/agents/{locator}")]
                // Task<BuildAgentDto> Agent([AliasAs("locator")] string agentlocator);
                return(Resolve <BuildAgentDto, BuildAgentListDto>(apiCall, BuildAgents));
            }

            throw new NotImplementedException($"End-point {apiCall.Method} : {apiCall.RequestPath} not implemented.");
        }
예제 #4
0
 private object Resolve <TDto, TListDto>(ApiCall apiCall, BaseRepository <TDto, TListDto> repository)
     where TDto : IdDto
     where TListDto : ListDto <TDto>, new()
 {
     if (apiCall.Method == HttpMethod.Get)
     {
         if (!apiCall.HasLocatorSegment)
         {
             return(repository.All());
         }
         else
         {
             return(repository.ById(apiCall.GetLocator()));
         }
     }
     else if (apiCall.Method == HttpMethod.Delete)
     {
         return(repository.Delete(apiCall.GetLocator()));
     }
     else
     {
         throw new NotImplementedException($"End-point {apiCall.Method} : {apiCall.RequestPath} not implemented.");
     }
 }
예제 #5
0
        private object ResolveVcsRoots(ApiCall apiCall)
        {
            if (apiCall.Method == HttpMethod.Post)
            {
                // [Headers("Accept: application/json", "Content-Type: application/xml")]
                // [Post("/app/rest/vcs-roots")]
                // Task<VcsRootDto> CreateVcsRoot([Body] string vcsRootXml);
                return(this.VcsRoots.Create(apiCall.Content));
            }
            else if (apiCall.Method == HttpMethod.Get)
            {
                if (!apiCall.HasLocatorSegment)
                {
                    // [Headers("Accept: application/json")]
                    // [Get("/app/rest/vcs-roots")]
                    // Task<VcsRootListDto> VcsRoots();
                    return(this.VcsRoots.All());
                }
                else
                {
                    // [Headers("Accept: application/json")]
                    // [Get("/app/rest/vcs-roots/{id}")]
                    // Task<VcsRootDto> VcsRoot(string id);
                    return(this.VcsRoots.ById(apiCall.GetLocator()));
                }
            }
            else if (apiCall.Method == HttpMethod.Delete)
            {
                // [Headers("Accept: application/json")]
                // [Delete("/app/rest/vcs-roots/{locator}")]
                // Task DeleteVcsRoot([AliasAs("locator")] string vcsRootLocator);
                return(this.VcsRoots.Delete(apiCall.GetLocator()));
            }

            throw new NotImplementedException($"End-point {apiCall.Method} : {apiCall.RequestPath} not implemented.");
        }
예제 #6
0
        private object ResolveBuildQueue(ApiCall apiCall)
        {
            if (apiCall.Method == HttpMethod.Post)
            {
                if (!apiCall.HasLocatorSegment)
                {
                    // [Headers("Accept: application/json")]
                    // [Post("/app/rest/buildQueue")]
                    // Task<TriggeredBuildDto> TriggerBuild([Body] TriggerBuildRequestDto value);
                    var request = JsonConvert.DeserializeObject <TriggerBuildRequestDto>(apiCall.Content);
                    return(BuildQueue.TriggerBuild(Builds, Users.ById("1"), request));
                }
                else
                {
                    // [Headers("Accept: application/json")]
                    // [Post("/app/rest/buildQueue/{id}")]
                    // Task RemoveQueuedBuild([AliasAs("id")] string buildId, [Body] BuildCancelRequestDto value);
                    var request = JsonConvert.DeserializeObject <BuildCancelRequestDto>(apiCall.Content);
                    var id      = apiCall.GetLocator();
                    BuildQueue.CancelBuild(id, Users.ById("1"), request);
                    return(id);
                }
            }
            else if (apiCall.Method == HttpMethod.Get)
            {
                // [Headers("Accept: application/json")]
                // [Get("/app/rest/buildQueue")]
                // Task<BuildListDto> QueuedBuilds(string locator);
                return(new BuildListDto
                {
                    Items = BuildQueue
                });
            }

            throw new NotImplementedException($"End-point {apiCall.Method} : {apiCall.RequestPath} not implemented.");
        }
예제 #7
0
        private object ResolveBuilds(ApiCall apiCall)
        {
            var id = apiCall.GetLocatorOrDefault();

            if (apiCall.Method == HttpMethod.Post)
            {
                if (String.IsNullOrEmpty(apiCall.PropertySegment))
                {
                    // [Headers("Accept: application/json")]
                    // [Post("/app/rest/builds/{id}")]
                    // Task CancelBuild([AliasAs("id")] string buildId, [Body] BuildCancelRequestDto value);
                    Builds.CancelBuild(id);
                    return(id);
                }
                else
                {
                    // [Headers("Accept: application/json")]
                    // [Post("/app/rest/builds/{id}/tags/")]
                    // Task AddTag([AliasAs("id")] string buildId, [Body] string tag);
                    Builds.AddTag(id, apiCall.Content);
                    return(id);
                }
            }
            else if (apiCall.Method == HttpMethod.Get)
            {
                if (!apiCall.HasLocatorSegment)
                {
                    // [Headers("Accept: application/json")]
                    // [Get("/app/rest/builds")]
                    // Task<BuildListDto> Builds([AliasAs("locator")] string buildLocator);
                    return(Builds.All());
                }

                if (String.IsNullOrEmpty(apiCall.PropertySegment))
                {
                    // [Headers("Accept: application/json")]
                    // [Get("/app/rest/builds/{id}")]
                    // Task<BuildDto> Build(string id);
                    return(Builds.ById(apiCall.GetLocator()));
                }
                else if (apiCall.PropertySegment == "resulting-properties")
                {
                    // [Headers("Accept: application/json")]
                    // [Get("/app/rest/builds/{id}/resulting-properties")]
                    // Task<ParametersDto> ResultingProperties([AliasAs("id")] string buildId);
                    return(Builds.ResultingProperties(id));
                }
                else if (apiCall.PropertySegment == "artifacts" && apiCall.DescriptorSegment == "children")
                {
                    // [Headers("Accept: application/json")]
                    // [Get("/app/rest/builds/{id}/artifacts/children/{**path}")]
                    // Task<ArtifactFileListDto> ArtifactChildren([AliasAs("id")] string buildId, [AliasAs("path")] string artifactPath, string locator, string fields);
                    return(Builds.Artifacts(id));
                }
                else if (apiCall.PropertySegment == "artifacts" && apiCall.DescriptorSegment == "content")
                {
                    // [Get("/app/rest/builds/{id}/artifacts/content/{**path}")]
                    // Task<Stream> ArtifactContent( [AliasAs("id")] string buildId, [AliasAs("path")] string artifactPath);
                    return(Builds.Content(id));
                }
            }
            else if (apiCall.Method == HttpMethod.Put)
            {
                if (apiCall.PropertySegment == "comment")
                {
                    // [Put("/app/rest/builds/{id}/comment/")]
                    // Task SetComment([AliasAs("id")] string buildId, [Body] string comment);
                    Builds.SetComment(id, apiCall.Content);
                    return(id);
                }
                else if (apiCall.PropertySegment == "tags")
                {
                    // [Put("/app/rest/builds/{id}/tags/")]
                    // Task ReplaceTags([AliasAs("id")] string buildId, [Body] TagsDto tags);
                    Builds.ReplaceTags(id, apiCall.JsonContentAs <TagsDto>());
                    return(id);
                }
                else if (apiCall.PropertySegment == "pin")
                {
                    // [Put("/app/rest/builds/{id}/pin/")]
                    // Task Pin([AliasAs("id")] string buildId, [Body] string comment);
                    Builds.Pin(id, apiCall.Content);
                    return(id);
                }
            }
            else if (apiCall.Method == HttpMethod.Delete)
            {
                // //The standard DELETE annotation doesn't allow to include a body, so we need to use our own.
                // //Probably it would be better to change Rest API here (https://youtrack.jetbrains.com/issue/TW-49178).
                // // @DELETE_WITH_BODY("/app/rest/builds/{id}/pin/")
                // [Delete("/app/rest/builds/{id}/pin/")]
                // Task Unpin([AliasAs("id")] string buildId, [Body] string comment);
                Builds.Unpin(id);
                return(id);
            }

            throw new NotImplementedException($"End-point {apiCall.Method} : {apiCall.RequestPath} not implemented.");
        }