Ejemplo n.º 1
0
        public void Apply(ServerAndConfigurationArgs args)
        {
            List <Microsoft.AnalysisServices.Tabular.Table> updatedTableCollection = new List <Microsoft.AnalysisServices.Tabular.Table>();

            // Read configuration file
            aggsConfig = JsonHelper.ToClass <AggsConfiguration>(File.ReadAllText(args.ConfigFile));

            #region Connect

            Connect(args.Server);

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine($"Start: {DateTime.Now.ToString("hh:mm:ss tt")}");
            Console.WriteLine($"Server: {args.Server}");
            Console.WriteLine($"Database: {aggsConfig.Database.Name}");

            #endregion

            #region Validate Configuration Against Model

            aggsConfig.Database.Tables.ForEach(x => ValidateConfigurationOfTable(x));

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine($"Validation successful");

            #endregion

            #region Update Model Compatibility

            //Set database compat level
            if (database.CompatibilityLevel < 1465)
            {
                database.CompatibilityLevel = 1465;
                database.Update();
            }

            #endregion

            #region Apply Model Changes

            var changesApplied = 0;
            aggsConfig.Database.Tables.ForEach(x =>
            {
                var delta = ApplyConfigurationOfTable(x);

                if (delta > 0)
                {
                    updatedTableCollection.Add(database.Model.Tables.Find(x.Name));
                }

                changesApplied += delta;
            }
                                               );

            if (changesApplied == 0)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine($"No changes applied to model");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine($"Applied model changes");
            }

            #endregion

            #region Expand Full

            if (changesApplied == 0)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Skipping write to database, no changes detected");
            }
            else
            {
                // Set database UpdateOptions to ExpandFull
                try
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.Write("Writing model changes to database ");
                    database.Update(Microsoft.AnalysisServices.UpdateOptions.ExpandFull);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("SUCCESS");
                }
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("FAILED");

                    throw e;
                }
            }

            #endregion

            #region Refresh Tables as Required

            if (changesApplied == 0)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Skipping table refresh, no changes detected");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Refreshing tables - begin: " + DateTime.Now.ToString("hh:mm:ss tt"));

                foreach (var tableObj in updatedTableCollection)
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.Write($"Refreshing table [{tableObj.Name}] ");

                    Table tableConfig = aggsConfig.Database.Tables.First(x => x.Name == tableObj.Name);
                    var   refreshType = (RefreshType)Enum.Parse(typeof(RefreshType), tableConfig.RefreshType);
                    tableObj.RequestRefresh(refreshType);

                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("COMPLETE");
                }

                // Removed this line which was throwing errors on large models, and it seems to commit the changes without it
                // database.Model.SaveChanges();

                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Refreshing tables - end: " + DateTime.Now.ToString("hh:mm:ss tt"));
            }

            #endregion
        }
Ejemplo n.º 2
0
 public static string ToJson(this AggsConfiguration self) => JsonConvert.SerializeObject(self, SetUpAggs.Converter.Settings);