Skip to content

Commit 64eaa2d

Browse files
author
JoshuaMiller
committed
async method repairs
1 parent e68e801 commit 64eaa2d

17 files changed

Lines changed: 110 additions & 87 deletions

Jenkins.Net/Internal/Commands/ArtifactGetCommand.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,28 @@ public ArtifactGetCommand(IJenkinsContext context, string jobName, string buildN
4747
}
4848
}
4949
};
50+
51+
#if NET_ASYNC
52+
OnWriteAsync = async (request, token) => {
53+
request.Method = "POST";
54+
};
55+
56+
OnReadAsync = async (response, token) => {
57+
using (var stream = response.GetResponseStream()) {
58+
if (stream == null) return;
59+
60+
try {
61+
Result = new MemoryStream();
62+
await stream.CopyToAsync(Result);
63+
Result.Seek(0, SeekOrigin.Begin);
64+
}
65+
catch {
66+
Result?.Dispose();
67+
throw;
68+
}
69+
}
70+
};
71+
#endif
5072
}
5173
}
5274
}

Jenkins.Net/Internal/Commands/BuildGetCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public BuildGetCommand(IJenkinsContext context, string jobName, string buildNumb
3535
Result = Activator.CreateInstance(typeof(T), args) as T;
3636
};
3737

38-
#if !NET40
38+
#if NET_ASYNC
3939
OnWriteAsync = async (request, token) => {
4040
request.Method = "POST";
4141
};

Jenkins.Net/Internal/Commands/BuildOutputCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public BuildOutputCommand(IJenkinsContext context, string jobName, string buildN
3636
}
3737
};
3838

39-
#if !NET40
39+
#if NET_ASYNC
4040
OnReadAsync = async (response, token) => {
4141
using (var stream = response.GetResponseStream()) {
4242
if (stream == null) return;

Jenkins.Net/Internal/Commands/BuildProgressiveHtmlCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public BuildProgressiveHtmlCommand(IJenkinsContext context, string jobName, stri
6060
}
6161
};
6262

63-
#if !NET40
63+
#if NET_ASYNC
6464
OnWriteAsync = async (request, token) => {
6565
request.Method = "POST";
6666
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";

Jenkins.Net/Internal/Commands/BuildProgressiveTextCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public BuildProgressiveTextCommand(IJenkinsContext context, string jobName, stri
6060
}
6161
};
6262

63-
#if NETFULL
63+
#if NET_ASYNC
6464
OnWriteAsync = async (request, token) => {
6565
request.Method = "POST";
6666
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";

Jenkins.Net/Internal/Commands/CrumbGetCommand.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ public CrumbGetCommand(IJenkinsContext context)
3232
Result = new JenkinsCrumb(document.Root);
3333
}
3434
};
35+
36+
#if NET_ASYNC
37+
OnWriteAsync = async (request, token) => {
38+
request.Method = "GET";
39+
};
40+
41+
OnReadAsync = async (response, token) => {
42+
using (var stream = response.GetResponseStream()) {
43+
if (stream == null) return;
44+
45+
var document = XDocument.Load(stream);
46+
if (document.Root == null) throw new ApplicationException("An empty response was returned!");
47+
48+
Result = new JenkinsCrumb(document.Root);
49+
}
50+
};
51+
#endif
3552
}
3653
}
3754
}

Jenkins.Net/Internal/Commands/JenkinsGetCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public JenkinsGetCommand(IJenkinsContext context)
2828
Result = new Jenkins(document.Root);
2929
};
3030

31-
#if NETFULL
31+
#if NET_ASYNC
3232
OnWriteAsync = async (request, token) => {
3333
request.Method = "GET";
3434
};

Jenkins.Net/Internal/Commands/JobBuildCommand.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ public JobBuildCommand(IJenkinsContext context, string jobName)
3232
QueueItemUrl = response.GetResponseHeader("Location")
3333
};
3434
};
35+
36+
#if NET_ASYNC
37+
OnWriteAsync = async (request, token) => {
38+
request.Method = "POST";
39+
};
40+
41+
OnReadAsync = async (response, token) => {
42+
if (response.StatusCode != System.Net.HttpStatusCode.Created)
43+
throw new JenkinsJobBuildException($"Expected HTTP status code 201 but found {(int)response.StatusCode}!");
44+
45+
Result = new JenkinsBuildResult {
46+
QueueItemUrl = response.GetResponseHeader("Location")
47+
};
48+
};
49+
#endif
3550
}
3651
}
3752
}

Jenkins.Net/Internal/Commands/JobBuildWithParametersCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public JobBuildWithParametersCommand(IJenkinsContext context, string jobName, ID
4646
};
4747
};
4848

49-
#if NETFULL
49+
#if NET_ASYNC
5050
OnWriteAsync = async (request, token) => {
5151
request.Method = "POST";
5252
};

Jenkins.Net/Internal/Commands/JobCreateCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public JobCreateCommand(IJenkinsContext context, string jobName, JenkinsProject
2929
WriteXml(request, job.Node);
3030
};
3131

32-
#if !NET40
32+
#if NET_ASYNC
3333
OnWriteAsync = async (request, token) => {
3434
request.Method = "POST";
3535
request.ContentType = "application/xml";

0 commit comments

Comments
 (0)