Пример #1
0
        private string GetDeletedSiteResourceId()
        {
            switch (ParameterSetName)
            {
            case FromDeletedResourceNameParameterSet:
                IEnumerable <string> locations;
                if (string.IsNullOrEmpty(Location))
                {
                    locations = ResourcesClient.GetDeletedSitesLocations();
                }
                else
                {
                    locations = new List <string> {
                        Location
                    };
                }

                var deletedSites = WebsitesClient.GetDeletedSitesFromLocations(locations).Where(ds =>
                {
                    bool match = string.Equals(ds.ResourceGroup, ResourceGroupName, StringComparison.InvariantCultureIgnoreCase) &&
                                 string.Equals(ds.Name, Name, StringComparison.InvariantCultureIgnoreCase);
                    if (!string.IsNullOrEmpty(Slot))
                    {
                        match = match && string.Equals(ds.Slot, Slot, StringComparison.InvariantCultureIgnoreCase);
                    }
                    return(match);
                });
                if (!deletedSites.Any())
                {
                    throw new Exception("Deleted app not found");
                }
                DeletedSite lastDeleted = deletedSites.OrderBy(ds => DateTime.Parse(ds.DeletedTimestamp, new System.Globalization.CultureInfo("en-US"))).Last();
                if (deletedSites.Count() > 1)
                {
                    WriteWarning("Found multiple matching deleted apps. Restoring the most recently deleted app, deleted at " + lastDeleted.DeletedTimestamp);
                }
                return("/subscriptions/" + DefaultContext.Subscription.Id + "/providers/Microsoft.Web/locations/" + lastDeleted.GeoRegionName + "/deletedSites/" + lastDeleted.DeletedSiteId);

            case FromDeletedAppParameterSet:
                return("/subscriptions/" + InputObject.SubscriptionId + "/providers/Microsoft.Web/locations/" + InputObject.Location + "/deletedSites/" + InputObject.DeletedSiteId);

            default:
                throw new Exception("Parameter set error");
            }
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            IEnumerable <string> locations;

            if (string.IsNullOrEmpty(Location))
            {
                locations = ResourcesClient.GetDeletedSitesLocations();
            }
            else
            {
                locations = new List <string> {
                    Location
                };
            }

            IEnumerable <PSAzureDeletedWebApp> deletedSites = WebsitesClient.GetDeletedSitesFromLocations(locations)
                                                              .Where(ds => ds.DeletedSiteId.HasValue)
                                                              .Select(ds => new PSAzureDeletedWebApp(ds, DefaultContext.Subscription.Id));

            if (!string.IsNullOrEmpty(ResourceGroupName))
            {
                deletedSites = deletedSites.Where(ds => string.Equals(ResourceGroupName, ds.ResourceGroupName, StringComparison.InvariantCultureIgnoreCase));
            }
            if (!string.IsNullOrEmpty(Name))
            {
                deletedSites = deletedSites.Where(ds => string.Equals(Name, ds.Name, StringComparison.InvariantCultureIgnoreCase));
            }
            if (!string.IsNullOrEmpty(Slot))
            {
                deletedSites = deletedSites.Where(ds => string.Equals(Slot, ds.Slot, StringComparison.InvariantCultureIgnoreCase));
            }

            WriteObject(deletedSites, true);
        }