CommandLine NuGet
This commit is contained in:
parent
206f4c0bf8
commit
3f310a2402
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using CommandLine;
|
||||
using CommandLine.Text;
|
||||
|
||||
namespace AsPartitionProcessing.SampleClient
|
||||
{
|
||||
class ArgumentOptions
|
||||
{
|
||||
[Option('m', "ExecutionMode", HelpText = "Execution mode of SampleClient. Possible values are InitializeInline, InitializeFromDatabase, MergePartitions, DefragPartitionedTables.")]
|
||||
public string ExecutionMode { get; set; }
|
||||
|
||||
[Option('t', "MergeTable", HelpText = "When ExecutionMode=MergePartitions, name of the partitioned table in the tabular model.")]
|
||||
public string MergeTable { get; set; }
|
||||
|
||||
[Option('g', "TargetGranularity", HelpText = "When ExecutionMode=MergePartitions, granularity of the newly created partition. Possible values are Yearly or Monthly.")]
|
||||
public string TargetGranularity { get; set; }
|
||||
|
||||
[Option('k', "MergePartitionKey", HelpText = "When ExecutionMode=MergePartitions, target partition key. If year, follow yyyy; if month follow yyyymm.")]
|
||||
public string MergePartitionKey { get; set; }
|
||||
|
||||
[ParserState]
|
||||
public IParserState LastParserState { get; set; }
|
||||
|
||||
[HelpOption]
|
||||
public string GetUsage()
|
||||
{
|
||||
return HelpText.AutoBuild(this, (HelpText current) => HelpText.DefaultParsingErrorsHandler(this, current));
|
||||
}
|
||||
}
|
||||
}
|
@ -34,6 +34,10 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="CommandLine, Version=1.9.71.2, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.AnalysisServices, Version=13.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Microsoft SQL Server\130\SDK\Assemblies\Microsoft.AnalysisServices.DLL</HintPath>
|
||||
@ -56,6 +60,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ArgumentOptions.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Settings.Designer.cs">
|
||||
@ -66,6 +71,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
|
@ -5,18 +5,40 @@ using System.Diagnostics;
|
||||
|
||||
namespace AsPartitionProcessing.SampleClient
|
||||
{
|
||||
enum SampleExecutionMode
|
||||
#region enum ExecutionMode
|
||||
|
||||
/// <summary>
|
||||
/// Execution mode of the SampleClient application.
|
||||
/// </summary>
|
||||
enum ExecutionMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialize configuration inline using sample values.
|
||||
/// </summary>
|
||||
InitializeInline,
|
||||
|
||||
/// <summary>
|
||||
/// Initialize from configuration and logging database.
|
||||
/// </summary>
|
||||
InitializeFromDatabase,
|
||||
|
||||
/// <summary>
|
||||
/// Merge partitions in a table based on other parameters.
|
||||
/// </summary>
|
||||
MergePartitions,
|
||||
|
||||
/// <summary>
|
||||
/// Defragment partitioned tables in the model. List of partitioned tables defined in the configuration and logging database.
|
||||
/// </summary>
|
||||
DefragPartitionedTables
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
class Program
|
||||
{
|
||||
//Set sample execution mode here:
|
||||
private static SampleExecutionMode _executionMode = SampleExecutionMode.InitializeInline;
|
||||
private static ExecutionMode _executionMode = ExecutionMode.InitializeInline;
|
||||
|
||||
static int Main(string[] args)
|
||||
{
|
||||
@ -27,44 +49,16 @@ namespace AsPartitionProcessing.SampleClient
|
||||
string mergeTable = "Internet Sales";
|
||||
Granularity mergeTargetGranuarity = Granularity.Yearly;
|
||||
string mergePartitionKey = "2012";
|
||||
bool help;
|
||||
|
||||
if (args.Length > 0)
|
||||
{
|
||||
switch (args[0])
|
||||
{
|
||||
case "InitializeInline":
|
||||
_executionMode = SampleExecutionMode.InitializeInline;
|
||||
break;
|
||||
|
||||
case "InitializeFromDatabase":
|
||||
_executionMode = SampleExecutionMode.InitializeFromDatabase;
|
||||
break;
|
||||
|
||||
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":
|
||||
_executionMode = SampleExecutionMode.DefragPartitionedTables;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ArgumentException($"Command-line argument {args[0]} not recognized.");
|
||||
//break;
|
||||
}
|
||||
}
|
||||
ParseArgs(args, ref mergeTable, ref mergeTargetGranuarity, ref mergePartitionKey, out help);
|
||||
if (help)
|
||||
return 0; //ERROR_SUCCESS
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
if (_executionMode == SampleExecutionMode.InitializeInline)
|
||||
if (_executionMode == ExecutionMode.InitializeInline)
|
||||
{
|
||||
//Perform Processing
|
||||
PartitionProcessor.PerformProcessing(InitializeInline(), LogMessage);
|
||||
@ -79,17 +73,17 @@ namespace AsPartitionProcessing.SampleClient
|
||||
|
||||
switch (_executionMode)
|
||||
{
|
||||
case SampleExecutionMode.InitializeFromDatabase:
|
||||
case ExecutionMode.InitializeFromDatabase:
|
||||
//Perform Processing
|
||||
PartitionProcessor.PerformProcessing(modelConfig, LogMessage);
|
||||
break;
|
||||
|
||||
case SampleExecutionMode.MergePartitions:
|
||||
case ExecutionMode.MergePartitions:
|
||||
//Perform Merging
|
||||
PartitionProcessor.MergePartitions(modelConfig, LogMessage, mergeTable, mergeTargetGranuarity, mergePartitionKey);
|
||||
break;
|
||||
|
||||
case SampleExecutionMode.DefragPartitionedTables:
|
||||
case ExecutionMode.DefragPartitionedTables:
|
||||
//Perform Defrag
|
||||
PartitionProcessor.DefragPartitionedTables(modelConfig, LogMessage);
|
||||
break;
|
||||
@ -104,7 +98,7 @@ namespace AsPartitionProcessing.SampleClient
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine();
|
||||
Console.WriteLine(exc.Message, null);
|
||||
Console.WriteLine(exc.Message);
|
||||
Console.WriteLine();
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
|
||||
@ -117,17 +111,76 @@ namespace AsPartitionProcessing.SampleClient
|
||||
return 1360; //ERROR_GENERIC_NOT_MAPPED
|
||||
}
|
||||
}
|
||||
|
||||
if (Debugger.IsAttached)
|
||||
finally
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.WriteLine("Press any key to exit.");
|
||||
Console.ReadKey();
|
||||
if (Debugger.IsAttached)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.WriteLine("Press any key to exit.");
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
|
||||
return 0; //ERROR_SUCCESS
|
||||
}
|
||||
|
||||
private static void ParseArgs(string[] args, ref string mergeTable, ref Granularity mergeTargetGranuarity, ref string mergePartitionKey, out bool help)
|
||||
{
|
||||
help = false;
|
||||
if (args.Length > 0)
|
||||
{
|
||||
ArgumentOptions options = new ArgumentOptions();
|
||||
if (CommandLine.Parser.Default.ParseArguments(args, options))
|
||||
{
|
||||
Console.WriteLine($"Argument ExecutionMode: {options.ExecutionMode}");
|
||||
switch (options.ExecutionMode)
|
||||
{
|
||||
case "InitializeInline":
|
||||
_executionMode = ExecutionMode.InitializeInline;
|
||||
break;
|
||||
|
||||
case "InitializeFromDatabase":
|
||||
_executionMode = ExecutionMode.InitializeFromDatabase;
|
||||
break;
|
||||
|
||||
case "MergePartitions":
|
||||
_executionMode = ExecutionMode.MergePartitions;
|
||||
|
||||
if (options.MergeTable == null || options.TargetGranularity == null || options.MergePartitionKey == null)
|
||||
{
|
||||
throw new ArgumentException($"ExecutionMode MergePartitions additional arguments not provided or not recognized. Requires --MergeTable, --TargetGranularity, --MergePartitionKey.");
|
||||
}
|
||||
|
||||
Console.WriteLine($"Argument MergeTable: {options.MergeTable}");
|
||||
Console.WriteLine($"Argument TargetGranularity: {options.TargetGranularity}");
|
||||
Console.WriteLine($"Argument MergePartitionKey: {options.MergePartitionKey}");
|
||||
|
||||
mergeTable = options.MergeTable;
|
||||
mergeTargetGranuarity = options.TargetGranularity == "Yearly" ? Granularity.Yearly : Granularity.Monthly;
|
||||
mergePartitionKey = options.MergePartitionKey;
|
||||
break;
|
||||
|
||||
case "DefragPartitionedTables":
|
||||
_executionMode = ExecutionMode.DefragPartitionedTables;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ArgumentException($"Argument --ExecutionMode {options.ExecutionMode} not recognized.");
|
||||
//break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args[0].ToLower() != "--help")
|
||||
{
|
||||
throw new ArgumentException($"Arguments provided not recognized.");
|
||||
}
|
||||
|
||||
help = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static ModelConfiguration InitializeInline()
|
||||
{
|
||||
ModelConfiguration partitionedModel = new ModelConfiguration(
|
||||
@ -221,7 +274,7 @@ namespace AsPartitionProcessing.SampleClient
|
||||
|
||||
try
|
||||
{
|
||||
if (!(_executionMode == SampleExecutionMode.InitializeInline))
|
||||
if (!(_executionMode == ExecutionMode.InitializeInline))
|
||||
{
|
||||
ConfigDatabaseHelper.LogMessage(message, partitionedModel);
|
||||
}
|
||||
|
@ -8,9 +8,9 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyTitle("AsPartitionProcessing.SampleClient")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft Corporation")]
|
||||
[assembly: AssemblyCompany(" ")]
|
||||
[assembly: AssemblyProduct("AsPartitionProcessing.SampleClient")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft Corporation 2016")]
|
||||
[assembly: AssemblyCopyright(" ")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
|
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="CommandLineParser" version="1.9.71" targetFramework="net452" />
|
||||
</packages>
|
Loading…
Reference in New Issue
Block a user