Exemple #1
0
        private void ReportRecommendations(DatabaseSizeRecommendation recommendation)
        {
            var sb = new StringBuilder();

            sb.AppendFormat("Current Database Size :{0}", recommendation.CurrentSize);
            sb.AppendLine();
            sb.AppendFormat("Current Database Max Size: {0}", recommendation.CurrentMaxSize);
            sb.AppendLine();
            sb.AppendFormat("Recommended Database Max Size: {0}", recommendation.MaxSize);
            sb.AppendLine();
            sb.AppendFormat("Recommended Database Edition : {0}", recommendation.Edition);

            Report(sb.ToString());
        }
Exemple #2
0
        protected override async void Execute()
        {
            string bd = CloudConfigurationManager.GetSetting("DatabaseConnectionString");

            var query = new GetDatabaseSizeRecommendation(databaseName);

            DatabaseSizeRecommendation recommendation = await Database <EmptyDbContext>
                                                        .Model(() => new EmptyDbContext(bd))
                                                        .WithCache()
                                                        .QueryAsync(query);

            DatabaseSizeRecommendation databaseSizeRecommendation = recommendation;

            ReportRecommendations(databaseSizeRecommendation);

            if (databaseSizeRecommendation.CurrentMaxSize == databaseSizeRecommendation.MaxSize)
            {
                return;
            }
            if (databaseSizeRecommendation.CurrentMaxSize == absoluteMaxSize)
            {
                return;
            }
            if (databaseSizeRecommendation.MaxSize > absoluteMaxSize)
            {
                return;
            }

            Report(Resources.SqlDatabaseAutoScaler_Applying_Recommendations);

            string m = CloudConfigurationManager.GetSetting("MasterDatabaseConnectionString");

            Task result = Database <EmptyDbContext> .Model(() => new EmptyDbContext(m))
                          .DoWithoutTransactionAsync(model => model.Database.ExecuteSqlCommand("ALTER DATABASE ["
                                                                                               + databaseName
                                                                                               + "] MODIFY (EDITION='"
                                                                                               +
                                                                                               databaseSizeRecommendation.Edition
                                                                                               + "', MAXSIZE="
                                                                                               +
                                                                                               databaseSizeRecommendation.MaxSize
                                                                                               + "GB)"));

            result.Wait();
        }