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
16 changes: 10 additions & 6 deletions gremlin-dotnet/Examples/BasicGremlin/BasicGremlin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,32 @@ under the License.

public class BasicGremlinExample
{
static readonly string ServerHost = Environment.GetEnvironmentVariable("GREMLIN_SERVER_HOST") ?? "localhost";
static readonly int ServerPort = int.Parse(Environment.GetEnvironmentVariable("GREMLIN_SERVER_PORT") ?? "8182");
static readonly string VertexLabel = Environment.GetEnvironmentVariable("VERTEX_LABEL") ?? "person";

static async Task Main()
{
var server = new GremlinServer("localhost", 8182);
var server = new GremlinServer(ServerHost, ServerPort);
using var remoteConnection = new DriverRemoteConnection(new GremlinClient(server), "g");
var g = Traversal().WithRemote(remoteConnection);

// Basic Gremlin: adding and retrieving data
var v1 = g.AddV("person").Property("name", "marko").Next();
var v2 = g.AddV("person").Property("name", "stephen").Next();
var v3 = g.AddV("person").Property("name", "vadas").Next();
var v1 = g.AddV(VertexLabel).Property("name", "marko").Next();
var v2 = g.AddV(VertexLabel).Property("name", "stephen").Next();
var v3 = g.AddV(VertexLabel).Property("name", "vadas").Next();

// Be sure to use a terminating step like Next() or Iterate() so that the traversal "executes"
// Iterate() does not return any data and is used to just generate side-effects (i.e. write data to the database)
g.V(v1).AddE("knows").To(v2).Property("weight", 0.75).Iterate();
g.V(v1).AddE("knows").To(v3).Property("weight", 0.75).Iterate();

// Retrieve the data from the "marko" vertex
var marko = await g.V().Has("person", "name", "marko").Values<string>("name").Promise(t => t.Next());
var marko = await g.V().Has(VertexLabel, "name", "marko").Values<string>("name").Promise(t => t.Next());
Console.WriteLine("name: " + marko);

// Find the "marko" vertex and then traverse to the people he "knows" and return their data
var peopleMarkoKnows = await g.V().Has("person", "name", "marko").Out("knows").Values<string>("name").Promise(t => t.ToList());
var peopleMarkoKnows = await g.V().Has(VertexLabel, "name", "marko").Out("knows").Values<string>("name").Promise(t => t.ToList());
foreach (var person in peopleMarkoKnows)
{
Console.WriteLine("marko knows " + person);
Expand Down
25 changes: 13 additions & 12 deletions gremlin-dotnet/Examples/Connections/Connections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ under the License.

public class ConnectionExample
{
static readonly string ServerHost = Environment.GetEnvironmentVariable("GREMLIN_SERVER_HOST") ?? "localhost";
static readonly int ServerPort = int.Parse(Environment.GetEnvironmentVariable("GREMLIN_SERVER_PORT") ?? "8182");
static readonly string VertexLabel = Environment.GetEnvironmentVariable("VERTEX_LABEL") ?? "connection";

static void Main()
{
WithRemote();
Expand All @@ -34,41 +38,38 @@ static void Main()
// Connecting to the server
static void WithRemote()
{
var server = new GremlinServer("localhost", 8182);
var server = new GremlinServer(ServerHost, ServerPort);
using var remoteConnection = new DriverRemoteConnection(new GremlinClient(server), "g");
var g = Traversal().WithRemote(remoteConnection);

// Drop existing vertices
g.V().Drop().Iterate();

// Simple query to verify connection
var v = g.AddV().Iterate();
var count = g.V().Count().Next();
var v = g.AddV(VertexLabel).Iterate();
var count = g.V().HasLabel(VertexLabel).Count().Next();
Console.WriteLine("Vertex count: " + count);
}

// Connecting to the server with customized configurations
static void WithConf()
{
using var remoteConnection = new DriverRemoteConnection(new GremlinClient(
new GremlinServer(hostname: "localhost", port: 8182, enableSsl: false, username: "", password: "")), "g");
new GremlinServer(hostname: ServerHost, port: ServerPort, enableSsl: false, username: "", password: "")), "g");
var g = Traversal().WithRemote(remoteConnection);

var v = g.AddV().Iterate();
var count = g.V().Count().Next();
var v = g.AddV(VertexLabel).Iterate();
var count = g.V().HasLabel(VertexLabel).Count().Next();
Console.WriteLine("Vertex count: " + count);
}

// Specifying a serializer
static void WithSerializer()
{
var server = new GremlinServer("localhost", 8182);
var server = new GremlinServer(ServerHost, ServerPort);
var client = new GremlinClient(server, new GraphSON3MessageSerializer());
using var remoteConnection = new DriverRemoteConnection(client, "g");
var g = Traversal().WithRemote(remoteConnection);

var v = g.AddV().Iterate();
var count = g.V().Count().Next();
var v = g.AddV(VertexLabel).Iterate();
var count = g.V().HasLabel(VertexLabel).Count().Next();
Console.WriteLine("Vertex count: " + count);
}
}
10 changes: 8 additions & 2 deletions gremlin-dotnet/Examples/ModernTraversals/ModernTraversals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ under the License.

public class ModernTraversalExample
{
static readonly string ServerHost = Environment.GetEnvironmentVariable("GREMLIN_SERVER_HOST") ?? "localhost";
static readonly int ServerPort = int.Parse(Environment.GetEnvironmentVariable("GREMLIN_SERVER_PORT") ?? "8182");
static readonly bool IsDocker = Environment.GetEnvironmentVariable("DOCKER_ENVIRONMENT") == "true";

static void Main()
{
var server = new GremlinServer("localhost", 8182);
using var remoteConnection = new DriverRemoteConnection(new GremlinClient(server), "g");
var server = new GremlinServer(ServerHost, ServerPort);
// Use gmodern in CI environment, default connection locally
var traversalSource = IsDocker ? "gmodern" : "g";
using var remoteConnection = new DriverRemoteConnection(new GremlinClient(server), traversalSource);
var g = Traversal().WithRemote(remoteConnection);

/*
Expand Down
11 changes: 10 additions & 1 deletion gremlin-dotnet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,19 @@ services:
- ../gremlin-tools/gremlin-socket-server/conf:/gremlin-dotnet/gremlin-socket-server/conf/
environment:
- DOCKER_ENVIRONMENT=true
- GREMLIN_SERVER_HOST=gremlin-server-test-dotnet
- GREMLIN_SERVER_PORT=45940
- VERTEX_LABEL=dotnet-example
working_dir: /gremlin-dotnet
command: >
bash -c "dotnet tool update -g dotnet-trx; dotnet test ./Gremlin.Net.sln -c Release --logger trx; /root/.dotnet/tools/trx;
EXIT_CODE=$$?; chown -R `stat -c "%u:%g" .` .; exit $$EXIT_CODE"
EXIT_CODE=$$?;
echo 'Running examples...';
dotnet run --project Examples/BasicGremlin/BasicGremlin.csproj;
dotnet run --project Examples/Connections/Connections.csproj;
dotnet run --project Examples/ModernTraversals/ModernTraversals.csproj;
echo 'All examples completed successfully';
chown -R `stat -c \"%u:%g\" .` .; exit $$EXIT_CODE"
depends_on:
gremlin-server-test-dotnet:
condition: service_healthy
Expand Down
16 changes: 10 additions & 6 deletions gremlin-examples/gremlin-dotnet/BasicGremlin/BasicGremlin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,32 @@ under the License.

public class BasicGremlinExample
{
static readonly string ServerHost = "localhost";
static readonly int ServerPort = 8182;
static readonly string VertexLabel = "person";

static async Task Main()
{
var server = new GremlinServer("localhost", 8182);
var server = new GremlinServer(ServerHost, ServerPort);
using var remoteConnection = new DriverRemoteConnection(new GremlinClient(server), "g");
var g = Traversal().WithRemote(remoteConnection);

// Basic Gremlin: adding and retrieving data
var v1 = g.AddV("person").Property("name", "marko").Next();
var v2 = g.AddV("person").Property("name", "stephen").Next();
var v3 = g.AddV("person").Property("name", "vadas").Next();
var v1 = g.AddV(VertexLabel).Property("name", "marko").Next();
var v2 = g.AddV(VertexLabel).Property("name", "stephen").Next();
var v3 = g.AddV(VertexLabel).Property("name", "vadas").Next();

// Be sure to use a terminating step like Next() or Iterate() so that the traversal "executes"
// Iterate() does not return any data and is used to just generate side-effects (i.e. write data to the database)
g.V(v1).AddE("knows").To(v2).Property("weight", 0.75).Iterate();
g.V(v1).AddE("knows").To(v3).Property("weight", 0.75).Iterate();

// Retrieve the data from the "marko" vertex
var marko = await g.V().Has("person", "name", "marko").Values<string>("name").Promise(t => t.Next());
var marko = await g.V().Has(VertexLabel, "name", "marko").Values<string>("name").Promise(t => t.Next());
Console.WriteLine("name: " + marko);

// Find the "marko" vertex and then traverse to the people he "knows" and return their data
var peopleMarkoKnows = await g.V().Has("person", "name", "marko").Out("knows").Values<string>("name").Promise(t => t.ToList());
var peopleMarkoKnows = await g.V().Has(VertexLabel, "name", "marko").Out("knows").Values<string>("name").Promise(t => t.ToList());
foreach (var person in peopleMarkoKnows)
{
Console.WriteLine("marko knows " + person);
Expand Down
25 changes: 13 additions & 12 deletions gremlin-examples/gremlin-dotnet/Connections/Connections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ under the License.

public class ConnectionExample
{
static readonly string ServerHost = "localhost";
static readonly int ServerPort = 8182;
static readonly string VertexLabel = "connection";

static void Main()
{
WithRemote();
Expand All @@ -34,41 +38,38 @@ static void Main()
// Connecting to the server
static void WithRemote()
{
var server = new GremlinServer("localhost", 8182);
var server = new GremlinServer(ServerHost, ServerPort);
using var remoteConnection = new DriverRemoteConnection(new GremlinClient(server), "g");
var g = Traversal().WithRemote(remoteConnection);

// Drop existing vertices
g.V().Drop().Iterate();

// Simple query to verify connection
var v = g.AddV().Iterate();
var count = g.V().Count().Next();
var v = g.AddV(VertexLabel).Iterate();
var count = g.V().HasLabel(VertexLabel).Count().Next();
Console.WriteLine("Vertex count: " + count);
}

// Connecting to the server with customized configurations
static void WithConf()
{
using var remoteConnection = new DriverRemoteConnection(new GremlinClient(
new GremlinServer(hostname: "localhost", port: 8182, enableSsl: false, username: "", password: "")), "g");
new GremlinServer(hostname: ServerHost, port: ServerPort, enableSsl: false, username: "", password: "")), "g");
var g = Traversal().WithRemote(remoteConnection);

var v = g.AddV().Iterate();
var count = g.V().Count().Next();
var v = g.AddV(VertexLabel).Iterate();
var count = g.V().HasLabel(VertexLabel).Count().Next();
Console.WriteLine("Vertex count: " + count);
}

// Specifying a serializer
static void WithSerializer()
{
var server = new GremlinServer("localhost", 8182);
var server = new GremlinServer(ServerHost, ServerPort);
var client = new GremlinClient(server, new GraphSON3MessageSerializer());
using var remoteConnection = new DriverRemoteConnection(client, "g");
var g = Traversal().WithRemote(remoteConnection);

var v = g.AddV().Iterate();
var count = g.V().Count().Next();
var v = g.AddV(VertexLabel).Iterate();
var count = g.V().HasLabel(VertexLabel).Count().Next();
Console.WriteLine("Vertex count: " + count);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ under the License.

public class ModernTraversalExample
{
static readonly string ServerHost = "localhost";
static readonly int ServerPort = 8182;

static void Main()
{
var server = new GremlinServer("localhost", 8182);
var server = new GremlinServer(ServerHost, ServerPort);
using var remoteConnection = new DriverRemoteConnection(new GremlinClient(server), "g");
var g = Traversal().WithRemote(remoteConnection);

Expand Down
Loading