Skip to content

Commit

Permalink
BlazoriseLicenseChecker: Null checks and apply defaults for unlicense…
Browse files Browse the repository at this point in the history
…d limits (#5648)
  • Loading branch information
David-Moreira authored Jul 26, 2024
1 parent 703b618 commit 85d95ef
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Source/Blazorise/Licensing/BlazoriseLicenseChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ internal string GetPrintMessage()
/// Null if no limit is set.
/// </summary>
/// <returns></returns>
public int? GetAutoCompleteRowsLimit()
public int? GetAutocompleteRowsLimit()
{
return blazoriseLicenseProvider.GetAutocompleteRowsLimit();
}
Expand Down
57 changes: 57 additions & 0 deletions Source/Blazorise/Licensing/BlazoriseLicenseLimitsHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace Blazorise.Licensing;

/// <summary>
/// Ultimately provides sane defaults for Blazorise licensing, in case required scoped services are not provided
/// </summary>
public static class BlazoriseLicenseLimitsHelper
{
/// <summary>
/// Returns the maximum number of rows that can be displayed.
/// Null if no limit is set.
/// </summary>
/// <returns></returns>
public static int? GetDataGridRowsLimit( BlazoriseLicenseChecker blazoriseLicenseChecker )
{
return blazoriseLicenseChecker is null ? BlazoriseLicenseProvider.DEFAULT_UNLICENSED_LIMIT_DATAGRID_MAX_ROWS : blazoriseLicenseChecker.GetDataGridRowsLimit();
}

/// <summary>
/// Returns the maximum number of rows that can be displayed.
/// Null if no limit is set.
/// </summary>
/// <returns></returns>
public static int? GetAutocompleteRowsLimit( BlazoriseLicenseChecker blazoriseLicenseChecker )
{
return blazoriseLicenseChecker is null ? BlazoriseLicenseProvider.DEFAULT_UNLICENSED_LIMIT_AUTOCOMPLETE_MAX_ROWS : blazoriseLicenseChecker.GetAutocompleteRowsLimit();
}

/// <summary>
/// Returns the maximum number of rows that can be displayed.
/// Null if no limit is set.
/// </summary>
/// <returns></returns>
public static int? GetChartsRowsLimit( BlazoriseLicenseChecker blazoriseLicenseChecker )
{
return blazoriseLicenseChecker is null ? BlazoriseLicenseProvider.DEFAULT_UNLICENSED_LIMIT_CHARTS_MAX_ROWS : blazoriseLicenseChecker.GetChartsRowsLimit();
}

/// <summary>
/// Returns the maximum number of rows that can be displayed.
/// Null if no limit is set.
/// </summary>
/// <returns></returns>
public static int? GetListViewRowsLimit( BlazoriseLicenseChecker blazoriseLicenseChecker )
{
return blazoriseLicenseChecker is null ? BlazoriseLicenseProvider.DEFAULT_UNLICENSED_LIMIT_LISTVIEW_MAX_ROWS : blazoriseLicenseChecker.GetListViewRowsLimit();
}

/// <summary>
/// Returns the maximum number of rows that can be displayed.
/// Null if no limit is set.
/// </summary>
/// <returns></returns>
public static int? GetTreeViewRowsLimit( BlazoriseLicenseChecker blazoriseLicenseChecker )
{
return blazoriseLicenseChecker is null ? BlazoriseLicenseProvider.DEFAULT_UNLICENSED_LIMIT_TREEVIEW_MAX_ROWS : blazoriseLicenseChecker.GetTreeViewRowsLimit();
}
}
15 changes: 10 additions & 5 deletions Source/Blazorise/Licensing/BlazoriseLicenseProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ namespace Blazorise.Licensing;
public sealed class BlazoriseLicenseProvider
{
#region Members
internal const int DEFAULT_UNLICENSED_LIMIT_DATAGRID_MAX_ROWS = 1000;
internal const int DEFAULT_UNLICENSED_LIMIT_AUTOCOMPLETE_MAX_ROWS = 1000;
internal const int DEFAULT_UNLICENSED_LIMIT_CHARTS_MAX_ROWS = 10;
internal const int DEFAULT_UNLICENSED_LIMIT_LISTVIEW_MAX_ROWS = 1000;
internal const int DEFAULT_UNLICENSED_LIMIT_TREEVIEW_MAX_ROWS = 100;

private static readonly Assembly CurrentAssembly = typeof( BlazoriseLicenseProvider ).Assembly;

Expand Down Expand Up @@ -205,7 +210,7 @@ private static BlazoriseLicenseResult ResolveBlazoriseLicenseResult( License lic
}
else if ( Result == BlazoriseLicenseResult.Unlicensed )
{
limitsDataGridMaxRows = 1000;
limitsDataGridMaxRows = DEFAULT_UNLICENSED_LIMIT_DATAGRID_MAX_ROWS;
}

return limitsDataGridMaxRows;
Expand Down Expand Up @@ -233,7 +238,7 @@ private static BlazoriseLicenseResult ResolveBlazoriseLicenseResult( License lic
}
else if ( Result == BlazoriseLicenseResult.Unlicensed )
{
limitsAutocompleteMaxRows = 1000;
limitsAutocompleteMaxRows = DEFAULT_UNLICENSED_LIMIT_AUTOCOMPLETE_MAX_ROWS;
}

return limitsAutocompleteMaxRows;
Expand Down Expand Up @@ -261,7 +266,7 @@ private static BlazoriseLicenseResult ResolveBlazoriseLicenseResult( License lic
}
else if ( Result == BlazoriseLicenseResult.Unlicensed )
{
limitsChartsMaxRows = 10;
limitsChartsMaxRows = DEFAULT_UNLICENSED_LIMIT_CHARTS_MAX_ROWS;
}

return limitsChartsMaxRows;
Expand Down Expand Up @@ -289,7 +294,7 @@ private static BlazoriseLicenseResult ResolveBlazoriseLicenseResult( License lic
}
else if ( Result == BlazoriseLicenseResult.Unlicensed )
{
limitsListViewMaxRows = 1000;
limitsListViewMaxRows = DEFAULT_UNLICENSED_LIMIT_LISTVIEW_MAX_ROWS;
}

return limitsListViewMaxRows;
Expand Down Expand Up @@ -317,7 +322,7 @@ private static BlazoriseLicenseResult ResolveBlazoriseLicenseResult( License lic
}
else if ( Result == BlazoriseLicenseResult.Unlicensed )
{
limitsTreeViewMaxRows = 100;
limitsTreeViewMaxRows = DEFAULT_UNLICENSED_LIMIT_TREEVIEW_MAX_ROWS;
}

return limitsTreeViewMaxRows;
Expand Down
4 changes: 2 additions & 2 deletions Source/Extensions/Blazorise.Charts/BaseChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void LimitDataSets( params TDataSet[] datasets )
if ( datasets.IsNullOrEmpty() )
return;

var chartsRowLimit = LicenseChecker.GetChartsRowsLimit();
var chartsRowLimit = BlazoriseLicenseLimitsHelper.GetChartsRowsLimit( LicenseChecker );

if ( !chartsRowLimit.HasValue )
return;
Expand All @@ -92,7 +92,7 @@ private void LimitDataSets( params TDataSet[] datasets )

private List<TItem> LimitData( List<TItem> data )
{
var chartsRowLimit = LicenseChecker.GetChartsRowsLimit();
var chartsRowLimit = BlazoriseLicenseLimitsHelper.GetChartsRowsLimit( LicenseChecker );

if ( !chartsRowLimit.HasValue )
return data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ where text.StartsWith( Search, StringComparison.OrdinalIgnoreCase )
}
}

var maxRowsLimit = LicenseChecker.GetAutoCompleteRowsLimit();
var maxRowsLimit = BlazoriseLicenseLimitsHelper.GetAutocompleteRowsLimit( LicenseChecker );

if ( maxRowsLimit.HasValue )
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Extensions/Blazorise.Components/ListView.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public partial class ListView<TItem> : ComponentBase

private IEnumerable<TItem> GetData()
{
var maxRowsLimit = LicenseChecker.GetListViewRowsLimit();
var maxRowsLimit = BlazoriseLicenseLimitsHelper.GetListViewRowsLimit( LicenseChecker );

if ( maxRowsLimit.HasValue )
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Extensions/Blazorise.DataGrid/DataGrid.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2357,7 +2357,7 @@ where CompareFilterValues( cellStringValue, stringSearchValue, column.GetFilterM
}
}

var maxRowsLimit = LicenseChecker.GetDataGridRowsLimit();
var maxRowsLimit = BlazoriseLicenseLimitsHelper.GetDataGridRowsLimit( LicenseChecker );

if ( maxRowsLimit.HasValue )
{
Expand Down
5 changes: 1 addition & 4 deletions Source/Extensions/Blazorise.TreeView/TreeView.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Blazorise.TreeView.Internal;
using Blazorise.Utilities;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
#endregion

namespace Blazorise.TreeView;
Expand Down Expand Up @@ -131,8 +130,6 @@ private void SearchTryRemoveNode( List<TreeViewNodeState<TNode>> nodeStates, TNo
/// <returns>Returns the awaitable task.</returns>
public async Task Reload()
{
var maxRowsLimit = LicenseChecker.GetTreeViewRowsLimit();

treeViewNodeStates = new();

await foreach ( var nodeState in Nodes.ToNodeStates( HasChildNodesAsync, DetermineHasChildNodes, ( node ) => ExpandedNodes?.Contains( node ) == true, DetermineIsDisabled ) )
Expand All @@ -145,7 +142,7 @@ public async Task Reload()

private void AddTreeViewNodeState( TreeViewNodeState<TNode> treeViewNodeState )
{
var maxRowsLimit = LicenseChecker.GetTreeViewRowsLimit();
var maxRowsLimit = BlazoriseLicenseLimitsHelper.GetTreeViewRowsLimit( LicenseChecker );

if ( maxRowsLimit.HasValue )
{
Expand Down

0 comments on commit 85d95ef

Please sign in to comment.