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

                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId);
                string vaultName         = resourceIdentifier.ResourceName;
                string resourceGroupName = resourceIdentifier.ResourceGroupName;

                string shouldProcessName = InputItem.Id;

                string itemType     = "";
                string itemName     = "";
                string containerUri = "";
                if (ShouldProcess(shouldProcessName, VerbsLifecycle.Disable))
                {
                    Dictionary <UriEnums, string> keyValueDict =
                        HelperUtils.ParseUri(InputItem.Id);

                    itemType = HelperUtils.GetProtectableItemUri(
                        keyValueDict, InputItem.Id).Split(';')[0];
                    itemName = HelperUtils.GetProtectableItemUri(
                        keyValueDict, InputItem.Id).Split(';')[1];
                    containerUri = HelperUtils.GetContainerUri(
                        keyValueDict, InputItem.Id);

                    bool isDisableAutoProtectionSuccessful = false;

                    try
                    {
                        ODataQuery <ServiceClientModel.ProtectionIntentQueryObject> queryParams = null;
                        string backupManagementType = ServiceClientModel.BackupManagementType.AzureWorkload;
                        queryParams = new ODataQuery <ServiceClientModel.ProtectionIntentQueryObject>(
                            q => q.ItemType == itemType &&
                            q.ItemName == itemName &&
                            q.ParentName == containerUri &&
                            q.BackupManagementType == backupManagementType);

                        var itemResponses = ServiceClientAdapter.ListProtectionIntent(
                            queryParams,
                            vaultName: vaultName,
                            resourceGroupName: resourceGroupName);

                        string intentName = null;
                        foreach (var itemResponse in itemResponses)
                        {
                            string itemNameResponse      = "";
                            string containerNameResponse = "";

                            Dictionary <UriEnums, string> keyValueDictResponse =
                                HelperUtils.ParseUri(itemResponse.Properties.ItemId);
                            itemNameResponse = HelperUtils.GetProtectableItemUri(
                                keyValueDictResponse, itemResponse.Properties.ItemId).ToLower();
                            containerNameResponse = HelperUtils.GetContainerUri(
                                keyValueDictResponse, itemResponse.Properties.ItemId);

                            if (String.Compare(itemNameResponse, itemName, true) == 0 &&
                                String.Compare(containerUri.Split(';')[3], containerNameResponse.Split(';')[2], true) == 0)
                            {
                                intentName = itemResponse.Name;
                                break;
                            }
                        }

                        var deleteResponse = ServiceClientAdapter.DeleteProtectionIntent(
                            intentName,
                            vaultName: vaultName,
                            resourceGroupName: resourceGroupName);

                        isDisableAutoProtectionSuccessful = true;
                    }
                    catch
                    {
                    }
                    if (PassThru.IsPresent)
                    {
                        WriteObject(isDisableAutoProtectionSuccessful);
                    }
                }
            });
        }