Skip to content

Commit 8ae8bf9

Browse files
committed
v1.5.0
- Moved XML into embedded files. - Commands to Enum - Candidate Attachment upload
1 parent 61330ce commit 8ae8bf9

32 files changed

+18168
-903
lines changed

CLARiNET.csproj

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,52 @@
77
<PackageIcon>CLARiNET.ico</PackageIcon>
88
<PackageIconUrl />
99
<ApplicationIcon>CLARiNET.ico</ApplicationIcon>
10-
<Version>1.2.1</Version>
10+
<Version>1.5.0</Version>
1111
</PropertyGroup>
1212

13+
<ItemGroup>
14+
<None Remove="Resources\ContentTypes.json" />
15+
<None Remove="Resources\Get_Worker_Photos_Request.xml" />
16+
<None Remove="Resources\Put_Candidate_Attachment_Request.xml" />
17+
<None Remove="Resources\Put_Drive_Document_Content_Request.xml" />
18+
<None Remove="Resources\Put_Drive_Document_Content_Request_Trashed.xml" />
19+
<None Remove="Resources\Put_Worker_Document_Request.xml" />
20+
<None Remove="Resources\Put_Worker_Photo_Request.xml" />
21+
<None Remove="Resources\WDEnvironments.xml" />
22+
<None Remove="Resources\WorkdayContentTypes.txt" />
23+
<None Remove="Resources\Worker_Reference.txt" />
24+
</ItemGroup>
25+
1326
<ItemGroup>
1427
<PackageReference Include="CommandLineParser" Version="2.9.1" />
15-
<PackageReference Include="HtmlAgilityPack" Version="1.11.55" />
16-
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="8.0.0" />
17-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
18-
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="8.0.0" />
28+
<PackageReference Include="HtmlAgilityPack" Version="1.11.71" />
29+
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="9.0.0" />
30+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
31+
<PackageReference Include="System.CodeDom" Version="9.0.0" />
32+
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="9.0.0" />
33+
</ItemGroup>
34+
35+
<ItemGroup>
36+
<EmbeddedResource Include="Resources\ContentTypes.json" />
37+
<EmbeddedResource Include="Resources\Get_Worker_Photos_Request.xml" />
38+
<EmbeddedResource Include="Resources\Put_Candidate_Attachment_Request.xml" />
39+
<EmbeddedResource Include="Resources\Put_Drive_Document_Content_Request.xml" />
40+
<EmbeddedResource Include="Resources\Put_Drive_Document_Content_Request_Trashed.xml" />
41+
<EmbeddedResource Include="Resources\Put_Worker_Document_Request.xml" />
42+
<EmbeddedResource Include="Resources\Put_Worker_Photo_Request.xml" />
43+
<EmbeddedResource Include="Resources\WDEnvironments.xml" />
44+
<EmbeddedResource Include="Resources\WorkdayContentTypes.txt" />
45+
<EmbeddedResource Include="Resources\Worker_Reference.txt" />
1946
</ItemGroup>
2047

2148
<ItemGroup>
22-
<Compile Update="Resources.Designer.cs">
23-
<DesignTime>True</DesignTime>
24-
<AutoGen>True</AutoGen>
25-
<DependentUpon>Resources.resx</DependentUpon>
49+
<Compile Update="Resources\ResourceFile.cs">
50+
<Generator></Generator>
2651
</Compile>
2752
</ItemGroup>
2853

2954
<ItemGroup>
30-
<EmbeddedResource Update="Resources.resx">
31-
<Generator>ResXFileCodeGenerator</Generator>
32-
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
33-
</EmbeddedResource>
55+
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
3456
</ItemGroup>
3557

3658
</Project>

CandidateAttachment.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5+
using System.Net.Mime;
56
using System.Text;
67
using System.Threading.Tasks;
78
using System.Xml;
@@ -19,22 +20,24 @@ public static string Upload(string file, byte[] bytes, string soapUrl, string pr
1920

2021
try
2122
{
22-
xmlData = Resources.Put_Candidate_Attachment_Request;
23+
xmlData = ResourceFile.Read("Put_Candidate_Attachment_Request.xml");
2324
string[] fileVars = Path.GetFileName(file).Split("~");
2425
if (fileVars.Length > 1)
2526
{
2627
Console.WriteLine("\n\nProcessing {0} for {1} on {2}", fileVars[2], fileVars[0], fileVars[1]);
2728
string candidateId = fileVars[0];
2829
string applicationId = fileVars[1];
2930
string filename = fileVars[2];
31+
string contentType = WDContentType.Lookup(filename);
3032
string comment = "";
3133
// worker id ~ filename
3234
// TODO: Manifest for comment and content type?
3335
xmlData = xmlData.Replace("{candidateId}", candidateId)
3436
.Replace("{applicationId}", applicationId)
35-
.Replace("{filename}", filename)
37+
.Replace("{filename}", filename.EscapeXml())
3638
.Replace("{filedata}", Convert.ToBase64String(bytes))
37-
.Replace("{comment}", comment);
39+
.Replace("{comment}", comment.EscapeXml())
40+
.Replace("{contentType}", contentType);
3841

3942
result = WDWebService.CallAPI(options.Username + "@" + options.Tenant, options.Password, soapUrl, xmlData);
4043
if (result.IndexOf("<?xml") == 0)

CommandLineAuth.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using Microsoft.Extensions.Options;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace CLARiNET
9+
{
10+
internal class CommandLineAuth
11+
{
12+
public static string UsernameOption(string userName)
13+
{
14+
// Username
15+
if (String.IsNullOrEmpty(userName))
16+
{
17+
Console.WriteLine("Enter the username:\n");
18+
userName = Console.ReadLine().Trim();
19+
Console.WriteLine("");
20+
}
21+
return userName;
22+
}
23+
24+
public static string PasswordOption(string password)
25+
{
26+
if (String.IsNullOrEmpty(password))
27+
{
28+
Console.WriteLine("Enter the password (will not be displayed):\n");
29+
password = PasswordPrompt();
30+
}
31+
else
32+
{
33+
password = Crypto.Unprotect(password);
34+
}
35+
return password;
36+
}
37+
38+
public static string PasswordPrompt()
39+
{
40+
string pass = string.Empty;
41+
ConsoleKey key;
42+
do
43+
{
44+
var keyInfo = Console.ReadKey(intercept: true);
45+
key = keyInfo.Key;
46+
47+
if (key == ConsoleKey.Backspace && pass.Length > 0)
48+
{
49+
Console.Write("\b \b");
50+
pass = pass[0..^1];
51+
}
52+
else if (!char.IsControl(keyInfo.KeyChar))
53+
{
54+
Console.Write("*");
55+
pass += keyInfo.KeyChar;
56+
}
57+
} while (key != ConsoleKey.Enter);
58+
return pass;
59+
}
60+
61+
public static void OptionsEncrypt()
62+
{
63+
Console.WriteLine("Enter a password to encrypt:\n");
64+
string pass = CommandLineAuth.PasswordPrompt();
65+
string encPass = "";
66+
try
67+
{
68+
encPass = Crypto.Protect(pass);
69+
}
70+
// Perform a retry
71+
catch
72+
{
73+
encPass = Crypto.Protect(pass);
74+
}
75+
Console.WriteLine("\n\n" + encPass);
76+
Console.WriteLine("\n");
77+
}
78+
}
79+
}

CommandLineCommand.cs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using Microsoft.Extensions.Options;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace CLARiNET
9+
{
10+
public static class CommandLineCommand
11+
{
12+
public static string CommandGet(string command)
13+
{
14+
if (String.IsNullOrEmpty(command))
15+
{
16+
string[] commands = Commands.COMMAND_LIST.Split("\n");
17+
PrintCommand(commands);
18+
Console.WriteLine("Enter the number that identifies the CLARiNET Command (1 - " + commands.Length + "):\n");
19+
command = Console.ReadLine().Trim().ToUpper();
20+
Console.WriteLine("");
21+
}
22+
return command;
23+
}
24+
25+
public static string CommandValidate(string command)
26+
{
27+
// Ensure Command is uppercase.
28+
if (command != null)
29+
{
30+
command = command.Trim().ToUpper();
31+
}
32+
33+
int ndx = 0;
34+
if (int.TryParse(command, out ndx))
35+
{
36+
string[] commands = Commands.COMMAND_LIST.Split("\n");
37+
command = commands[ndx - 1];
38+
}
39+
40+
41+
// Check for valid commands
42+
switch (command.ToEnum<Command>())
43+
{
44+
case Command.CLAR_UPLOAD:
45+
case Command.CLAR_DOWNLOAD:
46+
case Command.DRIVE_UPLOAD:
47+
case Command.DRIVE_TRASH:
48+
case Command.PHOTO_DOWNLOAD:
49+
case Command.PHOTO_UPLOAD:
50+
case Command.DOCUMENT_UPLOAD:
51+
case Command.CANDIDATE_ATTACHMENT_UPLOAD:
52+
break;
53+
default:
54+
throw new Exception("Invalid command. Please use --help for a list of valid commands.");
55+
}
56+
Console.WriteLine("\n\nCommand: " + command + "\n");
57+
58+
return command;
59+
}
60+
61+
public static void PrintCommand(string[] commands)
62+
{
63+
string[] commandName = new string[3];
64+
string colFormat = "{0,-35} {1,-35} {2,-35}\n";
65+
66+
Console.WriteLine("-- Commands --\n");
67+
for (int ndx = 0; ndx < commands.Length; ndx++)
68+
{
69+
if (ndx > 0 && ndx % 3 == 0)
70+
{
71+
Console.Write(colFormat, commandName[0], commandName[1], commandName[2]);
72+
commandName = new string[3];
73+
}
74+
if (commandName[0] == null)
75+
{
76+
commandName[0] = ndx + 1 + ") " + commands[ndx];
77+
}
78+
else
79+
{
80+
if (commandName[1] == null)
81+
{
82+
commandName[1] = ndx + 1 + ") " + commands[ndx];
83+
}
84+
else
85+
{
86+
commandName[2] = ndx + 1 + ") " + commands[ndx];
87+
}
88+
}
89+
}
90+
if (commandName[0] != null)
91+
{
92+
Console.Write(colFormat, commandName[0], commandName[1], commandName[2]);
93+
}
94+
Console.WriteLine("\n");
95+
}
96+
}
97+
}

CommandLineEnv.cs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using Microsoft.Extensions.Options;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Xml.Linq;
8+
9+
namespace CLARiNET
10+
{
11+
public static class CommandLineEnv
12+
{
13+
public static (string, string) EnvironmentOption(string envNumStr, List<XElement> envs)
14+
{
15+
string host = null;
16+
if (String.IsNullOrEmpty(envNumStr))
17+
{
18+
do
19+
{
20+
PrintEnvironments(envs);
21+
Console.WriteLine("Enter the number that identifies the Workday environment (1 - " + envs.Count + "):\n");
22+
envNumStr = Console.ReadLine().Trim();
23+
Console.WriteLine("");
24+
int envNum = 0;
25+
if (int.TryParse(envNumStr, out envNum))
26+
{
27+
if (envNum <= envs.Count)
28+
{
29+
host = envs[envNum - 1].Element(XName.Get("e2-endpoint")).Value;
30+
if (host == "{custom}")
31+
{
32+
Console.WriteLine("Enter a custom Host (ex: wcpdev-services1.wd101.myworkday.com):\n");
33+
host = Console.ReadLine().Trim();
34+
35+
}
36+
37+
Console.WriteLine("\nHost: " + host + "\n");
38+
Console.WriteLine("Is the Host correct? (Y/N)\n");
39+
}
40+
}
41+
else
42+
{
43+
Console.WriteLine("Entry was incorrect. Press {enter} to continue.\n");
44+
}
45+
} while (Console.ReadLine().Trim().ToUpper() != "Y");
46+
Console.WriteLine("\n");
47+
}
48+
else
49+
{
50+
// Look up the host based on the number.
51+
if (int.TryParse(envNumStr, out _))
52+
{
53+
host = envs[(int.Parse(envNumStr)) - 1].Element(XName.Get("e2-endpoint")).Value;
54+
}
55+
else
56+
{
57+
host = envNumStr;
58+
}
59+
}
60+
return (envNumStr, host);
61+
}
62+
63+
public static void PrintEnvironments(List<XElement> envs)
64+
{
65+
string[] envName = new string[3];
66+
string colFormat = "{0,-35} {1,-35} {2,-35}\n";
67+
68+
Console.WriteLine("-- Workday Environments --\n");
69+
for (int ndx = 0; ndx < envs.Count; ndx++)
70+
{
71+
if (ndx > 0 && ndx % 3 == 0)
72+
{
73+
Console.Write(colFormat, envName[0], envName[1], envName[2]);
74+
envName = new string[3];
75+
}
76+
if (envName[0] == null)
77+
{
78+
envName[0] = ndx + 1 + ") " + envs[ndx].FirstAttribute.Value;
79+
}
80+
else
81+
{
82+
if (envName[1] == null)
83+
{
84+
envName[1] = ndx + 1 + ") " + envs[ndx].FirstAttribute.Value;
85+
}
86+
else
87+
{
88+
envName[2] = ndx + 1 + ") " + envs[ndx].FirstAttribute.Value;
89+
}
90+
}
91+
}
92+
if (envName[0] != null)
93+
{
94+
Console.Write(colFormat, envName[0], envName[1], envName[2]);
95+
}
96+
Console.WriteLine("\n");
97+
}
98+
}
99+
}

0 commit comments

Comments
 (0)