private static async Task CleanupExistingExtensions(string source, SubscriptionListOperationResponse.Subscription subscription, HostedServiceListResponse.HostedService service, ComputeManagementClient computeClient, ExtensionImage availableDiagnosticsExtension) { // Get whatever is currently on Production Logger.InfoFormat("[" + source + "] " + "Retrieving current deployment details and currently used extensions..."); DeploymentGetResponse currentProductionSlotDetails = null, currentStagingSlotDetails = null; var details = computeClient.HostedServices.GetDetailed(service.ServiceName); if (details.Deployments.Where(s => s.DeploymentSlot == DeploymentSlot.Production).Any()) { currentProductionSlotDetails = await computeClient.Deployments.GetBySlotAsync(service.ServiceName, DeploymentSlot.Production); } if (details.Deployments.Where(s => s.DeploymentSlot == DeploymentSlot.Staging).Any()) { currentStagingSlotDetails = await computeClient.Deployments.GetBySlotAsync(service.ServiceName, DeploymentSlot.Staging); } // Compile a list of diagnostic id's still in use List <string> diagIdsInUse = new List <string>(); if (currentProductionSlotDetails != null && currentProductionSlotDetails.ExtensionConfiguration != null) { diagIdsInUse.AddRange(currentProductionSlotDetails.ExtensionConfiguration.AllRoles.Select(s => s.Id)); diagIdsInUse.AddRange(currentProductionSlotDetails.ExtensionConfiguration.NamedRoles.SelectMany(s => s.Extensions).Select(s => s.Id)); } if (currentStagingSlotDetails != null && currentStagingSlotDetails.ExtensionConfiguration != null) { diagIdsInUse.AddRange(currentStagingSlotDetails.ExtensionConfiguration.AllRoles.Select(s => s.Id)); diagIdsInUse.AddRange(currentStagingSlotDetails.ExtensionConfiguration.NamedRoles.SelectMany(s => s.Extensions).Select(s => s.Id)); } // Check if diag extension already exists for this service. If so, delete it. Logger.InfoFormat("[" + source + "] " + "Retrieving all extensions for {0}...", service.ServiceName); var currentExtensions = await computeClient.HostedServices.ListExtensionsAsync(service.ServiceName); foreach (var currentDiagExtension in currentExtensions.Where(d => d.Type == availableDiagnosticsExtension.Type)) { if (diagIdsInUse.Contains(currentDiagExtension.Id)) { Logger.InfoFormat("[" + source + "] " + "Skip deleting diagnostics extension {0}, because it is in use by the deployment", currentDiagExtension.Id); } else { Logger.InfoFormat("[" + source + "] " + "Deleting unused diagnostics extension named {0}...", currentDiagExtension.Id); try { var deleteOperation = await computeClient.HostedServices.DeleteExtensionAsync(service.ServiceName, currentDiagExtension.Id); await WaitForOperationAsync(source, subscription, computeClient, deleteOperation.RequestId); } catch (Exception) { Logger.ErrorFormat("[" + source + "] " + "Couldn't delete extension {0}, might be in use...", currentDiagExtension.Id); } } } }
public void Select (ExtensionImage image) { ImageModel.CopyFrom (image); }