Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,3 @@ MigrationBackup/

# Fody - auto-generated XML schema
FodyWeavers.xsd
.gitattributes
9 changes: 8 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<NoWarn>$(NoWarn);CA2007;CS1591;NU1605;SA1101;SA1124;SA1309;SA1600;SA1633</NoWarn>

<Configurations>Debug;Release;Test</Configurations>
<MauiVersion>9.0.10</MauiVersion>

<!-- Generate the lock file -->
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
Expand All @@ -27,6 +26,14 @@
<RestoreLockedMode Condition="'$(ContinuousIntegrationBuild)' == 'true'">true</RestoreLockedMode>
</PropertyGroup>

<PropertyGroup Condition="$(TargetFramework.Contains('net8.0'))">
<MauiVersion>8.0.100</MauiVersion>
</PropertyGroup>

<PropertyGroup Condition="$(TargetFramework.Contains('net9.0'))">
<MauiVersion>9.0.12</MauiVersion>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="..\stylecop.json">
<Link>stylecop.json</Link>
Expand Down
1 change: 1 addition & 0 deletions Maui.DataGrid.Sample.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Root Files", "Root Files", "{175C8F2C-B5A2-4AAE-A858-2D4A1E8F073E}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitattributes = .gitattributes
.gitignore = .gitignore
Directory.Build.props = Directory.Build.props
LICENSE = LICENSE
Expand Down
64 changes: 38 additions & 26 deletions Maui.DataGrid.Sample/Utils/DummyDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,64 @@ namespace Maui.DataGrid.Sample.Utils;

internal static class DummyDataProvider
{
private static List<Team>? _realTeams;
private static readonly List<Team> RealTeams = LoadTeamsFromResource();

public static List<Team> GetTeams(int numberOfCopies = 1)
{
if (_realTeams == null)
if (numberOfCopies == 1)
{
var assembly = typeof(DummyDataProvider).GetTypeInfo().Assembly;
return RealTeams;
}

using var stream = assembly.GetManifestResourceStream("Maui.DataGrid.Sample.teams.json")
?? throw new FileNotFoundException("Could not load teams.json");
return GenerateRandomTeams(numberOfCopies);
}

using var reader = new StreamReader(stream);
var json = reader.ReadToEnd();
private static List<Team> LoadTeamsFromResource()
{
var assembly = typeof(DummyDataProvider).GetTypeInfo().Assembly;

_realTeams = JsonSerializer.Deserialize<List<Team>>(json)
?? throw new InvalidOperationException("Could not deserialize teams.json");
}
using var stream = assembly.GetManifestResourceStream("Maui.DataGrid.Sample.teams.json")
?? throw new FileNotFoundException("Could not load teams.json");

if (numberOfCopies == 1)
{
return _realTeams;
}
using var reader = new StreamReader(stream);
var json = reader.ReadToEnd();

return JsonSerializer.Deserialize<List<Team>>(json)
?? throw new InvalidOperationException("Could not deserialize teams.json");
}

var teams = new List<Team>(_realTeams);
private static List<Team> GenerateRandomTeams(int numberOfCopies)
{
var teams = new List<Team>(RealTeams);

for (var i = 0; i < numberOfCopies; i++)
{
foreach (var realTeam in _realTeams)
foreach (var realTeam in RealTeams)
{
var totalGames = RandomNumberGenerator.GetInt32(72, 83); // Total games in a season
var won = RandomNumberGenerator.GetInt32(20, Math.Min(60, totalGames)); // Random wins between 20 and the lesser of 60 or total games
var lost = totalGames - won; // Losses are the remaining games
var homeWins = RandomNumberGenerator.GetInt32(10, Math.Min(won, totalGames / 2)); // Home wins between 10 and half of total games or total wins
var roadWins = won - homeWins; // Road wins are the remaining wins
var last10Wins = RandomNumberGenerator.GetInt32(0, Math.Min(10, won)); // Wins in the last 10 games, but not more than total wins
var streakResult = (GameResult)RandomNumberGenerator.GetInt32(0, 2); // Random streak result (Win or Loss)
var streakLength = Math.Min(10, streakResult == GameResult.Won ? won : lost); // Streak length between 0 and 10, but not more than total wins or losses

var randomTeam = new Team
{
Name = $"{realTeam.Name} {i}",
Won = RandomNumberGenerator.GetInt32(0, 50),
Lost = RandomNumberGenerator.GetInt32(0, 50),
Percentage = Math.Round(RandomDouble() * 100) / 100,
Won = won,
Lost = lost,
Percentage = (double)won / totalGames,
Conf = $"{realTeam.Conf} {RandomNumberGenerator.GetInt32(1, 10)}",
Div = $"{realTeam.Div} {RandomNumberGenerator.GetInt32(1, 10)}",
Home = $"{RandomNumberGenerator.GetInt32(1, 10)}",
Road = $"{RandomNumberGenerator.GetInt32(1, 10)}",
Last10 = $"{RandomNumberGenerator.GetInt32(1, 10)}",
Home = $"{homeWins}-{(totalGames / 2) - homeWins}", // Home record
Road = $"{roadWins}-{(totalGames / 2) - roadWins}", // Road record
Last10 = $"{last10Wins}-{10 - last10Wins}", // Last 10 games record
Streak = new Streak
{
Result = (GameResult)RandomNumberGenerator.GetInt32(0, 2),
NumStreak = RandomNumberGenerator.GetInt32(0, 10),
Result = streakResult,
NumStreak = streakLength,
},
Logo = realTeam.Logo,
};
Expand All @@ -61,6 +75,4 @@ public static List<Team> GetTeams(int numberOfCopies = 1)

return teams;
}

private static double RandomDouble() => (double)RandomNumberGenerator.GetInt32(int.MaxValue) / int.MaxValue;
}
4 changes: 3 additions & 1 deletion Maui.DataGrid.Sample/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace Maui.DataGrid.Sample.ViewModels;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.Diagnostics;
using CommunityToolkit.Maui.Core.Extensions;
using CommunityToolkit.Maui.Views;
using Maui.DataGrid.Sample.Models;
using Maui.DataGrid.Sample.Utils;
Expand All @@ -11,7 +12,8 @@ internal sealed class MainViewModel : ViewModelBase
{
public MainViewModel()
{
Teams = new(DummyDataProvider.GetTeams());
// To play with more data use DummyDataProvider.GetTeams(100)
Teams = DummyDataProvider.GetTeams().ToObservableCollection();
TeamColumnVisible = true;
WonColumnVisible = true;
HeaderBordersVisible = true;
Expand Down
Loading
Loading