-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathQueueGetItemCommand.cs
More file actions
56 lines (44 loc) · 1.77 KB
/
QueueGetItemCommand.cs
File metadata and controls
56 lines (44 loc) · 1.77 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
using JenkinsNET.Models;
using System;
using System.Xml.Linq;
namespace JenkinsNET.Internal.Commands
{
internal class QueueGetItemCommand : JenkinsHttpCommand
{
public JenkinsQueueItem Result {get; private set;}
public QueueGetItemCommand(IJenkinsContext context, int itemNumber)
{
if (context == null)
throw new ArgumentNullException(nameof(context));
Url = NetPath.Combine(context.BaseUrl, "queue/item", itemNumber.ToString(), "api/xml");
UserName = context.UserName;
Password = context.Password;
ExtraHeaders = context.ExtraHeaders;
Crumb = context.Crumb;
OnWrite = request => {
request.Method = "POST";
};
OnRead = response => {
using (var stream = response.GetResponseStream()) {
if (stream == null) return;
var document = XDocument.Load(stream);
if (document.Root == null) throw new ApplicationException("An empty response was returned!");
Result = new JenkinsQueueItem(document.Root);
}
};
#if NET_ASYNC
OnWriteAsync = async (request, token) => {
request.Method = "POST";
};
OnReadAsync = async (response, token) => {
using (var stream = response.GetResponseStream()) {
if (stream == null) return;
var document = XDocument.Load(stream);
if (document.Root == null) throw new ApplicationException("An empty response was returned!");
Result = new JenkinsQueueItem(document.Root);
}
};
#endif
}
}
}