Permalink
Browse files

First real commit.

  • Loading branch information...
1 parent c0e2025 commit 42ddafe883231f16098ec2fc7e1d656051f844b6 @elishnevsky committed Oct 26, 2012
Showing with 2,220 additions and 0 deletions.
  1. +6 −0 .nuget/NuGet.Config
  2. BIN .nuget/NuGet.exe
  3. +150 −0 .nuget/NuGet.targets
  4. +33 −0 Ext.Direct.Mvc3.sln
  5. +20 −0 LICENSE.txt
  6. +5 −0 packages/repositories.config
  7. +22 −0 src/Ext.Direct.Mvc/Attributes/DirectEventAttribute.cs
  8. +28 −0 src/Ext.Direct.Mvc/Attributes/DirectHandleErrorAttribute.cs
  9. +9 −0 src/Ext.Direct.Mvc/Attributes/DirectIgnoreAttribute.cs
  10. +9 −0 src/Ext.Direct.Mvc/Attributes/FormHandlerAttribute.cs
  11. +9 −0 src/Ext.Direct.Mvc/Attributes/NamedArgumentsAttributes.cs
  12. +59 −0 src/Ext.Direct.Mvc/DirectAction.cs
  13. +18 −0 src/Ext.Direct.Mvc/DirectApiController.cs
  14. +41 −0 src/Ext.Direct.Mvc/DirectController.cs
  15. +43 −0 src/Ext.Direct.Mvc/DirectDataResponse.cs
  16. +52 −0 src/Ext.Direct.Mvc/DirectErrorResponse.cs
  17. +26 −0 src/Ext.Direct.Mvc/DirectEventResponse.cs
  18. +13 −0 src/Ext.Direct.Mvc/DirectException.cs
  19. +78 −0 src/Ext.Direct.Mvc/DirectMethod.cs
  20. +29 −0 src/Ext.Direct.Mvc/DirectMethodInvoker.cs
  21. +214 −0 src/Ext.Direct.Mvc/DirectProvider.cs
  22. +67 −0 src/Ext.Direct.Mvc/DirectRequest.cs
  23. +79 −0 src/Ext.Direct.Mvc/DirectResponse.cs
  24. +88 −0 src/Ext.Direct.Mvc/DirectResult.cs
  25. +18 −0 src/Ext.Direct.Mvc/DirectRouterController.cs
  26. +83 −0 src/Ext.Direct.Mvc/DirectValueProvider.cs
  27. BIN src/Ext.Direct.Mvc/Ext.Direct.Mvc.snk
  28. +102 −0 src/Ext.Direct.Mvc/Ext.Direct.Mvc3.csproj
  29. +12 −0 src/Ext.Direct.Mvc/Extensions/JsonExtensions.cs
  30. +22 −0 src/Ext.Direct.Mvc/Extensions/MethodExtensions.cs
  31. +21 −0 src/Ext.Direct.Mvc/Extensions/TypeExtensions.cs
  32. +36 −0 src/Ext.Direct.Mvc/Properties/AssemblyInfo.cs
  33. +81 −0 src/Ext.Direct.Mvc/ProviderConfiguration.cs
  34. +39 −0 src/Ext.Direct.Mvc/RequestDataConverter.cs
  35. +135 −0 src/Ext.Direct.Mvc/Resources/DirectResources.Designer.cs
  36. +144 −0 src/Ext.Direct.Mvc/Resources/DirectResources.resx
  37. +4 −0 src/Ext.Direct.Mvc/packages.config
  38. +19 −0 test/Ext.Direct.Mvc3Test/Controllers/BasicController.cs
  39. +16 −0 test/Ext.Direct.Mvc3Test/Controllers/HomeController.cs
  40. +138 −0 test/Ext.Direct.Mvc3Test/Ext.Direct.Mvc3Test.csproj
  41. +1 −0 test/Ext.Direct.Mvc3Test/Global.asax
  42. +30 −0 test/Ext.Direct.Mvc3Test/Global.asax.cs
  43. +19 −0 test/Ext.Direct.Mvc3Test/Properties/AssemblyInfo.cs
  44. +31 −0 test/Ext.Direct.Mvc3Test/Views/Home/Index.cshtml
  45. +58 −0 test/Ext.Direct.Mvc3Test/Views/Web.config
  46. +30 −0 test/Ext.Direct.Mvc3Test/Web.Debug.config
  47. +31 −0 test/Ext.Direct.Mvc3Test/Web.Release.config
  48. +48 −0 test/Ext.Direct.Mvc3Test/Web.config
  49. +4 −0 test/Ext.Direct.Mvc3Test/packages.config
View
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <solution>
+ <add key="disableSourceControlIntegration" value="true" />
+ </solution>
+</configuration>
View
Binary file not shown.
View
@@ -0,0 +1,150 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
+
+ <!-- Enable the restore command to run before builds -->
+ <RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>
+
+ <!-- Property that enables building a package from a project -->
+ <BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
+
+ <!-- Determines if package restore consent is required to restore packages -->
+ <RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>
+
+ <!-- Download NuGet.exe if it does not already exist -->
+ <DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
+ </PropertyGroup>
+
+ <ItemGroup Condition=" '$(PackageSources)' == '' ">
+ <!-- Package sources used to restore packages. By default will used the registered sources under %APPDATA%\NuGet\NuGet.Config -->
+ <!--
+ <PackageSource Include="https://nuget.org/api/v2/" />
+ <PackageSource Include="https://my-nuget-source/nuget/" />
+ -->
+ </ItemGroup>
+
+ <PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
+ <!-- Windows specific commands -->
+ <NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
+ <PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
+ </PropertyGroup>
+
+ <PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
+ <!-- We need to launch nuget.exe with the mono command if we're not on windows -->
+ <NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
+ <PackagesConfig>packages.config</PackagesConfig>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <!-- NuGet command -->
+ <NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\nuget.exe</NuGetExePath>
+ <PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
+
+ <NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
+ <NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>
+
+ <PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
+
+ <RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
+ <!-- Commands -->
+ <RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(RequireConsentSwitch) -solutionDir "$(SolutionDir) "</RestoreCommand>
+ <BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand>
+
+ <!-- We need to ensure packages are restored prior to assembly resolve -->
+ <ResolveReferencesDependsOn Condition="$(RestorePackages) == 'true'">
+ RestorePackages;
+ $(ResolveReferencesDependsOn);
+ </ResolveReferencesDependsOn>
+
+ <!-- Make the build depend on restore packages -->
+ <BuildDependsOn Condition="$(BuildPackage) == 'true'">
+ $(BuildDependsOn);
+ BuildPackage;
+ </BuildDependsOn>
+ </PropertyGroup>
+
+ <Target Name="CheckPrerequisites">
+ <!-- Raise an error if we're unable to locate nuget.exe -->
+ <Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
+ <SetEnvironmentVariable EnvKey="VisualStudioVersion" EnvValue="$(VisualStudioVersion)" Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' " />
+ <!--
+ Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
+ This effectively acts as a lock that makes sure that the download operation will only happen once and all
+ parallel builds will have to wait for it to complete.
+ -->
+ <MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT" />
+ </Target>
+
+ <Target Name="_DownloadNuGet">
+ <DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
+ </Target>
+
+ <Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
+ <Exec Command="$(RestoreCommand)"
+ Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
+
+ <Exec Command="$(RestoreCommand)"
+ LogStandardErrorAsError="true"
+ Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
+ </Target>
+
+ <Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
+ <Exec Command="$(BuildCommand)"
+ Condition=" '$(OS)' != 'Windows_NT' " />
+
+ <Exec Command="$(BuildCommand)"
+ LogStandardErrorAsError="true"
+ Condition=" '$(OS)' == 'Windows_NT' " />
+ </Target>
+
+ <UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
+ <ParameterGroup>
+ <OutputFilename ParameterType="System.String" Required="true" />
+ </ParameterGroup>
+ <Task>
+ <Reference Include="System.Core" />
+ <Using Namespace="System" />
+ <Using Namespace="System.IO" />
+ <Using Namespace="System.Net" />
+ <Using Namespace="Microsoft.Build.Framework" />
+ <Using Namespace="Microsoft.Build.Utilities" />
+ <Code Type="Fragment" Language="cs">
+ <![CDATA[
+ try {
+ OutputFilename = Path.GetFullPath(OutputFilename);
+
+ Log.LogMessage("Downloading latest version of NuGet.exe...");
+ WebClient webClient = new WebClient();
+ webClient.DownloadFile("https://nuget.org/nuget.exe", OutputFilename);
+
+ return true;
+ }
+ catch (Exception ex) {
+ Log.LogErrorFromException(ex);
+ return false;
+ }
+ ]]>
+ </Code>
+ </Task>
+ </UsingTask>
+
+ <UsingTask TaskName="SetEnvironmentVariable" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
+ <ParameterGroup>
+ <EnvKey ParameterType="System.String" Required="true" />
+ <EnvValue ParameterType="System.String" Required="true" />
+ </ParameterGroup>
+ <Task>
+ <Using Namespace="System" />
+ <Code Type="Fragment" Language="cs">
+ <![CDATA[
+ try {
+ Environment.SetEnvironmentVariable(EnvKey, EnvValue, System.EnvironmentVariableTarget.Process);
+ }
+ catch {
+ }
+ ]]>
+ </Code>
+ </Task>
+ </UsingTask>
+</Project>
View
@@ -0,0 +1,33 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2012
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ext.Direct.Mvc3", "src\Ext.Direct.Mvc\Ext.Direct.Mvc3.csproj", "{A521832A-D1FB-468F-BA7C-1FAE0F7F45EA}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ext.Direct.Mvc3Test", "test\Ext.Direct.Mvc3Test\Ext.Direct.Mvc3Test.csproj", "{D689FA7E-74DC-477B-A69F-EA6FF4C7739B}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{64FA027D-43BA-4FF9-B83C-C6B39B7B73D5}"
+ ProjectSection(SolutionItems) = preProject
+ .nuget\NuGet.Config = .nuget\NuGet.Config
+ .nuget\NuGet.exe = .nuget\NuGet.exe
+ .nuget\NuGet.targets = .nuget\NuGet.targets
+ EndProjectSection
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {A521832A-D1FB-468F-BA7C-1FAE0F7F45EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A521832A-D1FB-468F-BA7C-1FAE0F7F45EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A521832A-D1FB-468F-BA7C-1FAE0F7F45EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A521832A-D1FB-468F-BA7C-1FAE0F7F45EA}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D689FA7E-74DC-477B-A69F-EA6FF4C7739B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D689FA7E-74DC-477B-A69F-EA6FF4C7739B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D689FA7E-74DC-477B-A69F-EA6FF4C7739B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D689FA7E-74DC-477B-A69F-EA6FF4C7739B}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
View
@@ -0,0 +1,20 @@
+Copyright 2012 Eugene Lishnevsky
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<repositories>
+ <repository path="..\src\Ext.Direct.Mvc\packages.config" />
+ <repository path="..\test\Ext.Direct.Mvc3Test\packages.config" />
+</repositories>
@@ -0,0 +1,22 @@
+using System;
+using Ext.Direct.Mvc.Resources;
+
+namespace Ext.Direct.Mvc {
+
+ [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
+ public sealed class DirectEventAttribute : Attribute {
+
+ public DirectEventAttribute(string name) {
+ if (String.IsNullOrEmpty(name)) {
+ throw new ArgumentException(DirectResources.Common_NullOrEmpty, "name");
+ }
+
+ Name = name;
+ }
+
+ public string Name {
+ get;
+ private set;
+ }
+ }
+}
@@ -0,0 +1,28 @@
+using System;
+using System.Web.Mvc;
+
+namespace Ext.Direct.Mvc {
+
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
+ public class DirectHandleErrorAttribute : FilterAttribute, IExceptionFilter {
+
+ public void OnException(ExceptionContext filterContext) {
+ if (filterContext == null) {
+ throw new ArgumentNullException("filterContext");
+ }
+
+ if (filterContext.ExceptionHandled) {
+ return;
+ }
+
+ var exception = filterContext.Exception;
+ var directRequest = filterContext.HttpContext.Items[DirectRequest.DirectRequestKey] as DirectRequest;
+
+ if (directRequest != null) {
+ var errorResponse = new DirectErrorResponse(directRequest, exception);
+ errorResponse.Write(filterContext.HttpContext.Response);
+ filterContext.ExceptionHandled = true;
+ }
+ }
+ }
+}
@@ -0,0 +1,9 @@
+using System;
+
+namespace Ext.Direct.Mvc {
+
+ [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
+ public sealed class DirectIgnoreAttribute : Attribute {
+
+ }
+}
@@ -0,0 +1,9 @@
+using System;
+
+namespace Ext.Direct.Mvc {
+
+ [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
+ public sealed class FormHandlerAttribute : Attribute {
+
+ }
+}
@@ -0,0 +1,9 @@
+using System;
+
+namespace Ext.Direct.Mvc {
+
+ [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
+ public sealed class NamedArgumentsAttribute : Attribute {
+
+ }
+}
@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Web.Mvc;
+using Ext.Direct.Mvc.Resources;
+using Newtonsoft.Json;
+
+namespace Ext.Direct.Mvc {
+
+ public class DirectAction {
+
+ private readonly Dictionary<string, DirectMethod> _methods;
+
+ public string Name {
+ get;
+ private set;
+ }
+
+ public DirectAction(Type type) {
+ Name = type.Name;
+ if (Name.EndsWith("Controller")) {
+ Name = Name.Substring(0, Name.IndexOf("Controller", StringComparison.InvariantCultureIgnoreCase));
+ }
+ _methods = new Dictionary<string, DirectMethod>();
+ Configure(type);
+ }
+
+ private void Configure(Type type) {
+ var methods = type.GetMethods()
+ .Where(x =>
+ x.IsPublic &&
+ (x.ReturnType == typeof(ActionResult) || x.ReturnType.IsSubclassOf(typeof(ActionResult))) &&
+ !x.HasAttribute<DirectIgnoreAttribute>()
+ );
+
+ foreach (MethodInfo method in methods) {
+ var directMethod = new DirectMethod(method);
+ if (_methods.ContainsKey(directMethod.Name)) {
+ throw new Exception(String.Format(DirectResources.DirectAction_MethodExists, directMethod.Name, Name));
+ }
+ _methods.Add(directMethod.Name, directMethod);
+ }
+ }
+
+ public DirectMethod GetMethod(string name) {
+ return _methods.ContainsKey(name) ? _methods[name] : null;
+ }
+
+ public void WriteJson(JsonWriter writer) {
+ writer.WritePropertyName(Name);
+ writer.WriteStartArray();
+ foreach (var method in _methods.Values) {
+ method.WriteJson(writer);
+ }
+ writer.WriteEndArray();
+ }
+ }
+}
@@ -0,0 +1,18 @@
+using System;
+using System.Web.Mvc;
+
+namespace Ext.Direct.Mvc {
+
+ public class DirectApiController : Controller {
+
+ private readonly DirectProvider _provider = DirectProvider.GetCurrent();
+
+ [AcceptVerbs("GET")]
+ public ActionResult Index() {
+ // for integration with the Ext Designer
+ bool json = (HttpContext.Request.QueryString["format"] == "json");
+ _provider.Name = HttpContext.Request.QueryString["name"];
+ return JavaScript(_provider.ToString(json));
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 42ddafe

Please sign in to comment.