-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,108 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
src/Microsoft.OData.ModelBuilder/Config/QueryConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.OData.ModelBuilder.Config | ||
{ | ||
/// <summary> | ||
/// Query configuration which contains <see cref="ModelBoundQuerySettings"/>. | ||
/// </summary> | ||
public class QueryConfiguration | ||
{ | ||
internal const int DefaultMaxExpansionDepth = 2; | ||
|
||
private ModelBoundQuerySettings _querySettings; | ||
|
||
/// <summary> | ||
/// Gets or sets the <see cref="ModelBoundQuerySettings"/>. | ||
/// </summary> | ||
public ModelBoundQuerySettings ModelBoundQuerySettings | ||
{ | ||
get | ||
{ | ||
return _querySettings; | ||
} | ||
set | ||
{ | ||
_querySettings = value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Sets the Countable in <see cref="ModelBoundQuerySettings"/>. | ||
/// </summary> | ||
public virtual void SetCount(bool enableCount) | ||
{ | ||
GetModelBoundQuerySettingsOrDefault().Countable = enableCount; | ||
} | ||
|
||
/// <summary> | ||
/// Sets the MaxTop in <see cref="ModelBoundQuerySettings"/>. | ||
/// </summary> | ||
public virtual void SetMaxTop(int? maxTop) | ||
{ | ||
GetModelBoundQuerySettingsOrDefault().MaxTop = maxTop; | ||
} | ||
|
||
/// <summary> | ||
/// Sets the PageSize in <see cref="ModelBoundQuerySettings"/>. | ||
/// </summary> | ||
public virtual void SetPageSize(int? pageSize) | ||
{ | ||
GetModelBoundQuerySettingsOrDefault().PageSize = pageSize; | ||
} | ||
|
||
/// <summary> | ||
/// Sets the ExpandConfigurations in <see cref="ModelBoundQuerySettings"/>. | ||
/// </summary> | ||
public virtual void SetExpand(IEnumerable<string> properties, int? maxDepth, SelectExpandType expandType) | ||
{ | ||
GetModelBoundQuerySettingsOrDefault(); | ||
if (properties == null) | ||
{ | ||
ModelBoundQuerySettings.DefaultExpandType = expandType; | ||
ModelBoundQuerySettings.DefaultMaxDepth = maxDepth ?? DefaultMaxExpansionDepth; | ||
} | ||
else | ||
{ | ||
foreach (var property in properties) | ||
{ | ||
ModelBoundQuerySettings.ExpandConfigurations[property] = new ExpandConfiguration | ||
{ | ||
ExpandType = expandType, | ||
MaxDepth = maxDepth ?? DefaultMaxExpansionDepth | ||
}; | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Sets the SelectConfigurations in <see cref="ModelBoundQuerySettings"/>. | ||
/// </summary> | ||
public virtual void SetSelect(IEnumerable<string> properties, SelectExpandType selectType) | ||
{ | ||
GetModelBoundQuerySettingsOrDefault(); | ||
if (properties == null) | ||
{ | ||
ModelBoundQuerySettings.DefaultSelectType = selectType; | ||
} | ||
else | ||
{ | ||
foreach (var property in properties) | ||
{ | ||
ModelBoundQuerySettings.SelectConfigurations[property] = selectType; | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Sets the OrderByConfigurations in <see cref="ModelBoundQuerySettings"/>. | ||
/// </summary> | ||
public virtual void SetOrderBy(IEnumerable<string> properties, bool enableOrderBy) | ||
{ | ||
GetModelBoundQuerySettingsOrDefault(); | ||
if (properties == null) | ||
{ | ||
ModelBoundQuerySettings.DefaultEnableOrderBy = enableOrderBy; | ||
} | ||
else | ||
{ | ||
foreach (var property in properties) | ||
{ | ||
ModelBoundQuerySettings.OrderByConfigurations[property] = enableOrderBy; | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Sets the FilterConfigurations in <see cref="ModelBoundQuerySettings"/>. | ||
/// </summary> | ||
public virtual void SetFilter(IEnumerable<string> properties, bool enableFilter) | ||
{ | ||
GetModelBoundQuerySettingsOrDefault(); | ||
if (properties == null) | ||
{ | ||
ModelBoundQuerySettings.DefaultEnableFilter = enableFilter; | ||
} | ||
else | ||
{ | ||
foreach (var property in properties) | ||
{ | ||
ModelBoundQuerySettings.FilterConfigurations[property] = enableFilter; | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets the <see cref="ModelBoundQuerySettings"/> or create it depends on the default settings. | ||
/// </summary> | ||
internal ModelBoundQuerySettings GetModelBoundQuerySettingsOrDefault() | ||
{ | ||
if (_querySettings == null) | ||
{ | ||
_querySettings = new ModelBoundQuerySettings(ModelBoundQuerySettings.DefaultModelBoundQuerySettings); | ||
} | ||
|
||
return _querySettings; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.