My first .Net project

33 views
Skip to first unread message

Sparsity T

unread,
Feb 14, 2013, 8:11:16 AM2/14/13
to dex...@googlegroups.com
Hello,

If you are using Visual studio and want to construct your first project with DEX, follow these short instructions:

- Create the C# console application

- Replace the Program.cs with the sample:

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();
        }
    }
}

- Add a reference in the project (Menu Project -> AddReference) to the library "dexnet.dll".

- Put the other dlls in a directory where the application can found it. The easier way is to put them where the application exe is created. Or set the working directory to the directory where you have the dlls. But you could also put them with the windows dlls.


And here it is your first project with .Net!


More details in the Starting Guide.

Reply all
Reply to author
Forward
0 new messages