public static void SetStatus(this UpgradeStep step, UpgradeStepStatus status) { var method = typeof(UpgradeStep).GetProperty(nameof(UpgradeStep.Status))?.GetSetMethod(nonPublic: true); if (method is null) { throw new InvalidOperationException("Could not find UpgradeStep.Status property"); } method.Invoke(step, new object[] { status }); }
public bool TryAddStep(UpgradeStep newStep) { if (newStep is null) { throw new ArgumentNullException(nameof(newStep)); } _logger.LogDebug("Attempting to add upgrade step {Id}", newStep.Id); // Find a place in the order after all dependencies var dependencies = newStep.DependsOn.ToList(); var index = 0; for (index = 0; index < _steps.Count && dependencies.Any(); index++) { var currentId = _steps[index].Id; if (dependencies.Contains(currentId)) { dependencies.RemoveAll(d => d.Equals(currentId, StringComparison.Ordinal)); } if (newStep.DependencyOf.Contains(currentId, StringComparer.Ordinal)) { _logger.LogError("Could not add dependency {UpgradeStep} because its dependent step {Dependent} is executed before all of its dependencies are satisfied", newStep.Id, currentId); return(false); } } if (dependencies.Any()) { _logger.LogError("Could not add dependency {UpgradeStep} because dependencies were not satisfied: {Dependencies}", newStep.Id, string.Join(", ", dependencies)); return(false); } _steps.Insert(index, newStep); _logger.LogDebug("Inserted upgrade step {UpgradeStep} at index {Index}", newStep.Id, index); return(true); }
public static IDisposable TimeStep(this ITelemetry telemetry, string commandName, UpgradeStep step) => telemetry.TimeEvent($"step", onComplete: (p, _) => { p.Add("CommandName", commandName); p.Add("Step Status", step.Status.ToString()); });