public override Execution ContinueWith(ITaskExecutionContext <MaintenanceWorkItem> context) { UCommerceMaintenanceConfiguration configuration = context.EnsureConfiguration(_configuration); if (!configuration.IndexMaintenance.Enabled) { return(Execution.StepOver); } return(base.ContinueWith(context)); }
private static string BuildScript(UCommerceMaintenanceConfiguration configuration) { var script = new StringBuilder(); foreach (var table in configuration.IndexMaintenance.Tables.EmptyIfNull()) { if (!table.Enabled) { continue; } script.Append(string.Join(string.Empty, table.Indicies.Where(x => x.Reorganize).Select(index => $@" ALTER INDEX [{index.Name}] ON [dbo].[{table.Name}] REORGANIZE;"))); } return(script.ToString()); }
public override void Execute(ITaskExecutionContext <MaintenanceWorkItem> context) { UCommerceMaintenanceConfiguration configuration = context.EnsureConfiguration(_configuration); string script = BuildScript(configuration); if (script.Length > 0) { context.Log.Message(@"Executing sql: {0}", script); using (IDbConnection connection = _uCommerceDb.GetConnection()) { connection.Open(); var command = new CommandDefinition( script, cancellationToken: context.CancellationToken, commandTimeout: configuration.IndexMaintenance.CommandTimeout.GetValueOrDefault(int.MaxValue)); connection.ExecuteAsync(command).Wait(context.CancellationToken); } } }