-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplicationOptions.cs
197 lines (161 loc) · 6.57 KB
/
ApplicationOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
using System;
using System.Configuration;
using AWS = Autodesk.Connectivity.WebServices;
using Serilog.Core;
using Serilog.Events;
namespace ImportObjectProperties
{
public enum ImportType
{
File,
Item,
CustomEntity,
}
class ApplicationOptions
{
private ApplicationOptions()
{
ObjectType = ImportType.File;
AuthenticationType = AWS.AuthTyp.Vault;
Server = "localhost";
UserName = "Administrator";
Password = string.Empty;
KnowledgeVault = "Vault";
InputFile = string.Empty;
EnableDebugMessages = false;
CSVSeparator = char.MinValue;
Encoding = "UTF-8";
UseExplorerUtil = false;
}
public ImportType ObjectType { get; private set; }
public AWS.AuthTyp AuthenticationType { get; private set; }
public string InputFile { get; private set; }
public string KnowledgeVault { get; private set; }
public string Server { get; private set; }
public string UserName { get; private set; }
public string Password { get; private set; }
public bool EnableDebugMessages { get; private set; }
public string Encoding { get; private set; }
public char CSVSeparator { get; private set; }
public string DescriptionProperty { get; private set; }
public string TitleProperty { get; private set; }
public string UnitsProperty { get; private set; }
public bool UseExplorerUtil { get; private set; }
public LoggingLevelSwitch LoggingLevelSwitch { get; set; }
public static LoggingLevelSwitch loggingLevelSwitch = new LoggingLevelSwitch();
public static ApplicationOptions Parse(string[] args)
{
ApplicationOptions result = new ApplicationOptions();
byte flags = 0;
for (int i = 0; i < args.Length; i++)
{
string arg = args[i];
if (0 == string.Compare("-t", arg, true))
{
string objectType = args[++i];
if (objectType.ToLower().Equals("file"))
result.ObjectType = ImportType.File;
else if (objectType.ToLower().Equals("item"))
result.ObjectType = ImportType.Item;
else if (objectType.ToLower().Equals("custent"))
result.ObjectType = ImportType.CustomEntity;
flags |= 0x01;
}
else if (arg.Equals("-a", StringComparison.CurrentCultureIgnoreCase))
{
string authType = args[++i];
if (authType.Equals("Vault", StringComparison.CurrentCultureIgnoreCase) || authType.Equals("V", StringComparison.CurrentCultureIgnoreCase))
{
result.AuthenticationType = AWS.AuthTyp.Vault;
}
if (authType.Equals("Windows", StringComparison.CurrentCultureIgnoreCase) || authType.Equals("W", StringComparison.CurrentCultureIgnoreCase))
{
result.AuthenticationType = AWS.AuthTyp.Vault;
}
flags |= 0x02;
}
else if (0 == string.Compare("-s", arg, true))
{
result.Server = args[++i];
flags |= 0x04;
}
else if (0 == string.Compare("-db", arg, true))
{
result.KnowledgeVault = args[++i];
flags |= 0x08;
}
else if (0 == string.Compare("-u", arg, true))
{
result.UserName = args[++i];
flags |= 0x10;
}
else if (0 == string.Compare("-p", arg, true))
{
result.Password = args[++i];
flags |= 0x20;
}
else if (0 == string.Compare("-l", arg, true))
{
string nextArg = args[++i];
if (string.Compare(nextArg, "d", true) == 0)
{
loggingLevelSwitch.MinimumLevel = LogEventLevel.Debug;
result.EnableDebugMessages = true;
}
flags |= 0x30;
}
else if (0 == string.Compare("-e", arg, true))
{
result.Encoding = args[++i];
flags |= 0x40;
}
else
{
if (0 == (flags & 0x40))
{
result.InputFile = arg;
flags |= 0x50;
}
}
}
if (flags < 0x50)
{
throw new ArgumentException();
}
LoadConfiguration(result);
return result;
}
private static void LoadConfiguration(ApplicationOptions options)
{
string separator = ConfigurationManager.AppSettings["CSVSeparatorInASCII"];
if (string.IsNullOrEmpty(separator) == false)
{
int code = Convert.ToInt32(separator);
options.CSVSeparator = Convert.ToChar(code);
}
string descriptionPropertyName = ConfigurationManager.AppSettings["ItemCoDescriptionPropertyName"];
if (string.IsNullOrEmpty(descriptionPropertyName))
{
descriptionPropertyName = "Description (Item,CO)";
}
options.DescriptionProperty = descriptionPropertyName;
string titlePropertyName = ConfigurationManager.AppSettings["ItemCoTitlePropertyName"];
if (string.IsNullOrEmpty(titlePropertyName))
{
titlePropertyName = "Title (Item,CO)";
}
options.TitleProperty = titlePropertyName;
string unitsPropertyName = ConfigurationManager.AppSettings["ItemUnitsPropertyName"];
if (string.IsNullOrEmpty(unitsPropertyName))
{
unitsPropertyName = "Units";
}
options.UnitsProperty = unitsPropertyName;
string useExplorerUtil = ConfigurationManager.AppSettings["UseExplorerUtil"];
if (string.IsNullOrEmpty(useExplorerUtil) == false)
{
options.UseExplorerUtil = Convert.ToBoolean(useExplorerUtil);
}
}
}
}