public GraphRepository(IConfiguration configuration) { var client = new GraphClient(new Uri(configuration.GetGraphDbUrl())); client.Connect(); Client = client; }
public void TestInitialise() { graphClientSub = Substitute.For<IGraphClient>(); var cypher = Substitute.For<ICypherFluentQuery>(); graphClientSub.Cypher.Returns(cypher); }
public GremlinQuery(IGraphClient client, string queryText, IDictionary<string, object> queryParameters, IList<string> declarations ) { this.client = client; this.queryText = queryText; this.queryParameters = queryParameters; this.queryDeclarations = declarations; }
public NetworkContext(IOptions<AppSettings> options) { var appSettings = options.Options; _db = new GraphClient(new Uri(appSettings.Neo4jConnection));//, appSettings.Neo4jUserName, // appSettings.Neo4jPassword); _db.Connect(); }
public SitecoreGraph() { //var graph = new SitecoreGraph(client); //_graphClient = client; _graphClient = Sitecore.DependencyInjection.ContainerContexts.WindsorContainerContext.Instance.Resolve<IGraphClient>(); }
private string ReadSchemaTxt(IGraphClient graphClient) { var commandObj = new { command = "schema", engine = "shell" }; string jsonCommand = JsonConvert.SerializeObject(commandObj); HttpWebRequest commandRequest = this.httpManager.GetConsoleCommandRequest(graphClient, jsonCommand); string result = this.httpManager.GetCommandResponse(commandRequest).Trim(new[] { '[', ']', ' ' }); return result; }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); _neo4jClient = new GraphClient(new Uri(ConfigurationManager.ConnectionStrings["Graphene"].ConnectionString)); Glimpse.Neo4jClient.Plugin.RegisterGraphClient(_neo4jClient); }
public void DropAllIndexes(IGraphClient graphClient) { List<IIndexMetadata> indexMetadataList = this.indexHelper.ListAllIndexes(graphClient); foreach (IIndexMetadata indexMetadata in indexMetadataList) { if (indexMetadata.Type == TypeId.Index) { this.indexHelper.DropIndex(graphClient, indexMetadata.Label, indexMetadata.Property); } else if (indexMetadata.Type == TypeId.Constraint) { this.indexHelper.DropConstraint(graphClient, indexMetadata.Label, indexMetadata.Property); } } }
public virtual List<IIndexMetadata> ListAllIndexes(IGraphClient graphClient) { var indexMetadataList = this.indexMetadataFactory.GetList(); string[] indexData = this.schemaReader.GetSchemaIndexData(graphClient); if (indexData != null) { List<IndexGroup> indexConstraintGroups = indexData.Select(g => new IndexGroup { Indexes = g.Trim(';').Split(';') }).ToList(); indexMetadataList.AddRange(this.BuildConstraintList(indexConstraintGroups)); indexMetadataList.AddRange(this.BuildIndexList(indexConstraintGroups)); } return indexMetadataList; }
public static void Register(HttpConfiguration config) { // Web API 配置和服务 // Web API 路由 config.MapHttpAttributeRoutes(); config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); config.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml"); config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType); var url = ConfigurationManager.AppSettings["GraphDBUrl"]; var client = new GraphClient(new Uri(url)); client.Connect(); GraphClient = client; }
public static void Register(HttpConfiguration config) { // Web API configuration and services // Web API routes config.MapHttpAttributeRoutes(); var url = ConfigurationManager.AppSettings["GraphDBUrl"]; var client = new GraphClient(new Uri(url), "neo4j", "123456"); client.Connect(); GraphClient = client; config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); }
public virtual HttpWebRequest GetConsoleCommandRequest(IGraphClient graphClient, string jsonCommand) { string absoluteUri = graphClient.RootEndpoint.AbsoluteUri.TrimEnd('/'); string Url = absoluteUri.Substring(0, absoluteUri.LastIndexOf('/')) + Resources.CONSOLEPATH; var request = (HttpWebRequest)WebRequest.Create(Url); request.Method = Resources.METHOD; request.Accept = Resources.ACCEPT; request.Host = Resources.HOST; request.KeepAlive = true; request.ContentType = Resources.CONTENTTYPE; request.Referer = Resources.REFERER; request.Headers.Add("Authorization", this.GetAuthorizationHeaderValue(graphClient.ExecutionConfiguration)); byte[] postBuffer = Encoding.UTF8.GetBytes(jsonCommand); request.ContentLength = postBuffer.Length; Stream postDataStream = request.GetRequestStream(); postDataStream.Write(postBuffer, 0, postBuffer.Length); postDataStream.Close(); return request; }
protected virtual void TryInit() { if (_graphClient != null) return; if (_rootUri == null) throw new InvalidOperationException("The root URI should be set before this Neo4j service intance can be used."); try { _graphClient = _graphClientPool.GetClient(_rootUri); } catch (Exception ex) { if (ex.IsFatal()) throw; var message = "Acquiring a graph client for the graph " + _graphDescriptor.Name + " with the url " + _rootUri + " failed."; Logger.Error(ex, message); throw new ApplicationException(message, ex); } }
public string[] GetSchemaIndexData(IGraphClient graphClient) { string[] indexData = null; string schemaTxt = this.ReadSchemaTxt(graphClient); if (schemaTxt != string.Empty) { byte[] byteArray = Encoding.UTF8.GetBytes(schemaTxt); var textParser = new TextFieldParser(new MemoryStream(byteArray)); textParser.SetDelimiters(","); string[] dataPair = textParser.ReadFields(); if (dataPair != null) { indexData = dataPair[0].TrimEnd(new[] { '\r', '\n' }) .Replace(@"\r\n\r\n", "\t") .Replace(@"\r\n", ";") .Split('\t'); } } return indexData; }
public static void Register(HttpConfiguration config) { // Web API configuration and services // Web API routes config.MapHttpAttributeRoutes(); config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); config.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml"); config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType); //Use an IoC container and register as a Singleton var url = ConfigurationManager.AppSettings["GraphDBUrl"]; var user = ConfigurationManager.AppSettings["GraphDBUser"]; var password = ConfigurationManager.AppSettings["GraphDBPassword"]; var client = new GraphClient(new Uri(url), user, password); client.Connect(); GraphClient = client; }
public NodeReference(long id, IGraphClient client) { this.id = id; this.client = client; }
private static object SerializeDictionary(Type type, object value, IList <JsonConverter> converters, IGraphClient gc) { var keyType = type.GetGenericArguments()[0]; if (keyType != typeof(string)) { throw new NotSupportedException( $"Dictionary had keys with type '{keyType.Name}'. Only dictionaries with type '{nameof(String)}' are supported."); } var serialized = new Dictionary <string, object>(); foreach (var item in (dynamic)value) { string key = item.Key; object entry = item.Value; serialized[key] = Serialize(entry, converters, gc); } return(serialized); }
public ConnectedVertexSelector(IGraphClient graphClient, string relation) : base(graphClient) { _relation = relation; }
private static object SerializeObject(Type type, object value, IList <JsonConverter> converters, IGraphClient gc) { return(type.GetProperties(BindingFlags.Instance | BindingFlags.Public) .Where(pi => !(pi.GetIndexParameters().Any() || pi.IsDefined(typeof(JsonIgnoreAttribute)))) .ToDictionary(pi => pi.Name, pi => Serialize(pi.GetValue(value), converters, gc, pi.CustomAttributes))); }
private static object SerializeCollection(IEnumerable value, IList <JsonConverter> converters, IGraphClient gc) { return(value.Cast <object>().Select(x => Serialize(x, converters, gc)).ToArray()); }
public Neo4jPersistenceTestModule(IGraphClient graphClient) { this.graphClient = graphClient; }
public void DropIndex(IGraphClient graphClient, string label, string property) { this.indexHelper.DropIndex(graphClient, label, property); }
public StudentRepository(IGraphClient client, IRedisConnectionBuilder builder, IHubContext <MessageHub> hub) { _client = client; _redisConnection = builder.Connection; _hub = hub; }
public Handler(IOptions <Neo4JSettings> neo4jSettingsOptions) { _neo4jSettings = neo4jSettingsOptions.Value; _client = new GraphClient(new Uri(_neo4jSettings.Server), _neo4jSettings.UserName, _neo4jSettings.Password); }
public CypherJsonDeserializer(IGraphClient client, CypherResultMode resultMode, CypherResultFormat resultFormat) : this(client, resultMode, resultFormat, false) { }
public CrudRepository(IGraphClient graphClient) { this.Client = graphClient; }
public AuthenticationService(MongoService mongoService, IGraphClient graphClient) { _mongoService = mongoService; _graphClient = graphClient; }
public SelectSelector(IGraphClient graphClient, params string[] selectors) : base(graphClient) { Selectors = selectors; }
protected GraphClientBasedExecutionPolicy(IGraphClient client) { Client = client; }
public AulaRepository(IGraphClient graphClient) { _graphClient = graphClient; }
// This is internal for now because we ultimately want to remove the dependency // on IGraphClient once we move the Execute* methods to here internal GremlinClient(IGraphClient client) { this.client = client; }
public static void RegisterGraphClient(IGraphClient client) { var inspector = new OperationCompletedEventInspector(); client.OperationCompleted += inspector.OperationCompletedLog; }
public Neo4jTaskRepository(IGraphClient graphClient) { this.graphClient = graphClient; }
private static object Serialize(object value, IList <JsonConverter> converters, IGraphClient gc, IEnumerable <CustomAttributeData> customAttributes = null) { if (value == null) { return(null); } var type = value.GetType(); var typeInfo = type.GetTypeInfo(); var converter = converters.FirstOrDefault(c => c.CanConvert(type)); if (converter != null) { var serializer = new CustomJsonSerializer { JsonConverters = converters, JsonContractResolver = ((IRawGraphClient)gc).JsonContractResolver }; return(JsonConvert.DeserializeObject <CustomJsonConverterHelper>(serializer.Serialize(new { value })).Value); } if (customAttributes != null && customAttributes.Any(x => x.AttributeType == typeof(Neo4jDateTimeAttribute))) { return(value); } if (typeInfo.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary <,>)) { return(SerializeDictionary(type, value, converters, gc)); } if (typeInfo.IsClass && type != typeof(string)) { if (typeInfo.IsArray || typeInfo.ImplementedInterfaces.Contains(typeof(IEnumerable))) { return(SerializeCollection((IEnumerable)value, converters, gc)); } return(SerializeObject(type, value, converters, gc)); } return(SerializePrimitive(type, typeInfo, value)); }
public NodeReference(long id, IGraphClient client) : base(id, client) { CheckTNode(); }
public Neo4jPersistenceProvider(IGraphClient graphClient, IObjectSerializer objectSerializer) { this.graphClient = graphClient; this.objectSerializer = objectSerializer; }
public DocumentsDataService(IConnectionFactory connFactory, IPathsDataService paths, IDocumentsWorkflowsService documentsWorkflows) { this.client = connFactory.GetConnection(); this.paths = paths; this.documentsWorkflows = documentsWorkflows; }
public void DropConstraint(IGraphClient graphClient, string label, string property) { string firstArg = string.Format("c:{0}", label); string secondtArg = string.Format("c.{0}", property); graphClient.Cypher.DropUniqueConstraint(firstArg, secondtArg).ExecuteWithoutResults(); }
public Neo4jController(IGraphClient client, ICrudService crudService) { this.crudService = crudService; this.client = client; }
public ArtistRepository(IGraphClient graphClient) : base(graphClient) { }
private void PersistNode(INode node, IWorkflowDefinition definition, IGraphClient client) { foreach (var outgoingTransition in node.OutgoingTransitions) { client.Cypher.Match("(source:Node {Identifier: {sourceId}})") .Merge("(dest:Node {Identifier: {destId}})") .Merge("(source)-[t:TRANSITION]->(dest)") .Set("source = {source}") .Set("dest = {dest}") .Set("t = {transition}") .WithParams(new { source = new NodeModel { Identifier = node.Identifier, OperationType = node.Operation.AssemblyQualifiedName, IsEndNode = definition.EndNodes.Contains(node) }, dest = new NodeModel { Identifier = outgoingTransition.Destination.Identifier, OperationType = outgoingTransition.Destination.Operation.AssemblyQualifiedName, IsEndNode = definition.EndNodes.Contains(outgoingTransition.Destination) }, sourceId = node.Identifier, destId = outgoingTransition.Destination.Identifier, transition = new TransitionModel { Identifier = outgoingTransition.Identifier, IsDefault = outgoingTransition.IsDefault } }) .ExecuteWithoutResults(); PersistNode(outgoingTransition.Destination, definition, client); } }
/// <summary> /// Submits the given query to the <see cref="Gremlin.Net.CosmosDb.IGraphClient"/> /// and returns the result /// </summary> /// <typeparam name="T"></typeparam> /// <param name="graphClient">The graph client.</param> /// <param name="gremlinQuery">The traversal query.</param> /// <returns>Returns the result</returns> /// <exception cref="ArgumentNullException">traversal</exception> public static Task <IReadOnlyCollection <T> > SubmitAsync <T>(this IGraphClient graphClient, string gremlinQuery) { return(graphClient.SubmitAsync <T>(gremlinQuery, BuildDefaultSerializerSettings())); }
public RestExecutionPolicy(IGraphClient client) : base(client) { }
/// <summary> /// Submits the given traversal query to the <see cref="Gremlin.Net.CosmosDb.IGraphClient"/> /// and returns the result /// </summary> /// <typeparam name="T"></typeparam> /// <param name="graphClient">The graph client.</param> /// <param name="traversal">The traversal.</param> /// <returns>Returns the result</returns> /// <exception cref="ArgumentNullException">traversal</exception> public static Task <IReadOnlyCollection <T> > SubmitAsync <T>(this IGraphClient graphClient, ITraversal traversal) { return(graphClient.SubmitAsync <T>(traversal, BuildDefaultSerializerSettings())); }
public void DropIndex(IGraphClient graphClient, string label, string property) { string dropString = string.Format("INDEX ON :{0}({1})", label, property); graphClient.Cypher.Drop(dropString).ExecuteWithoutResults(); }
/// <summary> /// Submits the given traversal query to the <see cref="Gremlin.Net.CosmosDb.IGraphClient"/> /// and returns the result /// </summary> /// <typeparam name="S"></typeparam> /// <typeparam name="E"></typeparam> /// <param name="graphClient">The graph client.</param> /// <param name="traversal">The traversal.</param> /// <returns>Returns the result</returns> /// <exception cref="ArgumentNullException">traversal</exception> public static Task <IReadOnlyCollection <E> > SubmitAsync <S, E>(this IGraphClient graphClient, ISchemaBoundTraversal <S, E> traversal) { return(graphClient.SubmitAsync(traversal, BuildDefaultSerializerSettings())); }
public Task<HttpResponseMessage> EnqueueTask(string commandDescription, IGraphClient client, IExecutionPolicy policy, CypherQuery query) { // grab the endpoint in the same thread var txBaseEndpoint = policy.BaseEndpoint; var serializedQuery = policy.SerializeRequest(query); var task = new Task<HttpResponseMessage>(() => Request.With(client.ExecutionConfiguration) .Post(Endpoint ?? txBaseEndpoint) .WithJsonContent(serializedQuery) // HttpStatusCode.Created may be returned when emitting the first query on a transaction .WithExpectedStatusCodes(HttpStatusCode.OK, HttpStatusCode.Created) .ExecuteAsync( commandDescription, responseTask => { // we need to check for errors returned by the transaction. The difference with a normal REST cypher // query is that the errors are embedded within the result object, instead of having a 400 bad request // status code. var response = responseTask.Result; policy.AfterExecution(TransactionHttpUtils.GetMetadataFromResponse(response), this); return response; }) .Result ); _taskQueue.Add(task, _cancellationTokenSource.Token); if (_consumer == null) { _consumer = () => { while (true) { try { Task queuedTask; if (!_taskQueue.TryTake(out queuedTask, 0, _cancellationTokenSource.Token)) { // no items to consume _consumer = null; break; } queuedTask.RunSynchronously(); } catch (InvalidOperationException) { // we are done, CompleteAdding has been called break; } catch (OperationCanceledException) { // we are done, we were canceled break; } } }; _consumer.BeginInvoke(null, null); } return task; }
/// <summary> /// Submits the given traversal query to the <see cref="Gremlin.Net.CosmosDb.IGraphClient"/> /// and returns the result /// </summary> /// <typeparam name="S"></typeparam> /// <param name="graphClient">The graph client.</param> /// <param name="traversal">The traversal.</param> /// <returns>Returns the result</returns> /// <exception cref="ArgumentNullException">traversal</exception> public static Task <IReadOnlyCollection <Edge> > SubmitAsync <S>(this IGraphClient graphClient, ITraversal <S, Gremlin.Net.Structure.Edge> traversal) { return(graphClient.SubmitAsync <Edge>(traversal)); }
public StubClientPool() { var client = new GraphClient(new Uri("http://localhost:7474/db/data/")); client.Connect(); _client = client; }
public WhereSelector(IGraphClient graphClient, Expression <Func <T, bool> > expression) : base(graphClient) { _expression = expression; }
public NodeIndexExecutionPolicy(IGraphClient client) : base(client) { }
public UserRepository(IGraphClient client) : base(client) { }
public CypherFluentQuery(IGraphClient client, bool isWrite = true) : this(client, new QueryWriter(), isWrite) { IsWrite = isWrite; }
public static IStatementResult Run(this ITransaction session, CypherQuery query, IGraphClient gc) { return(session.Run(query.QueryText, query.ToNeo4jDriverParameters(gc))); }
public List<IIndexMetadata> ListAllIndexes(IGraphClient graphClient) { return this.indexHelper.ListAllIndexes(graphClient); }
// ReSharper disable once InconsistentNaming public static Dictionary <string, object> ToNeo4jDriverParameters(this CypherQuery query, IGraphClient gc) { return(query.QueryParameters.ToDictionary(item => item.Key, item => Serialize(item.Value))); }
public GroupRepository(IGraphClient client) : base(client) { _generator = new Generator(); }
/// <summary> /// Submits the given traversal query to the <see cref="Gremlin.Net.CosmosDb.IGraphClient"/> /// and returns the result /// </summary> /// <typeparam name="S"></typeparam> /// <typeparam name="E"></typeparam> /// <param name="graphClient">The graph client.</param> /// <param name="traversal">The traversal.</param> /// <param name="serializerSettings">The serializer settings.</param> /// <returns>Returns the result</returns> /// <exception cref="ArgumentNullException">traversal</exception> public static Task <IReadOnlyCollection <E> > SubmitAsync <S, E>(this IGraphClient graphClient, ITraversal <S, E> traversal, JsonSerializerSettings serializerSettings) { return(graphClient.SubmitAsync <E>(traversal, serializerSettings)); }
public BaseRepository(IGraphClient graphClient) { _graphClient = graphClient; }
public virtual string GetSchemaTxt(IGraphClient graphClient) { return(this.ReadSchemaTxt(graphClient)); }