Exemple #1
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                WriteDebug(Resources.MakingClientCall);
                string itemName = string.Empty;

                CSMSetProtectionRequest input = new CSMSetProtectionRequest();
                input.Properties          = new CSMSetProtectionRequestProperties();
                input.Properties.PolicyId = Policy.PolicyId;

                if (Item.GetType() == typeof(AzureRMBackupItem))
                {
                    itemName = (Item as AzureRMBackupItem).ItemName;
                }

                else if (Item.GetType() == typeof(AzureRMBackupContainer))
                {
                    WriteDebug(String.Format(Resources.ContainerTypeInput, Item.GetType()));

                    if ((Item as AzureRMBackupContainer).ContainerType == AzureBackupContainerType.AzureVM.ToString())
                    {
                        itemName = (Item as AzureRMBackupContainer).ContainerUniqueName;
                    }
                    else
                    {
                        throw new Exception(Resources.UnknownItemType);
                    }
                }

                else
                {
                    throw new Exception(Resources.UnknownItemType);
                }

                var operationId = AzureBackupClient.EnableProtection(Item.ResourceGroupName, Item.ResourceName, Item.ContainerUniqueName, itemName, input);
                WriteDebug(Resources.EnableAzureBackupProtection);

                var operationStatus = TrackOperation(Item.ResourceGroupName, Item.ResourceName, operationId);
                this.WriteObject(GetCreatedJobs(Item.ResourceGroupName,
                                                Item.ResourceName,
                                                new Models.AzureRMBackupVault(Item.ResourceGroupName, Item.ResourceName, Item.Location),
                                                operationStatus.JobList).FirstOrDefault());
            });
        }