public override void ExecuteCmdlet() { if (string.IsNullOrEmpty(Name)) { // If the website name was not specified as a parameter try to infer it Name = GitWebsite.ReadConfiguration().Name; } Name = WebsitesClient.GetWebsiteNameFromFullName(Name); List <Site> sites = WebsitesClient.GetWebsiteSlots(Name); if (sites.Count < 2) { throw new PSInvalidOperationException(Resources.SwapWebsiteSlotRequire2SlotsWarning); } string slot1 = Slot1; string slot2 = Slot2; string[] slots = sites.Select(site => WebsitesClient.GetSlotName(site.Name) ?? WebsiteSlotName.Production.ToString()).ToArray(); if (slot1 == null && slot2 == null) { // If slots not specified make sure there are only 2 slots and use them if (slots.Length == 2) { slot1 = slots[0]; slot2 = slots[1]; } else { throw new PSInvalidOperationException(Resources.SwapWebsiteSlotSpecifySlotsWarning); } } else if (slot1 != null && slot2 != null) { // If both slots specified make sure they exist and use them VerifySlotExists(slots, slot1); VerifySlotExists(slots, slot2); } else { // If only one slot is specified make sure it exists and that there are only 2 slots if (slots.Length == 2) { if (slot1 != null) { VerifySlotExists(slots, slot1); } if (slot2 != null) { VerifySlotExists(slots, slot2); } slot1 = slots[0]; slot2 = slots[1]; } else { throw new PSInvalidOperationException(Resources.SwapWebsiteSlotSpecifySlotsWarning); } } ConfirmAction( Force.IsPresent, string.Format(Resources.SwapWebsiteSlotWarning, Name, slot1, slot2), Resources.SwappingWebsite, Name, () => WebsitesClient.SwitchSlots(sites.First().WebSpace, Name, slot1, slot2)); }