-
Notifications
You must be signed in to change notification settings - Fork 0
/
MoveItemAction.cs
78 lines (67 loc) · 2.35 KB
/
MoveItemAction.cs
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Web;
using Inedo.BuildMaster;
using Inedo.BuildMaster.Extensibility.Actions;
using Inedo.BuildMaster.Web;
namespace Inedo.BuildMasterExtensions.Artifactory
{
[ActionProperties(
"Move Item",
"Moves an item to a new location.")]
[Tag("Artifactory")]
[CustomEditor(typeof(MoveItemActionEditor))]
public class MoveItemAction : ArtifactoryActionBase
{
[Persistent]
public string SourceItemName { get; set; }
[Persistent]
public string DestinationRepository { get; set; }
[Persistent]
public string DestinationItemName { get; set; }
[Persistent]
public bool SuppressCrossLayoutTranslation { get; set; }
public override string ToString()
{
return string.Format("Move {0} in repository {1} to {2} in repository {3}", this.SourceItemName, this.RepositoryKey,
this.DestinationItemName, this.DestinationRepository);
}
public MoveItemAction()
{
this.UsesRepositoryKey = true;
}
internal string Test()
{
return ProcessRemoteCommand(null, null);
}
protected override void Execute()
{
this.ExecuteRemoteCommand(null);
}
protected override string ProcessRemoteCommand(string name, string[] args)
{
return MakeRequest();
}
internal string MakeRequest()
{
string url = this.Server.EndsWith("/") ? this.Server : this.Server + "/" +
"api/move/{0}/{1}?to={2}/{3}";
if (this.SuppressCrossLayoutTranslation)
{
url += "&suppressLayouts=1";
}
var resp = Request(RequestType.Post,null,url,this.RepositoryKey, this.SourceItemName,
this.DestinationRepository, this.DestinationItemName);
if (HttpStatusCode.OK!= resp.StatusCode)
{
LogError("Error moving {0} in repository {1} to {2} in repository {3}. Error code is {4}", this.SourceItemName, this.RepositoryKey,
this.DestinationItemName, this.DestinationRepository, resp.StatusCode);
return null;
}
return "OK";
}
}
}