@@ -24,6 +24,10 @@ under the License.
2424
2525public class ConnectionExample
2626{
27+ static readonly string ServerHost = Environment . GetEnvironmentVariable ( "GREMLIN_SERVER_HOST" ) ?? "localhost" ;
28+ static readonly int ServerPort = int . Parse ( Environment . GetEnvironmentVariable ( "GREMLIN_SERVER_PORT" ) ?? "8182" ) ;
29+ static readonly string VertexLabel = Environment . GetEnvironmentVariable ( "VERTEX_LABEL" ) ?? "connection" ;
30+
2731 static void Main ( )
2832 {
2933 WithRemote ( ) ;
@@ -34,41 +38,38 @@ static void Main()
3438 // Connecting to the server
3539 static void WithRemote ( )
3640 {
37- var server = new GremlinServer ( "localhost" , 8182 ) ;
41+ var server = new GremlinServer ( ServerHost , ServerPort ) ;
3842 using var remoteConnection = new DriverRemoteConnection ( new GremlinClient ( server ) , "g" ) ;
3943 var g = Traversal ( ) . WithRemote ( remoteConnection ) ;
4044
41- // Drop existing vertices
42- g . V ( ) . Drop ( ) . Iterate ( ) ;
43-
4445 // Simple query to verify connection
45- var v = g . AddV ( ) . Iterate ( ) ;
46- var count = g . V ( ) . Count ( ) . Next ( ) ;
46+ var v = g . AddV ( VertexLabel ) . Iterate ( ) ;
47+ var count = g . V ( ) . HasLabel ( VertexLabel ) . Count ( ) . Next ( ) ;
4748 Console . WriteLine ( "Vertex count: " + count ) ;
4849 }
4950
5051 // Connecting to the server with customized configurations
5152 static void WithConf ( )
5253 {
5354 using var remoteConnection = new DriverRemoteConnection ( new GremlinClient (
54- new GremlinServer ( hostname : "localhost" , port : 8182 , enableSsl : false , username : "" , password : "" ) ) , "g" ) ;
55+ new GremlinServer ( hostname : ServerHost , port : ServerPort , enableSsl : false , username : "" , password : "" ) ) , "g" ) ;
5556 var g = Traversal ( ) . WithRemote ( remoteConnection ) ;
5657
57- var v = g . AddV ( ) . Iterate ( ) ;
58- var count = g . V ( ) . Count ( ) . Next ( ) ;
58+ var v = g . AddV ( VertexLabel ) . Iterate ( ) ;
59+ var count = g . V ( ) . HasLabel ( VertexLabel ) . Count ( ) . Next ( ) ;
5960 Console . WriteLine ( "Vertex count: " + count ) ;
6061 }
6162
6263 // Specifying a serializer
6364 static void WithSerializer ( )
6465 {
65- var server = new GremlinServer ( "localhost" , 8182 ) ;
66+ var server = new GremlinServer ( ServerHost , ServerPort ) ;
6667 var client = new GremlinClient ( server , new GraphSON3MessageSerializer ( ) ) ;
6768 using var remoteConnection = new DriverRemoteConnection ( client , "g" ) ;
6869 var g = Traversal ( ) . WithRemote ( remoteConnection ) ;
6970
70- var v = g . AddV ( ) . Iterate ( ) ;
71- var count = g . V ( ) . Count ( ) . Next ( ) ;
71+ var v = g . AddV ( VertexLabel ) . Iterate ( ) ;
72+ var count = g . V ( ) . HasLabel ( VertexLabel ) . Count ( ) . Next ( ) ;
7273 Console . WriteLine ( "Vertex count: " + count ) ;
7374 }
7475}
0 commit comments