-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathJenkinsClientViews.cs
More file actions
64 lines (60 loc) · 2.09 KB
/
JenkinsClientViews.cs
File metadata and controls
64 lines (60 loc) · 2.09 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
using JenkinsNET.Exceptions;
using JenkinsNET.Internal.Commands;
using JenkinsNET.Models;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace JenkinsNET
{
/// <summary>
/// A collection of methods used for interacting with Jenkins Views API.
/// </summary>
/// <remarks>
/// Used internally by <seealso cref="JenkinsClient"/>
/// </remarks>
public sealed class JenkinsClientViews
{
private readonly IJenkinsContext _context;
internal JenkinsClientViews(IJenkinsContext context)
{
_context = context;
}
/// <summary>
/// Creates a new View in Jenkins.
/// </summary>
/// <param name="viewName">The name of the View to create.</param>
/// <param name="view">The description of the Job to create.</param>
/// <exception cref="JenkinsNetException"></exception>
public void Create(string viewName, JenkinsProject view)
{
try
{
new ViewCreateCommand(_context, viewName, view).Run();
}
catch (Exception error)
{
throw new JenkinsNetException($"Failed to create Jenkins View '{viewName}'!", error);
}
}
#if NET_ASYNC
/// <summary>
/// Creates a new View in Jenkins asynchronously.
/// </summary>
/// <param name="viewName">The name of the View to create.</param>
/// <param name="view">The description of the View to create.</param>
/// <param name="token">An optional token for aborting the request.</param>
/// <exception cref="JenkinsNetException"></exception>
public async Task CreateAsync(string viewName, JenkinsProject view, CancellationToken token = default)
{
try
{
await new ViewCreateCommand(_context, viewName, view).RunAsync(token);
}
catch (Exception error)
{
throw new JenkinsNetException($"Failed to create Jenkins Job '{viewName}'!", error);
}
}
#endif
}
}