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 ( "\n Host: " + 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
+ }
0 commit comments