Skip to content

Commit 52c8d26

Browse files
Merge pull request #2 from plv2/master
add an asynchrones DataGrid demo that support source change via sorting & filtering
2 parents 9139eb8 + 5675b27 commit 52c8d26

41 files changed

Lines changed: 1598 additions & 45 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/AlphaChiTech.Virtualization/bin
2+
/AlphaChiTech.Virtualization/obj
3+
/DataGridDemo/bin
4+
/DataGridDemo/obj
5+
/packages

.nuget/NuGet.Config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<solution>
4+
<add key="disableSourceControlIntegration" value="true" />
5+
</solution>
6+
</configuration>

.nuget/NuGet.exe

1.59 MB
Binary file not shown.

.nuget/NuGet.targets

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
5+
6+
<!-- Enable the restore command to run before builds -->
7+
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>
8+
9+
<!-- Property that enables building a package from a project -->
10+
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
11+
12+
<!-- Determines if package restore consent is required to restore packages -->
13+
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>
14+
15+
<!-- Download NuGet.exe if it does not already exist -->
16+
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
17+
</PropertyGroup>
18+
19+
<ItemGroup Condition=" '$(PackageSources)' == '' ">
20+
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
21+
<!-- The official NuGet package source (https://www.nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
22+
<!--
23+
<PackageSource Include="https://www.nuget.org/api/v2/" />
24+
<PackageSource Include="https://my-nuget-source/nuget/" />
25+
-->
26+
</ItemGroup>
27+
28+
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
29+
<!-- Windows specific commands -->
30+
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
31+
</PropertyGroup>
32+
33+
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
34+
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
35+
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
36+
</PropertyGroup>
37+
38+
<PropertyGroup>
39+
<PackagesProjectConfig Condition=" '$(OS)' == 'Windows_NT'">$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config</PackagesProjectConfig>
40+
<PackagesProjectConfig Condition=" '$(OS)' != 'Windows_NT'">$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config</PackagesProjectConfig>
41+
</PropertyGroup>
42+
43+
<PropertyGroup>
44+
<PackagesConfig Condition="Exists('$(MSBuildProjectDirectory)\packages.config')">$(MSBuildProjectDirectory)\packages.config</PackagesConfig>
45+
<PackagesConfig Condition="Exists('$(PackagesProjectConfig)')">$(PackagesProjectConfig)</PackagesConfig>
46+
</PropertyGroup>
47+
48+
<PropertyGroup>
49+
<!-- NuGet command -->
50+
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath>
51+
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
52+
53+
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
54+
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 "$(NuGetExePath)"</NuGetCommand>
55+
56+
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
57+
58+
<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
59+
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>
60+
61+
<PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT'">"$(SolutionDir) "</PaddedSolutionDir>
62+
<PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir>
63+
64+
<!-- Commands -->
65+
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand>
66+
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>
67+
68+
<!-- We need to ensure packages are restored prior to assembly resolve -->
69+
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
70+
RestorePackages;
71+
$(BuildDependsOn);
72+
</BuildDependsOn>
73+
74+
<!-- Make the build depend on restore packages -->
75+
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
76+
$(BuildDependsOn);
77+
BuildPackage;
78+
</BuildDependsOn>
79+
</PropertyGroup>
80+
81+
<Target Name="CheckPrerequisites">
82+
<!-- Raise an error if we're unable to locate nuget.exe -->
83+
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
84+
<!--
85+
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
86+
This effectively acts as a lock that makes sure that the download operation will only happen once and all
87+
parallel builds will have to wait for it to complete.
88+
-->
89+
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
90+
</Target>
91+
92+
<Target Name="_DownloadNuGet">
93+
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
94+
</Target>
95+
96+
<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
97+
<Exec Command="$(RestoreCommand)"
98+
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
99+
100+
<Exec Command="$(RestoreCommand)"
101+
LogStandardErrorAsError="true"
102+
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
103+
</Target>
104+
105+
<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
106+
<Exec Command="$(BuildCommand)"
107+
Condition=" '$(OS)' != 'Windows_NT' " />
108+
109+
<Exec Command="$(BuildCommand)"
110+
LogStandardErrorAsError="true"
111+
Condition=" '$(OS)' == 'Windows_NT' " />
112+
</Target>
113+
114+
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
115+
<ParameterGroup>
116+
<OutputFilename ParameterType="System.String" Required="true" />
117+
</ParameterGroup>
118+
<Task>
119+
<Reference Include="System.Core" />
120+
<Using Namespace="System" />
121+
<Using Namespace="System.IO" />
122+
<Using Namespace="System.Net" />
123+
<Using Namespace="Microsoft.Build.Framework" />
124+
<Using Namespace="Microsoft.Build.Utilities" />
125+
<Code Type="Fragment" Language="cs">
126+
<![CDATA[
127+
try {
128+
OutputFilename = Path.GetFullPath(OutputFilename);
129+
130+
Log.LogMessage("Downloading latest version of NuGet.exe...");
131+
WebClient webClient = new WebClient();
132+
webClient.DownloadFile("https://www.nuget.org/nuget.exe", OutputFilename);
133+
134+
return true;
135+
}
136+
catch (Exception ex) {
137+
Log.LogErrorFromException(ex);
138+
return false;
139+
}
140+
]]>
141+
</Code>
142+
</Task>
143+
</UsingTask>
144+
</Project>

AlphaChiTech.Virtualization.sln

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 2013
4-
VisualStudioVersion = 12.0.30723.0
4+
VisualStudioVersion = 12.0.31101.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlphaChiTech.Virtualization", "AlphaChiTech.Virtualization\AlphaChiTech.Virtualization.csproj", "{5455EE53-36B9-48E8-B1F0-EB7C6ABB7A57}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataGridAsyncDemo", "DataGridAsyncDemo\DataGridAsyncDemo.csproj", "{B1235F30-C8A9-4A18-B870-A7F23F214039}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{90A3E488-4EFC-4E8C-BE36-B03651A95625}"
11+
ProjectSection(SolutionItems) = preProject
12+
.nuget\NuGet.Config = .nuget\NuGet.Config
13+
.nuget\NuGet.exe = .nuget\NuGet.exe
14+
.nuget\NuGet.targets = .nuget\NuGet.targets
15+
EndProjectSection
16+
EndProject
817
Global
9-
GlobalSection(TeamFoundationVersionControl) = preSolution
10-
SccNumberOfProjects = 2
11-
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
12-
SccTeamFoundationServer = https://alphachitech.visualstudio.com/defaultcollection
13-
SccLocalPath0 = .
14-
SccProjectUniqueName1 = AlphaChiTech.Virtualization\\AlphaChiTech.Virtualization.csproj
15-
SccProjectName1 = AlphaChiTech.Virtualization
16-
SccLocalPath1 = AlphaChiTech.Virtualization
17-
EndGlobalSection
1818
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1919
Debug|Any CPU = Debug|Any CPU
2020
Release|Any CPU = Release|Any CPU
@@ -24,6 +24,10 @@ Global
2424
{5455EE53-36B9-48E8-B1F0-EB7C6ABB7A57}.Debug|Any CPU.Build.0 = Debug|Any CPU
2525
{5455EE53-36B9-48E8-B1F0-EB7C6ABB7A57}.Release|Any CPU.ActiveCfg = Release|Any CPU
2626
{5455EE53-36B9-48E8-B1F0-EB7C6ABB7A57}.Release|Any CPU.Build.0 = Release|Any CPU
27+
{B1235F30-C8A9-4A18-B870-A7F23F214039}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28+
{B1235F30-C8A9-4A18-B870-A7F23F214039}.Debug|Any CPU.Build.0 = Debug|Any CPU
29+
{B1235F30-C8A9-4A18-B870-A7F23F214039}.Release|Any CPU.ActiveCfg = Release|Any CPU
30+
{B1235F30-C8A9-4A18-B870-A7F23F214039}.Release|Any CPU.Build.0 = Release|Any CPU
2731
EndGlobalSection
2832
GlobalSection(SolutionProperties) = preSolution
2933
HideSolutionNode = FALSE

AlphaChiTech.Virtualization/IPagedSourceProviderAsync.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ public interface IPagedSourceProviderAsync<T> : IPagedSourceProvider<T>
1414

1515
Task<int> GetCountAsync();
1616

17+
Task<int> IndexOfAsync( T item );
1718
}
1819
}

AlphaChiTech.Virtualization/PagedSourceProviderMakeAsync.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,39 @@ namespace AlphaChiTech.Virtualization
88
{
99
public class PagedSourceProviderMakeAsync<T> : BasePagedSourceProvider<T>, IPagedSourceProviderAsync<T>
1010
{
11-
public PagedSourceProviderMakeAsync()
11+
private Func<T, Task<int>> _FuncIndexOfAsync = null;
12+
private Func<int, int, int, T> _FuncGetPlaceHolder = null;
13+
14+
public PagedSourceProviderMakeAsync()
1215
{
1316
}
1417

1518
public PagedSourceProviderMakeAsync(
1619
Func<int, int, PagedSourceItemsPacket<T>> funcGetItemsAt = null,
1720
Func<int> funcGetCount = null,
18-
Func<T, int> funcIndexOf = null,
21+
Func<T, Task<int>> funcIndexOfAsync = null,
1922
Action<int> actionOnReset = null,
2023
Func<int, int, int, T> funcGetPlaceHolder = null
2124
)
22-
: base(funcGetItemsAt, funcGetCount, funcIndexOf, actionOnReset)
25+
: base(funcGetItemsAt, funcGetCount, null, actionOnReset)
26+
//: base(funcGetItemsAt, funcGetCount, funcIndexOf, actionOnReset)
2327
{
2428
this.FuncGetPlaceHolder = funcGetPlaceHolder;
29+
_FuncIndexOfAsync = funcIndexOfAsync;
2530
}
2631

27-
private Func<int, int, int, T> _FuncGetPlaceHolder = null;
28-
2932
public Func<int, int, int, T> FuncGetPlaceHolder
3033
{
3134
get { return _FuncGetPlaceHolder; }
3235
set { _FuncGetPlaceHolder = value; }
3336
}
3437

38+
public Func<T, Task<int>> FuncIndexOfAsync
39+
{
40+
get { return _FuncIndexOfAsync; }
41+
set { _FuncIndexOfAsync = value; }
42+
}
43+
3544
public Task<PagedSourceItemsPacket<T>> GetItemsAtAsync(int pageoffset, int count, bool usePlaceholder)
3645
{
3746
var tcs = new TaskCompletionSource<PagedSourceItemsPacket<T>>();
@@ -72,5 +81,15 @@ public Task<int> GetCountAsync()
7281

7382
return tcs.Task;
7483
}
84+
85+
public Task<int> IndexOfAsync( T item )
86+
{
87+
var ret = default( Task<int> );
88+
89+
if (_FuncIndexOfAsync != null)
90+
ret = _FuncIndexOfAsync.Invoke( item );
91+
92+
return ret;
93+
}
7594
}
7695
}

AlphaChiTech.Virtualization/PaginationManager.cs

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,8 @@ public int GetCount(bool asyncOK)
791791
{
792792
if (!asyncOK)
793793
{
794-
ret = this.ProviderAsync.Count;
794+
ret = this.ProviderAsync.GetCountAsync().Result;
795+
//ret = this.ProviderAsync.Count;
795796
_LocalCount = ret;
796797
}
797798
else
@@ -859,42 +860,49 @@ public int IndexOf(T item)
859860
}
860861
else
861862
{
862-
return this.ProviderAsync.IndexOf(item);
863+
return this.ProviderAsync.IndexOfAsync( item ).Result;
864+
//return this.ProviderAsync.IndexOf(item);
863865
}
864866
}
865867

866868
/// <summary>
867869
/// Resets the specified count.
868870
/// </summary>
869871
/// <param name="count">The count.</param>
870-
public void OnReset(int count)
872+
public void OnReset( int count )
871873
{
872-
if(count < 0)
874+
CancelAllRequests();
875+
876+
lock (_PageLock)
877+
{
878+
DropAllDeltasAndPages();
879+
}
880+
881+
ClearOptimizations();
882+
883+
if (count < 0)
884+
{
885+
_HasGotCount = false;
886+
}
887+
else
888+
{
889+
lock (this)
873890
{
874-
_HasGotCount = false;
875-
return;
891+
_LocalCount = count;
892+
_HasGotCount = true;
876893
}
877-
878-
CancelAllRequests();
879-
880-
lock (_PageLock)
881-
{
882-
DropAllDeltasAndPages();
883-
}
884-
885-
ClearOptimizations();
886-
_HasGotCount = true;
887-
888-
if (!IsAsync)
889-
{
890-
this.Provider.OnReset(count);
891-
}
892-
else
893-
{
894-
this.ProviderAsync.OnReset(count);
895-
}
896-
897-
RaiseCountChanged(true, count);
894+
}
895+
896+
if (!IsAsync)
897+
{
898+
this.Provider.OnReset( count );
899+
}
900+
else
901+
{
902+
this.ProviderAsync.OnReset( count );
903+
}
904+
905+
RaiseCountChanged( true, count );
898906
}
899907

900908
/// <summary>

AlphaChiTech.Virtualization/VirtualizationManager.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public void ProcessActions()
7171
switch (action.ThreadModel)
7272
{
7373
case VirtualActionThreadModelEnum.UseUIThread:
74+
if (UIThreadExcecuteAction == null) // PLV
75+
throw new Exception( "VirtualizationManager isn’t already initialized ! set the VirtualizationManager’s UIThreadExcecuteAction (VirtualizationManager.Instance.UIThreadExcecuteAction = a => Dispatcher.Invoke( a );)" );
7476
UIThreadExcecuteAction.Invoke(() => action.DoAction());
7577
break;
7678
case VirtualActionThreadModelEnum.Background:
@@ -115,6 +117,8 @@ public void AddAction(Action action)
115117

116118
public void RunOnUI(IVirtualizationAction action)
117119
{
120+
if (UIThreadExcecuteAction == null) // PLV
121+
throw new Exception( "VirtualizationManager isn’t already initialized ! set the VirtualizationManager’s UIThreadExcecuteAction (VirtualizationManager.Instance.UIThreadExcecuteAction = a => Dispatcher.Invoke( a );)" );
118122
UIThreadExcecuteAction.Invoke(() => action.DoAction());
119123
}
120124

AlphaChiTech.Virtualization/VirtualizingObservableCollection.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,10 +682,13 @@ void InternalClear()
682682
{
683683
if(this.Provider != null)
684684
{
685-
this.Provider.OnReset(this.Provider.GetCount(false));
686-
} else
685+
//this.Provider.OnReset( this.Provider.GetCount( false ) );
686+
this.Provider.OnReset( -1 );
687+
}
688+
else
687689
{
688-
this.ProviderAsync.OnReset(Task.Run(() => this.ProviderAsync.Count).Result);
690+
//this.ProviderAsync.OnReset( Task.Run( () => this.ProviderAsync.Count ).Result );
691+
this.ProviderAsync.OnReset( -1 );
689692
}
690693
}
691694

0 commit comments

Comments
 (0)