Пример #1
0
        private void GetByName()
        {
            Do(() =>
            {
                if (string.IsNullOrEmpty(Slot))
                {
                    List <Site> websites = WebsitesClient.GetWebsiteSlots(Name);
                    Cache.SaveSites(CurrentSubscription.SubscriptionId, new Sites(websites));

                    if (websites.Count > 1)
                    {
                        WriteWebsites(websites);
                    }
                    else if (websites.Count == 1)
                    {
                        Site websiteObject = websites[0];
                        WriteWebsite(websiteObject);
                    }
                }
                else
                {
                    Site websiteObject = WebsitesClient.GetWebsite(Name, Slot);
                    WriteWebsite(websiteObject);
                }
            });
        }
Пример #2
0
        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);
            string      slotName = null;
            string      webspace = null;

            if (sites.Count != 2)
            {
                throw new PSInvalidOperationException("The website must have exactly two slots to apply swap");
            }
            else
            {
                foreach (Site website in sites)
                {
                    string currentSlotName = WebsitesClient.GetSlotName(website.Name) ?? WebsiteSlotName.Production.ToString();
                    if (!currentSlotName.Equals(WebsiteSlotName.Production.ToString(), System.StringComparison.OrdinalIgnoreCase))
                    {
                        slotName = currentSlotName;
                        webspace = website.WebSpace;
                        break;
                    }
                }
            }

            ConfirmAction(
                Force.IsPresent,
                string.Format(Resources.SwapWebsiteSlotWarning, Name, slotName),
                Resources.SwappingWebsite,
                Name,
                () =>
            {
                WebsitesClient.SwitchSlot(webspace, Name, slotName);
            });
        }
        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;
            }

            List <Site>    sites = WebsitesClient.GetWebsiteSlots(Name);
            IList <string> remoteRepositories = Git.GetRemoteRepositories();

            // Clear all existing remotes that are created by us
            foreach (string remoteName in remoteRepositories)
            {
                if (remoteName.StartsWith("azure"))
                {
                    Git.RemoveRemoteRepository(remoteName);
                }
            }

            foreach (Site website in sites)
            {
                string repositoryUri      = website.GetProperty("RepositoryUri");
                string publishingUsername = PublishingUsername;
                string uri        = Git.GetUri(repositoryUri, website.RepositorySiteName, publishingUsername);
                string slot       = WebsitesClient.GetSlotName(website.Name);
                string remoteName = string.Empty;

                if (!string.IsNullOrEmpty(slot) && !slot.Equals(WebsiteSlotName.Production.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    remoteName = "-" + slot;
                }

                Git.AddRemoteRepository(string.Format("azure{0}", remoteName), uri);
            }
        }
Пример #4
0
        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));
        }