├── .editorconfig ├── .github └── workflows │ └── dotnet.yml ├── .gitignore ├── LICENSE ├── README.md ├── bVirtualization.Infrastructure.Build ├── Program.cs └── bVirtualization.Infrastructure.Build.csproj ├── bVirtualization.Tests.Unit ├── Services │ ├── VirtualizationServiceTests.Exceptions.cs │ ├── VirtualizationServiceTests.Logic.cs │ └── VirtualizationServiceTests.cs ├── Views │ └── Components │ │ └── BVirtualizations │ │ ├── BVirtualizationComponentTests.Render.cs │ │ └── BVirtualizationComponentTests.cs └── bVirtualization.Tests.Unit.csproj ├── bVirtualization.sln └── bVirtualization ├── Brokers └── DataSources │ ├── DataSourceBroker.cs │ └── IDataSourceBroker.cs ├── Models ├── BVirutalizationComponents │ └── BVirutalizationComponentState.cs └── Virtualizations │ └── Exceptions │ └── VirtualizationServiceException.cs ├── Pages └── DeleteMePage.razor ├── Services ├── IVirtualizationService.cs ├── VirtualizationService.Exceptions.cs └── VirtualizationService.cs ├── Views ├── Base │ ├── LabelBase.razor │ ├── LabelBase.razor.cs │ ├── VirtualizationBase.razor │ └── VirtualizationBase.razor.cs └── Components │ ├── BVirtualizationComponent.razor │ └── BVirtualizationComponent.razor.cs ├── _Imports.razor └── bVirtualization.csproj /.editorconfig: -------------------------------------------------------------------------------- 1 | # Rules in this file were initially inferred by Visual Studio IntelliCode from the D:\bVirtualization codebase based on best match to current usage at 4/10/2021 2 | # You can modify the rules from these initially generated values to suit your own policies 3 | # You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference 4 | [*.cs] 5 | 6 | file_header_template = ---------------------------------------------------------------\nCopyright (c) Brian Parker & Hassan Habib All rights reserved.\nLicensed under the MIT License.\nSee License.txt in the project root for license information.\n--------------------------------------------------------------- -------------------------------------------------------------------------------- /.github/workflows/dotnet.yml: -------------------------------------------------------------------------------- 1 | name: .Net 2 | on: 3 | push: 4 | branches: 5 | - main 6 | pull_request: 7 | branches: 8 | - main 9 | jobs: 10 | build: 11 | runs-on: windows-2019 12 | steps: 13 | - name: Check Out 14 | uses: actions/checkout@v2 15 | - name: Setup .Net 16 | uses: actions/setup-dotnet@v1 17 | with: 18 | dotnet-version: 6.0.101 19 | include-prerelease: true 20 | - name: Restore 21 | run: dotnet restore 22 | - name: Build 23 | run: dotnet build --no-restore 24 | - name: Test 25 | run: dotnet test --no-build --verbosity normal 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Hassan Rezk Habib 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![.NET](https://github.com/hassanhabib/bVirtualization/actions/workflows/dotnet.yml/badge.svg)](https://github.com/hassanhabib/bVirtualization/actions/workflows/dotnet.yml) 2 | [![The Standard - COMPLIANT](https://img.shields.io/badge/The_Standard-COMPLIANT-2ea44f)](https://github.com/hassanhabib/The-Standard) 3 | 4 | # bVirtualization 5 | This is a Blazor component for Virtualization that supports infinite scrolling with ANY type of data source, whether it's an API or Database or just simply a file on your computer or just in memory! 6 | 7 | 8 | ## Summary 9 | This is a Blazor Library to provide engineers with Blazor UI components that enables them to develop software with infinite scrolling capabilities. 10 | 11 | The main idea here is to provide a datasource-agnostic component that may be integrated and plugged in with any back-end supporting capability for providing data in the most seamless and easy way possible. 12 | 13 | One of the fundamental purposes of this component to close the gap between the WASM client and whatever datasource that the component can integrate with with something as simple as three lines of code or less. 14 | 15 | Ideally, this product is built to improve the engineering experience for developing UI components in Blazor. 16 | 17 | 18 | 19 | For any questions or inquiries about this component please contact the following engineers: 20 | 21 | Brian Parker (brian.parker@hotmail.com.au) 22 | 23 | Hassan Habib (hassanhabib@live.com) 24 | -------------------------------------------------------------------------------- /bVirtualization.Infrastructure.Build/Program.cs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------- 2 | // Copyright (c) Brian Parker & Hassan Habib All rights reserved. 3 | // Licensed under the MIT License. 4 | // See License.txt in the project root for license information. 5 | // --------------------------------------------------------------- 6 | 7 | using System.Collections.Generic; 8 | using ADotNet.Clients; 9 | using ADotNet.Models.Pipelines.GithubPipelines.DotNets; 10 | using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks; 11 | using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks.SetupDotNetTaskV1s; 12 | 13 | namespace bVirtualization.Infrastructure.Build 14 | { 15 | internal class Program 16 | { 17 | static void Main(string[] args) 18 | { 19 | var adotNetClient = new ADotNetClient(); 20 | 21 | var githubPipeline = new GithubPipeline 22 | { 23 | Name = ".Net", 24 | 25 | OnEvents = new Events 26 | { 27 | Push = new PushEvent 28 | { 29 | Branches = new string[] { "main" } 30 | }, 31 | 32 | PullRequest = new PullRequestEvent 33 | { 34 | Branches = new string[] { "main" } 35 | } 36 | }, 37 | 38 | Jobs = new Jobs 39 | { 40 | Build = new BuildJob 41 | { 42 | RunsOn = BuildMachines.Windows2019, 43 | 44 | Steps = new List 45 | { 46 | new CheckoutTaskV2 47 | { 48 | Name = "Check Out" 49 | }, 50 | 51 | new SetupDotNetTaskV1 52 | { 53 | Name = "Setup .Net", 54 | 55 | TargetDotNetVersion = new TargetDotNetVersion 56 | { 57 | DotNetVersion = "6.0.101", 58 | IncludePrerelease = true 59 | } 60 | }, 61 | 62 | new RestoreTask 63 | { 64 | Name = "Restore" 65 | }, 66 | 67 | new DotNetBuildTask 68 | { 69 | Name = "Build" 70 | }, 71 | 72 | new TestTask 73 | { 74 | Name = "Test" 75 | } 76 | } 77 | } 78 | } 79 | }; 80 | 81 | adotNetClient.SerializeAndWriteToFile(githubPipeline, "../../../../.github/workflows/dotnet.yml"); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /bVirtualization.Infrastructure.Build/bVirtualization.Infrastructure.Build.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /bVirtualization.Tests.Unit/Services/VirtualizationServiceTests.Exceptions.cs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------- 2 | // Copyright (c) Brian Parker & Hassan Habib All rights reserved. 3 | // Licensed under the MIT License. 4 | // See License.txt in the project root for license information. 5 | // --------------------------------------------------------------- 6 | 7 | using System; 8 | using bVirtualization.Models.Virtualizations.Exceptions; 9 | using Moq; 10 | using Xunit; 11 | 12 | namespace bVirtualization.Tests.Unit.Services 13 | { 14 | public partial class VirtualizationServiceTests 15 | { 16 | [Fact] 17 | public void ShouldThrowServiceExceptionOnTakeSkipIfServiceErrorOccurs() 18 | { 19 | // given 20 | uint someStartAt = GetRandomPositiveNumber(); 21 | uint somePageSize = GetRandomPositiveNumber(); 22 | string randomMessage = GetRandomMessage(); 23 | var serviceException = new Exception(randomMessage); 24 | 25 | var expectedVirtualizationServiceException = 26 | new VirtualizationServiceException(serviceException); 27 | 28 | this.dataSourceBrokerMock.Setup(broker => 29 | broker.TakeSkip(It.IsAny(), It.IsAny())) 30 | .Throws(serviceException); 31 | 32 | // when 33 | Action takeSkipAction = () => 34 | this.virtualizationService.LoadPage( 35 | someStartAt, 36 | somePageSize); 37 | 38 | // then 39 | Assert.Throws(takeSkipAction); 40 | 41 | this.dataSourceBrokerMock.Verify(broker => 42 | broker.TakeSkip(It.IsAny(), It.IsAny()), 43 | Times.Once()); 44 | 45 | this.dataSourceBrokerMock.VerifyNoOtherCalls(); 46 | } 47 | 48 | [Fact] 49 | public void ShouldThrowServiceExceptionOnRetrieveNextPageIfServiceErrorOccurs() 50 | { 51 | string randomMessage = GetRandomMessage(); 52 | var serviceException = new Exception(randomMessage); 53 | 54 | var expectedVirtualizationServiceException = 55 | new VirtualizationServiceException(serviceException); 56 | 57 | this.dataSourceBrokerMock.Setup(broker => 58 | broker.TakeSkip(It.IsAny(), It.IsAny())) 59 | .Throws(serviceException); 60 | 61 | // when 62 | Action retrieveNextPageAction = () => 63 | this.virtualizationService.RetrieveNextPage(); 64 | 65 | // then 66 | Assert.Throws(retrieveNextPageAction); 67 | 68 | this.dataSourceBrokerMock.Verify(broker => 69 | broker.TakeSkip(It.IsAny(), It.IsAny()), 70 | Times.Once()); 71 | 72 | this.dataSourceBrokerMock.VerifyNoOtherCalls(); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /bVirtualization.Tests.Unit/Services/VirtualizationServiceTests.Logic.cs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------- 2 | // Copyright (c) Brian Parker & Hassan Habib All rights reserved. 3 | // Licensed under the MIT License. 4 | // See License.txt in the project root for license information. 5 | // --------------------------------------------------------------- 6 | 7 | using System.Linq; 8 | using FluentAssertions; 9 | using Moq; 10 | using Xunit; 11 | 12 | namespace bVirtualization.Tests.Unit.Services 13 | { 14 | public partial class VirtualizationServiceTests 15 | { 16 | [Fact] 17 | public void ShouldSkipAndTakeOnLoadFirstPageFromDataSource() 18 | { 19 | // given 20 | uint randomStartAt = GetRandomPositiveNumber(); 21 | uint randomPageSize = GetRandomPositiveNumber(); 22 | uint inputStartAt = randomStartAt; 23 | uint inputPageSize = randomPageSize; 24 | uint expectedPageSize = inputPageSize; 25 | uint expectedPosition = inputStartAt; 26 | 27 | IQueryable randomQueryable = 28 | CreateRandomQueryable(); 29 | 30 | IQueryable returnedQueryable = randomQueryable; 31 | IQueryable expectedQueryable = returnedQueryable; 32 | 33 | this.dataSourceBrokerMock.Setup(source => 34 | source.TakeSkip(inputStartAt, inputPageSize)) 35 | .Returns(returnedQueryable); 36 | 37 | // when 38 | IQueryable actualQueryable = 39 | this.virtualizationService.LoadPage( 40 | inputStartAt, 41 | inputPageSize); 42 | 43 | uint actualPageSize = 44 | this.virtualizationService.GetPageSize(); 45 | 46 | uint actualPosition = 47 | this.virtualizationService.GetCurrentPosition(); 48 | 49 | // then 50 | actualQueryable.Should().BeEquivalentTo(expectedQueryable); 51 | actualPageSize.Should().Be(expectedPageSize); 52 | actualPosition.Should().Be(expectedPosition); 53 | 54 | this.dataSourceBrokerMock.Verify(source => 55 | source.TakeSkip(inputStartAt, inputPageSize), 56 | Times.Once); 57 | 58 | this.dataSourceBrokerMock.VerifyNoOtherCalls(); 59 | } 60 | 61 | [Fact] 62 | public void ShouldRetrieveNextPage() 63 | { 64 | // given 65 | uint randomStartAt = GetRandomPositiveNumber(); 66 | uint randomPageSize = GetRandomPositiveNumber(); 67 | uint inputStartAt = randomStartAt; 68 | uint inputPageSize = randomPageSize; 69 | uint expectedStartAt = inputStartAt + inputPageSize; 70 | uint expectedCurrentPosition = expectedStartAt; 71 | uint expectedPageSize = inputPageSize; 72 | 73 | IQueryable retrievedNextPage = 74 | CreateRandomQueryable(); 75 | 76 | IQueryable expectedNextPage = 77 | retrievedNextPage; 78 | 79 | this.dataSourceBrokerMock.Setup(broker => 80 | broker.TakeSkip(expectedStartAt, inputPageSize)) 81 | .Returns(retrievedNextPage); 82 | 83 | // when 84 | this.virtualizationService.LoadPage( 85 | inputStartAt, 86 | inputPageSize); 87 | 88 | IQueryable actualNextPage = 89 | this.virtualizationService.RetrieveNextPage(); 90 | 91 | uint actualCurrentPosition = 92 | this.virtualizationService.GetCurrentPosition(); 93 | 94 | uint actualPageSize = 95 | this.virtualizationService.GetPageSize(); 96 | 97 | // then 98 | actualNextPage.Should().BeEquivalentTo(expectedNextPage); 99 | actualCurrentPosition.Should().Be(expectedCurrentPosition); 100 | actualPageSize.Should().Be(expectedPageSize); 101 | 102 | this.dataSourceBrokerMock.Verify(broker => 103 | broker.TakeSkip(inputStartAt, inputPageSize), 104 | Times.Once); 105 | 106 | this.dataSourceBrokerMock.Verify(broker => 107 | broker.TakeSkip(expectedStartAt, inputPageSize), 108 | Times.Once); 109 | 110 | this.dataSourceBrokerMock.VerifyNoOtherCalls(); 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /bVirtualization.Tests.Unit/Services/VirtualizationServiceTests.cs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------- 2 | // Copyright (c) Brian Parker & Hassan Habib All rights reserved. 3 | // Licensed under the MIT License. 4 | // See License.txt in the project root for license information. 5 | // --------------------------------------------------------------- 6 | 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using bVirtualization.Brokers.DataSources; 10 | using bVirtualization.Services; 11 | using Moq; 12 | using Tynamix.ObjectFiller; 13 | 14 | namespace bVirtualization.Tests.Unit.Services 15 | { 16 | public partial class VirtualizationServiceTests 17 | { 18 | 19 | private readonly Mock> dataSourceBrokerMock; 20 | private readonly IVirtualizationService virtualizationService; 21 | 22 | public VirtualizationServiceTests() 23 | { 24 | this.dataSourceBrokerMock = new Mock>(); 25 | 26 | this.virtualizationService = new VirtualizationService( 27 | dataSourceBroker: this.dataSourceBrokerMock.Object); 28 | } 29 | 30 | private static uint GetRandomPositiveNumber() => 31 | (uint)new IntRange(min: 0, max: 10).GetValue(); 32 | 33 | private static string GetRandomMessage() => 34 | new MnemonicString().GetValue(); 35 | 36 | public static IQueryable CreateRandomQueryable() => 37 | CreateQueryableFiller().Create().AsQueryable(); 38 | 39 | private static object CreateRandomObject() => 40 | new MnemonicString().GetValue(); 41 | 42 | public static Filler> CreateQueryableFiller() 43 | { 44 | var filler = new Filler>(); 45 | 46 | filler.Setup() 47 | .OnType().Use(CreateRandomObject()); 48 | 49 | return filler; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /bVirtualization.Tests.Unit/Views/Components/BVirtualizations/BVirtualizationComponentTests.Render.cs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------- 2 | // Copyright (c) Brian Parker & Hassan Habib All rights reserved. 3 | // Licensed under the MIT License. 4 | // See License.txt in the project root for license information. 5 | // --------------------------------------------------------------- 6 | 7 | using System.Linq; 8 | using Bunit; 9 | using bVirtualization.Models.BVirutalizationComponents; 10 | using bVirtualization.Views.Components; 11 | using FluentAssertions; 12 | using Microsoft.AspNetCore.Components; 13 | using Xunit; 14 | 15 | namespace bVirtualization.Tests.Unit.Views.Components.BVirtualizations 16 | { 17 | public partial class BVirtualizationComponentTests 18 | { 19 | [Fact] 20 | public void ShouldInitializeComponent() 21 | { 22 | // given 23 | BVirutalizationComponentState expectedState = 24 | BVirutalizationComponentState.Loading; 25 | 26 | // when 27 | var initialBVirtualizationComponent = 28 | new BVirtualizationComponent(); 29 | 30 | // then 31 | initialBVirtualizationComponent.State.Should().Be(expectedState); 32 | initialBVirtualizationComponent.DataSource.Should().BeNull(); 33 | initialBVirtualizationComponent.ChildContent.Should().BeNull(); 34 | initialBVirtualizationComponent.Label.Should().BeNull(); 35 | initialBVirtualizationComponent.ErrorMessage.Should().BeNull(); 36 | } 37 | 38 | [Fact] 39 | public void ShouldRenderContent() 40 | { 41 | // given 42 | BVirutalizationComponentState expectedState = 43 | BVirutalizationComponentState.Content; 44 | 45 | IQueryable randomData = 46 | CreateRandomQueryable(); 47 | 48 | IQueryable inputDataSource = 49 | randomData; 50 | 51 | IQueryable expectedDataSource = 52 | inputDataSource; 53 | 54 | RenderFragment inputChildContent = 55 | CreateRenderFragment(typeof(SomeComponent)); 56 | 57 | RenderFragment expectedChildContent = 58 | inputChildContent; 59 | 60 | var componentParameters = new ComponentParameter[] 61 | { 62 | ComponentParameter.CreateParameter( 63 | nameof(BVirtualizationComponent.ChildContent), 64 | inputChildContent), 65 | 66 | ComponentParameter.CreateParameter( 67 | nameof(BVirtualizationComponent.DataSource), 68 | inputDataSource) 69 | }; 70 | 71 | // when 72 | this.renderedComponent = 73 | RenderComponent>(componentParameters); 74 | 75 | // then 76 | this.renderedComponent.Instance.State 77 | .Should().Be(expectedState); 78 | 79 | this.renderedComponent.Instance.ChildContent 80 | .Should().BeEquivalentTo(expectedChildContent); 81 | 82 | this.renderedComponent.Instance.DataSource.Should() 83 | .BeEquivalentTo(expectedDataSource); 84 | 85 | this.renderedComponent.FindComponents>() 86 | .Count().Should().Be(expectedDataSource.Count()); 87 | 88 | this.renderedComponent.Instance.ErrorMessage.Should().BeNull(); 89 | this.renderedComponent.Instance.Label.Should().BeNull(); 90 | } 91 | 92 | [Fact] 93 | public void ShouldRenderErrorWhenExceptionOccurs() 94 | { 95 | // given 96 | BVirutalizationComponentState expectedState = 97 | BVirutalizationComponentState.Error; 98 | 99 | string expectedErrorMessage = 100 | "Virtualization service error ocurred, contact support."; 101 | 102 | IQueryable someData = null; 103 | 104 | RenderFragment someChildContent = 105 | CreateRenderFragment(typeof(SomeComponent)); 106 | 107 | var componentParameters = new ComponentParameter[] 108 | { 109 | ComponentParameter.CreateParameter( 110 | nameof(BVirtualizationComponent.ChildContent), 111 | someChildContent), 112 | 113 | ComponentParameter.CreateParameter( 114 | nameof(BVirtualizationComponent.DataSource), 115 | someData) 116 | }; 117 | 118 | // when 119 | this.renderedComponent = 120 | RenderComponent>(componentParameters); 121 | 122 | // then 123 | this.renderedComponent.Instance.State.Should().Be(expectedState); 124 | this.renderedComponent.Instance.ErrorMessage.Should().Be(expectedErrorMessage); 125 | this.renderedComponent.Instance.Label.Should().NotBeNull(); 126 | this.renderedComponent.Instance.Label.Value.Should().Be(expectedErrorMessage); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /bVirtualization.Tests.Unit/Views/Components/BVirtualizations/BVirtualizationComponentTests.cs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------- 2 | // Copyright (c) Brian Parker & Hassan Habib All rights reserved. 3 | // Licensed under the MIT License. 4 | // See License.txt in the project root for license information. 5 | // --------------------------------------------------------------- 6 | 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | using Bunit; 11 | using bVirtualization.Views.Components; 12 | using Microsoft.AspNetCore.Components; 13 | using Microsoft.Extensions.DependencyInjection; 14 | using Moq; 15 | using Tynamix.ObjectFiller; 16 | 17 | namespace bVirtualization.Tests.Unit.Views.Components.BVirtualizations 18 | { 19 | public partial class BVirtualizationComponentTests : TestContext 20 | { 21 | private IRenderedComponent> renderedComponent; 22 | private Mock> dataSourceMock; 23 | 24 | public BVirtualizationComponentTests() 25 | { 26 | this.dataSourceMock = new Mock>(); 27 | this.Services.AddOptions(); 28 | this.JSInterop.Mode = JSRuntimeMode.Loose; 29 | } 30 | 31 | public static IQueryable CreateRandomQueryable() => 32 | CreateQueryableFiller().Create().AsQueryable(); 33 | 34 | private static object CreateRandomObject() => 35 | new MnemonicString().GetValue(); 36 | 37 | private static int GetRandomNumber() => 38 | new IntRange(min: 2, max: 10).GetValue(); 39 | 40 | private static RenderFragment CreateRenderFragment(Type type) => 41 | context => builder => 42 | { 43 | builder.OpenComponent(0, type); 44 | builder.CloseComponent(); 45 | }; 46 | 47 | public static Filler> CreateQueryableFiller() 48 | { 49 | var filler = new Filler>(); 50 | 51 | filler.Setup() 52 | .OnType().Use(() => CreateRandomObject()); 53 | 54 | return filler; 55 | } 56 | } 57 | 58 | public class SomeComponent : ComponentBase { } 59 | } 60 | -------------------------------------------------------------------------------- /bVirtualization.Tests.Unit/bVirtualization.Tests.Unit.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | runtime; build; native; contentfiles; analyzers; buildtransitive 19 | all 20 | 21 | 22 | runtime; build; native; contentfiles; analyzers; buildtransitive 23 | all 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /bVirtualization.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31717.71 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bVirtualization", "bVirtualization\bVirtualization.csproj", "{B17C3DC0-8513-4BBD-93EA-53A1E346AF72}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bVirtualization.Tests.Unit", "bVirtualization.Tests.Unit\bVirtualization.Tests.Unit.csproj", "{96693E1F-33CC-441E-89A1-596A17E5E575}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F890C46B-4ACF-4D99-B194-B8695645A10D}" 11 | ProjectSection(SolutionItems) = preProject 12 | .editorconfig = .editorconfig 13 | EndProjectSection 14 | EndProject 15 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bVirtualization.Infrastructure.Build", "bVirtualization.Infrastructure.Build\bVirtualization.Infrastructure.Build.csproj", "{463FC4B3-ACD9-4E2F-9D6B-7A6369685364}" 16 | EndProject 17 | Global 18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 19 | Debug|Any CPU = Debug|Any CPU 20 | Release|Any CPU = Release|Any CPU 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {B17C3DC0-8513-4BBD-93EA-53A1E346AF72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 24 | {B17C3DC0-8513-4BBD-93EA-53A1E346AF72}.Debug|Any CPU.Build.0 = Debug|Any CPU 25 | {B17C3DC0-8513-4BBD-93EA-53A1E346AF72}.Release|Any CPU.ActiveCfg = Release|Any CPU 26 | {B17C3DC0-8513-4BBD-93EA-53A1E346AF72}.Release|Any CPU.Build.0 = Release|Any CPU 27 | {96693E1F-33CC-441E-89A1-596A17E5E575}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 28 | {96693E1F-33CC-441E-89A1-596A17E5E575}.Debug|Any CPU.Build.0 = Debug|Any CPU 29 | {96693E1F-33CC-441E-89A1-596A17E5E575}.Release|Any CPU.ActiveCfg = Release|Any CPU 30 | {96693E1F-33CC-441E-89A1-596A17E5E575}.Release|Any CPU.Build.0 = Release|Any CPU 31 | {463FC4B3-ACD9-4E2F-9D6B-7A6369685364}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {463FC4B3-ACD9-4E2F-9D6B-7A6369685364}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {463FC4B3-ACD9-4E2F-9D6B-7A6369685364}.Release|Any CPU.ActiveCfg = Release|Any CPU 34 | {463FC4B3-ACD9-4E2F-9D6B-7A6369685364}.Release|Any CPU.Build.0 = Release|Any CPU 35 | EndGlobalSection 36 | GlobalSection(SolutionProperties) = preSolution 37 | HideSolutionNode = FALSE 38 | EndGlobalSection 39 | GlobalSection(ExtensibilityGlobals) = postSolution 40 | SolutionGuid = {E556F6C2-D037-4CDE-A675-ACEBDFA1587A} 41 | EndGlobalSection 42 | EndGlobal 43 | -------------------------------------------------------------------------------- /bVirtualization/Brokers/DataSources/DataSourceBroker.cs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------- 2 | // Copyright (c) Brian Parker & Hassan Habib All rights reserved. 3 | // Licensed under the MIT License. 4 | // See License.txt in the project root for license information. 5 | // --------------------------------------------------------------- 6 | 7 | using System.Linq; 8 | 9 | namespace bVirtualization.Brokers.DataSources 10 | { 11 | public class DataSourceBroker : IDataSourceBroker 12 | { 13 | private readonly IQueryable dataSource; 14 | 15 | public DataSourceBroker(IQueryable dataSource) => 16 | this.dataSource = dataSource; 17 | 18 | public IQueryable TakeSkip(uint startAt, uint pageSize) => 19 | this.dataSource.Skip((int)startAt).Take((int)pageSize); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /bVirtualization/Brokers/DataSources/IDataSourceBroker.cs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------- 2 | // Copyright (c) Brian Parker & Hassan Habib All rights reserved. 3 | // Licensed under the MIT License. 4 | // See License.txt in the project root for license information. 5 | // --------------------------------------------------------------- 6 | 7 | using System.Linq; 8 | 9 | namespace bVirtualization.Brokers.DataSources 10 | { 11 | public interface IDataSourceBroker 12 | { 13 | public IQueryable TakeSkip(uint startAt, uint pageSize); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /bVirtualization/Models/BVirutalizationComponents/BVirutalizationComponentState.cs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------- 2 | // Copyright (c) Brian Parker & Hassan Habib All rights reserved. 3 | // Licensed under the MIT License. 4 | // See License.txt in the project root for license information. 5 | // --------------------------------------------------------------- 6 | 7 | namespace bVirtualization.Models.BVirutalizationComponents 8 | { 9 | public enum BVirutalizationComponentState 10 | { 11 | Loading, 12 | Content, 13 | Error 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /bVirtualization/Models/Virtualizations/Exceptions/VirtualizationServiceException.cs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------- 2 | // Copyright (c) Brian Parker & Hassan Habib All rights reserved. 3 | // Licensed under the MIT License. 4 | // See License.txt in the project root for license information. 5 | // --------------------------------------------------------------- 6 | 7 | using System; 8 | 9 | namespace bVirtualization.Models.Virtualizations.Exceptions 10 | { 11 | public class VirtualizationServiceException : Exception 12 | { 13 | public VirtualizationServiceException(Exception innerException) 14 | : base(message: "Virtualization service error ocurred, contact support.", innerException) 15 | { } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /bVirtualization/Pages/DeleteMePage.razor: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /bVirtualization/Services/IVirtualizationService.cs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------- 2 | // Copyright (c) Brian Parker & Hassan Habib All rights reserved. 3 | // Licensed under the MIT License. 4 | // See License.txt in the project root for license information. 5 | // --------------------------------------------------------------- 6 | 7 | using System.Linq; 8 | 9 | namespace bVirtualization.Services 10 | { 11 | public interface IVirtualizationService 12 | { 13 | IQueryable LoadPage(uint startAt, uint pageSize); 14 | IQueryable RetrieveNextPage(); 15 | uint GetCurrentPosition(); 16 | uint GetPageSize(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /bVirtualization/Services/VirtualizationService.Exceptions.cs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------- 2 | // Copyright (c) Brian Parker & Hassan Habib All rights reserved. 3 | // Licensed under the MIT License. 4 | // See License.txt in the project root for license information. 5 | // --------------------------------------------------------------- 6 | 7 | using System; 8 | using System.Linq; 9 | using bVirtualization.Models.Virtualizations.Exceptions; 10 | 11 | namespace bVirtualization.Services 12 | { 13 | public partial class VirtualizationService 14 | { 15 | private delegate IQueryable ReturningQueryableFunction(); 16 | 17 | private IQueryable TryCatch(ReturningQueryableFunction returningQueryableFunction) 18 | { 19 | try 20 | { 21 | return returningQueryableFunction(); 22 | } 23 | catch (Exception exception) 24 | { 25 | var virtualizationServiceException = 26 | new VirtualizationServiceException(exception); 27 | 28 | throw virtualizationServiceException; 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /bVirtualization/Services/VirtualizationService.cs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------- 2 | // Copyright (c) Brian Parker & Hassan Habib All rights reserved. 3 | // Licensed under the MIT License. 4 | // See License.txt in the project root for license information. 5 | // --------------------------------------------------------------- 6 | 7 | using System.Linq; 8 | using bVirtualization.Brokers.DataSources; 9 | 10 | namespace bVirtualization.Services 11 | { 12 | public partial class VirtualizationService : IVirtualizationService 13 | { 14 | private readonly IDataSourceBroker dataSourceBroker; 15 | private uint currentPageSize; 16 | private uint currentPosition; 17 | 18 | public VirtualizationService(IDataSourceBroker dataSourceBroker) => 19 | this.dataSourceBroker = dataSourceBroker; 20 | 21 | public IQueryable LoadPage(uint startAt, uint pageSize) => 22 | TryCatch(() => 23 | { 24 | this.currentPosition = startAt; 25 | this.currentPageSize = pageSize; 26 | 27 | return this.dataSourceBroker.TakeSkip(startAt, pageSize); 28 | }); 29 | 30 | public IQueryable RetrieveNextPage() => 31 | TryCatch(() => 32 | { 33 | this.currentPosition += this.currentPageSize; 34 | 35 | return this.dataSourceBroker.TakeSkip( 36 | this.currentPosition, 37 | this.currentPageSize); 38 | }); 39 | 40 | public uint GetCurrentPosition() => 41 | this.currentPosition; 42 | 43 | public uint GetPageSize() => 44 | this.currentPageSize; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /bVirtualization/Views/Base/LabelBase.razor: -------------------------------------------------------------------------------- 1 |  2 | -------------------------------------------------------------------------------- /bVirtualization/Views/Base/LabelBase.razor.cs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------- 2 | // Copyright (c) Brian Parker & Hassan Habib All rights reserved. 3 | // Licensed under the MIT License. 4 | // See License.txt in the project root for license information. 5 | // --------------------------------------------------------------- 6 | 7 | using Microsoft.AspNetCore.Components; 8 | 9 | namespace bVirtualization.Views.Base 10 | { 11 | public partial class LabelBase 12 | { 13 | [Parameter] 14 | public string Value { get; set; } 15 | 16 | public void SetValue(string value) 17 | { 18 | this.Value = value; 19 | InvokeAsync(workItem: StateHasChanged); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /bVirtualization/Views/Base/VirtualizationBase.razor: -------------------------------------------------------------------------------- 1 | @typeparam T 2 | @using Microsoft.AspNetCore.Components.Web.Virtualization 3 | 4 | 6 | @ChildContent(context) 7 | -------------------------------------------------------------------------------- /bVirtualization/Views/Base/VirtualizationBase.razor.cs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------- 2 | // Copyright (c) Brian Parker & Hassan Habib All rights reserved. 3 | // Licensed under the MIT License. 4 | // See License.txt in the project root for license information. 5 | // --------------------------------------------------------------- 6 | 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | using Microsoft.AspNetCore.Components; 10 | using Microsoft.AspNetCore.Components.Web.Virtualization; 11 | 12 | namespace bVirtualization.Views.Base 13 | { 14 | public partial class VirtualizationBase : ComponentBase 15 | { 16 | [Parameter] 17 | public RenderFragment ChildContent { get; set; } 18 | 19 | [Parameter] 20 | public int OverscanCount { get; set; } = 3; 21 | 22 | [Parameter] 23 | public CallBackSourceDelegate CallBackSource { get; set; } 24 | 25 | private async ValueTask> GetItemsAsync( 26 | ItemsProviderRequest request) 27 | { 28 | var data = CallBackSource.Invoke(request.StartIndex, request.Count); 29 | 30 | return new ItemsProviderResult(data.DataSource, data.TotalCount); 31 | } 32 | } 33 | 34 | public delegate (IQueryable DataSource, int TotalCount) 35 | CallBackSourceDelegate(int startIndex, int count); 36 | } 37 | -------------------------------------------------------------------------------- /bVirtualization/Views/Components/BVirtualizationComponent.razor: -------------------------------------------------------------------------------- 1 | @typeparam T 2 | @using bVirtualization.Views.Base 3 | @using PrettyBlazor 4 | 5 | 6 | 7 | 8 | @ChildContent(context) 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /bVirtualization/Views/Components/BVirtualizationComponent.razor.cs: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------- 2 | // Copyright (c) Brian Parker & Hassan Habib All rights reserved. 3 | // Licensed under the MIT License. 4 | // See License.txt in the project root for license information. 5 | // --------------------------------------------------------------- 6 | 7 | using System.Linq; 8 | using bVirtualization.Brokers.DataSources; 9 | using bVirtualization.Models.BVirutalizationComponents; 10 | using bVirtualization.Services; 11 | using bVirtualization.Views.Base; 12 | using Microsoft.AspNetCore.Components; 13 | 14 | namespace bVirtualization.Views.Components 15 | { 16 | public partial class BVirtualizationComponent : ComponentBase 17 | { 18 | [Parameter] 19 | public RenderFragment ChildContent { get; set; } 20 | 21 | [Parameter] 22 | public IQueryable DataSource { get; set; } 23 | 24 | public BVirutalizationComponentState State { get; set; } 25 | public string ErrorMessage { get; set; } 26 | public LabelBase Label { get; set; } 27 | private IDataSourceBroker dataSourceBroker; 28 | private IVirtualizationService virtualizationService; 29 | 30 | protected override void OnInitialized() 31 | { 32 | this.dataSourceBroker = 33 | new DataSourceBroker(this.DataSource); 34 | 35 | this.virtualizationService = 36 | new VirtualizationService(this.dataSourceBroker); 37 | 38 | this.State = BVirutalizationComponentState.Content; 39 | base.OnInitialized(); 40 | } 41 | 42 | private (IQueryable DataSource, int TotalCount) RetrieveData( 43 | int index, 44 | int quantity) 45 | { 46 | try 47 | { 48 | 49 | IQueryable data = this.virtualizationService 50 | .LoadPage((uint)index, (uint)quantity); 51 | 52 | int totalCount = data.Count(); 53 | 54 | return (data, totalCount); 55 | 56 | } 57 | catch (System.Exception exception) 58 | { 59 | this.State = BVirutalizationComponentState.Error; 60 | this.ErrorMessage = exception.Message; 61 | InvokeAsync(StateHasChanged); 62 | return default; 63 | } 64 | } 65 | 66 | public bool IsStateContent => 67 | this.State == BVirutalizationComponentState.Content; 68 | 69 | public bool IsStateError => 70 | this.State == BVirutalizationComponentState.Error; 71 | } 72 | } -------------------------------------------------------------------------------- /bVirtualization/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNetCore.Components.Web 2 | -------------------------------------------------------------------------------- /bVirtualization/bVirtualization.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net6.0 5 | disable 6 | disable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | --------------------------------------------------------------------------------