1 |
using System; |
2 |
using System.Collections.Generic; |
3 |
using System.Text; |
4 |
using System.Xml; |
5 |
using System.IO; |
6 |
using System.Globalization; |
7 |
using System.Text.RegularExpressions; |
8 |
|
9 |
namespace xmlTools |
10 |
{ |
11 |
class Program |
12 |
{ |
13 |
public static readonly string toolsVersion = "0.8c"; |
14 |
private static appErrors lastError; |
15 |
|
16 |
public enum appErrors |
17 |
{ |
18 |
// 1-19 Errors with input parameters |
19 |
ERROR_PARAMS = 1, |
20 |
FILE_NOT_FOUND = 2, |
21 |
ELEMENT_NOT_SPECIFIED=3, |
22 |
ELEMENT_NOT_FOUND=4, |
23 |
// 20-199 General application errors |
24 |
BACKUPS_ALREADY_EXISTS=20, |
25 |
NUMBER_VALUES_TO_REPLACE_NE_AVAILABLE_VALUES = 21, |
26 |
INVALID_POSITIONS_RANGE=22, |
27 |
// 200-299 Patch operations errors |
28 |
PATCH_ADDTO_PROCESS_ERROR = 200, |
29 |
PATCH_REMOVE_PROCESS_ERROR = 201, |
30 |
PATCH_COMMAND_PROCESS_ERROR=202, |
31 |
PATCH_ELEMENT_NOT_FOUND=203, |
32 |
PATCH_ADDTO_ERROR_PARSING_XML=204, |
33 |
PATCH_COMMAND_NOT_FOUND=205 |
34 |
} |
35 |
|
36 |
public static void printAppError(appErrors error, string description, bool exitApp=false){ |
37 |
Console.Error.WriteLine("Error Code: "+(int)error); |
38 |
Console.Error.WriteLine(description); |
39 |
|
40 |
if (exitApp) |
41 |
{ |
42 |
Environment.Exit(1); |
43 |
} |
44 |
|
45 |
lastError = error; |
46 |
} |
47 |
|
48 |
public static int Main(string[] args) |
49 |
{ |
50 |
try |
51 |
{ |
52 |
//We use a command parse library due to its advantages |
53 |
CLAP.Parser.RunConsole<ParametersParser>(args); |
54 |
return (int)lastError; |
55 |
} |
56 |
catch (Exception e) |
57 |
{ |
58 |
printAppError(appErrors.ERROR_PARAMS, "Error processing parameters:\n" + e.ToString()); |
59 |
return (int)appErrors.ERROR_PARAMS; |
60 |
} |
61 |
} |
62 |
} |
63 |
} |