Skip to content

Commit

Permalink
proper filter for webapp and function app (#993)
Browse files Browse the repository at this point in the history
* proper filter for webapp and function app

* minor refactor

* fix after review
  • Loading branch information
weidongxu-microsoft authored Mar 5, 2020
1 parent 5ca9dab commit 25c8d87
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
23 changes: 13 additions & 10 deletions src/ResourceManagement/AppService/FunctionAppsImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ internal partial class FunctionAppsImpl :
///GENMHASH:95834C6C7DA388E666B705A62A7D02BF:437A8ECA353AAE23242BFC82A5066CC3
public override IEnumerable<IFunctionApp> ListByResourceGroup(string resourceGroupName)
{
Func<SiteInner, IFunctionApp> converter = inner =>
{
return Extensions.Synchronize(() => PopulateModelAsync(inner));
};

return Extensions.Synchronize(() => Inner.ListByResourceGroupAsync(resourceGroupName))
.AsContinuousCollection(link => Extensions.Synchronize(() => Inner.ListByResourceGroupNextAsync(link)))
.Select(inner => converter(inner));
return base.ListByResourceGroup(resourceGroupName).Where(this.FilterFunctionApp);
}

public override async Task<IPagedCollection<IFunctionApp>> ListByResourceGroupAsync(string resourceGroupName, bool loadAllPages = true, CancellationToken cancellationToken = default(CancellationToken))
Expand All @@ -48,7 +41,12 @@ public override IEnumerable<IFunctionApp> ListByResourceGroup(string resourceGro
Inner.ListByResourceGroupNextAsync,
async (inner, cancellation) => await PopulateModelAsync(inner, cancellation),
loadAllPages, cancellationToken);
return PagedCollection<IFunctionApp, SiteInner>.CreateFromEnumerable(collection.Where(w => "functionapp".Equals(w.Inner.Kind, StringComparison.OrdinalIgnoreCase)));
return PagedCollection<IFunctionApp, SiteInner>.CreateFromEnumerable(collection.Where(this.FilterFunctionApp));
}

public override IEnumerable<IFunctionApp> List()
{
return base.List().Where(this.FilterFunctionApp);
}

public override async Task<IPagedCollection<IFunctionApp>> ListAsync(bool loadAllPages = true, CancellationToken cancellationToken = default(CancellationToken))
Expand All @@ -58,7 +56,12 @@ public override IEnumerable<IFunctionApp> ListByResourceGroup(string resourceGro
Inner.ListNextAsync,
async (inner, cancellation) => await PopulateModelAsync(inner, cancellation),
loadAllPages, cancellationToken);
return PagedCollection<IFunctionApp, SiteInner>.CreateFromEnumerable(collection.Where(w => "functionapp".Equals(w.Inner.Kind, StringComparison.OrdinalIgnoreCase)));
return PagedCollection<IFunctionApp, SiteInner>.CreateFromEnumerable(collection.Where(this.FilterFunctionApp));
}

private bool FilterFunctionApp(IFunctionApp w)
{
return w.Inner.Kind != null && w.Inner.Kind.ToLower().Split(new char[] { ',' }).Contains("functionapp");
}

///GENMHASH:0679DF8CA692D1AC80FC21655835E678:586E2B084878E8767487234B852D8D20
Expand Down
23 changes: 13 additions & 10 deletions src/ResourceManagement/AppService/WebAppsImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,7 @@ internal partial class WebAppsImpl :

public override IEnumerable<IWebApp> ListByResourceGroup(string resourceGroupName)
{
Func<SiteInner, IWebApp> converter = inner =>
{
return Extensions.Synchronize(() => PopulateModelAsync(inner));
};

return Extensions.Synchronize(() => Inner.ListByResourceGroupAsync(resourceGroupName))
.AsContinuousCollection(link => Extensions.Synchronize(() => Inner.ListByResourceGroupNextAsync(link)))
.Select(inner => converter(inner));
return base.ListByResourceGroup(resourceGroupName).Where(this.FilterWebApp);
}

public override async Task<IPagedCollection<IWebApp>> ListByResourceGroupAsync(string resourceGroupName, bool loadAllPages = true, CancellationToken cancellationToken = default(CancellationToken))
Expand All @@ -49,7 +42,12 @@ public override IEnumerable<IWebApp> ListByResourceGroup(string resourceGroupNam
Inner.ListByResourceGroupNextAsync,
async (inner, cancellation) => await PopulateModelAsync(inner, cancellation),
loadAllPages, cancellationToken);
return PagedCollection<IWebApp, SiteInner>.CreateFromEnumerable(collection.Where(w => w.Inner.Kind != null && w.Inner.Kind.Split(new char[] { ',' }).Contains("app")));
return PagedCollection<IWebApp, SiteInner>.CreateFromEnumerable(collection.Where(this.FilterWebApp));
}

public override IEnumerable<IWebApp> List()
{
return base.List().Where(this.FilterWebApp);
}

public override async Task<IPagedCollection<IWebApp>> ListAsync(bool loadAllPages = true, CancellationToken cancellationToken = default(CancellationToken))
Expand All @@ -59,7 +57,12 @@ public override IEnumerable<IWebApp> ListByResourceGroup(string resourceGroupNam
Inner.ListNextAsync,
async (inner, cancellation) => await PopulateModelAsync(inner, cancellation),
loadAllPages, cancellationToken);
return PagedCollection<IWebApp, SiteInner>.CreateFromEnumerable(collection.Where(w => w.Inner.Kind != null && w.Inner.Kind.Split(new char[] { ',' }).Contains("app")));
return PagedCollection<IWebApp, SiteInner>.CreateFromEnumerable(collection.Where(this.FilterWebApp));
}

private bool FilterWebApp(IWebApp w)
{
return w.Inner.Kind != null && w.Inner.Kind.Split(new char[] { ',' }).Contains("app");
}

///GENMHASH:0679DF8CA692D1AC80FC21655835E678:586E2B084878E8767487234B852D8D20
Expand Down

0 comments on commit 25c8d87

Please sign in to comment.