source: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/BMX41000/IHS BMX Framework/IndianHealthService.BMXNet.WinForm/Configuration/CommandLineArguments.cs

Last change on this file was 1146, checked in by Sam Habiel, 14 years ago

Initial Import of BMX4

File size: 2.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Xml.Serialization;
5
6namespace IndianHealthService.BMXNet.WinForm.Configuration
7{
8 internal class CommandLineArguments
9 {
10 //command line, no forward slashes in value /flag /key:value /key:"two part value"
11 public Settings ParseSlashKeyValue(String[] arguments, bool ignoreErrors)
12 {
13 Settings answer = new Settings();
14 foreach (String each in arguments)
15 {
16 String toParse = each;
17 try
18 {
19 if (!each.EndsWith(".exe"))
20 {
21 if (toParse.StartsWith(@"""") && toParse.EndsWith(@""""))
22 {
23 toParse = toParse.Substring(1, toParse.Length - 2);
24 }
25 String[] peices = toParse.Split(new char[] { ':' });
26 String key = null;
27 String value = null;
28 if (peices.Length > 0)
29 {
30 key = peices[0];
31 if (key.StartsWith(@"/"))
32 {
33 key = key.Substring(1, key.Length - 1);
34 }
35
36 if (peices.Length == 1)
37 {
38 value = "true";
39 }
40 else if (peices.Length == 2)
41 {
42 value = peices[1].Replace(@"""", "");
43 }
44 else
45 {
46 key = null;
47 }
48 }
49
50 if (key == null)
51 {
52 throw new Exception(@"Unable to find command key.");
53 }
54 else
55 {
56 answer.AddSetting(new Setting() { Name = key.Trim(), Value = value.Trim(), IsPersistent = false });
57 }
58 }
59 }
60 catch (Exception problem)
61 {
62 if (!ignoreErrors)
63 {
64 throw new Exception(@"Unable to parse command-line arguments. Valid format is /flag /key:value /key:""two part value"", no forward slashes allowed", problem);
65 }
66 }
67 }
68
69 return answer;
70 }
71 }
72}
Note: See TracBrowser for help on using the repository browser.