Skip to content
Open
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
4 changes: 2 additions & 2 deletions Ext.Direct.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ext.Direct", "Ext.Direct\Ext.Direct.csproj", "{653B211D-FEFA-483B-A284-6431C8598ED4}"
EndProject
Global
Expand Down
4 changes: 2 additions & 2 deletions Ext.Direct/ComplexObjectConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override bool CanConvert(Type objectType)
return false;
}

public override object ReadJson(JsonReader reader, Type objectType)
public override object ReadJson(JsonReader reader, Type objectType, object existingValue=null, JsonSerializer serializer=null)
{
if (reader.TokenType == JsonToken.StartArray)
return ReadArray(reader);
Expand Down Expand Up @@ -87,7 +87,7 @@ private object ReadObject(JsonReader reader)
return null;
}

public override void WriteJson(JsonWriter writer, object value)
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer=null)
{
throw new NotImplementedException();
}
Expand Down
69 changes: 61 additions & 8 deletions Ext.Direct/DirectProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Linq;
using System.Text.RegularExpressions;

namespace Ext.Direct
{
Expand Down Expand Up @@ -42,16 +43,29 @@ internal static DirectExecutionResponse Execute(DirectProvider provider, HttpReq
{
UTF8Encoding encoding = new UTF8Encoding();
string json = encoding.GetString(httpRequest.BinaryRead(httpRequest.TotalBytes));
List<DirectRequest> requests = JsonConvert.DeserializeObject<List<DirectRequest>>(json);
if (requests.Count > 0)
/**************************************************************************************
skygreen:解决bug:Self referencing loop
参考:http://stackoverflow.com/questions/7397207/json-net-error-self-referencing-loop-detected-for-type
**************************************************************************************/
if (substr_count(json,"data")>1)
{
JArray raw = JArray.Parse(json);
int i = 0;
foreach (DirectRequest request in requests)
List<DirectRequest> requests = JsonConvert.DeserializeObject<List<DirectRequest>>(json);
if (requests.Count > 0)
{
request.RequestData = (JObject) raw[i];
JArray raw = JArray.Parse(json);
int i = 0;
foreach (DirectRequest request in requests)
{
request.RequestData = (JObject)raw[i];
responses.Add(DirectProcessor.ProcessRequest(provider, request));
++i;
}
}
else
{
DirectRequest request = JsonConvert.DeserializeObject<DirectRequest>(json);
request.RequestData = JObject.Parse(json);
responses.Add(DirectProcessor.ProcessRequest(provider, request));
++i;
}
}
else
Expand All @@ -62,7 +76,11 @@ internal static DirectExecutionResponse Execute(DirectProvider provider, HttpReq
}
}
DirectExecutionResponse response = new DirectExecutionResponse();
JsonSerializerSettings outputSettings = new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Ignore };

JsonSerializerSettings outputSettings = new JsonSerializerSettings() {
DefaultValueHandling = DefaultValueHandling.Ignore,
ReferenceLoopHandling =ReferenceLoopHandling.Ignore
};
foreach (JsonConverter converter in converters)
{
outputSettings.Converters.Add(converter);
Expand All @@ -80,6 +98,41 @@ internal static DirectExecutionResponse Execute(DirectProvider provider, HttpReq
return response;
}

/// <summary>
/// 计算字符串出现的次数
/// </summary>
/// <param name="haystack">必需。规定要检查的字符串。</param>
/// <param name="needle">要搜索的字符串</param>
/// <param name="type">查找方式,默认0:正则表达式方式,这种方式如果子字符串有特殊符号不推荐用;其他:标准的查找子字符串的方式</param>
/// <returns></returns>
public static int substr_count(string haystack, string needle,int type=0)
{

int count = 0;
if (type == 0)
{
if (haystack != String.Empty && needle != String.Empty)
{
MatchCollection mc = Regex.Matches(haystack, needle);
count = mc.Count;
}
}
else
{
for (int i = 0; i < haystack.Length; i++)
{
for (int j = 1; j <= (haystack.Length - i); j++)
{
if (haystack.Substring(i, j) == needle)
{
count++;
}
}
}
}
return count;
}

private static DirectResponse ProcessRequest(DirectProvider provider, DirectRequest request)
{
DirectResponse r = new DirectResponse(request);
Expand Down
41 changes: 38 additions & 3 deletions Ext.Direct/Ext.Direct.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -10,8 +10,29 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Ext.Direct</RootNamespace>
<AssemblyName>Ext.Direct</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -21,6 +42,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -29,11 +51,12 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\newton\Bin\Newtonsoft.Json.dll</HintPath>
<HintPath>..\..\Betterlife.Net\Library\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
Expand Down Expand Up @@ -72,6 +95,18 @@
<Compile Include="Attributes\ParseAsJsonAttribute.cs" />
<Compile Include="ResultConverter.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
4 changes: 2 additions & 2 deletions Ext.Direct/ResultConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public override bool CanConvert(Type objectType)
return objectType.IsSubclassOf(typeof(JContainer));
}

public override object ReadJson(JsonReader reader, Type objectType)
public override object ReadJson(JsonReader reader, Type objectType, object existingValue = null, JsonSerializer serializer = null)
{
//no custom reading here
throw new NotImplementedException();
}

public override void WriteJson(JsonWriter writer, object value)
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer = null)
{
JContainer o = value as JContainer;
if (o != null)
Expand Down
Binary file modified Ext.Direct/bin/Debug/Ext.Direct.dll
Binary file not shown.
Binary file modified Ext.Direct/bin/Debug/Ext.Direct.pdb
Binary file not shown.
Binary file modified Ext.Direct/bin/Debug/Newtonsoft.Json.dll
Binary file not shown.
Binary file modified Ext.Direct/bin/Release/Ext.Direct.dll
Binary file not shown.
Binary file modified Ext.Direct/bin/Release/Ext.Direct.pdb
Binary file not shown.
Binary file modified Ext.Direct/bin/Release/Newtonsoft.Json.dll
Binary file not shown.
6 changes: 6 additions & 0 deletions Ext.Direct/obj/Debug/Ext.Direct.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ D:\Real\Ext.Direct\Ext.Direct\bin\Debug\Newtonsoft.Json.dll
D:\Real\Ext.Direct\Ext.Direct\obj\Debug\ResolveAssemblyReference.cache
D:\Real\Ext.Direct\Ext.Direct\obj\Debug\Ext.Direct.dll
D:\Real\Ext.Direct\Ext.Direct\obj\Debug\Ext.Direct.pdb
C:\Net\Ext.Direct\Ext.Direct\bin\Debug\Ext.Direct.dll
C:\Net\Ext.Direct\Ext.Direct\bin\Debug\Ext.Direct.pdb
C:\Net\Ext.Direct\Ext.Direct\bin\Debug\Newtonsoft.Json.dll
C:\Net\Ext.Direct\Ext.Direct\obj\Debug\Ext.Direct.csprojResolveAssemblyReference.cache
C:\Net\Ext.Direct\Ext.Direct\obj\Debug\Ext.Direct.dll
C:\Net\Ext.Direct\Ext.Direct\obj\Debug\Ext.Direct.pdb
Binary file modified Ext.Direct/obj/Debug/Ext.Direct.dll
Binary file not shown.
Binary file modified Ext.Direct/obj/Debug/Ext.Direct.pdb
Binary file not shown.
12 changes: 12 additions & 0 deletions Ext.Direct/obj/Release/Ext.Direct.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,15 @@ D:\Real\Ext.Direct\Ext.Direct\bin\Release\Newtonsoft.Json.dll
D:\Real\Ext.Direct\Ext.Direct\obj\Release\ResolveAssemblyReference.cache
D:\Real\Ext.Direct\Ext.Direct\obj\Release\Ext.Direct.dll
D:\Real\Ext.Direct\Ext.Direct\obj\Release\Ext.Direct.pdb
E:\Net\Ext.Direct\Ext.Direct\obj\Release\Ext.Direct.dll
E:\Net\Ext.Direct\Ext.Direct\obj\Release\Ext.Direct.pdb
E:\Net\Ext.Direct\Ext.Direct\bin\Release\Ext.Direct.dll
E:\Net\Ext.Direct\Ext.Direct\bin\Release\Ext.Direct.pdb
E:\Net\Ext.Direct\Ext.Direct\bin\Release\Newtonsoft.Json.dll
E:\Net\Ext.Direct\Ext.Direct\obj\Release\Ext.Direct.csprojResolveAssemblyReference.cache
C:\Net\Ext.Direct\Ext.Direct\bin\Release\Ext.Direct.dll
C:\Net\Ext.Direct\Ext.Direct\bin\Release\Ext.Direct.pdb
C:\Net\Ext.Direct\Ext.Direct\bin\Release\Newtonsoft.Json.dll
C:\Net\Ext.Direct\Ext.Direct\obj\Release\Ext.Direct.csprojResolveAssemblyReference.cache
C:\Net\Ext.Direct\Ext.Direct\obj\Release\Ext.Direct.dll
C:\Net\Ext.Direct\Ext.Direct\obj\Release\Ext.Direct.pdb
Binary file modified Ext.Direct/obj/Release/Ext.Direct.dll
Binary file not shown.
Binary file modified Ext.Direct/obj/Release/Ext.Direct.pdb
Binary file not shown.