Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit db472d9

Browse files
committed
Improved extensibility and support for Json.
Refactored code to add better extensibility and allow override on key methods. Included an abstract DataTablesJsonParser class to help you parse your Json when needed. Removed some typos and minor changes to code documentation.
1 parent bdf5fd4 commit db472d9

File tree

11 files changed

+409
-55
lines changed

11 files changed

+409
-55
lines changed

.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.58 MB
Binary file not shown.

.nuget/NuGet.targets

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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>packages.$(MSBuildProjectName.Replace(' ', '_')).config</PackagesProjectConfig>
40+
</PropertyGroup>
41+
42+
<Choose>
43+
<When Condition="Exists('$(PackagesProjectConfig)')">
44+
<PropertyGroup>
45+
<PackagesConfig>$(PackagesProjectConfig)</PackagesConfig>
46+
</PropertyGroup>
47+
</When>
48+
<When Condition="Exists('packages.config')">
49+
<PropertyGroup>
50+
<PackagesConfig>packages.config</PackagesConfig>
51+
</PropertyGroup>
52+
</When>
53+
</Choose>
54+
55+
<PropertyGroup>
56+
<!-- NuGet command -->
57+
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath>
58+
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
59+
60+
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
61+
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>
62+
63+
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
64+
65+
<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
66+
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>
67+
68+
<PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT'">"$(SolutionDir) "</PaddedSolutionDir>
69+
<PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir>
70+
71+
<!-- Commands -->
72+
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand>
73+
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>
74+
75+
<!-- We need to ensure packages are restored prior to assembly resolve -->
76+
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
77+
RestorePackages;
78+
$(BuildDependsOn);
79+
</BuildDependsOn>
80+
81+
<!-- Make the build depend on restore packages -->
82+
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
83+
$(BuildDependsOn);
84+
BuildPackage;
85+
</BuildDependsOn>
86+
</PropertyGroup>
87+
88+
<Target Name="CheckPrerequisites">
89+
<!-- Raise an error if we're unable to locate nuget.exe -->
90+
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
91+
<!--
92+
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
93+
This effectively acts as a lock that makes sure that the download operation will only happen once and all
94+
parallel builds will have to wait for it to complete.
95+
-->
96+
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
97+
</Target>
98+
99+
<Target Name="_DownloadNuGet">
100+
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
101+
</Target>
102+
103+
<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
104+
<Exec Command="$(RestoreCommand)"
105+
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
106+
107+
<Exec Command="$(RestoreCommand)"
108+
LogStandardErrorAsError="true"
109+
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
110+
</Target>
111+
112+
<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
113+
<Exec Command="$(BuildCommand)"
114+
Condition=" '$(OS)' != 'Windows_NT' " />
115+
116+
<Exec Command="$(BuildCommand)"
117+
LogStandardErrorAsError="true"
118+
Condition=" '$(OS)' == 'Windows_NT' " />
119+
</Target>
120+
121+
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
122+
<ParameterGroup>
123+
<OutputFilename ParameterType="System.String" Required="true" />
124+
</ParameterGroup>
125+
<Task>
126+
<Reference Include="System.Core" />
127+
<Using Namespace="System" />
128+
<Using Namespace="System.IO" />
129+
<Using Namespace="System.Net" />
130+
<Using Namespace="Microsoft.Build.Framework" />
131+
<Using Namespace="Microsoft.Build.Utilities" />
132+
<Code Type="Fragment" Language="cs">
133+
<![CDATA[
134+
try {
135+
OutputFilename = Path.GetFullPath(OutputFilename);
136+
137+
Log.LogMessage("Downloading latest version of NuGet.exe...");
138+
WebClient webClient = new WebClient();
139+
webClient.DownloadFile("https://www.nuget.org/nuget.exe", OutputFilename);
140+
141+
return true;
142+
}
143+
catch (Exception ex) {
144+
Log.LogErrorFromException(ex);
145+
return false;
146+
}
147+
]]>
148+
</Code>
149+
</Task>
150+
</UsingTask>
151+
</Project>

DataTables.Mvc.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ VisualStudioVersion = 12.0.30110.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataTables.Mvc", "DataTables.Mvc\DataTables.Mvc.csproj", "{431ADB89-3DA0-4E18-9AF0-984B917E6EB8}"
77
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{ADC2DA96-7473-4B8D-A2DF-EB01DE222EED}"
9+
ProjectSection(SolutionItems) = preProject
10+
.nuget\NuGet.Config = .nuget\NuGet.Config
11+
.nuget\NuGet.exe = .nuget\NuGet.exe
12+
.nuget\NuGet.targets = .nuget\NuGet.targets
13+
EndProjectSection
14+
EndProject
815
Global
916
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1017
Debug|Any CPU = Debug|Any CPU

DataTables.Mvc/DataTables.Mvc.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<TargetFrameworkProfile />
15+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
16+
<RestorePackages>true</RestorePackages>
1517
</PropertyGroup>
1618
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1719
<DebugSymbols>true</DebugSymbols>
@@ -75,6 +77,7 @@
7577
<ItemGroup>
7678
<Compile Include="Column.cs" />
7779
<Compile Include="DataTablesBinder.cs" />
80+
<Compile Include="DataTablesJsonBinder.cs" />
7881
<Compile Include="DataTablesResponse.cs" />
7982
<Compile Include="IDataTablesRequest.cs" />
8083
<Compile Include="NameValueCollectionExtensions.cs" />
@@ -85,6 +88,7 @@
8588
<None Include="packages.config" />
8689
</ItemGroup>
8790
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
91+
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
8892
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
8993
Other similar extension points exist, see Microsoft.Common.targets.
9094
<Target Name="BeforeBuild">

0 commit comments

Comments
 (0)