Ejemplo n.º 1
0
        private string GetDeletedSiteResourceId()
        {
            switch (ParameterSetName)
            {
            case FromDeletedResourceNameParameterSet:
                var deletedSites = WebsitesClient.GetDeletedSites().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)).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/deletedSites/" + lastDeleted.DeletedSiteId);

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

            default:
                throw new Exception("Parameter set error");
            }
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            IEnumerable <PSAzureDeletedWebApp> deletedSites = WebsitesClient.GetDeletedSites()
                                                              .Where(ds => ds.DeletedSiteId.HasValue)
                                                              .Select(ds =>
                                                                      new PSAzureDeletedWebApp()
            {
                DeletedSiteId     = ds.DeletedSiteId.Value,
                DeletionTime      = DateTime.Parse(ds.DeletedTimestamp, System.Globalization.CultureInfo.InvariantCulture),
                SubscriptionId    = DefaultContext.Subscription.Id,
                ResourceGroupName = ds.ResourceGroup,
                Name = ds.DeletedSiteName,
                Slot = ds.Slot
            }
                                                                      );

            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);
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            IEnumerable <PSAzureDeletedWebApp> deletedSites = WebsitesClient.GetDeletedSites()
                                                              .Where(ds => ds.DeletedSiteId.HasValue)
                                                              .Select(ds =>
                                                                      new PSAzureDeletedWebApp()
            {
                DeletedSiteId     = ds.DeletedSiteId.Value,
                DeletionTime      = DateTime.Parse(ds.DeletedTimestamp),
                SubscriptionId    = DefaultContext.Subscription.Id,
                ResourceGroupName = ds.ResourceGroup,
                Name = ds.DeletedSiteName,
                Slot = ds.Slot
            }
                                                                      );

            // Filter out deleted sites older than 30 days.
            // They can't be restored and eventually will not be returned by the GetDeletedSites API.
            deletedSites = deletedSites.Where(ds => ds.DeletionTime >= DateTime.UtcNow.AddDays(-30)).OrderBy(ds => ds.DeletionTime);

            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);
        }