using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.sparsity.dex.gdb;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
//
// Create a sample database
//
DexConfig cfg = new DexConfig();
Dex dex = new Dex(cfg);
Database db = dex.Create("HelloWorld.dex", "HelloWorld");
Session sess = db.NewSession();
Graph g = sess.GetGraph();
// Add a node type with two attributes
int nodeType = g.NewNodeType("TheNodeType");
int idAttribute = g.NewAttribute(nodeType, "id", DataType.Long, AttributeKind.Unique);
int nameAttribute = g.NewAttribute(nodeType, "name", DataType.String, AttributeKind.Indexed);
// Add a directed edge type with an attribute
int edgeType = g.NewEdgeType("TheEdgeType", true, false);
// Add a node
long hellow = g.NewNode(nodeType);
Value value = new Value();
g.SetAttribute(hellow, idAttribute, value.SetLong(1));
g.SetAttribute(hellow, nameAttribute, value.SetString("Hellow"));
// Add another node
long world = g.NewNode(nodeType);
g.SetAttribute(world, idAttribute, value.SetLong(2));
g.SetAttribute(world, nameAttribute, value.SetString("World"));
// Add an edge
long theEdge = g.NewEdge(edgeType, hellow, world);
// Get the neighbors of the first node using the edges of "TheEdgeType" type
Objects neighbors = g.Neighbors(hellow, edgeType, EdgesDirection.Outgoing);
// Say hello to the neighbors
ObjectsIterator it = neighbors.Iterator();
while (it.HasNext())
{
long neighborOid = it.Next();
g.GetAttribute(neighborOid, edgeType, value);
System.Console.WriteLine("Hello " + value.GetString());
}
// The ObjectsIterator must be closed
it.Close();
// The Objects must be closed
neighbors.Close();
// Close the database
sess.Close();
db.Close();
dex.Close();
}
}
}