-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSettings.cs
188 lines (157 loc) · 5.52 KB
/
Settings.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.BizTalk.ExplorerOM;
using System.IO;
using static Ox.BizTalk.TrackedMessageExtractor.ConsoleTools;
namespace Ox.BizTalk.TrackedMessageExtractor
{
/// <summary>
/// Setings for the application
/// </summary>
public class Settings
{
public string InFile { get; set; }
public string OutputDirectory { get; set; }
public string FilenameProperty { get; set; }
public string FilenameSchema { get; set; }
public string BizTalkMgmtDb { get; set; }
public string BizTalkMgmtHost { get; set; }
public string BizTalkDTADb { get; set; }
public string BizTalkDTAHost { get; set; }
public bool QuitWhenDone { get; set; }
public Settings()
{
this.FilenameProperty = "ReceivedFileName";
this.FilenameSchema = "http://schemas.microsoft.com/BizTalk/2003/file-properties";
this.QuitWhenDone = false;
try
{
BizTalkWmiSearcher.PopulateWmiSettings(this);
}
catch { }
}
/// <summary>
/// Checks for missing settings and prompts for them.
/// </summary>
public void PromptForMissing()
{
if (String.IsNullOrEmpty(this.InFile))
{
do
{
var file = PromptFor<String>("Message id file");
if (!File.Exists(file))
{
WriteColourfulLine(CON_COLOUR_WARN, "File does not exist.");
}
this.InFile = file;
} while (String.IsNullOrEmpty(this.InFile));
}
if(String.IsNullOrEmpty(this.OutputDirectory))
{
do
{
var dir = PromptFor<String>("Output directory", Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
if (!Directory.Exists(dir))
{
WriteColourfulLine(CON_COLOUR_WARN, "Directory does not exist.");
}
this.OutputDirectory = dir;
} while (String.IsNullOrEmpty(this.OutputDirectory));
}
if (String.IsNullOrEmpty(this.BizTalkMgmtHost))
this.BizTalkMgmtHost = PromptFor<String>("SQL Host for BizTalkMgmtDb");
if (String.IsNullOrEmpty(this.BizTalkMgmtDb))
this.BizTalkMgmtDb = PromptFor<String>("Database name for BizTalkMgmtDb", "BizTalkMgmtDb");
if (String.IsNullOrEmpty(this.BizTalkDTAHost))
this.BizTalkDTAHost = PromptFor<String>("SQL Host for BizTalkDTADb", this.BizTalkMgmtHost);
if (String.IsNullOrEmpty(this.BizTalkDTADb))
this.BizTalkDTADb = PromptFor<String>("Database name for BizTalkDTADb", "BizTalkDTADb");
}
/// <summary>
/// Handles external program arguments and converts them to settings
/// </summary>
/// <param name="args">External arguments</param>
/// <returns>False means exit gracefully</returns>
public bool ProcessArguments(string[] args)
{
bool runprogram = true;
foreach (var arg in args)
{
string key = arg;
string value = arg;
// Split out arguments from values
if (arg.Contains("="))
{
var split = arg.Split('=');
if (split.Length != 2)
{
throw new ArgumentException("Argument '{0}' not understood.", arg);
}
key = split[0];
value = split[1];
}
switch (key.ToLower())
{
case "--help":
case "-h":
case "/?":
string about = "Bulk saves BizTalk messages from the BizTalkDTADb health and tracking database (if they exist).\nTracking needs to be enabled in BizTalk to save messages.\n\nMessages will be saved to the current working directory unless overridden.\n\nWMI will be used to locate the server, if available.";
Console.WriteLine(about + Environment.NewLine);
Console.WriteLine("Usage:");
Console.WriteLine(" --in=PATH Line delimetered file of BizTalk message ids");
Console.WriteLine(" --mgmthost=SQLHOST Hostname of Mgmt SQL server/instance to connect to");
Console.WriteLine(" --dtahost=SQLHOST Hostname of the DTA SQL server/isntance");
Console.WriteLine(" --mgmtdb=DB Database name of BizTalkMgmtDb");
Console.WriteLine(" --dtadb=DB Database name of the BizTalkDTADb");
Console.WriteLine(" --out=PATH Alternative output directory");
Console.WriteLine(" --nameschema=URI Context namespace to use for deriving original filename");
Console.WriteLine(" --nameproperty=NAME Context property name to use for deriving original filename");
Console.WriteLine(" --quit Do not prompt for program closure at end");
Console.WriteLine("\nExamples:");
Console.WriteLine(" --in=messages.txt --out=c:\\ --nameschema=http://schemas.microsoft.com/BizTalk/2003/file-properties --nameproperty=ReceivedFileName --mgmthost=localhost --mgmtdb=BizTalkMgmtDb --dtahost=localhost --dtadb=BizTalkDTADb");
runprogram = false;
break;
case "--in":
if(!File.Exists(value))
{
throw new ArgumentException("Invalid input file " + value);
}
this.InFile = value;
break;
case "--mgmthost":
this.BizTalkMgmtHost = value;
break;
case "--dtahost":
this.BizTalkDTAHost = value;
break;
case "--mgmtdb":
this.BizTalkMgmtDb = value;
break;
case "--dtadb":
this.BizTalkDTADb = value;
break;
case "--out":
if (!Directory.Exists(value))
{
throw new ArgumentException("Invalid output directory " + value);
}
this.OutputDirectory = value;
break;
case "--nameschema":
this.FilenameSchema = value;
break;
case "--nameproperty":
this.FilenameProperty = value;
break;
case "--quit":
this.QuitWhenDone = true;
break;
}
}
return runprogram;
}
}
}