Skip to content

Commit ae6f372

Browse files
committed
v1.0.8
- Added CLAR_DOWNLOAD feature
1 parent 2ff3d02 commit ae6f372

File tree

5 files changed

+94
-27
lines changed

5 files changed

+94
-27
lines changed

CLARiNET.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<PackageIcon>CLARiNET.ico</PackageIcon>
88
<PackageIconUrl />
99
<ApplicationIcon>CLARiNET.ico</ApplicationIcon>
10-
<Version>1.0.6</Version>
10+
<Version>1.0.8</Version>
1111
</PropertyGroup>
1212

1313
<ItemGroup>

CommandLineOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ namespace CLARiNET
99
{
1010
public class Options
1111
{
12-
[Value(index: 0, MetaName = "Command", Required = false, HelpText = "CLARiNET Commands:\n\nCLAR_UPLOAD\nDRIVE_UPLOAD\nDRIVE_TRASH")]
12+
[Value(index: 0, MetaName = "Command", Required = false, HelpText = "CLARiNET Commands:\n\nCLAR_UPLOAD\nCLAR_DOWNLOAD\nDRIVE_UPLOAD\nDRIVE_TRASH")]
1313
public string Command { get; set; }
1414

1515
[Value(index: 1, MetaName = "File or Directory", Required = false, HelpText = "Path or Path and file name")]
1616
public string Path { get; set; }
1717

18-
[Value(index: 2, MetaName = "Parameters", Required = false, HelpText = "Parameters for the command (For CLAR_UPLOAD, enter the Cloud Collection)")]
18+
[Value(index: 2, MetaName = "Parameters", Required = false, HelpText = "Parameters for the command (For CLAR_UPLOAD and CLAR_DOWNLOAD, enter the Cloud Collection)")]
1919
public string Parameters { get; set; }
2020

2121
[Value(index: 3, MetaName = "Environment Number", Required = false, HelpText = "Number associated with a Workday environment (list all with -w parameter)")]

Program.cs

Lines changed: 80 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
using System.IO;
55
using CommandLine;
66
using System.Reflection;
7+
using System.Net;
8+
using System.Text;
9+
using System.Xml.XPath;
10+
using System.Xml;
711

812
namespace CLARiNET
913
{
@@ -56,16 +60,15 @@ static void Main(string[] args)
5660
// Option UI
5761
OptionsUI();
5862

63+
// Post Init and UI Option Handling
5964
switch (options.Command)
6065
{
6166
case Command.CLAR_UPLOAD:
62-
cloudCollection = options.Parameters;
67+
case Command.CLAR_DOWNLOAD:
6368
break;
6469
case Command.DRIVE_UPLOAD:
65-
soapUrl = SoapUrlBuild();
66-
break;
6770
case Command.DRIVE_TRASH:
68-
soapUrl = SoapUrlBuild();
71+
soapUrl = SoapUrlBuild(options.Command);
6972
break;
7073
}
7174

@@ -76,12 +79,20 @@ static void Main(string[] args)
7679

7780
files = Directory.GetFiles(options.Path, searchPattern, new EnumerationOptions { MatchCasing = MatchCasing.CaseInsensitive });
7881

79-
if (options.Command == Command.DRIVE_TRASH)
80-
{
81-
if (files.Length > 0)
82-
{
83-
files = File.ReadAllLines(files[0]);
84-
}
82+
// Special file handling
83+
switch (options.Command)
84+
{
85+
case Command.CLAR_DOWNLOAD:
86+
files = new string[] { Path.Combine(options.Path, options.Parameters + "." + DateTime.Now.ToString("s").Replace(":", ".") + ".clar") };
87+
break;
88+
case Command.DRIVE_TRASH:
89+
if (files.Length > 0)
90+
{
91+
files = File.ReadAllLines(files[0]);
92+
}
93+
break;
94+
default:
95+
break;
8596
}
8697

8798
foreach (string file in files)
@@ -93,7 +104,18 @@ static void Main(string[] args)
93104
case Command.CLAR_UPLOAD:
94105
bytes = File.ReadAllBytes(file);
95106
Console.WriteLine("\n\nDeploying the CLAR and awaiting the result...\n\n");
96-
result = WDWebService.CallRest(options.Tenant, options.Username + "@" + options.Tenant, options.Password, restUrl, "PUT", bytes);
107+
result = Encoding.Default.GetString(WDWebService.CallRest(options.Tenant, options.Username + "@" + options.Tenant, options.Password, restUrl, WebRequestMethods.Http.Put, bytes));
108+
break;
109+
case Command.CLAR_DOWNLOAD:
110+
Console.WriteLine("\n\nDownloading the CLAR and awaiting the result...\n\n");
111+
bytes = WDWebService.CallRest(options.Tenant, options.Username + "@" + options.Tenant, options.Password, restUrl + "?fmt=clar", WebRequestMethods.Http.Get, null);
112+
File.WriteAllBytes(file, bytes);
113+
result = Encoding.Default.GetString(WDWebService.CallRest(options.Tenant, options.Username + "@" + options.Tenant, options.Password, restUrl, WebRequestMethods.Http.Get, null));
114+
File.WriteAllText(file.Replace(".clar", ".xml"), result);
115+
XDocument xDoc = XDocument.Parse(result);
116+
XmlNamespaceManager xnm = new XmlNamespaceManager(new NameTable());
117+
xnm.AddNamespace("default", "urn:com.workday/esb/cloud/10.0");
118+
result = "Last Uploaded to Workday: " + DateTime.Parse(xDoc.XPathSelectElement("//default:deployed-since", xnm).Value).ToLocalTime().ToString("s");
97119
break;
98120
case Command.DRIVE_UPLOAD:
99121
bytes = File.ReadAllBytes(file);
@@ -222,13 +244,25 @@ static bool InitOptions(string[] args)
222244
options.Command = options.Command.Trim().ToUpper();
223245
}
224246

225-
// Set search pattern if parameters are included.
247+
// Set search pattern and cloud collection if parameters are included.
226248
if (options != null && options.Parameters != null)
227249
{
228-
if (options.Command != Command.CLAR_UPLOAD)
250+
switch (options.Command)
229251
{
230-
searchPattern = options.Parameters;
231-
}
252+
case Command.CLAR_UPLOAD:
253+
case Command.CLAR_DOWNLOAD:
254+
cloudCollection = options.Parameters;
255+
if (options.Command == Command.CLAR_DOWNLOAD)
256+
{
257+
searchPattern = "";
258+
options.Parameters = Path.GetFileName(Path.TrimEndingDirectorySeparator(options.Parameters));
259+
}
260+
break;
261+
case Command.DRIVE_UPLOAD:
262+
case Command.DRIVE_TRASH:
263+
searchPattern = options.Parameters;
264+
break;
265+
}
232266
}
233267

234268
return true;
@@ -282,9 +316,10 @@ static void CommandOption()
282316
// Check for valid commands
283317
switch (options.Command)
284318
{
285-
case Command.DRIVE_UPLOAD:
286-
case Command.DRIVE_TRASH:
287319
case Command.CLAR_UPLOAD:
320+
case Command.CLAR_DOWNLOAD:
321+
case Command.DRIVE_UPLOAD:
322+
case Command.DRIVE_TRASH:
288323
break;
289324
default:
290325
throw new Exception("Invalid command. Please use --help for a list of valid commands.");
@@ -301,6 +336,7 @@ static void PathOption()
301336
switch (options.Command)
302337
{
303338
case Command.CLAR_UPLOAD:
339+
case Command.CLAR_DOWNLOAD:
304340
options.Path = appDir;
305341
break;
306342
case Command.DRIVE_UPLOAD:
@@ -321,11 +357,16 @@ static void ParameterOption()
321357
switch (options.Command)
322358
{
323359
case Command.CLAR_UPLOAD:
360+
case Command.CLAR_DOWNLOAD:
324361
Console.WriteLine("Enter the Cloud Collection:\n");
325362
cloudCollection = Console.ReadLine().Trim();
326-
Console.WriteLine("");
363+
Console.WriteLine("");
327364
options.Parameters = cloudCollection;
328365
searchPattern = "*.clar";
366+
if (options.Command == Command.CLAR_DOWNLOAD)
367+
{
368+
searchPattern = "";
369+
}
329370
break;
330371
case Command.DRIVE_UPLOAD:
331372
options.Parameters = "*.*";
@@ -337,6 +378,7 @@ static void ParameterOption()
337378
break;
338379
}
339380
}
381+
340382
Console.WriteLine("Using parameters: " + options.Parameters + "\n");
341383
}
342384

@@ -357,7 +399,17 @@ static void FilesCheck()
357399
}
358400
else
359401
{
360-
throw new Exception("No files found.");
402+
if (options.Command == Command.CLAR_DOWNLOAD)
403+
{
404+
if (!Directory.Exists(options.Path))
405+
{
406+
throw new Exception("Directory does not exist.");
407+
}
408+
}
409+
else
410+
{
411+
throw new Exception("No files found.");
412+
}
361413
}
362414
}
363415

@@ -430,11 +482,18 @@ static void PasswordOption()
430482
}
431483
}
432484

433-
static string SoapUrlBuild()
485+
static string SoapUrlBuild(string command)
434486
{
435487
string soapUrl = ccxUrl.Replace("{host}", host);
436488
soapUrl = WDWebService.GetServiceURL(soapUrl, options.Tenant, options.Username, options.Password);
437-
soapUrl += "/{tenant}/Drive/{version}";
489+
switch (options.Command)
490+
{
491+
case Command.DRIVE_UPLOAD:
492+
case Command.DRIVE_TRASH:
493+
soapUrl += "/{tenant}/Drive/{version}";
494+
break;
495+
}
496+
438497
return soapUrl;
439498
}
440499

Strings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace CLARiNET
99
public struct Command
1010
{
1111
public const string CLAR_UPLOAD = "CLAR_UPLOAD";
12+
public const string CLAR_DOWNLOAD = "CLAR_DOWNLOAD";
1213
public const string DRIVE_UPLOAD = "DRIVE_UPLOAD";
1314
public const string DRIVE_TRASH = "DRIVE_TRASH";
1415
public const string DRIVE_DOWNLOAD = "DRIVE_DOWNLOAD";

WDWebService.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace CLARiNET
1212
{
1313
public class WDWebService
1414
{
15-
public static string CallRest(string tenant, string username, string password, string url, string method, byte[] data)
15+
public static byte[] CallRest(string tenant, string username, string password, string url, string method, byte[] data)
1616
{
1717
using (var webClient = new WebClient())
1818
{
@@ -24,10 +24,17 @@ public static string CallRest(string tenant, string username, string password, s
2424
webClient.Credentials = new NetworkCredential(username, password);
2525
webClient.Headers.Add("X-Originator", "CLARiNET");
2626
webClient.Headers.Add("X-Tenant", tenant);
27-
return Encoding.Default.GetString(webClient.UploadData(url, data));
27+
if (method == WebRequestMethods.Http.Get)
28+
{
29+
return webClient.DownloadData(url);
30+
}
31+
else
32+
{
33+
return webClient.UploadData(url, data);
34+
}
2835
}
2936
}
30-
return "";
37+
return null;
3138
}
3239

3340
public static string WrapSOAP(string username, string password, string xmlBody)

0 commit comments

Comments
 (0)