Advertisement
Guest User

Untitled

a guest
May 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.87 KB | None | 0 0
  1.  
  2. // Assembly location: X:\files\avaya\Manager.exe
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Globalization;
  7. using System.Net;
  8.  
  9. namespace Avaya.IPOffice.Manager
  10. {
  11. public class CommandLine
  12. {
  13. private bool _primary = true;
  14. private string _commonFileArea = "manager_files";
  15. private string _username = "";
  16. private string _password = "";
  17. private string _decryptedPassword = "";
  18. private Dictionary<string, string> _args = new Dictionary<string, string>();
  19. private const int _minumumArgLength = 3;
  20. private bool _isValid;
  21.  
  22. public static CommandLine Parse(string[] args)
  23. {
  24. CommandLine commandLine = new CommandLine();
  25. for (int index = 1; index < args.Length; ++index)
  26. {
  27. if (args[index] != null)
  28. {
  29. if (args[index].Length >= 3 && (int) args[index][0] == (int) char.Parse("/") && args[index].IndexOf(":") > -1)
  30. {
  31. int num1 = 0;
  32. int num2 = args[index].IndexOf(":");
  33. string str1 = args[index].Substring(num1 + 1, num2 - 1);
  34. string str2 = args[index].Substring(num2 + 1, args[index].Length - num2 - 1);
  35. if (string.Compare(str1, "ip") == 0 && MainForm.Instance != null)
  36. MainForm.Instance.IsCommandLineAndContainsIP = true;
  37. if (string.Compare(str1, "input") == 0 && !str2.Contains("\\"))
  38. {
  39. if (MainForm._appData != null && !string.IsNullOrEmpty(MainForm._appData.WorkingDirectory))
  40. {
  41. string str3 = MainForm._appData.WorkingDirectory;
  42. if (str3.EndsWith("\\") || str3.EndsWith(";"))
  43. str3 = str3.Substring(0, str3.Length - 1);
  44. str2 = str3 + "\\" + str2;
  45. }
  46. }
  47. if (!commandLine._args.ContainsKey(str1))
  48. {
  49. if (str1.ToUpper() == "SYSTEMTYPE" && str2.ToUpper() == "IP OFFICE")
  50. commandLine._args.Add(str1, "ABG B5800");
  51. else
  52. commandLine._args.Add(str1, str2);
  53. }
  54. }
  55. else
  56. {
  57. if (args.Length != 2 || (int) args[index][0] == (int) char.Parse("/"))
  58. return commandLine;
  59. commandLine._args.Add("input", args[1]);
  60. }
  61. }
  62. }
  63. if (!string.IsNullOrEmpty(commandLine.Launch) && EnumLaunchDef.GetLaunchType(commandLine.Launch) == LaunchType.CONFIG_ONLINE)
  64. {
  65. IPAddress address = (IPAddress) null;
  66. if (IPAddress.TryParse(commandLine.IP, out address) && !string.IsNullOrEmpty(commandLine.UserName) && !string.IsNullOrEmpty(commandLine.Password))
  67. {
  68. commandLine._isValid = true;
  69. }
  70. else
  71. {
  72. commandLine._isValid = false;
  73. return commandLine;
  74. }
  75. }
  76. else
  77. {
  78. foreach (string key in commandLine._args.Keys)
  79. {
  80. if (key == "input" || key == "output" || (key == "launch" || key == "action") || (key == "type" || key == "name" || (key == "wavlist" || key == "ip")) || (key == "user" || key == "password" || (key == "caption" || key == "locale") || (key == "systemtype" || key == "extntype" || (key == "addvmlocales" || key == "primary"))) || (key == "dir" || key == "remote" || (key == "baseport" || key == "encryptcredential") || (key == "version" || key == "targetversion")))
  81. {
  82. commandLine._isValid = true;
  83. }
  84. else
  85. {
  86. commandLine._isValid = false;
  87. return commandLine;
  88. }
  89. }
  90. if (commandLine.Launch == LaunchType.TEMPLATE.ToString() && !commandLine._args.ContainsKey("type"))
  91. {
  92. commandLine._isValid = false;
  93. return commandLine;
  94. }
  95. if (commandLine._args.ContainsKey("type"))
  96. {
  97. if (Convert.ToInt32((object) EnumTemplateTypeDefinitions.GetTemplateType(commandLine._args["type"])) != Convert.ToInt32((object) TemplateType.None))
  98. {
  99. commandLine._isValid = true;
  100. }
  101. else
  102. {
  103. commandLine._isValid = false;
  104. return commandLine;
  105. }
  106. }
  107. if (commandLine._args.ContainsKey("input") && commandLine._args["input"].Trim().Length == 0)
  108. {
  109. commandLine._isValid = false;
  110. return commandLine;
  111. }
  112. commandLine._isValid = true;
  113. }
  114. return commandLine;
  115. }
  116.  
  117. public bool IsValid
  118. {
  119. get
  120. {
  121. return this._isValid;
  122. }
  123. }
  124.  
  125. public string InputFile
  126. {
  127. get
  128. {
  129. return this.GetValue("input");
  130. }
  131. }
  132.  
  133. public string OutputFile
  134. {
  135. get
  136. {
  137. return this.GetValue("output");
  138. }
  139. }
  140.  
  141. public string Launch
  142. {
  143. get
  144. {
  145. return this.GetValue("launch");
  146. }
  147. }
  148.  
  149. public string Type
  150. {
  151. get
  152. {
  153. return this.GetValue("type");
  154. }
  155. }
  156.  
  157. public string Name
  158. {
  159. get
  160. {
  161. return this.GetValue("name");
  162. }
  163. }
  164.  
  165. public string Action
  166. {
  167. get
  168. {
  169. if (this.GetValue("action") == "upgrade")
  170. return "edit";
  171. return this.GetValue("action");
  172. }
  173. set
  174. {
  175. this.SetValue("action", value);
  176. }
  177. }
  178.  
  179. public string WavList
  180. {
  181. get
  182. {
  183. return this.GetValue("wavlist");
  184. }
  185. }
  186.  
  187. public string IP
  188. {
  189. get
  190. {
  191. return this.GetValue("ip");
  192. }
  193. }
  194.  
  195. public string UserName
  196. {
  197. get
  198. {
  199. if (!string.IsNullOrEmpty(this.GetValue("user")))
  200. return this.GetValue("user");
  201. return this._username;
  202. }
  203. set
  204. {
  205. this._username = value;
  206. }
  207. }
  208.  
  209. public string Password
  210. {
  211. get
  212. {
  213. if (string.IsNullOrEmpty(this.GetValue("password")))
  214. return this._password;
  215. if (!this.EncryptCredential || MainForm.Instance == null)
  216. return this.GetValue("password");
  217. if (string.IsNullOrEmpty(this._decryptedPassword))
  218. this._decryptedPassword = MainForm.Instance.DecryptCommandLineParameter(this.GetValue("password"));
  219. return this._decryptedPassword;
  220. }
  221. set
  222. {
  223. this._password = value;
  224. }
  225. }
  226.  
  227. public string Caption
  228. {
  229. get
  230. {
  231. return this.GetValue("caption");
  232. }
  233. }
  234.  
  235. public string Locale
  236. {
  237. get
  238. {
  239. return this.GetValue("locale");
  240. }
  241. }
  242.  
  243. public string SystemType
  244. {
  245. get
  246. {
  247. return this.GetValue("systemtype");
  248. }
  249. }
  250.  
  251. public double DeviceVersion
  252. {
  253. get
  254. {
  255. string str = this.GetValue("version");
  256. try
  257. {
  258. return Convert.ToDouble(str);
  259. }
  260. catch (Exception ex)
  261. {
  262. return 9.0;
  263. }
  264. }
  265. }
  266.  
  267. public double TargetVersion
  268. {
  269. get
  270. {
  271. string str = this.GetValue("targetversion");
  272. try
  273. {
  274. if (string.IsNullOrEmpty(str))
  275. return 0.0;
  276. return Convert.ToDouble(str);
  277. }
  278. catch (Exception ex)
  279. {
  280. return 9.0;
  281. }
  282. }
  283. }
  284.  
  285. public string ExtnType
  286. {
  287. get
  288. {
  289. return this.GetValue("extntype");
  290. }
  291. }
  292.  
  293. public string VMLocales2Add
  294. {
  295. get
  296. {
  297. return this.GetValue("addvmlocales");
  298. }
  299. }
  300.  
  301. public string CentralDirectory
  302. {
  303. get
  304. {
  305. if (!string.IsNullOrEmpty(this.GetValue("dir")))
  306. return this.GetValue("dir");
  307. return this._commonFileArea;
  308. }
  309. }
  310.  
  311. public void SetPrimary(bool value)
  312. {
  313. this._primary = value;
  314. }
  315.  
  316. public bool IsPrimary
  317. {
  318. get
  319. {
  320. if (!string.IsNullOrEmpty(this.GetValue("primary")))
  321. {
  322. try
  323. {
  324. return Convert.ToBoolean(this.GetValue("primary"), (IFormatProvider) CultureInfo.InvariantCulture);
  325. }
  326. catch (Exception ex)
  327. {
  328. }
  329. }
  330. return this._primary;
  331. }
  332. }
  333.  
  334. public bool IsRemote
  335. {
  336. get
  337. {
  338. if (!string.IsNullOrEmpty(this.GetValue("remote")))
  339. {
  340. try
  341. {
  342. return Convert.ToBoolean(this.GetValue("remote"), (IFormatProvider) CultureInfo.InvariantCulture);
  343. }
  344. catch (Exception ex)
  345. {
  346. }
  347. }
  348. return false;
  349. }
  350. }
  351.  
  352. public int BasePort
  353. {
  354. get
  355. {
  356. if (!string.IsNullOrEmpty(this.GetValue("baseport")))
  357. {
  358. try
  359. {
  360. return Convert.ToInt32(this.GetValue("baseport"), (IFormatProvider) CultureInfo.InvariantCulture);
  361. }
  362. catch (Exception ex)
  363. {
  364. }
  365. }
  366. return 0;
  367. }
  368. }
  369.  
  370. public bool EncryptCredential
  371. {
  372. get
  373. {
  374. if (!string.IsNullOrEmpty(this.GetValue("encryptcredential")))
  375. {
  376. try
  377. {
  378. return Convert.ToBoolean(this.GetValue("encryptcredential"), (IFormatProvider) CultureInfo.InvariantCulture);
  379. }
  380. catch (Exception ex)
  381. {
  382. }
  383. }
  384. return false;
  385. }
  386. }
  387.  
  388. public bool HasValue(string key)
  389. {
  390. return this._args.ContainsKey(key);
  391. }
  392.  
  393. private string GetValue(string key)
  394. {
  395. if (this._args.ContainsKey(key))
  396. return this._args[key];
  397. return string.Empty;
  398. }
  399.  
  400. private void SetValue(string key, string value)
  401. {
  402. if (!this._args.ContainsKey(key))
  403. return;
  404. this._args[key] = value;
  405. }
  406.  
  407. public void ClearAll()
  408. {
  409. this._args.Clear();
  410. }
  411. }
  412. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement