Command line execution and more readable logic for _executionMode

This commit is contained in:
christianwade 2017-01-04 20:50:54 -08:00
parent a8196b30ad
commit 65bc278f66
2 changed files with 83 additions and 37 deletions

View File

@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AnalysisServices.Tabular; using Microsoft.AnalysisServices.Tabular;
using System.Diagnostics;
namespace AsPartitionProcessing.SampleClient namespace AsPartitionProcessing.SampleClient
{ {
@ -16,44 +16,75 @@ namespace AsPartitionProcessing.SampleClient
class Program class Program
{ {
//Set sample execution mode here: //Set sample execution mode here:
const SampleExecutionMode ExecutionMode = SampleExecutionMode.InitializeInline; private static SampleExecutionMode _executionMode = SampleExecutionMode.InitializeInline;
static void Main(string[] args) static void Main(string[] args)
{ {
try try
{ {
List<ModelConfiguration> modelsConfig; #region Set execution mode from command-line argument if specified.
if (ExecutionMode == SampleExecutionMode.InitializeInline)
if (args.Length == 1)
{ {
modelsConfig = InitializeInline(); switch (args[0])
{
case "InitializeInline":
_executionMode = SampleExecutionMode.InitializeInline;
break;
case "InitializeFromDatabase":
_executionMode = SampleExecutionMode.InitializeFromDatabase;
break;
case "MergePartitions":
_executionMode = SampleExecutionMode.MergePartitions;
break;
case "DefragPartitionedTables":
_executionMode = SampleExecutionMode.DefragPartitionedTables;
break;
default:
throw new InvalidOperationException($"Command-line argument {args[0]} not recognized.");
//break;
}
}
#endregion
if (_executionMode == SampleExecutionMode.InitializeInline)
{
//Perform Processing
PartitionProcessor.PerformProcessing(InitializeInline(), LogMessage);
} }
else else
{ {
modelsConfig = InitializeFromDatabase(); List<ModelConfiguration> modelsConfig = InitializeFromDatabase();
}
foreach (ModelConfiguration modelConfig in modelsConfig) foreach (ModelConfiguration modelConfig in modelsConfig)
{ {
if (!modelConfig.IntegratedAuth) //For Azure AS SetCredentials(modelConfig); //For Azure AS
{
Console.WriteLine();
Console.Write("User name for AS server: ");
modelConfig.UserName = Console.ReadLine();
Console.Write("Password for AS server: ");
modelConfig.Password = ReadPassword();
}
if (ExecutionMode == SampleExecutionMode.MergePartitions) switch (_executionMode)
{
PartitionProcessor.MergePartitions(modelConfig, LogMessage, "Internet Sales", Granularity.Yearly, "2012");
}
else if (ExecutionMode == SampleExecutionMode.DefragPartitionedTables)
{
PartitionProcessor.DefragPartitionedTables(modelConfig, LogMessage);
}
else
{ {
case SampleExecutionMode.InitializeFromDatabase:
//Perform Processing
PartitionProcessor.PerformProcessing(modelConfig, LogMessage); PartitionProcessor.PerformProcessing(modelConfig, LogMessage);
break;
case SampleExecutionMode.MergePartitions:
//Perform Merging
PartitionProcessor.MergePartitions(modelConfig, LogMessage, "Internet Sales", Granularity.Yearly, "2012");
break;
case SampleExecutionMode.DefragPartitionedTables:
//Perform Defrag
PartitionProcessor.DefragPartitionedTables(modelConfig, LogMessage);
break;
default:
break;
}
} }
} }
} }
@ -65,12 +96,15 @@ namespace AsPartitionProcessing.SampleClient
Console.WriteLine(); Console.WriteLine();
} }
if (Debugger.IsAttached)
{
Console.ForegroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Press any key to exit."); Console.WriteLine("Press any key to exit.");
Console.ReadKey(); Console.ReadKey();
} }
}
private static List<ModelConfiguration> InitializeInline() private static ModelConfiguration InitializeInline()
{ {
ModelConfiguration partitionedModel = new ModelConfiguration( ModelConfiguration partitionedModel = new ModelConfiguration(
modelConfigurationID: 1, modelConfigurationID: 1,
@ -135,7 +169,7 @@ namespace AsPartitionProcessing.SampleClient
#endregion #endregion
return new List<ModelConfiguration> { partitionedModel }; return partitionedModel;
} }
private static List<ModelConfiguration> InitializeFromDatabase() private static List<ModelConfiguration> InitializeFromDatabase()
@ -163,7 +197,7 @@ namespace AsPartitionProcessing.SampleClient
try try
{ {
if (!(ExecutionMode == SampleExecutionMode.InitializeInline)) if (!(_executionMode == SampleExecutionMode.InitializeInline))
{ {
ConfigDatabaseHelper.LogMessage(message, partitionedModel); ConfigDatabaseHelper.LogMessage(message, partitionedModel);
} }
@ -182,7 +216,19 @@ namespace AsPartitionProcessing.SampleClient
} }
} }
public static string ReadPassword() private static void SetCredentials(ModelConfiguration modelConfig)
{
if (!modelConfig.IntegratedAuth) //For Azure AS
{
Console.WriteLine();
Console.Write("User name for AS server: ");
modelConfig.UserName = Console.ReadLine();
Console.Write("Password for AS server: ");
modelConfig.Password = ReadPassword();
}
}
private static string ReadPassword()
{ {
string password = ""; string password = "";
ConsoleKeyInfo info = Console.ReadKey(true); ConsoleKeyInfo info = Console.ReadKey(true);

View File

@ -579,13 +579,13 @@ namespace AsPartitionProcessing
switch (partitioningConfiguration.Granularity) switch (partitioningConfiguration.Granularity)
{ {
case Granularity.Daily: case Granularity.Daily:
selectQueryTemplate = "SELECT * FROM {0} WHERE {1} = {2} ORDER BY {1}"; selectQueryTemplate = "SELECT * FROM {0} WHERE CAST(CONVERT(varchar, {1}, 112) AS int) = {2} ORDER BY {1}";
break; break;
case Granularity.Monthly: case Granularity.Monthly:
selectQueryTemplate = "SELECT * FROM {0} WHERE FLOOR({1} / 100) = {2} ORDER BY {1}"; selectQueryTemplate = "SELECT * FROM {0} WHERE FLOOR(CAST(CONVERT(varchar, {1}, 112) AS int) / 100) = {2} ORDER BY {1}";
break; break;
default: //Granularity.Yearly: default: //Granularity.Yearly:
selectQueryTemplate = "SELECT * FROM {0} WHERE FLOOR({1} / 10000) = {2} ORDER BY {1}"; selectQueryTemplate = "SELECT * FROM {0} WHERE FLOOR(CAST(CONVERT(varchar, {1}, 112) AS int) / 10000) = {2} ORDER BY {1}";
break; break;
} }
Partition newPartition; Partition newPartition;