public void GraphServerConstructorTest()
        {
            using (var GraphServer = new BifrostHTTPServer(new IPPort(8080)) {
                                         ServerName = "GraphServer v0.1"
                                     } as IBifrostHTTPServer)
            {

                GraphServer.CreateNewGraph("123");

                Assert.IsNotNull(GraphServer);
                Assert.IsNotNull(GraphServer.ServerName);
                Assert.AreEqual("GraphServer v0.1", GraphServer.ServerName);

                var graphs = GraphServer.ToList();
                Assert.IsNotNull(graphs);
                Assert.AreEqual(1, graphs.Count);

                var graph1 = graphs[0];
                Assert.IsNotNull(graph1);
                Assert.IsNotNull(graph1.IdKey);
                Assert.IsNotNull(graph1.RevIdKey);
                Assert.AreEqual(123UL, graph1.Id);

            }
        }
        public void AddPropertyGraphTest()
        {
            using (var GraphServer = new BifrostHTTPServer(new IPPort(8080)) {
                                         ServerName = "GraphServer v0.1"
                                     } as IBifrostHTTPServer)
            {

                GraphServer.CreateNewGraph("123");

                var graph = GraphServer.CreateNewGraph("256");
                Assert.IsNotNull(graph);
                Assert.IsNotNull(graph.IdKey);
                Assert.IsNotNull(graph.RevIdKey);
                Assert.AreEqual(256UL, graph.Id);

                var graphs = GraphServer.ToList();
                Assert.IsNotNull(graphs);
                Assert.AreEqual(2, graphs.Count);

                var graphIds = (from _graph in graphs select _graph.Id).ToList();
                Assert.IsTrue(graphIds.Contains("123"));
                Assert.IsTrue(graphIds.Contains("256"));

            }
        }
Example #3
0
 /// <summary>
 /// Start a new TCP/HTTP/REST based graph server.
 /// </summary>
 /// <param name="Graph">A graph.</param>
 /// <param name="Port">The listening port.</param>
 /// <param name="Autostart">Autostart the server.</param>
 public static IBifrostHTTPServer StartHTTPServer(this IGenericPropertyGraph<String, Int64, String, String, Object,
                                                                       String, Int64, String, String, Object,
                                                                       String, Int64, String, String, Object,
                                                                       String, Int64, String, String, Object> Graph,
                                            IPPort Port,
                                            Boolean Autostart = false)
 {
     var Server = new BifrostHTTPServer(Port, Autostart);
     Server.AddGraph(Graph);
     return Server;
 }
Example #4
0
        /// <summary>
        /// Run the tutorial.
        /// </summary>
        public void Run()
        {
            var g1 = GenericDemoGraphFactory.Create();

            var g2 = g1.AsReadOnly();

            using (var GraphServer = new BifrostHTTPServer(new IPPort(8080))
            {
                ServerName = "Vanaheimr Bifrost HTTP Server v0.1"
            } as IBifrostHTTPServer)
            {

                GraphServer.CreateNewGraph("123", "The first graph");

                var graph = GraphServer.CreateNewGraph("512", "demo graph", g => g.SetProperty(GraphDBOntology.Description().Suffix, "the second graph").SetProperty("hello", "world!").SetProperty("graphs", "are cool!"));
                var a1 = graph.ContainsKey("hello");
                var a2 = graph.ContainsKey("world!");
                var a3 = graph.ContainsKey("graphs");
                var a4 = graph.ContainsKey("are cool!");
                var a5 = graph.ContainsKey(GraphDBOntology.Description().Suffix);

                var c1 = graph.ContainsValue(123UL);

                var t = false;
                graph.UseProperty("Id", success => t = true);
                var ii = "i = " + t;

                var b1 = graph.Contains("Id", 123UL);
                var b2 = graph is IProperties<String, Object>;

                var aa = graph.GetProperties(null);

                var deleted3 = graph.Remove().ToList();
                var deleted1 = graph.Remove("hello");

                // ---------------------------------------------------------------

                var v1 = graph.AddVertex(v => v.SetProperty("Name", "Vertex1"));
                var v2 = graph.AddVertex(v => v.SetProperty("Name", "Vertex2"));
                var e1 = graph.AddEdge(v1, v2, "knows", e => e.SetProperty("Name", "Edge1"));

                var allV = graph.Vertices().ToList();
                var allE = graph.Edges().ToList();

                // ---------------------------------------------------------------

                //var HTTPClient1 = new HTTPClient(IPv4Address.Parse("127.0.0.1"), new IPPort(8080));
                //var _request1 = HTTPClient1.GET("/").//AccountId/RepositoryId/TransactionId/GraphId/VerticesById?Id=2&Id=3").
                //                              SetProtocolVersion(HTTPVersion.HTTP_1_1).
                //                              SetUserAgent("Hermod HTTP Client v0.1").
                //                              SetConnection("keep-alive").
                //                              AddAccept(HTTPContentType.JSON_UTF8, 1);

                //HTTPClient1.Execute(_request1, response => Console.WriteLine(response.Content.ToUTF8String()));

                //// ---------------------------------------------------------------

                //var HTTPClient2 = new HTTPClient(IPv4Address.Parse("127.0.0.1"), new IPPort(8080));
                //var _request2 = HTTPClient2.GET("/123/description").//AccountId/RepositoryId/TransactionId/GraphId/VerticesById?Id=2&Id=3").
                //                              SetProtocolVersion(HTTPVersion.HTTP_1_1).
                //                              SetUserAgent("Hermod HTTP Client v0.1").
                //                              SetConnection("keep-alive").
                //                              AddAccept(HTTPContentType.JSON_UTF8, 1);

                //HTTPClient2.Execute(_request2, response => Console.WriteLine(response.Content.ToUTF8String()));

                // ---------------------------------------------------------------

            //#if !__MonoCS__

            //                var JavaScriptEngine = new Jurassic.ScriptEngine();
            //                //Console.WriteLine(engine.Evaluate("5 * 10 + 2"));
            //                //engine.SetGlobalValue("interop", 15);
            //                //engine.ExecuteFile(@"c:\test.js");
            //                //engine.Evaluate("interop = interop + 5");
            //                //Console.WriteLine(engine.GetGlobalValue<int>("interop"));

            //                JavaScriptEngine.Evaluate("function VertexFilter(vertex) { return vertex.Name == 'Vertex1' }");

            //                foreach (var Vertex in graph.Vertices())
            //                {
            //                    //engine.SetGlobalValue("vertex", new JSPropertyVertex(_vv, engine));

            //                    //engine.SetGlobalFunction("test", new Func<int, int, int>((a, b) => a + b));
            //                    //Console.WriteLine(engine.Evaluate<int>("test(5, 6)"));

            //                    //engine.Evaluate("var yesorno = vertex.Id > 1");
            //                    //var Id      = engine.GetGlobalValue  ("vertex.Id");
            //                    //var yesorno = engine.GetGlobalValue<Boolean>("yesorno");

            //                    if (JavaScriptEngine.CallGlobalFunction<Boolean>("VertexFilter", new JSPropertyVertex(Vertex, JavaScriptEngine)))
            //                        Console.WriteLine(Vertex.Id);

            //                }

            //                var aaa = from   V2
            //                          in     graph.Vertices()
            //                          where  JavaScriptEngine.CallGlobalFunction<Boolean>("VertexFilter", new JSPropertyVertex(V2, JavaScriptEngine))
            //                          select V2;

            //                var aaaa = aaa.ToList();

            //                var GraphClient = new RemotePropertyGraph(IPv4Address.Parse("127.0.0.1"), new IPPort(8080)) { Id = 512 };
            //                Console.WriteLine(GraphClient.Description);

            //                //foreach (var V3 in GraphClient.Vertices())
            //                //    Console.WriteLine(V3.Id);
            //#endif
                while (true)
                    Thread.Sleep(100);

            }
        }
        public void NewPropertyGraphTest()
        {
            using (var GraphServer = new BifrostHTTPServer(new IPPort(8080)) {
                                         ServerName = "GraphServer v0.1"
                                     } as IBifrostHTTPServer)
            {

                GraphServer.CreateNewGraph("123");

                var graph = GraphServer.CreateNewGraph("512", "demo graph", g => g.SetProperty("hello", "world!"));
                Assert.IsNotNull(graph);
                Assert.IsNotNull(graph.IdKey);
                Assert.IsNotNull(graph.RevIdKey);
                Assert.AreEqual(512UL, graph.Id);
                Assert.IsTrue(graph.ContainsKey("hello"));
                Assert.IsTrue(graph.ContainsValue("world!"));
                Assert.IsTrue(graph.Contains("hello", "world!"));

                var graphs = GraphServer.ToList();
                Assert.IsNotNull(graphs);
                Assert.AreEqual(2, graphs.Count);

                var graphIds = (from _graph in graphs select _graph.Id).ToList();
                Assert.IsTrue(graphIds.Contains("123"));
                Assert.IsTrue(graphIds.Contains("512"));

            }
        }
Example #6
0
 protected IBifrostHTTPServer CreateGraph(String GraphId)
 {
     var GraphServer = new BifrostHTTPServer();
     GraphServer.CreateNewGraph(GraphId);
     return GraphServer;
 }
Example #7
0
        /// <summary>
        /// Run the tutorial.
        /// </summary>
        public void Run()
        {
            var g1 = DemoGraphFactory.Create();

            var g2 = g1.AsReadOnly();


            using (var GraphServer = new BifrostHTTPServer(new IPPort(8080), (id, descr, init) => GraphFactory.CreateGenericPropertyGraph_WithStringIds(id, descr, () => new VetoVote(), init))
            {
                ServerName = "Vanaheimr Bifrost HTTP Server v0.1"
            } as IBifrostHTTPServer)
            {
                GraphServer.CreateNewGraph("123", "The first graph");

                var graph = GraphServer.CreateNewGraph("512", "demo graph", g => g.SetProperty(GraphDBOntology.Description.Suffix, "the second graph").SetProperty("hello", "world!").SetProperty("graphs", "are cool!"));
                var a1    = graph.ContainsKey("hello");
                var a2    = graph.ContainsKey("world!");
                var a3    = graph.ContainsKey("graphs");
                var a4    = graph.ContainsKey("are cool!");
                var a5    = graph.ContainsKey(GraphDBOntology.Description.Suffix);

                var c1 = graph.ContainsValue(123UL);

                var t = false;
                graph.UseProperty("Id", success => t = true);
                var ii = "i = " + t;

                var b1 = graph.Contains("Id", 123UL);
                var b2 = graph is IProperties <String, Object>;

                var aa = graph.GetProperties(null);

                var deleted3 = graph.Remove().ToList();
                var deleted1 = graph.Remove("hello");

                // ---------------------------------------------------------------

                var v1 = graph.AddVertex(v => v.SetProperty("Name", "Vertex1"));
                var v2 = graph.AddVertex(v => v.SetProperty("Name", "Vertex2"));
                var e1 = graph.AddEdge(v1, v2, "knows", e => e.SetProperty("Name", "Edge1"));

                var allV = graph.Vertices().ToList();
                var allE = graph.Edges().ToList();


                // ---------------------------------------------------------------


                //var HTTPClient1 = new HTTPClient(IPv4Address.Parse("127.0.0.1"), new IPPort(8080));
                //var _request1 = HTTPClient1.GET("/").//AccountId/RepositoryId/TransactionId/GraphId/VerticesById?Id=2&Id=3").
                //                              SetProtocolVersion(HTTPVersion.HTTP_1_1).
                //                              SetUserAgent("Hermod HTTP Client v0.1").
                //                              SetConnection("keep-alive").
                //                              AddAccept(HTTPContentType.JSON_UTF8, 1);

                //HTTPClient1.Execute(_request1, response => Console.WriteLine(response.Content.ToUTF8String()));

                //// ---------------------------------------------------------------

                //var HTTPClient2 = new HTTPClient(IPv4Address.Parse("127.0.0.1"), new IPPort(8080));
                //var _request2 = HTTPClient2.GET("/123/description").//AccountId/RepositoryId/TransactionId/GraphId/VerticesById?Id=2&Id=3").
                //                              SetProtocolVersion(HTTPVersion.HTTP_1_1).
                //                              SetUserAgent("Hermod HTTP Client v0.1").
                //                              SetConnection("keep-alive").
                //                              AddAccept(HTTPContentType.JSON_UTF8, 1);

                //HTTPClient2.Execute(_request2, response => Console.WriteLine(response.Content.ToUTF8String()));

                // ---------------------------------------------------------------

//#if !__MonoCS__

//                var JavaScriptEngine = new Jurassic.ScriptEngine();
//                //Console.WriteLine(engine.Evaluate("5 * 10 + 2"));
//                //engine.SetGlobalValue("interop", 15);
//                //engine.ExecuteFile(@"c:\test.js");
//                //engine.Evaluate("interop = interop + 5");
//                //Console.WriteLine(engine.GetGlobalValue<int>("interop"));

//                JavaScriptEngine.Evaluate("function VertexFilter(vertex) { return vertex.Name == 'Vertex1' }");

//                foreach (var Vertex in graph.Vertices())
//                {
//                    //engine.SetGlobalValue("vertex", new JSPropertyVertex(_vv, engine));

//                    //engine.SetGlobalFunction("test", new Func<int, int, int>((a, b) => a + b));
//                    //Console.WriteLine(engine.Evaluate<int>("test(5, 6)"));

//                    //engine.Evaluate("var yesorno = vertex.Id > 1");
//                    //var Id      = engine.GetGlobalValue  ("vertex.Id");
//                    //var yesorno = engine.GetGlobalValue<Boolean>("yesorno");

//                    if (JavaScriptEngine.CallGlobalFunction<Boolean>("VertexFilter", new JSPropertyVertex(Vertex, JavaScriptEngine)))
//                        Console.WriteLine(Vertex.Id);

//                }

//                var aaa = from   V2
//                          in     graph.Vertices()
//                          where  JavaScriptEngine.CallGlobalFunction<Boolean>("VertexFilter", new JSPropertyVertex(V2, JavaScriptEngine))
//                          select V2;

//                var aaaa = aaa.ToList();


//                var GraphClient = new RemotePropertyGraph(IPv4Address.Parse("127.0.0.1"), new IPPort(8080)) { Id = 512 };
//                Console.WriteLine(GraphClient.Description);

//                //foreach (var V3 in GraphClient.Vertices())
//                //    Console.WriteLine(V3.Id);
//#endif
                while (true)
                {
                    Thread.Sleep(100);
                }
            }
        }