private static Tuple<string, string> GetAllResourceNameAndLocation(EventData eventEntry, string resourceGroupName, string resourceUri, ResourceManagementClient resclient)
        {
            Tuple<string, string> resultSet = new Tuple<string, string>(string.Empty, string.Empty);

            if (!string.IsNullOrWhiteSpace(resourceGroupName) && !string.IsNullOrWhiteSpace(resourceUri))
            {
                try
                {
                    ResourceListParameters reslist = new ResourceListParameters();

                    reslist.ResourceGroupName = eventEntry.ResourceGroupName;

                    ResourceListResult resresult = resclient.Resources.List(reslist);

                    foreach (GenericResourceExtended resource in resresult.Resources)
                    {
                        if (resource.Id == eventEntry.ResourceUri)
                        {
                            resultSet = new Tuple<string, string>(resource.Name, resource.Location);
                            break;
                        }
                    }
                }
                catch
                {
                    return resultSet;
                }
            }

            return resultSet;
        }
        public async Task<IEnumerable<JsonExtendedResource>> List(
            [Metadata("Resource group", "Optional. Only return resources that are inside this resource group.")]string resourceGroup = null,
            [Metadata("Resource type", "Optional. Only return resources of this type. You need to include the provider namespace as well, for example: Microsoft.Logic/workflows.")]string resourceType = null,
            [Metadata("Tag name", "Optional. Only return resources with this tag name.")]string tagName = null,
            [Metadata("Tag value", "Optional. Only return resources with this tag value. You must also specify a tag name to specify a value.")]string tagValue = null
            )
        {
            var client = await ResourceUtilities.GetClient().ConfigureAwait(continueOnCapturedContext: false);

            var parameters = new Microsoft.Azure.Management.Resources.Models.ResourceListParameters();

            parameters.ResourceGroupName = resourceGroup;
            parameters.ResourceType = resourceType;
            parameters.TagName = tagName;
            parameters.TagValue = tagValue;

            var resourceListResult = new ResourceListResult();

            resourceListResult = await client.Resources.ListAsync(parameters, CancellationToken.None).ConfigureAwait(continueOnCapturedContext: false);

            return resourceListResult.Resources.Select(x => new JsonExtendedResource(x));
        }
        public void GetsAllResourceGroupResources()
        {
            FilterResourcesOptions options = new FilterResourcesOptions() { ResourceGroup = resourceGroupName };
            Resource resource1 = new Resource() { Id = "resourceId", Location = resourceGroupLocation, Name = resourceName };
            Resource resource2 = new Resource() { Id = "resourceId2", Location = resourceGroupLocation, Name = resourceName + "2" };
            ResourceListParameters actualParameters = new ResourceListParameters();
            resourceOperationsMock.Setup(f => f.ListAsync(It.IsAny<ResourceListParameters>(), new CancellationToken()))
                .Returns(Task.Factory.StartNew(() => new ResourceListResult
                {
                    Resources = new List<Resource>() { resource1, resource2 }
                }))
                .Callback((ResourceListParameters p, CancellationToken ct) => { actualParameters = p; });

            List<Resource> result = resourcesClient.FilterResources(options);

            Assert.Equal(2, result.Count);
            Assert.True(string.IsNullOrEmpty(actualParameters.ResourceType));
        }
        public void GetsAllResourcesUsingResourceType()
        {
            FilterResourcesOptions options = new FilterResourcesOptions() { ResourceGroup = resourceGroupName, ResourceType = "websites" };
            GenericResourceExtended resource1 = new GenericResourceExtended() { Id = "resourceId", Location = resourceGroupLocation, Name = resourceName };
            GenericResourceExtended resource2 = new GenericResourceExtended() { Id = "resourceId2", Location = resourceGroupLocation, Name = resourceName + "2", };
            ResourceListParameters actualParameters = new ResourceListParameters();
            resourceOperationsMock.Setup(f => f.ListAsync(It.IsAny<ResourceListParameters>(), new CancellationToken()))
                .Returns(Task.Factory.StartNew(() => new ResourceListResult
                {
                    Resources = new List<GenericResourceExtended>() { resource1, resource2 }
                }))
                .Callback((ResourceListParameters p, CancellationToken ct) => { actualParameters = p; });

            List<GenericResourceExtended> result = resourcesClient.FilterResources(options);

            Assert.Equal(2, result.Count);
            Assert.Equal(options.ResourceType, actualParameters.ResourceType);
        }
 /// <summary>
 /// Get all of the resources under a subscription.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Resources.IResourceOperations.
 /// </param>
 /// <param name='parameters'>
 /// Optional. Query parameters. If null is passed returns all resource
 /// groups.
 /// </param>
 /// <returns>
 /// List of resource groups.
 /// </returns>
 public static Task<ResourceListResult> ListAsync(this IResourceOperations operations, ResourceListParameters parameters)
 {
     return operations.ListAsync(parameters, CancellationToken.None);
 }
 /// <summary>
 /// Get all of the resources under a subscription.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Resources.IResourceOperations.
 /// </param>
 /// <param name='parameters'>
 /// Optional. Query parameters. If null is passed returns all resource
 /// groups.
 /// </param>
 /// <returns>
 /// List of resource groups.
 /// </returns>
 public static ResourceListResult List(this IResourceOperations operations, ResourceListParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IResourceOperations)s).ListAsync(parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }