diff --git a/Jenkins.Net/Internal/Commands/NodesGetCommand.cs b/Jenkins.Net/Internal/Commands/NodesGetCommand.cs new file mode 100644 index 0000000..186bc23 --- /dev/null +++ b/Jenkins.Net/Internal/Commands/NodesGetCommand.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using JenkinsNET.Models; + +namespace JenkinsNET.Internal.Commands +{ + internal class NodesGetCommand : JenkinsHttpCommand + { + public IEnumerable Result { get; private set; } + + public NodesGetCommand(IJenkinsContext context) + { + if (context == null) + throw new ArgumentNullException(nameof(context)); + + Url = NetPath.Combine(context.BaseUrl, "computer/", "api/xml"); + + UserName = context.UserName; + Password = context.Password; + + OnWrite = request => { + request.Method = "GET"; + }; + + OnRead = response => { + var document = ReadXml(response); + Result = document.Root.WrapGroup("computer", n => new JenkinsNode(n)); + }; + + } + + } +} \ No newline at end of file diff --git a/Jenkins.Net/Jenkins.Net.csproj b/Jenkins.Net/Jenkins.Net.csproj index 77c290d..fa06ba8 100644 --- a/Jenkins.Net/Jenkins.Net.csproj +++ b/Jenkins.Net/Jenkins.Net.csproj @@ -34,6 +34,12 @@ 1591;1701;1702 + + TRACE + + + TRACE + diff --git a/Jenkins.Net/JenkinsClient.cs b/Jenkins.Net/JenkinsClient.cs index 86fd421..a33e1dd 100644 --- a/Jenkins.Net/JenkinsClient.cs +++ b/Jenkins.Net/JenkinsClient.cs @@ -65,6 +65,11 @@ public string Password { /// public JenkinsClientArtifacts Artifacts {get;} + /// + /// Group of methods for interacting with Jenkins Executors. + /// + public JenkinsClientNodes Nodes { get; } + /// /// Creates a new Jenkins Client. @@ -75,6 +80,7 @@ public JenkinsClient() Builds = new JenkinsClientBuilds(this); Queue = new JenkinsClientQueue(this); Artifacts = new JenkinsClientArtifacts(this); + Nodes = new JenkinsClientNodes(this); } /// diff --git a/Jenkins.Net/JenkinsClientJobs.cs b/Jenkins.Net/JenkinsClientJobs.cs index 3ca33e6..936f512 100644 --- a/Jenkins.Net/JenkinsClientJobs.cs +++ b/Jenkins.Net/JenkinsClientJobs.cs @@ -17,8 +17,7 @@ namespace JenkinsNET public sealed class JenkinsClientJobs { private readonly IJenkinsContext context; - - + internal JenkinsClientJobs(IJenkinsContext context) { this.context = context; diff --git a/Jenkins.Net/JenkinsClientNodes.cs b/Jenkins.Net/JenkinsClientNodes.cs new file mode 100644 index 0000000..e1d0d8c --- /dev/null +++ b/Jenkins.Net/JenkinsClientNodes.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using JenkinsNET.Exceptions; +using JenkinsNET.Internal.Commands; +using JenkinsNET.Models; + +namespace JenkinsNET +{ + public class JenkinsClientNodes + { + private readonly IJenkinsContext context; + + + internal JenkinsClientNodes(IJenkinsContext context) + { + this.context = context; + } + + /// + /// Gets the Jenkins Node information + /// + /// + public IEnumerable Get() + { + try { + var cmd = new NodesGetCommand(context); + cmd.Run(); + return cmd.Result; + } + catch (Exception error) { + throw new JenkinsNetException("Failed to retrieve Jenkins description!", error); + } + } + + } +} \ No newline at end of file diff --git a/Jenkins.Net/Models/JenkinsNode.cs b/Jenkins.Net/Models/JenkinsNode.cs new file mode 100644 index 0000000..3dd0f4f --- /dev/null +++ b/Jenkins.Net/Models/JenkinsNode.cs @@ -0,0 +1,62 @@ +using System.Diagnostics; +using System.Xml.Linq; +using System.Xml.XPath; +using JenkinsNET.Internal; + +namespace JenkinsNET.Models +{ + public class JenkinsNode + { + /// + /// Gets the base XML node. + /// + public XElement Node { get; } + + private string name; + private bool nameCached = false; + public string Name + { + get + { + if (nameCached) return name; + var node = Node.XPathSelectElement("./displayName"); + name = node?.Value; + nameCached = true; + return name; + } + } + + private string description; + private bool descriptionCached = false; + public string Description + { + get + { + if (descriptionCached) return description; + var node = Node.XPathSelectElement("./description"); + description = node?.Value; + descriptionCached = true; + return description; + } + } + + private bool online; + private bool onlineCached; + public bool Online + { + get + { + if (onlineCached) return online; + var node = Node.XPathSelectElement("./offline"); + online = node?.Value == "false"; + onlineCached = true; + return online; + } + } + + internal JenkinsNode(XElement node) + { + this.Node = node; + } + } +} \ No newline at end of file diff --git a/Jenkins.Net/Utilities/ProgressiveHtmlReader.cs b/Jenkins.Net/Utilities/ProgressiveHtmlReader.cs index ca5b132..9084c55 100644 --- a/Jenkins.Net/Utilities/ProgressiveHtmlReader.cs +++ b/Jenkins.Net/Utilities/ProgressiveHtmlReader.cs @@ -73,7 +73,7 @@ public void Update() IsComplete = true; } - #if !NET40 + #if !NET40 && NET_ASYNC /// /// Retrieves and appends any additional text returned /// by the running Jenkins Job asynchronously. diff --git a/Jenkins.Net/Utilities/ProgressiveTextReader.cs b/Jenkins.Net/Utilities/ProgressiveTextReader.cs index a29e69e..93960a1 100644 --- a/Jenkins.Net/Utilities/ProgressiveTextReader.cs +++ b/Jenkins.Net/Utilities/ProgressiveTextReader.cs @@ -73,7 +73,7 @@ public void Update() IsComplete = true; } - #if !NET40 + #if !NET40 && NET_ASYNC /// /// Retrieves and appends any additional text returned /// by the running Jenkins Job asynchronously.