Skip to content

Commit

Permalink
Merge pull request #39 from BenjaBobs/TreeParser
Browse files Browse the repository at this point in the history
Major overhaul and tree converting
  • Loading branch information
evo-terren authored Nov 15, 2018
2 parents d2263b2 + 489300e commit a3d16f3
Show file tree
Hide file tree
Showing 45 changed files with 776 additions and 278 deletions.
2 changes: 1 addition & 1 deletion GremlinSample/GremlinSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp2.1</TargetFramework>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>gremlinsample.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
Expand Down
5 changes: 2 additions & 3 deletions GremlinSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Threading.Tasks;
using Gremlin.Net.CosmosDb;
using GremlinSample.Schema;
using Newtonsoft.Json;
using System;
using System.Threading.Tasks;

namespace GremlinSample
{
Expand All @@ -19,7 +19,6 @@ internal static async Task Main()
{
Ages = new[] { 4, 6, 23 },
Id = "person-12345",
Label = "some-label",
Name = "my name"
};
var purchasedE = new PersonPurchasedProductEdge
Expand Down
3 changes: 2 additions & 1 deletion GremlinSample/Schema/PersonPurchasedProductEdge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace GremlinSample.Schema
{
[Label("purchased")]
public sealed class PersonPurchasedProductEdge : EdgeBase<PersonVertex, ProductVertex>
public sealed class PersonPurchasedProductEdge : ManyToManyEdge<PersonVertex, ProductVertex>
{
public string Id { get; set; }
}
}
4 changes: 3 additions & 1 deletion GremlinSample/Schema/PersonVertex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace GremlinSample.Schema
{
[Label("person")]
public class PersonVertex : VertexBase
public class PersonVertex : IVertex
{
public string Id { get; set; }

public int[] Ages { get; set; }

public string Name { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion GremlinSample/Schema/ProductVertex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace GremlinSample.Schema
{
[Label("product")]
public sealed class ProductVertex : VertexBase
public sealed class ProductVertex : IVertex
{
public string Id { get; set; }
public PersonPurchasedProductEdge People { get; }
}
}
5 changes: 4 additions & 1 deletion src/Gremlin.Net.CosmosDb/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
using System.Runtime.CompilerServices;
#if NET_CORE
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Gremlin.Net.CosmosDb.Tests")]
#endif
10 changes: 3 additions & 7 deletions src/Gremlin.Net.CosmosDb/GraphClient.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Threading.Tasks;
using Gremlin.Net.CosmosDb.Serialization;
using Gremlin.Net.CosmosDb.Structure;
using Gremlin.Net.Driver;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Gremlin.Net.CosmosDb
{
Expand Down Expand Up @@ -40,10 +39,7 @@ public GraphClient(string gremlinHostname, string databaseName, string graphName
/// <exception cref="ArgumentNullException">gremlinClient</exception>
internal GraphClient(IGremlinClient gremlinClient)
{
if (gremlinClient == null)
throw new ArgumentNullException(nameof(gremlinClient));

_gremlinClient = gremlinClient;
_gremlinClient = gremlinClient ?? throw new ArgumentNullException(nameof(gremlinClient));
}

/// <summary>
Expand Down
19 changes: 14 additions & 5 deletions src/Gremlin.Net.CosmosDb/Gremlin.Net.CosmosDb.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;netcoreapp2.0</TargetFrameworks>
<Authors>Terren Musselwhite</Authors>
<Company>evo</Company>
<PackageTags>gremlin cosmos cosmosdb gremlin.net</PackageTags>
Expand All @@ -11,15 +11,24 @@
<Version>0.3.4.0002-rc1</Version>
<PackageProjectUrl>https://github.com/evo-terren/Gremlin.Net.CosmosDb</PackageProjectUrl>
<RepositoryUrl>https://github.com/evo-terren/Gremlin.Net.CosmosDb</RepositoryUrl>
<SignAssembly>true</SignAssembly>
<DelaySign>false</DelaySign>
<AssemblyOriginatorKeyFile>gremlincosmos.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile></DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
<DefineConstants>NET_STANDARD</DefineConstants>
<SignAssembly>true</SignAssembly>
<DelaySign>false</DelaySign>
<AssemblyOriginatorKeyFile>gremlincosmos.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='netcoreapp2.0'">
<DefineConstants>NET_CORE</DefineConstants>
<SignAssembly>false</SignAssembly>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netstandard2.0\Gremlin.Net.CosmosDb.xml</DocumentationFile>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Gremlin.Net.CosmosDb/IGraphClient.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ private static JsonSerializerSettings BuildDefaultSerializerSettings()
Converters = new JsonConverter[]
{
new TreeJsonConverter(),
new EdgeBaseJsonConverter(),
new IEdgeJsonConverter(),
new ElementJsonConverter(),
new VertexBaseJsonConverter(),
new IVertexJsonConverter(),
new IsoDateTimeConverter
{
DateTimeStyles = DateTimeStyles.AdjustToUniversal
Expand Down
6 changes: 3 additions & 3 deletions src/Gremlin.Net.CosmosDb/IGraphTraversalSource.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class IGraphTraversalSourceExtensions
/// <param name="graphTraversalSource">The graph traversal source.</param>
/// <returns>Returns the resulting traversal</returns>
public static ISchemaBoundTraversal<object, TVertex> AddV<TVertex>(this IGraphTraversalSource graphTraversalSource)
where TVertex : VertexBase
where TVertex : IVertex
{
var label = LabelNameResolver.GetLabelName(typeof(TVertex));

Expand All @@ -31,7 +31,7 @@ public static ISchemaBoundTraversal<object, TVertex> AddV<TVertex>(this IGraphTr
/// <param name="vertex">The vertex to add.</param>
/// <returns>Returns the resulting traversal</returns>
public static ISchemaBoundTraversal<object, TVertex> AddV<TVertex>(this IGraphTraversalSource graphTraversalSource, TVertex vertex)
where TVertex : VertexBase
where TVertex : IVertex
{
return AddV(graphTraversalSource, vertex, new JsonSerializerSettings { ContractResolver = new ElementContractResolver() });
}
Expand All @@ -45,7 +45,7 @@ public static ISchemaBoundTraversal<object, TVertex> AddV<TVertex>(this IGraphTr
/// <param name="serializationSettings">The serialization settings.</param>
/// <returns>Returns the resulting traversal</returns>
public static ISchemaBoundTraversal<object, TVertex> AddV<TVertex>(this IGraphTraversalSource graphTraversalSource, TVertex vertex, JsonSerializerSettings serializationSettings)
where TVertex : VertexBase
where TVertex : IVertex
{
var label = LabelNameResolver.GetLabelName(typeof(TVertex));
var traversal = graphTraversalSource.AddV(label);
Expand Down
63 changes: 30 additions & 33 deletions src/Gremlin.Net.CosmosDb/ISchemaBoundTraversal.Schema.Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Gremlin.Net.CosmosDb.Structure;
using Gremlin.Net.Process.Traversal;
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Gremlin.Net.CosmosDb.Structure;
using Gremlin.Net.Process.Traversal;

namespace Gremlin.Net.CosmosDb
{
Expand All @@ -14,9 +14,6 @@ namespace Gremlin.Net.CosmosDb
/// </summary>
public static partial class ISchemaBoundTraversalExtensions
{
private static readonly Type TYPE_OF_ENUMERABLE = typeof(IEnumerable);
private static readonly Type TYPE_OF_STRING = typeof(string);

/// <summary>
/// Adds the "has()" step to the traversal, removing traversers that do not have a value
/// defined for the given property
Expand Down Expand Up @@ -115,9 +112,9 @@ public static ISchemaBoundTraversal<S, TElement> HasNot<S, TElement, TProperty>(
/// <param name="traversal">The traversal.</param>
/// <param name="edgeSelector">The edge selector.</param>
/// <returns>Returns the resulting traversal</returns>
public static ISchemaBoundTraversal<S, ToutVertex> In<S, TVertex, ToutVertex>(this ISchemaBoundTraversal<S, TVertex> traversal, Expression<Func<TVertex, EdgeBase<ToutVertex, TVertex>>> edgeSelector)
where TVertex : VertexBase
where ToutVertex : VertexBase
public static ISchemaBoundTraversal<S, ToutVertex> In<S, TVertex, ToutVertex>(this ISchemaBoundTraversal<S, TVertex> traversal, Expression<Func<TVertex, IEdge<ToutVertex, TVertex>>> edgeSelector)
where TVertex : IVertex
where ToutVertex : IVertex
{
var labelName = GetLabelName(typeof(TVertex), edgeSelector);

Expand All @@ -133,8 +130,8 @@ public static ISchemaBoundTraversal<S, ToutVertex> In<S, TVertex, ToutVertex>(th
/// <param name="traversal">The traversal.</param>
/// <param name="edgeSelectors">The edge selectors.</param>
/// <returns>Returns the resulting traversal</returns>
public static GraphTraversal<S, Gremlin.Net.Structure.Vertex> In<S, TVertex>(this ISchemaBoundTraversal<S, TVertex> traversal, params Expression<Func<TVertex, IHasInVertex<TVertex>>>[] edgeSelectors)
where TVertex : VertexBase
public static GraphTraversal<S, Gremlin.Net.Structure.Vertex> In<S, TVertex>(this ISchemaBoundTraversal<S, TVertex> traversal, params Expression<Func<TVertex, IHasInV<TVertex>>>[] edgeSelectors)
where TVertex : IVertex
{
if (edgeSelectors == null)
throw new ArgumentNullException(nameof(edgeSelectors));
Expand All @@ -156,10 +153,10 @@ public static ISchemaBoundTraversal<S, ToutVertex> In<S, TVertex, ToutVertex>(th
/// <param name="edgeSelector">The edge selector.</param>
/// <returns>Returns the resulting traversal</returns>
public static ISchemaBoundTraversal<S, TEdge> InE<S, TVertex, TEdge>(this ISchemaBoundTraversal<S, TVertex> traversal, Expression<Func<TVertex, TEdge>> edgeSelector)
where TVertex : VertexBase
where TEdge : IHasInVertex<TVertex>
where TVertex : IVertex
where TEdge : IHasInV<TVertex>
{
var labelName = LabelNameResolver.GetLabelName(typeof(TEdge));
var labelName = GetLabelName(typeof(TVertex), edgeSelector);

return traversal.AsGraphTraversal().InE(labelName).AsSchemaBound<S, TEdge>();
}
Expand All @@ -173,8 +170,8 @@ public static ISchemaBoundTraversal<S, TEdge> InE<S, TVertex, TEdge>(this ISchem
/// <param name="traversal">The traversal.</param>
/// <param name="edgeSelectors">The edge selectors.</param>
/// <returns>Returns the resulting traversal</returns>
public static GraphTraversal<S, Gremlin.Net.Structure.Edge> InE<S, TVertex>(this ISchemaBoundTraversal<S, TVertex> traversal, params Expression<Func<TVertex, IHasInVertex<TVertex>>>[] edgeSelectors)
where TVertex : VertexBase
public static GraphTraversal<S, Gremlin.Net.Structure.Edge> InE<S, TVertex>(this ISchemaBoundTraversal<S, TVertex> traversal, params Expression<Func<TVertex, IHasInV<TVertex>>>[] edgeSelectors)
where TVertex : IVertex
{
if (edgeSelectors == null)
throw new ArgumentNullException(nameof(edgeSelectors));
Expand All @@ -192,8 +189,8 @@ public static ISchemaBoundTraversal<S, TEdge> InE<S, TVertex, TEdge>(this ISchem
/// <typeparam name="TinVertex">The type of the vertex.</typeparam>
/// <param name="traversal">The traversal.</param>
/// <returns>Returns the resulting traversal</returns>
public static ISchemaBoundTraversal<S, TinVertex> InV<S, TinVertex>(this ISchemaBoundTraversal<S, IHasInVertex<TinVertex>> traversal)
where TinVertex : VertexBase
public static ISchemaBoundTraversal<S, TinVertex> InV<S, TinVertex>(this ISchemaBoundTraversal<S, IHasInV<TinVertex>> traversal)
where TinVertex : IVertex
{
return traversal.AsGraphTraversal().InV().AsSchemaBound<S, TinVertex>();
}
Expand All @@ -208,9 +205,9 @@ public static ISchemaBoundTraversal<S, TinVertex> InV<S, TinVertex>(this ISchema
/// <param name="traversal">The traversal.</param>
/// <param name="edgeSelector">The edge selector.</param>
/// <returns>Returns the resulting traversal</returns>
public static ISchemaBoundTraversal<S, TinVertex> Out<S, TVertex, TinVertex>(this ISchemaBoundTraversal<S, TVertex> traversal, Expression<Func<TVertex, EdgeBase<TVertex, TinVertex>>> edgeSelector)
where TVertex : VertexBase
where TinVertex : VertexBase
public static ISchemaBoundTraversal<S, TinVertex> Out<S, TVertex, TinVertex>(this ISchemaBoundTraversal<S, TVertex> traversal, Expression<Func<TVertex, IEdge<TVertex, TinVertex>>> edgeSelector)
where TVertex : IVertex
where TinVertex : IVertex
{
var labelName = GetLabelName(typeof(TVertex), edgeSelector);

Expand All @@ -226,8 +223,8 @@ public static ISchemaBoundTraversal<S, TinVertex> Out<S, TVertex, TinVertex>(thi
/// <param name="traversal">The traversal.</param>
/// <param name="edgeSelectors">The edge selectors.</param>
/// <returns>Returns the resulting traversal</returns>
public static GraphTraversal<S, Gremlin.Net.Structure.Vertex> Out<S, TVertex>(this ISchemaBoundTraversal<S, TVertex> traversal, params Expression<Func<TVertex, IHasOutVertex<TVertex>>>[] edgeSelectors)
where TVertex : VertexBase
public static GraphTraversal<S, Gremlin.Net.Structure.Vertex> Out<S, TVertex>(this ISchemaBoundTraversal<S, TVertex> traversal, params Expression<Func<TVertex, IHasOutV<TVertex>>>[] edgeSelectors)
where TVertex : IVertex
{
if (edgeSelectors == null)
throw new ArgumentNullException(nameof(edgeSelectors));
Expand All @@ -248,10 +245,10 @@ public static ISchemaBoundTraversal<S, TinVertex> Out<S, TVertex, TinVertex>(thi
/// <param name="edgeSelector">The edge selector.</param>
/// <returns>Returns the resulting traversal</returns>
public static ISchemaBoundTraversal<S, TEdge> OutE<S, TVertex, TEdge>(this ISchemaBoundTraversal<S, TVertex> traversal, Expression<Func<TVertex, TEdge>> edgeSelector)
where TVertex : VertexBase
where TEdge : IHasOutVertex<TVertex>
where TVertex : IVertex
where TEdge : IHasOutV<TVertex>
{
var labelName = LabelNameResolver.GetLabelName(typeof(TEdge));
var labelName = GetLabelName(typeof(TEdge), edgeSelector);

return traversal.AsGraphTraversal().OutE(labelName).AsSchemaBound<S, TEdge>();
}
Expand All @@ -264,8 +261,8 @@ public static ISchemaBoundTraversal<S, TEdge> OutE<S, TVertex, TEdge>(this ISche
/// <param name="traversal">The traversal.</param>
/// <param name="edgeSelectors">The edge selectors.</param>
/// <returns>Returns the resulting traversal</returns>
public static GraphTraversal<S, Gremlin.Net.Structure.Edge> OutE<S, TVertex>(this ISchemaBoundTraversal<S, TVertex> traversal, params Expression<Func<TVertex, IHasOutVertex<TVertex>>>[] edgeSelectors)
where TVertex : VertexBase
public static GraphTraversal<S, Gremlin.Net.Structure.Edge> OutE<S, TVertex>(this ISchemaBoundTraversal<S, TVertex> traversal, params Expression<Func<TVertex, IHasOutV<TVertex>>>[] edgeSelectors)
where TVertex : IVertex
{
if (edgeSelectors == null)
throw new ArgumentNullException(nameof(edgeSelectors));
Expand All @@ -283,8 +280,8 @@ public static ISchemaBoundTraversal<S, TEdge> OutE<S, TVertex, TEdge>(this ISche
/// <typeparam name="ToutVertex">The type of the vertex.</typeparam>
/// <param name="traversal">The traversal.</param>
/// <returns>Returns the resulting traversal</returns>
public static ISchemaBoundTraversal<S, ToutVertex> OutV<S, ToutVertex>(this ISchemaBoundTraversal<S, IHasOutVertex<ToutVertex>> traversal)
where ToutVertex : VertexBase
public static ISchemaBoundTraversal<S, ToutVertex> OutV<S, ToutVertex>(this ISchemaBoundTraversal<S, IHasOutV<ToutVertex>> traversal)
where ToutVertex : IVertex
{
return traversal.AsGraphTraversal().OutV().AsSchemaBound<S, ToutVertex>();
}
Expand Down Expand Up @@ -312,7 +309,7 @@ public static ISchemaBoundTraversal<S, TElement> Property<S, TElement, TProperty
}
//if the property is an enumerable, use sideEffect() to drop existing values before adding the new ones
//also, strings need to be special cased since most people don't think of strings as an enumerable of chars
else if (TYPE_OF_ENUMERABLE.IsAssignableFrom(propType) && propType != TYPE_OF_STRING)
else if (!TypeHelper.IsScalar(propType))
{
var enumerator = ((IEnumerable)value).GetEnumerator();
graphTraversal = graphTraversal.SideEffect(__.Properties<TElement>(propName).Drop());
Expand Down Expand Up @@ -352,7 +349,7 @@ public static ISchemaBoundTraversal<S, TElement> Property<S, TElement, TValue>(t
}
//special case for strings - most people don't think of strings as an array of chars
//so, don't treat them as enumerable properties
else if (value.GetType() == TYPE_OF_STRING)
else if (value.GetType() == TypeCache.String)
{
graphTraversal = graphTraversal.Property(propName, value);
}
Expand Down Expand Up @@ -399,7 +396,7 @@ private static string GetLabelName(Type sourceType, LambdaExpression lambda)
if (sourceType != propInfo.ReflectedType && !sourceType.IsSubclassOf(propInfo.ReflectedType))
throw new ArgumentException($"Expression '{lambda}' refers to a property that is not from type {sourceType}.");

return LabelNameResolver.GetLabelName(propInfo.PropertyType);
return LabelNameResolver.GetLabelName(propInfo);
}

/// <summary>
Expand Down
Loading

0 comments on commit a3d16f3

Please sign in to comment.