Skip to content

Commit 11cb8ff

Browse files
committed
Initial Commit
1 parent a6c1fa6 commit 11cb8ff

File tree

9 files changed

+618
-0
lines changed

9 files changed

+618
-0
lines changed

CLARiNET.csproj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
<Authors>Whitley Media</Authors>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="CommandLineParser" Version="2.8.0" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<Compile Update="Resources.Designer.cs">
15+
<DesignTime>True</DesignTime>
16+
<AutoGen>True</AutoGen>
17+
<DependentUpon>Resources.resx</DependentUpon>
18+
</Compile>
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<EmbeddedResource Update="Resources.resx">
23+
<Generator>ResXFileCodeGenerator</Generator>
24+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
25+
</EmbeddedResource>
26+
</ItemGroup>
27+
28+
</Project>

CLARiNET.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31515.178
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CLARiNET", "CLARiNET.csproj", "{62ABE936-15D8-496A-9149-53F4A8C15A5E}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{62ABE936-15D8-496A-9149-53F4A8C15A5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{62ABE936-15D8-496A-9149-53F4A8C15A5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{62ABE936-15D8-496A-9149-53F4A8C15A5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{62ABE936-15D8-496A-9149-53F4A8C15A5E}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {3BCBE28A-4EB3-46BE-8C5E-B14B323B6F82}
24+
EndGlobalSection
25+
EndGlobal

CommandLineOptions.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using CommandLine;
7+
8+
namespace CLARiNET
9+
{
10+
public class Options
11+
{
12+
[Value(index: 0,Required = false, HelpText = "Full path and file name for the CLAR")]
13+
public string ClarFile { get; set; }
14+
15+
[Value(index: 1, Required = false, HelpText = "Cloud Collection name")]
16+
public string CollectionName { get; set; }
17+
18+
[Value(index: 2, Required = false, HelpText = "Number associated with a Workday environment")]
19+
public string EnvNum { get; set; }
20+
21+
[Value(index: 3, Required = false, HelpText = "Workday Tenant")]
22+
public string Tenant { get; set; }
23+
24+
[Value(index: 4, Required = false, HelpText = "Username")]
25+
public string Username { get; set; }
26+
27+
[Value(index: 5, Required = false, HelpText = "Password")]
28+
public string Password { get; set; }
29+
30+
[Option('e', "environments", Required = false,
31+
HelpText =
32+
"Display the Workday environments and their associated numbers")]
33+
public bool PrintEnvironments { get; set; }
34+
35+
}
36+
}

Program.cs

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Xml.Linq;
4+
using System.IO;
5+
using CommandLine;
6+
using System.Reflection;
7+
8+
namespace CLARiNET
9+
{
10+
class Program
11+
{
12+
static void Main(string[] args)
13+
{
14+
Options options = new Options();
15+
string url = "https://{host}/ccx/cc-cloud-repo/collections/";
16+
string host = "";
17+
18+
try
19+
{
20+
XDocument xDoc = XDocument.Parse(Resources.WDEnvironments);
21+
List<XElement> envs = new List<XElement>(xDoc.Descendants(XName.Get("env")));
22+
23+
Console.WriteLine("\n** CLARiNET by Whitley Media **\n\n");
24+
25+
ParserResult<Options> pResult = Parser.Default.ParseArguments<Options>(args)
26+
.WithParsed<Options>(o =>
27+
{
28+
options = o;
29+
});
30+
if (pResult.Tag == ParserResultType.NotParsed)
31+
{
32+
return;
33+
}
34+
35+
if (options.PrintEnvironments)
36+
{
37+
PrintEnvironments(envs);
38+
return;
39+
}
40+
41+
// CLAR file
42+
if (options.ClarFile == null)
43+
{
44+
// Check for a single CLAR file in this directory.
45+
string[] files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.clar");
46+
if (files.Length == 1)
47+
{
48+
options.ClarFile = files[0];
49+
Console.WriteLine("Processing the CLAR file: " + options.ClarFile + "\n");
50+
}
51+
else
52+
{
53+
Console.WriteLine("Enter the full path and file name for the CLAR file:\n");
54+
options.ClarFile = Console.ReadLine().Trim();
55+
Console.WriteLine("");
56+
}
57+
}
58+
59+
// Collection Name
60+
if (options.CollectionName == null)
61+
{
62+
Console.WriteLine("Enter the Workday Cloud Collection name:\n");
63+
options.CollectionName = Console.ReadLine().Trim();
64+
Console.WriteLine("");
65+
}
66+
67+
// Environment Number
68+
if (options.EnvNum == null)
69+
{
70+
do
71+
{
72+
PrintEnvironments(envs);
73+
Console.WriteLine("Enter the number that identifies the Workday environment (1 - " + envs.Count + "):\n");
74+
options.EnvNum = Console.ReadLine().Trim();
75+
Console.WriteLine("");
76+
int envNum = 0;
77+
if (int.TryParse(options.EnvNum, out envNum))
78+
{
79+
if (envNum < envs.Count)
80+
{
81+
host = envs[envNum - 1].Element(XName.Get("e2-endpoint")).Value;
82+
Console.WriteLine("\nHost: " + host + "\n");
83+
Console.WriteLine("Is the Host correct? (Y/N)\n");
84+
}
85+
}
86+
else
87+
{
88+
Console.WriteLine("Entry was incorrect. Press {enter} to continue.\n");
89+
}
90+
} while (Console.ReadLine().Trim().ToUpper() != "Y");
91+
Console.WriteLine("\n");
92+
}
93+
else
94+
{
95+
// Look up the host based on the number.
96+
host = envs[(int.Parse(options.EnvNum)) - 1].Element(XName.Get("e2-endpoint")).Value;
97+
}
98+
99+
// Tenant
100+
if (options.Tenant == null)
101+
{
102+
Console.WriteLine("Enter the tenant:\n");
103+
options.Tenant = Console.ReadLine().Trim();
104+
Console.WriteLine("");
105+
}
106+
107+
// Username
108+
if (options.Username == null)
109+
{
110+
Console.WriteLine("Enter the username:\n");
111+
options.Username = Console.ReadLine().Trim();
112+
Console.WriteLine("");
113+
}
114+
115+
// Password
116+
if (options.Password == null)
117+
{
118+
Console.WriteLine("Enter the password (will not be displayed):\n");
119+
Console.Write("->");
120+
ConsoleColor color = Console.ForegroundColor;
121+
Console.CursorVisible = false;
122+
Console.ForegroundColor = Console.BackgroundColor;
123+
options.Password = Console.ReadLine().Trim();
124+
Console.WriteLine("");
125+
Console.ForegroundColor = color;
126+
Console.CursorVisible = true;
127+
}
128+
129+
Console.WriteLine("Deploying the CLAR and awaiting the result...\n\n");
130+
131+
// REST Call
132+
Byte[] bytes = File.ReadAllBytes(options.ClarFile);
133+
options.Username = options.Username + "@" + options.Tenant;
134+
url = url.Replace("{host}", host) + options.CollectionName;
135+
string result = WDWebService.CallRest(options.Tenant, options.Username, options.Password, url, "PUT", bytes);
136+
Console.WriteLine("Result:\n");
137+
Console.WriteLine(result);
138+
}
139+
catch (Exception ex)
140+
{
141+
Console.WriteLine(ex.Message);
142+
}
143+
}
144+
145+
private static void PrintEnvironments(List<XElement> envs)
146+
{
147+
string[] envName = new string[3];
148+
string colFormat = "{0,-35} {1,-35} {2,-35}\n";
149+
150+
Console.WriteLine("-- Workday Environments --\n");
151+
for (int ndx = 0; ndx < envs.Count; ndx++)
152+
{
153+
if (ndx > 0 && ndx % 3 == 0)
154+
{
155+
Console.Write(colFormat, envName[0], envName[1], envName[2]);
156+
envName = new string[3];
157+
}
158+
if (envName[0] == null)
159+
{
160+
envName[0] = ndx + 1 + ") " + envs[ndx].FirstAttribute.Value;
161+
}
162+
else
163+
{
164+
if (envName[1] == null)
165+
{
166+
envName[1] = ndx + 1 + ") " + envs[ndx].FirstAttribute.Value;
167+
}
168+
else
169+
{
170+
envName[2] = ndx + 1 + ") " + envs[ndx].FirstAttribute.Value;
171+
}
172+
}
173+
}
174+
if (envName[0] != null)
175+
{
176+
Console.Write(colFormat, envName[0], envName[1], envName[2]);
177+
}
178+
Console.WriteLine("\n");
179+
}
180+
}
181+
}

Properties/launchSettings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"profiles": {
3+
"CLARiNET": {
4+
"commandName": "Project"
5+
}
6+
}
7+
}

Resources.Designer.cs

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)