/// <summary>
        /// Gets a protected item
        /// </summary>
        /// <param name="containerName">Name of the container which this item belongs to</param>
        /// <param name="protectedItemName">Name of the item</param>
        /// <param name="queryFilter">Query filter</param>
        /// <returns>Protected item</returns>
        public ProtectedItemResponse GetProtectedItem(
                string containerName,
                string protectedItemName,
            GetProtectedItemQueryParam queryFilter)
        {
            string resourceName = BmsAdapter.GetResourceName();
            string resourceGroupName = BmsAdapter.GetResourceGroupName();

            return BmsAdapter.Client.ProtectedItems.GetAsync(
                                     resourceGroupName,
                                     resourceName,
                                     AzureFabricName,
                                     containerName,
                                     protectedItemName,
                                     queryFilter,
                                     BmsAdapter.GetCustomRequestHeaders(),
                                     BmsAdapter.CmdletCancellationToken).Result;
        }
        /// <summary>
        /// Lists protected items protected by the recovery services vault according to the provider data
        /// </summary>
        /// <returns>List of protected items</returns>
        public List<ItemBase> ListProtectedItems()
        {
            ContainerBase container =
                (ContainerBase)this.ProviderData[ItemParams.Container];
            string name = (string)this.ProviderData[ItemParams.AzureVMName];
            ItemProtectionStatus protectionStatus =
                (ItemProtectionStatus)this.ProviderData[ItemParams.ProtectionStatus];
            ItemProtectionState status = 
                (ItemProtectionState)this.ProviderData[ItemParams.ProtectionState];
            Models.WorkloadType workloadType =
                (Models.WorkloadType)this.ProviderData[ItemParams.WorkloadType];

            ProtectedItemListQueryParam queryParams = new ProtectedItemListQueryParam();
            queryParams.DatasourceType = ServiceClientModel.WorkloadType.VM;
            queryParams.BackupManagementType = ServiceClientModel.BackupManagementType.AzureIaasVM.ToString();

            List<ProtectedItemResource> protectedItems = new List<ProtectedItemResource>();
            string skipToken = null;
            PaginationRequest paginationRequest = null;
            do
            {
                var listResponse = ServiceClientAdapter.ListProtectedItem(queryParams, paginationRequest);
                protectedItems.AddRange(listResponse.ItemList.Value);

                ServiceClientHelpers.GetSkipTokenFromNextLink(listResponse.ItemList.NextLink, out skipToken);
                if (skipToken != null)
                {
                    paginationRequest = new PaginationRequest();
                    paginationRequest.SkipToken = skipToken;
                }
            } while (skipToken != null);

            // 1. Filter by container
            if (container != null)
            {
                protectedItems = protectedItems.Where(protectedItem =>
                {
                    Dictionary<UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id);
                    string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItem.Id);
                    return containerUri.Contains(container.Name);
                }).ToList();
            }

            List<ProtectedItemResponse> protectedItemGetResponses = new List<ProtectedItemResponse>();

            // 2. Filter by item's friendly name
            if (!string.IsNullOrEmpty(name))
            {
                protectedItems = protectedItems.Where(protectedItem =>
                {
                    Dictionary<UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id);
                    string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItem.Id);
                    return protectedItemUri.ToLower().Contains(name.ToLower());
                }).ToList();

                GetProtectedItemQueryParam getItemQueryParams = new GetProtectedItemQueryParam();
                getItemQueryParams.Expand = "extendedinfo";

                for (int i = 0; i < protectedItems.Count; i++)
                {
                    Dictionary<UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItems[i].Id);
                    string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItems[i].Id);
                    string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItems[i].Id);

                    var getResponse = ServiceClientAdapter.GetProtectedItem(containerUri, protectedItemUri, getItemQueryParams);
                    protectedItemGetResponses.Add(getResponse);
                }
            }

            List<ItemBase> itemModels = ConversionHelpers.GetItemModelList(protectedItems);

            if (!string.IsNullOrEmpty(name))
            {
                for (int i = 0; i < itemModels.Count; i++)
                {
                    AzureVmItemExtendedInfo extendedInfo = new AzureVmItemExtendedInfo();
                    var serviceClientExtendedInfo = ((AzureIaaSVMProtectedItem)protectedItemGetResponses[i].Item.Properties).ExtendedInfo;
                    if (serviceClientExtendedInfo.OldestRecoveryPoint.HasValue)
                    {
                        extendedInfo.OldestRecoveryPoint = serviceClientExtendedInfo.OldestRecoveryPoint;
                    }
                    extendedInfo.PolicyState = serviceClientExtendedInfo.PolicyInconsistent.ToString();
                    extendedInfo.RecoveryPointCount = serviceClientExtendedInfo.RecoveryPointCount;
                    ((AzureVmItem)itemModels[i]).ExtendedInfo = extendedInfo;
                }
            }

            // 3. Filter by item's Protection Status
            if (protectionStatus != 0)
            {
                itemModels = itemModels.Where(itemModel =>
                {
                    return ((AzureVmItem)itemModel).ProtectionStatus == protectionStatus;
                }).ToList();
            }

            // 4. Filter by item's Protection State
            if (status != 0)
            {
                itemModels = itemModels.Where(itemModel =>
                {
                    return ((AzureVmItem)itemModel).ProtectionState == status;
                }).ToList();
            }

            // 5. Filter by workload type
            if (workloadType != 0)
            {
                itemModels = itemModels.Where(itemModel =>
                {
                    return itemModel.WorkloadType == workloadType;
                }).ToList();
            }

            return itemModels;
        }
 /// <summary>
 /// Gets Info for the given item present in the given container
 /// specified by the names passed in the arguments. When the query
 /// parameter is used to pass the expand flag, this operation would
 /// return the extended info as well for the given item.This is an
 /// asynchronous operation. To determine whether the backend service
 /// has finished processing the request, call the Get Item Operation
 /// Result API.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.RecoveryServices.Backup.IProtectedItemOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. Resource group name of your recovery services vault.
 /// </param>
 /// <param name='resourceName'>
 /// Required. Name of your recovery services vault.
 /// </param>
 /// <param name='fabricName'>
 /// Required.
 /// </param>
 /// <param name='containerName'>
 /// Required.
 /// </param>
 /// <param name='protectedItemName'>
 /// Required.
 /// </param>
 /// <param name='queryFilter'>
 /// Optional.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// A single instance of a protected item response.
 /// </returns>
 public static Task<ProtectedItemResponse> GetAsync(this IProtectedItemOperations operations, string resourceGroupName, string resourceName, string fabricName, string containerName, string protectedItemName, GetProtectedItemQueryParam queryFilter, CustomRequestHeaders customRequestHeaders)
 {
     return operations.GetAsync(resourceGroupName, resourceName, fabricName, containerName, protectedItemName, queryFilter, customRequestHeaders, CancellationToken.None);
 }
        public ProtectedItemResponse GetProtectedItem(string rsVaultRgName, string rsVaultName, string containerName, string protectedItemName)
        {
            string fabricName = ConfigurationManager.AppSettings["AzureBackupFabricName"];
            var customHeader = CommonTestHelper.GetCustomRequestHeaders();

            GetProtectedItemQueryParam queryFilter = new GetProtectedItemQueryParam()
            {
                Expand = "extendedinfo"
            };
            ProtectedItemResponse response = Client.ProtectedItems.Get(rsVaultRgName, rsVaultName,
                fabricName, containerName, protectedItemName, queryFilter, customHeader);
            Assert.NotNull(response);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.NotNull(response.Item);

            return response;
        }
 /// <summary>
 /// Gets Info for the given item present in the given container
 /// specified by the names passed in the arguments. When the query
 /// parameter is used to pass the expand flag, this operation would
 /// return the extended info as well for the given item.This is an
 /// asynchronous operation. To determine whether the backend service
 /// has finished processing the request, call the Get Item Operation
 /// Result API.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.RecoveryServices.Backup.IProtectedItemOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. Resource group name of your recovery services vault.
 /// </param>
 /// <param name='resourceName'>
 /// Required. Name of your recovery services vault.
 /// </param>
 /// <param name='fabricName'>
 /// Required.
 /// </param>
 /// <param name='containerName'>
 /// Required.
 /// </param>
 /// <param name='protectedItemName'>
 /// Required.
 /// </param>
 /// <param name='queryFilter'>
 /// Optional.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// A single instance of a protected item response.
 /// </returns>
 public static ProtectedItemResponse Get(this IProtectedItemOperations operations, string resourceGroupName, string resourceName, string fabricName, string containerName, string protectedItemName, GetProtectedItemQueryParam queryFilter, CustomRequestHeaders customRequestHeaders)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IProtectedItemOperations)s).GetAsync(resourceGroupName, resourceName, fabricName, containerName, protectedItemName, queryFilter, customRequestHeaders);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }