public Node GetRootNode(ConnectionElement connection)
        {
            string response;
            var    status = Neo4jRestApi.GetRoot(Connection.GetDatabaseEndpoint(connection.DbUrl).Data, out response);

            if (status != HttpStatusCode.OK)
            {
                throw new Exception(string.Format("Error getting root node (http response:{0})", status));
            }

            JObject jo;

            try
            {
                jo = JObject.Parse(response);
            }
            catch (Exception e)
            {
                throw new Exception("Invalid json", e);
            }

            JToken referenceNode;

            if (!jo.TryGetValue("reference_node", out referenceNode))
            {
                throw new NodeNotFoundException("Reference node not found");
            }

            var graphStore = new RestNodeStore(referenceNode.Value <string>());

            return(new Node(graphStore));
        }
Beispiel #2
0
        public static ServiceRoot GetServiceRoot(string dbUrl)
        {
            ServiceRoot serviceRoot;

            if (!ServiceRoots.TryGetValue(dbUrl, out serviceRoot))
            {
                string response;

                if (Neo4jRestApi.GetRoot(GetDatabaseEndpoint(dbUrl).Data, out response) == HttpStatusCode.OK)
                {
                    serviceRoot = JsonConvert.DeserializeObject <ServiceRoot>(response);
                    ServiceRoots.TryAdd(dbUrl, serviceRoot);
                }
                else
                {
                    throw new ServiceRootNotFound();
                }
            }

            return(serviceRoot);
        }
Beispiel #3
0
        public static DatabaseEndpoint GetDatabaseEndpoint(string dbUrl)
        {
            DatabaseEndpoint endpoint;

            if (!DatabaseEndpoints.TryGetValue(dbUrl, out endpoint))
            {
                string response;

                if (Neo4jRestApi.GetRoot(dbUrl, out response) == HttpStatusCode.OK)
                {
                    endpoint = JsonConvert.DeserializeObject <DatabaseEndpoint>(response);
                    DatabaseEndpoints.TryAdd(dbUrl, endpoint);
                }
                else
                {
                    throw new DatabaseEndpointNotFound();
                }
            }

            return(endpoint);
        }