Skip to content

Commit

Permalink
Merge pull request #103 from tugberkugurlu/net45
Browse files Browse the repository at this point in the history
Upgraded to .NET 4.5
  • Loading branch information
cskardon committed Aug 3, 2015
2 parents 3eb9daa + 8ba4615 commit d5f0e24
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 107 deletions.
126 changes: 51 additions & 75 deletions Neo4jClient/GraphClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ HttpResponseMessage SendHttpRequest(HttpRequestMessage request, string commandDe
return task.Result;
}

Task<HttpResponseMessage> SendHttpRequestAsync(HttpRequestMessage request, string commandDescription, params HttpStatusCode[] expectedStatusCodes)
async Task<HttpResponseMessage> SendHttpRequestAsync(HttpRequestMessage request, string commandDescription, params HttpStatusCode[] expectedStatusCodes)
{
if (UseJsonStreamingIfAvailable && jsonStreamingAvailable)
{
Expand All @@ -167,14 +167,10 @@ Task<HttpResponseMessage> SendHttpRequestAsync(HttpRequestMessage request, strin
request.Headers.Authorization = new AuthenticationHeaderValue("Basic", credentials);
}

var baseTask = httpClient.SendAsync(request);
var continuationTask = baseTask.ContinueWith(requestTask =>
{
var response = requestTask.Result;
response.EnsureExpectedStatusCode(commandDescription, expectedStatusCodes);
return response;
});
return continuationTask;
var response = await httpClient.SendAsync(request).ConfigureAwait(false);
response.EnsureExpectedStatusCode(commandDescription, expectedStatusCodes);

return response;
}

T SendHttpRequestAndParseResultAs<T>(HttpRequestMessage request, params HttpStatusCode[] expectedStatusCodes) where T : new()
Expand Down Expand Up @@ -459,25 +455,20 @@ public virtual Node<TNode> Get<TNode>(NodeReference reference)
return task.Result;
}

public virtual Task<Node<TNode>> GetAsync<TNode>(NodeReference reference)
public virtual async Task<Node<TNode>> GetAsync<TNode>(NodeReference reference)
{
CheckRoot();

var nodeEndpoint = ResolveEndpoint(reference);
return
SendHttpRequestAsync(HttpGet(nodeEndpoint), HttpStatusCode.OK, HttpStatusCode.NotFound)
.ContinueWith(responseTask =>
{
var response = responseTask.Result;
var response = await SendHttpRequestAsync(HttpGet(nodeEndpoint), HttpStatusCode.OK, HttpStatusCode.NotFound).ConfigureAwait(false);

if (response.StatusCode == HttpStatusCode.NotFound)
return (Node<TNode>)null;
if (response.StatusCode == HttpStatusCode.NotFound)
return (Node<TNode>)null;

return response
.Content
.ReadAsJson<NodeApiResponse<TNode>>(JsonConverters,JsonContractResolver)
.ToNode(this);
});
return response
.Content
.ReadAsJson<NodeApiResponse<TNode>>(JsonConverters, JsonContractResolver)
.ToNode(this);
}

public virtual Node<TNode> Get<TNode>(NodeReference<TNode> reference)
Expand All @@ -497,25 +488,20 @@ public virtual Node<TNode> Get<TNode>(NodeReference<TNode> reference)
return task.Result;
}

public virtual Task<RelationshipInstance<TData>> GetAsync<TData>(RelationshipReference reference) where TData : class, new()
public virtual async Task<RelationshipInstance<TData>> GetAsync<TData>(RelationshipReference reference) where TData : class, new()
{
CheckRoot();

var endpoint = ResolveEndpoint(reference);
return
SendHttpRequestAsync(HttpGet(endpoint), HttpStatusCode.OK, HttpStatusCode.NotFound)
.ContinueWith(responseTask =>
{
var response = responseTask.Result;
var response = await SendHttpRequestAsync(HttpGet(endpoint), HttpStatusCode.OK, HttpStatusCode.NotFound).ConfigureAwait(false);

if (response.StatusCode == HttpStatusCode.NotFound)
return (RelationshipInstance<TData>)null;
if (response.StatusCode == HttpStatusCode.NotFound)
return (RelationshipInstance<TData>)null;

return response
.Content
.ReadAsJson<RelationshipApiResponse<TData>>(JsonConverters,JsonContractResolver)
.ToRelationshipInstance(this);
});
return response
.Content
.ReadAsJson<RelationshipApiResponse<TData>>(JsonConverters, JsonContractResolver)
.ToRelationshipInstance(this);
}

public void Update<TNode>(NodeReference<TNode> nodeReference, TNode replacementData, IEnumerable<IndexEntry> indexEntries = null)
Expand Down Expand Up @@ -806,36 +792,32 @@ IEnumerable<TResult> IRawGraphClient.ExecuteGetCypherResults<TResult>(CypherQuer
return task.Result;
}

Task<IEnumerable<TResult>> IRawGraphClient.ExecuteGetCypherResultsAsync<TResult>(CypherQuery query)
async Task<IEnumerable<TResult>> IRawGraphClient.ExecuteGetCypherResultsAsync<TResult>(CypherQuery query)
{
CheckRoot();

var stopwatch = new Stopwatch();
stopwatch.Start();

return
SendHttpRequestAsync(
HttpPostAsJson(RootApiResponse.Cypher, new CypherApiQuery(query)),
string.Format("The query was: {0}", query.QueryText),
HttpStatusCode.OK)
.ContinueWith(responseTask =>
{
var response = responseTask.Result;
var deserializer = new CypherJsonDeserializer<TResult>(this, query.ResultMode);
var results = deserializer
.Deserialize(response.Content.ReadAsString())
.ToList();

stopwatch.Stop();
OnOperationCompleted(new OperationCompletedEventArgs
{
QueryText = query.DebugQueryText,
ResourcesReturned = results.Count(),
TimeTaken = stopwatch.Elapsed
});
var response = await SendHttpRequestAsync(
HttpPostAsJson(RootApiResponse.Cypher, new CypherApiQuery(query)),
string.Format("The query was: {0}", query.QueryText),
HttpStatusCode.OK).ConfigureAwait(false);

return (IEnumerable<TResult>)results;
});
var deserializer = new CypherJsonDeserializer<TResult>(this, query.ResultMode);
var results = deserializer
.Deserialize(response.Content.ReadAsString())
.ToList();

stopwatch.Stop();
OnOperationCompleted(new OperationCompletedEventArgs
{
QueryText = query.DebugQueryText,
ResourcesReturned = results.Count(),
TimeTaken = stopwatch.Elapsed
});

return (IEnumerable<TResult>)results;
}

void IRawGraphClient.ExecuteCypher(CypherQuery query)
Expand All @@ -859,31 +841,25 @@ void IRawGraphClient.ExecuteCypher(CypherQuery query)
});
}

Task IRawGraphClient.ExecuteCypherAsync(CypherQuery query)
async Task IRawGraphClient.ExecuteCypherAsync(CypherQuery query)
{
CheckRoot();

var stopwatch = new Stopwatch();
stopwatch.Start();

return SendHttpRequestAsync(
await SendHttpRequestAsync(
HttpPostAsJson(RootApiResponse.Cypher, new CypherApiQuery(query)),
string.Format("The query was: {0}", query.QueryText),
HttpStatusCode.OK)
.ContinueWith(t =>
{
// Rethrow any exception (instead of using TaskContinuationOptions.OnlyOnRanToCompletion, which for failures, returns a canceled task instead of a faulted task)
var _ = t.Result;

stopwatch.Stop();
OnOperationCompleted(new OperationCompletedEventArgs
{
QueryText = query.DebugQueryText,
ResourcesReturned = 0,
TimeTaken = stopwatch.Elapsed
});
})
;
HttpStatusCode.OK).ConfigureAwait(false);

stopwatch.Stop();
OnOperationCompleted(new OperationCompletedEventArgs
{
QueryText = query.DebugQueryText,
ResourcesReturned = 0,
TimeTaken = stopwatch.Elapsed
});
}

[Obsolete("Gremlin support gets dropped with Neo4j 2.0. Please move to equivalent (but much more powerful and readable!) Cypher.")]
Expand Down
21 changes: 9 additions & 12 deletions Neo4jClient/Neo4jClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Neo4jClient</RootNamespace>
<AssemblyName>Neo4jClient</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -25,6 +26,7 @@
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\Neo4jClient.xml</DocumentationFile>
<NoWarn>1591</NoWarn>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -35,21 +37,18 @@
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\Neo4jClient.xml</DocumentationFile>
<NoWarn>1591</NoWarn>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.6.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.WebRequest, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.WebRequest.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down Expand Up @@ -209,9 +208,7 @@
<None Include="Neo4jClient.nuspec">
<SubType>Designer</SubType>
</None>
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
6 changes: 3 additions & 3 deletions Neo4jClient/Neo4jClient.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</dependencies>
</metadata>
<files>
<file src="bin\Release\Neo4jClient.dll" target="lib\net40" />
<file src="bin\Release\Neo4jClient.pdb" target="lib\net40" />
<file src="bin\Release\Neo4jClient.xml" target="lib\net40" />
<file src="bin\Release\Neo4jClient.dll" target="lib\net45" />
<file src="bin\Release\Neo4jClient.pdb" target="lib\net45" />
<file src="bin\Release\Neo4jClient.xml" target="lib\net45" />
</files>
</package>
4 changes: 2 additions & 2 deletions Neo4jClient/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net40" />
<package id="Newtonsoft.Json" version="6.0.3" targetFramework="net40" />
<package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.3" targetFramework="net45" />
</packages>
21 changes: 10 additions & 11 deletions Test/Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Neo4jClient.Test</RootNamespace>
<AssemblyName>Neo4jClient.Test</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -24,6 +25,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>true</UseVSHostingProcess>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -32,30 +34,27 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.6.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NSubstitute, Version=1.6.0.0, Culture=neutral, PublicKeyToken=92dd2e9066daa5ca, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NSubstitute.1.6.0.0\lib\NET40\NSubstitute.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=2.6.2.12296, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.WebRequest, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.WebRequest.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down
8 changes: 4 additions & 4 deletions Test/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net40" />
<package id="Newtonsoft.Json" version="6.0.3" targetFramework="net40" />
<package id="NSubstitute" version="1.6.0.0" targetFramework="net40" />
<package id="NUnit" version="2.6.2" targetFramework="net40" />
<package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.3" targetFramework="net45" />
<package id="NSubstitute" version="1.6.0.0" targetFramework="net45" />
<package id="NUnit" version="2.6.2" targetFramework="net45" />
</packages>

0 comments on commit d5f0e24

Please sign in to comment.