Skip to content

Commit c4e9617

Browse files
committed
v1.2.1
- Added Candidate Attachment Upload - Command Line Creator with "c" option.
1 parent 01526d7 commit c4e9617

File tree

7 files changed

+235
-89
lines changed

7 files changed

+235
-89
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.2.0</Version>
10+
<Version>1.2.1</Version>
1111
</PropertyGroup>
1212

1313
<ItemGroup>

CandidateAttachment.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Xml;
8+
using System.Xml.Linq;
9+
using System.Xml.XPath;
10+
11+
namespace CLARiNET
12+
{
13+
internal static class CandidateAttachments
14+
{
15+
public static string Upload(string file, byte[] bytes, string soapUrl, string processedDir, Options options)
16+
{
17+
string xmlData = "";
18+
string result = "";
19+
20+
try
21+
{
22+
xmlData = Resources.Put_Candidate_Attachment_Request;
23+
string[] fileVars = Path.GetFileName(file).Split("~");
24+
if (fileVars.Length > 1)
25+
{
26+
Console.WriteLine("\n\nProcessing {0} for {1} on {2}", fileVars[2], fileVars[0], fileVars[1]);
27+
string candidateId = fileVars[0];
28+
string applicationId = fileVars[1];
29+
string filename = fileVars[2];
30+
string comment = "";
31+
// worker id ~ filename
32+
// TODO: Manifest for comment and content type?
33+
xmlData = xmlData.Replace("{candidateId}", candidateId)
34+
.Replace("{applicationId}", applicationId)
35+
.Replace("{filename}", filename)
36+
.Replace("{filedata}", Convert.ToBase64String(bytes))
37+
.Replace("{comment}", comment);
38+
39+
result = WDWebService.CallAPI(options.Username + "@" + options.Tenant, options.Password, soapUrl, xmlData);
40+
if (result.IndexOf("<?xml") == 0)
41+
{
42+
string processedFile = Path.Combine(processedDir, Path.GetFileName(file));
43+
int num = 2;
44+
while (File.Exists(processedFile) && num < 100)
45+
{
46+
processedFile = Path.Combine(processedDir, Path.GetFileNameWithoutExtension(file) + "." + num.ToString("000") + Path.GetExtension(file));
47+
num++;
48+
}
49+
File.Move(file, processedFile);
50+
result = String.Format("Processed {0} for {1}", filename, candidateId);
51+
}
52+
}
53+
}
54+
catch (Exception ex)
55+
{
56+
Console.WriteLine("\n\nError: " + ex.Message);
57+
Console.WriteLine("\n");
58+
}
59+
60+
return result;
61+
}
62+
}
63+
}

CommandLineOptions.cs

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

1515
[Value(index: 1, MetaName = "File or Directory", Required = false, HelpText = "Path or Path and file name")]
@@ -28,7 +28,12 @@ public class Options
2828
public string Username { get; set; }
2929

3030
[Value(index: 6, MetaName = "Password", Required = false, HelpText = "Password (must be encrypted using the -e option)")]
31-
public string Password { get; set; }
31+
public string Password { get; set; }
32+
33+
[Option('c', "commandline", Required = false,
34+
HelpText =
35+
"Display the commandline and exit without executing the commands.")]
36+
public bool PrintCommandline { get; set; }
3237

3338
[Option('e', "encrypt", Required = false,
3439
HelpText =

Program.cs

Lines changed: 126 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,45 @@ static void Main(string[] args)
5757
return;
5858
}
5959

60-
// Option UI
61-
OptionsUI();
60+
61+
if (options != null)
62+
{
63+
// Command
64+
CommandOption();
65+
CommandValidate();
66+
// Path
67+
PathOption();
68+
PathValidate();
69+
// Parameters
70+
ParameterOption();
71+
ParameterValidate();
72+
// Files Check
73+
FilesCheck();
74+
// Environment
75+
EnvironmentOption();
76+
// Tenant
77+
TenantOption();
78+
// Username
79+
UsernameOption();
80+
// Password
81+
PasswordOption();
82+
}
83+
84+
if (options.PrintCommandline)
85+
{
86+
Console.WriteLine("\n\n");
87+
Console.WriteLine("clarinet {0} {1} {2} {3} {4} {5} {6}",
88+
options.Command,
89+
options.Path,
90+
options.Parameters,
91+
options.EnvNum,
92+
options.Tenant,
93+
options.Username,
94+
Crypto.Protect(options.Password));
95+
Console.WriteLine("\n\n");
96+
return;
97+
}
98+
6299

63100
// Post Init and UI Option Handling
64101
switch (options.Command)
@@ -71,6 +108,7 @@ static void Main(string[] args)
71108
case Command.PHOTO_DOWNLOAD:
72109
case Command.PHOTO_UPLOAD:
73110
case Command.DOCUMENT_UPLOAD:
111+
case Command.CANDIDATE_ATTACHMENT_UPLOAD:
74112
soapUrl = SoapUrlBuild(options.Command);
75113
break;
76114
}
@@ -111,6 +149,9 @@ static void Main(string[] args)
111149
case Command.DOCUMENT_UPLOAD:
112150
Console.WriteLine("\n\nUploading documents...\n\n");
113151
break;
152+
case Command.CANDIDATE_ATTACHMENT_UPLOAD:
153+
Console.WriteLine("\n\nUploading attachments...\n\n");
154+
break;
114155
default:
115156
break;
116157
}
@@ -153,6 +194,10 @@ static void Main(string[] args)
153194
bytes = File.ReadAllBytes(file);
154195
result = Documents.Upload(file, bytes, soapUrl, processedDir, options);
155196
break;
197+
case Command.CANDIDATE_ATTACHMENT_UPLOAD:
198+
bytes = File.ReadAllBytes(file);
199+
result = CandidateAttachments.Upload(file, bytes, soapUrl, processedDir, options);
200+
break;
156201
}
157202

158203
if (result.ToLower().IndexOf("<html") >= 0)
@@ -267,51 +312,6 @@ static bool InitOptions(string[] args)
267312
return false;
268313
}
269314

270-
// Ensure Command is uppercase.
271-
if (options != null && options.Command != null)
272-
{
273-
options.Command = options.Command.Trim().ToUpper();
274-
}
275-
276-
// Path parameter is a file
277-
if (options != null && options.Path != null && options.Command == Command.CLAR_UPLOAD)
278-
{
279-
if (File.Exists(options.Path))
280-
{
281-
searchPattern = Path.GetFileName(options.Path);
282-
options.Path = options.Path.Substring(0, options.Path.Length - searchPattern.Length);
283-
}
284-
}
285-
286-
// Set search pattern and cloud collection if parameters are included.
287-
if (options != null && options.Parameters != null)
288-
{
289-
switch (options.Command)
290-
{
291-
case Command.CLAR_UPLOAD:
292-
cloudCollection = options.Parameters;
293-
break;
294-
case Command.CLAR_DOWNLOAD:
295-
searchPattern = "";
296-
options.Parameters = Path.GetFileName(Path.TrimEndingDirectorySeparator(options.Parameters));
297-
cloudCollection = options.Parameters;
298-
break;
299-
case Command.DRIVE_UPLOAD:
300-
case Command.DRIVE_TRASH:
301-
searchPattern = options.Parameters;
302-
break;
303-
case Command.PHOTO_DOWNLOAD:
304-
searchPattern = options.Parameters;
305-
break;
306-
case Command.PHOTO_UPLOAD:
307-
case Command.DOCUMENT_UPLOAD:
308-
searchPattern = "*.*";
309-
break;
310-
default:
311-
break;
312-
}
313-
}
314-
315315
return true;
316316
}
317317

@@ -333,53 +333,52 @@ static void OptionsEncrypt()
333333
Console.WriteLine("\n");
334334
}
335335

336-
static void OptionsUI()
337-
{
338-
// Command
339-
CommandOption();
340-
// Path
341-
PathOption();
342-
// Parameters
343-
ParameterOption();
344-
// Files Check
345-
FilesCheck();
346-
// Environment
347-
EnvironmentOption();
348-
// Tenant
349-
TenantOption();
350-
// Username
351-
UsernameOption();
352-
// Password
353-
PasswordOption();
354-
}
355-
356336
static void CommandOption()
357337
{
358338
if (String.IsNullOrEmpty(options.Command))
359339
{
360340
Console.WriteLine("Enter the command:\n");
361341
options.Command = Console.ReadLine().Trim().ToUpper();
362-
Console.WriteLine("");
363-
// Check for valid commands
364-
switch (options.Command)
365-
{
366-
case Command.CLAR_UPLOAD:
367-
case Command.CLAR_DOWNLOAD:
368-
case Command.DRIVE_UPLOAD:
369-
case Command.DRIVE_TRASH:
370-
case Command.PHOTO_DOWNLOAD:
371-
case Command.PHOTO_UPLOAD:
372-
case Command.DOCUMENT_UPLOAD:
373-
break;
374-
default:
375-
throw new Exception("Invalid command. Please use --help for a list of valid commands.");
376-
}
342+
Console.WriteLine("");
343+
}
344+
}
345+
346+
static void CommandValidate()
347+
{
348+
// Ensure Command is uppercase.
349+
if (options.Command != null)
350+
{
351+
options.Command = options.Command.Trim().ToUpper();
352+
}
353+
// Check for valid commands
354+
switch (options.Command)
355+
{
356+
case Command.CLAR_UPLOAD:
357+
case Command.CLAR_DOWNLOAD:
358+
case Command.DRIVE_UPLOAD:
359+
case Command.DRIVE_TRASH:
360+
case Command.PHOTO_DOWNLOAD:
361+
case Command.PHOTO_UPLOAD:
362+
case Command.DOCUMENT_UPLOAD:
363+
case Command.CANDIDATE_ATTACHMENT_UPLOAD:
364+
break;
365+
default:
366+
throw new Exception("Invalid command. Please use --help for a list of valid commands.");
377367
}
378368
Console.WriteLine("\n\nCommand: " + options.Command + "\n");
379369
}
380370

381371
static void PathOption()
382372
{
373+
// Path parameter is a file
374+
if (options.Path != null && options.Command == Command.CLAR_UPLOAD)
375+
{
376+
if (File.Exists(options.Path))
377+
{
378+
searchPattern = Path.GetFileName(options.Path);
379+
options.Path = options.Path.Substring(0, options.Path.Length - searchPattern.Length);
380+
}
381+
}
383382
// Path or File
384383
if (String.IsNullOrEmpty(options.Path))
385384
{
@@ -400,12 +399,17 @@ static void PathOption()
400399
break;
401400
case Command.PHOTO_UPLOAD:
402401
case Command.DOCUMENT_UPLOAD:
402+
case Command.CANDIDATE_ATTACHMENT_UPLOAD:
403403
options.Path = inboundDir;
404404
break;
405405
default:
406406
break;
407-
}
408-
}
407+
}
408+
}
409+
}
410+
411+
static void PathValidate()
412+
{
409413
Console.WriteLine("Processing: " + options.Path + "\n");
410414
}
411415

@@ -446,12 +450,45 @@ static void ParameterOption()
446450
break;
447451
case Command.PHOTO_UPLOAD:
448452
case Command.DOCUMENT_UPLOAD:
453+
case Command.CANDIDATE_ATTACHMENT_UPLOAD:
449454
searchPattern = "*.*";
450455
break;
451456
}
452457
}
453-
454-
Console.WriteLine("Using parameters: " + options.Parameters + "\n");
458+
}
459+
460+
static void ParameterValidate()
461+
{
462+
// Set search pattern and cloud collection if parameters are included.
463+
if (options.Parameters != null)
464+
{
465+
switch (options.Command)
466+
{
467+
case Command.CLAR_UPLOAD:
468+
cloudCollection = options.Parameters;
469+
break;
470+
case Command.CLAR_DOWNLOAD:
471+
searchPattern = "";
472+
options.Parameters = Path.GetFileName(Path.TrimEndingDirectorySeparator(options.Parameters));
473+
cloudCollection = options.Parameters;
474+
break;
475+
case Command.DRIVE_UPLOAD:
476+
case Command.DRIVE_TRASH:
477+
searchPattern = options.Parameters;
478+
break;
479+
case Command.PHOTO_DOWNLOAD:
480+
searchPattern = options.Parameters;
481+
break;
482+
case Command.PHOTO_UPLOAD:
483+
case Command.DOCUMENT_UPLOAD:
484+
case Command.CANDIDATE_ATTACHMENT_UPLOAD:
485+
searchPattern = "*.*";
486+
break;
487+
default:
488+
break;
489+
}
490+
}
491+
Console.WriteLine("Using parameters: " + options.Parameters + "\n");
455492
}
456493

457494
static void FilesCheck()
@@ -571,6 +608,9 @@ static string SoapUrlBuild(string command)
571608
case Command.DOCUMENT_UPLOAD:
572609
soapUrl += "/{tenant}/Staffing/{version}";
573610
break;
611+
case Command.CANDIDATE_ATTACHMENT_UPLOAD:
612+
soapUrl += "/{tenant}/Recruiting/{version}";
613+
break;
574614
}
575615

576616
return soapUrl;

0 commit comments

Comments
 (0)