Esempio n. 1
0
        /// <summary>
        /// Creates the index on the master server
        /// </summary>
        /// <param name="indexName">Name of the index.</param>
        /// <param name="dropIfExists">if set to <c>true</c> [drop if exists].</param>
        public void CreateIndex(string indexName, bool dropIfExists)
        {
            if (dropIfExists)
            {
                DeleteIndex(indexName);
            }

            var indexConfiguration = new IndexConfiguration
            {
                Provider = IndexProvider.lucene,
                Type     = IndexType.fulltext
            };

            GraphPoolableClient client = null;

            try
            {
                client = GetClient();
                client.GetClient().CreateIndex(indexName, indexConfiguration, IndexFor.Node);
            }
            catch (Exception e)
            {
                LogException("CreateIndex", e);
                InformAboutHostProblems(client, e);
                throw;
            }
        }
Esempio n. 2
0
        public string GetObjectByPath(string path)
        {
            GraphPoolableClient client = null;

            try
            {
                client = GetClient();
                string uri     = client.ServiceHost;
                var    request = (HttpWebRequest)WebRequest.Create(uri + path);
                request.Method  = "GET";
                request.Accept  = "application/json";
                request.Timeout = _timeout;
                using (var responseStream = request.GetResponse().GetResponseStream())
                {
                    using (var reader = new StreamReader(responseStream))
                    {
                        var responseContent = reader.ReadToEnd();
                        return(responseContent);
                    }
                }
            }
            catch (Exception e)
            {
                LogException("GetObjectByPath", e);
                InformAboutHostProblems(client, e);
                throw;
            }
        }
Esempio n. 3
0
 private void InitializePool(string readClientHostName, string writeClientHostName)
 {
     if (!ReadWritePool.IsPoolReady(Pools.Neo4j))
     {
         GraphPoolableClient reader = new GraphPoolableClient(readClientHostName);
         GraphPoolableClient writer = new GraphPoolableClient(writeClientHostName);
         ReadWritePool.AddReadHosts(Pools.Neo4j, new[] { reader });
         ReadWritePool.AddWriteHosts(Pools.Neo4j, new[] { writer });
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Inserts the specified node on the master server
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="node">The node.</param>
        /// <param name="relationships">The relationships.</param>
        /// <returns></returns>
        public NodeResult <T> Insert <T>(T node, IEnumerable <IRelationshipAllowingParticipantNode <T> > relationships)
            where T : class
        {
            GraphPoolableClient client = GetClient();

            try
            {
                return(new NodeResult <T>(client.GetClient().Create(node, relationships.ToArray(), Enumerable.Empty <IndexEntry>()), node));
            }
            catch (Exception e)
            {
                LogException("Insert", e);
                InformAboutHostProblems(client, e);
                throw;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Creates the relationship on the master server
        /// </summary>
        /// <typeparam name="TNode">The type of the node.</typeparam>
        /// <typeparam name="TRelationship">The type of the relationship.</typeparam>
        /// <param name="nodeReference">The node reference.</param>
        /// <param name="relationshipAllowingParticipantNode">The relationship allowing participant node.</param>
        public void CreateRelationship <TNode, TRelationship>(NodeReference <TNode> nodeReference, TRelationship relationshipAllowingParticipantNode)
            where TRelationship : Relationship, IRelationshipAllowingSourceNode <TNode>
        {
            GraphPoolableClient client = null;

            try
            {
                client = GetClient();
                client.GetClient().CreateRelationship(nodeReference, relationshipAllowingParticipantNode);
            }
            catch (Exception e)
            {
                LogException("CreateRelationship", e);
                InformAboutHostProblems(client, e);
                throw;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Inserts the specified node on the master server
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="node">The node.</param>
        /// <param name="indexEntries">The index entries.</param>
        /// <returns></returns>
        public NodeResult <T> Insert <T>(T node, IEnumerable <IndexEntry> indexEntries)
            where T : class
        {
            GraphPoolableClient client = null;

            try
            {
                client = GetClient();
                return(new NodeResult <T>(client.GetClient().Create(node, null, indexEntries), node));
            }
            catch (Exception e)
            {
                LogException("Insert", e);
                InformAboutHostProblems(client, e);
                throw;
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Gets the specified node references on the slave server
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query">The query.</param>
        /// <returns></returns>
        public IEnumerable <NodeReference <T> > GetNodeReferences <T>(string query)
        {
            GraphPoolableClient client = null;

            try
            {
                client = GetClient();
                return(((IRawGraphClient)client.GetClient())
                       .ExecuteGetCypherResults <Node <T> >(new CypherQuery(query, null, CypherResultMode.Set))
                       .Select(t => t.Reference));
            }
            catch (Exception e)
            {
                LogException("GetNodeReferences", e);
                InformAboutHostProblems(client, e);
                throw;
            }
        }
Esempio n. 8
0
        private string ExecuteGremlinScript(string requestString)
        {
            IStopwatch          sw     = MonitoringTimers.Current.GetNewStopwatch(true);
            GraphPoolableClient client = null;

            try
            {
                client = GetClient();
                string uri     = client.ServiceHost;
                var    request = (HttpWebRequest)WebRequest.Create(uri + "/ext/GremlinPlugin/graphdb/execute_script");
                request.Method                 = "POST";
                request.ContentType            = "application/json; charset=utf-8";
                request.Accept                 = "application/json; stream=true";
                request.AutomaticDecompression = DecompressionMethods.GZip;
                request.Timeout                = _timeout;

                using (var stream = request.GetRequestStream())
                {
                    var bytes = Encoding.UTF8.GetBytes(requestString);
                    stream.Write(bytes, 0, bytes.Length);

                    using (var responseStream = request.GetResponse().GetResponseStream())
                    {
                        using (var reader = new StreamReader(responseStream))
                        {
                            string responseContent = reader.ReadToEnd();
                            Log.Debug("Neo4jContext.ExecuteGremlinScript", "response content", request.RequestUri, responseContent);
                            return(responseContent);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogException("ExecuteGremlinScript", e);
                InformAboutHostProblems(client, e);
                throw;
            }
            finally
            {
                sw.Stop();
                MonitoringTimers.Current.AddTime(Counters.Gremlin_ExecuteScript, sw);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Deletes the index on the master server
        /// </summary>
        /// <param name="indexName">Name of the index.</param>
        public void DeleteIndex(string indexName)
        {
            GraphPoolableClient client = null;

            try
            {
                client = GetClient();
                if (client.GetClient().CheckIndexExists(indexName, IndexFor.Node))
                {
                    client.GetClient().DeleteIndex(indexName, IndexFor.Node);
                }
            }
            catch (Exception e)
            {
                LogException("DeleteIndex", e);
                InformAboutHostProblems(client, e);
                throw;
            }
        }
Esempio n. 10
0
        public string GetWithCypherQuery(string query)
        {
            GraphPoolableClient client = null;
            string requestString       = query;

            try
            {
                client = GetClient();
                string uri     = client.ServiceHost;
                var    request = (HttpWebRequest)WebRequest.Create(uri + "/cypher");
                request.Method                 = "POST";
                request.ContentType            = "application/json; charset=utf-8";
                request.Accept                 = "application/json; stream=true";
                request.AutomaticDecompression = DecompressionMethods.GZip;
                request.Timeout                = _timeout;
                requestString = "{\"query\" : \"" + query + "\"}";
                Log.Debug("Neo4jContext.GetWithCypherQuery", "query", requestString);
                using (var stream = request.GetRequestStream())
                {
                    var bytes = Encoding.UTF8.GetBytes(requestString);
                    stream.Write(bytes, 0, bytes.Length);
                    using (var responseStream = request.GetResponse().GetResponseStream())
                    {
                        using (var reader = new StreamReader(responseStream))
                        {
                            var responseContent = reader.ReadToEnd();
                            Log.Debug("Neo4jContext.GetWithCypherQuery", "responseContent", responseContent);
                            return(responseContent);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogException("GetWithCypherQuery", e, requestString);
                InformAboutHostProblems(client, e);
                throw;
            }
        }
Esempio n. 11
0
        public string QueryBatch(string requestString)
        {
            GraphPoolableClient client = null;
            string queryResult         = string.Empty;

            try
            {
                client = GetClient();
                string uri     = client.ServiceHost;
                var    request = (HttpWebRequest)WebRequest.Create(uri + "/batch");
                request.Method                 = "POST";
                request.ContentType            = "application/json; charset=utf-8";
                request.Accept                 = "application/json";
                request.AutomaticDecompression = DecompressionMethods.GZip;
                //request.Timeout = _timeout;

                using (var stream = request.GetRequestStream())
                {
                    var bytes = Encoding.UTF8.GetBytes(requestString);
                    stream.Write(bytes, 0, bytes.Length);

                    using (var responseStream = request.GetResponse().GetResponseStream())
                    {
                        using (var reader = new StreamReader(responseStream))
                        {
                            queryResult = reader.ReadToEnd();
                        }
                    }
                }

                return(queryResult);
            }
            catch (Exception e)
            {
                LogException("QueryBatch", e);
                InformAboutHostProblems(client, e);
                throw;
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Deletes the specified node reference on the master server
        /// </summary>
        /// <param name="nodeReference">The node reference.</param>
        /// <returns></returns>
        public bool Delete(long nodeReference)
        {
            GraphPoolableClient client = null;

            try
            {
                client = GetClient();
                client.GetClient()
                .Cypher
                .Start(new { n = nodeReference })
                .Match("n-[r?]-()")
                .Delete("n, r")
                .ExecuteWithoutResults();
                return(true);
            }
            catch (Exception e)
            {
                LogException("Delete", e);
                InformAboutHostProblems(client, e);
                throw;
            }
        }