public override void Execute() { var list = Enum.GetValues(typeof(Scenarios)).Cast <Scenarios>().ToList(); try { foreach (var scenario in list) { if (scenario != Scenarios.All) { Console.WriteLine($"########## Starting Scenario {scenario} ##########"); var executable = ScenarioFactory.GetScenario(scenario); executable.Execute(); Console.WriteLine($"########## Finished Scenario {scenario} ##########"); } } } finally { foreach (var rgId in CleanUp) { ResourceIdentifier id = new ResourceIdentifier(rgId); var rg = new AzureResourceManagerClient().ResourceGroup(rgId); Console.WriteLine($"--------Deleting {rg.Id.Name}--------"); try { _ = rg.DeleteAsync(); } catch { //ignore exceptions in case rg doesn't exist } } } }
static void Main(string[] args) { Scenario scenario = null; try { scenario = ScenarioFactory.GetScenario(Scenarios.CreateSingleVmExample); scenario.Execute(); } finally { foreach (var rgId in Scenario.CleanUp) { ResourceIdentifier id = new ResourceIdentifier(rgId); var rg = new AzureResourceManagerClient().GetSubscriptionOperations(id.Subscription).GetResourceGroupOperations(id.ResourceGroup); Console.WriteLine($"--------Deleting {rg.Id.Name}--------"); try { _ = rg.DeleteAsync(); } catch { //ignore exceptions in case the rg doesn't exist } } } }
public override void Execute() { var client = new ResourcesManagementClient(Context.SubscriptionId, Context.Credential); var list = Enum.GetValues(typeof(Scenarios)).Cast <Scenarios>().ToList(); try { foreach (var scenario in list) { if (scenario != Scenarios.All) { var executable = ScenarioFactory.GetScenario(scenario); executable.Execute(); } } } finally { foreach (var rgId in CleanUp) { var name = GetResourceName(rgId); try { var rg = client.ResourceGroups.Get(name).Value; if (rg != null) { Console.WriteLine($"--------Deleting {rg.Name}--------"); _ = client.ResourceGroups.StartDelete(rg.Name).WaitForCompletionAsync().ConfigureAwait(false).GetAwaiter().GetResult(); } } catch { // ignore errors in get/delete } } } }