Command line args enhancement

This commit is contained in:
christianwade 2017-01-06 20:18:32 -08:00
parent 96763cb87d
commit e6a2b61643
2 changed files with 38 additions and 5 deletions

View File

@ -18,13 +18,17 @@ namespace AsPartitionProcessing.SampleClient
//Set sample execution mode here:
private static SampleExecutionMode _executionMode = SampleExecutionMode.InitializeInline;
static void Main(string[] args)
static int Main(string[] args)
{
try
{
#region Set execution mode from command-line argument if specified.
#region Set defaults for merging & read command-line arguments if provided
if (args.Length == 1)
string mergeTable = "Internet Sales";
Granularity mergeTargetGranuarity = Granularity.Yearly;
string mergePartitionKey = "2012";
if (args.Length > 0)
{
switch (args[0])
{
@ -38,6 +42,13 @@ namespace AsPartitionProcessing.SampleClient
case "MergePartitions":
_executionMode = SampleExecutionMode.MergePartitions;
if (!(args.Length == 4 && (args[2] == "Yearly" || args[2] == "Monthly")))
{
throw new ArgumentException($"MergePartitions additional arguments not provided or not recognized.");
}
mergeTable = args[1];
mergeTargetGranuarity = args[2] == "Yearly" ? Granularity.Yearly : Granularity.Monthly;
mergePartitionKey = args[3];
break;
case "DefragPartitionedTables":
@ -45,13 +56,14 @@ namespace AsPartitionProcessing.SampleClient
break;
default:
throw new InvalidOperationException($"Command-line argument {args[0]} not recognized.");
throw new ArgumentException($"Command-line argument {args[0]} not recognized.");
//break;
}
}
#endregion
if (_executionMode == SampleExecutionMode.InitializeInline)
{
//Perform Processing
@ -74,7 +86,7 @@ namespace AsPartitionProcessing.SampleClient
case SampleExecutionMode.MergePartitions:
//Perform Merging
PartitionProcessor.MergePartitions(modelConfig, LogMessage, "Internet Sales", Granularity.Yearly, "2012");
PartitionProcessor.MergePartitions(modelConfig, LogMessage, mergeTable, mergeTargetGranuarity, mergePartitionKey);
break;
case SampleExecutionMode.DefragPartitionedTables:
@ -94,6 +106,16 @@ namespace AsPartitionProcessing.SampleClient
Console.WriteLine();
Console.WriteLine(exc.Message, null);
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.White;
if (exc is ArgumentException)
{
return 160; //ERROR_BAD_ARGUMENTS
}
else
{
return 1360; //ERROR_GENERIC_NOT_MAPPED
}
}
if (Debugger.IsAttached)
@ -102,6 +124,8 @@ namespace AsPartitionProcessing.SampleClient
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
return 0; //ERROR_SUCCESS
}
private static ModelConfiguration InitializeInline()
@ -212,6 +236,7 @@ namespace AsPartitionProcessing.SampleClient
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
Console.ForegroundColor = ConsoleColor.White;
Environment.Exit(0); //Avoid recursion if errored connecting to db
}
}

View File

@ -212,6 +212,7 @@ namespace AsPartitionProcessing
LogMessage($"Inner exception message: {exc.InnerException.Message}", false);
}
LogMessage("", false);
Console.ForegroundColor = ConsoleColor.White;
}
finally
{
@ -342,6 +343,8 @@ namespace AsPartitionProcessing
{
LogMessage($"Inner exception message: {exc.InnerException.Message}", false);
}
LogMessage("", false);
Console.ForegroundColor = ConsoleColor.White;
}
finally
{
@ -415,6 +418,7 @@ namespace AsPartitionProcessing
LogMessage($"Inner exception message: {exc.InnerException.Message}", false);
}
LogMessage("", false);
Console.ForegroundColor = ConsoleColor.White;
}
finally
{
@ -578,6 +582,10 @@ namespace AsPartitionProcessing
string selectQueryTemplate;
switch (partitioningConfiguration.Granularity)
{
//Format that might work on more data sources, but requires flag to indicate whether partitioning column is date or integer YYYYMMDD or not:
// SELECT YEAR(CURRENT_TIMESTAMP) * 10000 + MONTH(CURRENT_TIMESTAMP) * 100 + DAY(CURRENT_TIMESTAMP)
//ANSI standard to get month from date is EXTRACT(MONTH FROM @DateTimeVarUnclean), which doesn't work with SQL Server
case Granularity.Daily:
selectQueryTemplate = "SELECT * FROM {0} WHERE CAST(CONVERT(varchar, {1}, 112) AS int) = {2} ORDER BY {1}";
break;