private void Parse(string[] args)
{
// Do these arguments the traditional way to maintain compatibility
if (args.Length < 3)
PrintUsageAndExit(-1);
SmugglerAction action = SmugglerAction.Export;
if (string.Equals(args[0], "in", StringComparison.OrdinalIgnoreCase))
action = SmugglerAction.Import;
else if (string.Equals(args[0], "out", StringComparison.OrdinalIgnoreCase))
action = SmugglerAction.Export;
else
PrintUsageAndExit(-1);
var url = args[1];
if (url == null)
{
PrintUsageAndExit(-1);
return;
}
connectionStringOptions.Url = url;
options.File = args[2];
if (options.File == null)
PrintUsageAndExit(-1);
try
{
optionSet.Parse(args);
}
catch (Exception e)
{
PrintUsageAndExit(e);
}
if (options.File != null && Directory.Exists(options.File))
{
incremental = true;
}
var smugglerApi = new SmugglerApi(connectionStringOptions);
try
{
switch (action)
{
case SmugglerAction.Import:
smugglerApi.ImportData(options, incremental);
break;
case SmugglerAction.Export:
smugglerApi.ExportData(options, incremental);
break;
}
}
catch (WebException e)
{
var httpWebResponse = e.Response as HttpWebResponse;
if (httpWebResponse == null)
throw;
Console.WriteLine("Error: " + e.Message);
Console.WriteLine("Http Status Code: " + httpWebResponse.StatusCode + " " + httpWebResponse.StatusDescription);
using (var reader = new StreamReader(httpWebResponse.GetResponseStream()))
{
string line;
while ((line = reader.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
Environment.Exit((int)httpWebResponse.StatusCode);
}
catch (Exception e)
{
Console.WriteLine(e);
Environment.Exit(-1);
}
}