diff --git a/AsPartitionProcessing/AsPartitionProcessing.SampleClient/Program.cs b/AsPartitionProcessing/AsPartitionProcessing.SampleClient/Program.cs index 91ab8e7..14c846f 100644 --- a/AsPartitionProcessing/AsPartitionProcessing.SampleClient/Program.cs +++ b/AsPartitionProcessing/AsPartitionProcessing.SampleClient/Program.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using Microsoft.AnalysisServices.Tabular; - +using System.Diagnostics; namespace AsPartitionProcessing.SampleClient { @@ -16,44 +16,75 @@ namespace AsPartitionProcessing.SampleClient class Program { //Set sample execution mode here: - const SampleExecutionMode ExecutionMode = SampleExecutionMode.InitializeInline; + private static SampleExecutionMode _executionMode = SampleExecutionMode.InitializeInline; static void Main(string[] args) { try { - List modelsConfig; - if (ExecutionMode == SampleExecutionMode.InitializeInline) + #region Set execution mode from command-line argument if specified. + + 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 { - modelsConfig = InitializeFromDatabase(); - } + List modelsConfig = InitializeFromDatabase(); - foreach (ModelConfiguration modelConfig in modelsConfig) - { - if (!modelConfig.IntegratedAuth) //For Azure AS + foreach (ModelConfiguration modelConfig in modelsConfig) { - Console.WriteLine(); - Console.Write("User name for AS server: "); - modelConfig.UserName = Console.ReadLine(); - Console.Write("Password for AS server: "); - modelConfig.Password = ReadPassword(); - } + SetCredentials(modelConfig); //For Azure AS - if (ExecutionMode == SampleExecutionMode.MergePartitions) - { - PartitionProcessor.MergePartitions(modelConfig, LogMessage, "Internet Sales", Granularity.Yearly, "2012"); - } - else if (ExecutionMode == SampleExecutionMode.DefragPartitionedTables) - { - PartitionProcessor.DefragPartitionedTables(modelConfig, LogMessage); - } - else - { - PartitionProcessor.PerformProcessing(modelConfig, LogMessage); + switch (_executionMode) + { + case SampleExecutionMode.InitializeFromDatabase: + //Perform Processing + 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.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(); + } } - private static List InitializeInline() + private static ModelConfiguration InitializeInline() { ModelConfiguration partitionedModel = new ModelConfiguration( modelConfigurationID: 1, @@ -135,7 +169,7 @@ namespace AsPartitionProcessing.SampleClient #endregion - return new List { partitionedModel }; + return partitionedModel; } private static List InitializeFromDatabase() @@ -163,7 +197,7 @@ namespace AsPartitionProcessing.SampleClient try { - if (!(ExecutionMode == SampleExecutionMode.InitializeInline)) + if (!(_executionMode == SampleExecutionMode.InitializeInline)) { 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 = ""; ConsoleKeyInfo info = Console.ReadKey(true); diff --git a/AsPartitionProcessing/AsPartitionProcessing/PartitionProcessor.cs b/AsPartitionProcessing/AsPartitionProcessing/PartitionProcessor.cs index bdd03b7..036e214 100644 --- a/AsPartitionProcessing/AsPartitionProcessing/PartitionProcessor.cs +++ b/AsPartitionProcessing/AsPartitionProcessing/PartitionProcessor.cs @@ -579,13 +579,13 @@ namespace AsPartitionProcessing switch (partitioningConfiguration.Granularity) { 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; 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; 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; } Partition newPartition;