/// <summary> /// Search from the originId to min and max level via any direction of edges /// </summary> /// <param name="arangoDatabase"></param> /// <param name="originId"></param> /// <param name="minDepth"></param> /// <param name="maxDepth"></param> /// <param name="edges"></param> /// <returns></returns> public static IEnumerable <RawEdgeTrace> TraverseRawFromOrigin( this IArangoDatabase arangoDatabase, string originId, int minDepth, int maxDepth, params Type[] edges) { var query = arangoDatabase.Query() .Traversal <JObject, JObject>(originId) .Depth(minDepth, maxDepth); if (edges != null) { foreach (var type in edges) { query = query.Edge(type.Name); } } return(query.AnyDirection() .Return(g => new RawEdgeTrace() { Edge = g.Edge, Vertex = g.Vertex }) .ToListAsync() .GetAwaiter() .GetResult()); }
/// <summary> /// Search from the originId to min and max level via any direction of edges /// </summary> /// <typeparam name="TTarget"></typeparam> /// <param name="arangoDatabase"></param> /// <param name="originId"></param> /// <param name="minDepth"></param> /// <param name="maxDepth"></param> /// <param name="edges"></param> /// <returns></returns> public static IEnumerable <TTarget> TraverseFromOrigin <TTarget>( this IArangoDatabase arangoDatabase, string originId, int minDepth, int maxDepth, params Type[] edges) where TTarget : VertexBase { var query = arangoDatabase.Query() .Traversal <TTarget, EdgeBase>(originId) .Depth(minDepth, maxDepth); if (edges != null) { foreach (var type in edges) { query = query.Edge(type.Name); } } return(query.AnyDirection() .Filter(g => AQL.Split(g.Vertex._id, "/")[0] == typeof(TTarget).Name) .Return(g => g.Vertex) .ToListAsync() .GetAwaiter() .GetResult()); }
/// <summary> /// Search from the originId to min and max level via any direction of edges /// </summary> /// <param name="arangoDatabase"></param> /// <param name="originId"></param> /// <param name="minDepth"></param> /// <param name="maxDepth"></param> /// <param name="edges"></param> /// <returns></returns> public static IEnumerable <EdgeTrace <TVertex, TEdge> > TraverseEdgeFromOrigin <TVertex, TEdge>( this IArangoDatabase arangoDatabase, string originId, int minDepth, int maxDepth, params Type[] edges) where TVertex : VertexBase where TEdge : EdgeBase { var query = arangoDatabase.Query() .Traversal <TVertex, TEdge>(originId) .Depth(minDepth, maxDepth); if (edges != null) { foreach (var type in edges) { query = query.Edge(type.Name); } } return(query.AnyDirection() .Return(g => new EdgeTrace <TVertex, TEdge>() { Edge = g.Edge, Vertex = g.Vertex }) .ToListAsync() .GetAwaiter() .GetResult()); }
public PropertyNames() { _toTest = new ObjectToSerialize(); _db = new ArangoDatabase(); _docSerializer = new DocumentSerializer(_db); _jsonSerializer = _docSerializer.CreateJsonSerializer(); }
public TestDatabaseSetup() { var sharedSetting = SharedSetting.Value; db = new ArangoDatabase(sharedSetting); ClearDatabase(); }
/// <summary> /// Constructor del controlador, es llamado cada vez que se genera la clase que es cuando ASP.NET Core necesite /// invocar a un método de esta clase, este constructor recibe 2 parametros que le son brindados /// mediante la inyección de dependencias que realiza ASP.NET Core, estos 2 parametros son utilizados /// para la inicialización de las propiedades de la clase /// </summary> /// <param name="notificationHub"></param> /// <param name="database"></param> /// <param name="projectReadOnlyHub"></param> public ProjectsController(IHubContext <NotificationHub> notificationHub, IArangoDatabase database, IHubContext <ReadOnlyProjectHub, IReadOnlyClient> projectReadOnlyHub) { ReadOnlyGroupHub = projectReadOnlyHub; Database = database; NotificationHub = notificationHub; }
public AqlModelVisitor(IArangoDatabase db) { QueryText = new StringBuilder(); QueryData = new QueryData(); CrudState = new VisitorCrudState(); this.Db = db; }
/// <summary> /// upsert edge to arango edge collection (T) /// </summary> /// <typeparam name="T"></typeparam> /// <param name="arangoDatabase"></param> /// <param name="item"></param> public static void UpsertEdge <T>(this IArangoDatabase arangoDatabase, T item) where T : EdgeBase { arangoDatabase.Query().Upsert <T>( arangoDB_item_for_upsert => new { _key = item._key }, _ => item, (_, old) => item) .Execute(); }
public UsersController(IConfiguration configuration, CloudBlobContainer container, IArangoDatabase database, IEmailSender sender, IPasswordHasher <User> passwordHasher) { EmailSender = sender; Database = database; Container = container; Configuration = configuration; PasswordHasher = passwordHasher; }
public static async Task <bool> IsAdmin(this IArangoDatabase database, string userId, string groupId) { var result = await database.CreateStatement <bool>( $@"LET isAdmin = (FOR v in 0..5000 INBOUND 'Group/{groupId}' Graph 'SubgroupGraph' PRUNE v.groupOwner == '{userId}' FILTER v.groupOwner == '{userId}' return v) return isAdmin != []").ToListAsync(); return(result.Count != 0 && result[0]); }
/// <summary> /// Constructor de ChatsController, recibe dos parametros, uno de ellos es una referencia al ChatHub de SignalR y el otro una referencia /// al NotificationHub de SignalR, ambos son inyectados por ASP.NET Core /// </summary> /// <param name="chatHub"></param> /// <param name="notificationHub"></param> /// <param name="database"></param> /// <param name="blobContainer"></param> public ChatsController(IHubContext <ChatHub> chatHub, IHubContext <NotificationHub> notificationHub, IArangoDatabase database, CloudBlobContainer blobContainer, IConfiguration configuration) { Configuration = configuration; BlobContainer = blobContainer; Database = database; _chatHub = chatHub; NotificationHub = notificationHub; }
/// <summary> /// Initializes a new instance of <see cref="ArangoQueryProvider"/> using a custom <see cref="IQueryParser"/>. /// </summary> public ArangoQueryProvider(Type queryableType, IQueryParser queryParser, IQueryExecutor executor, IArangoDatabase db) : base(LinqUtility.CheckNotNull("queryParser", queryParser), LinqUtility.CheckNotNull("executor", executor)) { LinqUtility.CheckNotNull("queryableType", queryableType); CheckQueryableType(queryableType); _queryableType = queryableType; this.db = db; }
internal static async Task Clear(IArangoDatabase db, string collectionName, CollectionType type = CollectionType.Document) { if ((await db.ListCollectionsAsync()).Any(c => c.Name == collectionName)) { await db.DropCollectionAsync(collectionName); } await db.CreateCollectionAsync(collectionName, type : type); }
public dataBaseManager(string urlWithPort, string database, string adminName, string password) { this.urlWithPort = urlWithPort; this.database = database; this.adminName = adminName; this.password = password; this.connect(); this.db = ArangoDatabase.CreateWithSetting(); }
public GenericStreamContent(IArangoDatabase db, Func<StreamWriter, Task> onStreamReady) { if (onStreamReady == null) throw new ArgumentNullException(nameof(onStreamReady)); this.db = db; this.onStreamReady = onStreamReady; this.Headers.ContentType = new MediaTypeHeaderValue("application/json"); }
/// <summary> /// test if the arango collection has this key /// </summary> /// <typeparam name="T"></typeparam> /// <param name="arangoDatabase"></param> /// <param name="key"></param> /// <returns></returns> public static bool HasKey <T>(this IArangoDatabase arangoDatabase, object key) where T : GraphBase { return(arangoDatabase.Query <T>() .Filter((item) => item._id == key.ToString()) .Return(item => item._key) .ToListAsync() .GetAwaiter() .GetResult() .Count > 0); }
public static async Task <Group> GetRootGroup(this IArangoDatabase database, string groupId) { var groups = database.CreateStatement <Group>($@" FOR g in 0..10000 INBOUND 'Group/{groupId}' Graph 'SubgroupGraph' PRUNE g.isRoot == true FILTER g.isRoot == true RETURN g"); return((await groups.ToListAsync()).FirstOrDefault()); }
/// <summary> /// get edge by key /// </summary> /// <typeparam name="T"></typeparam> /// <param name="arangoDatabase"></param> /// <param name="key"></param> /// <returns></returns> public static T GetEdgeByKey <T>(this IArangoDatabase arangoDatabase, object key) where T : EdgeBase { return(arangoDatabase.Query <T>() .Filter(item => item._key == key.ToString()) .Return(item => item) .ToListAsync() .GetAwaiter() .GetResult() .FirstOrDefault()); }
public CursorAsyncEnumerator(IArangoDatabase db, HttpCommand command, object data = null) { this.db = db; this.initiateCommand = command; this.CursorResult = new CursorResult { HasMore = true }; this.data = data; readerState = new ReaderState(); }
/// <summary> /// upsert an item to arango collection and ignore the null properties /// </summary> /// <typeparam name="T"></typeparam> /// <param name="arangoDatabase"></param> /// <param name="item"></param> public static void UpsertIgnoreNull <T>(this IArangoDatabase arangoDatabase, T item) where T : VertexBase { JObject jObject = JObject.FromObject(item, IgnoreNullJsonSerializer); arangoDatabase.Query().Upsert <T>( arangoDB_item_for_upsert => new { _key = item._key }, _ => jObject, (_, old) => jObject) .Execute(); }
/// <summary> /// Initializes a new instance of <see cref="DefaultQueryProvider"/> using a custom <see cref="IQueryParser"/>. /// </summary> /// <param name="queryableType"> /// A type implementing <see cref="IQueryable{T}"/>. This type is used to construct the chain of query operators. Must be a generic type /// definition. /// </param> /// <param name="queryParser">The <see cref="IQueryParser"/> used to parse queries. Specify an instance of /// <see cref="Parsing.Structure.QueryParser"/> for default behavior. See also <see cref="QueryParser.CreateDefault"/>.</param> /// <param name="executor">The <see cref="IQueryExecutor"/> used to execute queries against a specific query backend.</param> public AqlQueryProvider(Type queryableType, IQueryParser queryParser, IQueryExecutor executor, IArangoDatabase db) : base(CheckNotNull("queryParser", queryParser), CheckNotNull("executor", executor)) { CheckNotNull("queryableType", queryableType); CheckQueryableType(queryableType); this.db = db; _queryableType = queryableType; }
public GenericStreamContent(IArangoDatabase db, Func <StreamWriter, Task> onStreamReady) { if (onStreamReady == null) { throw new ArgumentNullException(nameof(onStreamReady)); } this.db = db; this.onStreamReady = onStreamReady; this.Headers.ContentType = new MediaTypeHeaderValue("application/json"); }
/// <summary> /// upsert edge with the from and to instances /// </summary> /// <typeparam name="TEdge"></typeparam> /// <typeparam name="TFrom"></typeparam> /// <typeparam name="TTo"></typeparam> /// <param name="arangoDatabase"></param> /// <param name="from"></param> /// <param name="to"></param> /// <param name="setter"></param> /// <returns></returns> public static TEdge UpsertEdge <TEdge, TFrom, TTo>(this IArangoDatabase arangoDatabase, TFrom from, TTo to, Action <TEdge> setter = null) where TEdge : EdgeBase, new() where TFrom : VertexBase where TTo : VertexBase { TEdge edge = new TEdge(); edge._from = $"{typeof(TFrom).Name}/{from._key}"; edge._to = $"{typeof(TTo).Name}/{to._key}"; edge.BuildIdWithFromTo(); setter?.Invoke(edge); arangoDatabase.UpsertEdge(edge); return(edge); }
/// <summary> /// upsert edge with the from and to instances /// </summary> /// <typeparam name="TEdge"></typeparam> /// <typeparam name="TFrom"></typeparam> /// <typeparam name="TTo"></typeparam> /// <param name="arangoDatabase"></param> /// <param name="from"></param> /// <param name="to"></param> /// <param name="setter"></param> /// <returns></returns> public static TEdge UpsertEdge <TEdge, TFrom, TTo>(this IArangoDatabase arangoDatabase, string keyFrom, string keyTo, Action <TEdge> setter = null) where TEdge : EdgeBase, new() where TFrom : VertexBase where TTo : VertexBase { TEdge edge = new TEdge(); edge._from = keyFrom.EnsureGraphId <TFrom>(); edge._to = keyTo.EnsureGraphId <TTo>(); edge.BuildIdWithFromTo(); setter?.Invoke(edge); arangoDatabase.UpsertEdge(edge); return(edge); }
/// <summary> /// upsert edge and ensure to side is unique /// </summary> /// <typeparam name="TEdge"></typeparam> /// <typeparam name="TFrom"></typeparam> /// <typeparam name="TTo"></typeparam> /// <param name="arangoDatabase"></param> /// <param name="from"></param> /// <param name="to"></param> /// <param name="setter"></param> /// <returns></returns> public static TEdge UpsertEdgeUniqueTo <TEdge, TFrom, TTo>(this IArangoDatabase arangoDatabase, TFrom from, TTo to, Action <TEdge> setter = null) where TEdge : EdgeBase, new() where TFrom : VertexBase where TTo : VertexBase { TEdge edge = new TEdge(); edge._from = from.GetId(); edge._to = to.GetId(); edge.BuildIdWithFromTo(); setter?.Invoke(edge); arangoDatabase.UpsertEdgeUniqueTo(edge); return(edge); }
public LoginController(IConfiguration configuration, IArangoDatabase database, HttpClient httpClient, CloudBlobContainer container, IPasswordHasher <User> passwordHasher, IEmailSender emailSender, IDataProtectionProvider protector) { DataProtector = protector.CreateProtector("MaxOrg.NewPassword").ToTimeLimitedDataProtector(); EmailSender = emailSender; Container = container; HttpClient = httpClient; Database = database; Configuration = configuration; m_passwordHasher = passwordHasher; }
private void CreateCollection(IArangoDatabase db, string collectionName, CollectionType type = CollectionType.Document) { try { db.CreateCollection(collectionName, type: type); } catch (Exception) { // ignore, it already exists } }
/// <summary> /// upsert edge to arango collection (T) and ensure the to side is unique /// </summary> /// <typeparam name="T"></typeparam> /// <param name="arangoDatabase"></param> /// <param name="item"></param> public static void UpsertEdgeUniqueTo <T>(this IArangoDatabase arangoDatabase, T item) where T : EdgeBase { arangoDatabase.Query <T>() .Filter(item_to_remove => item_to_remove._to == item._to) .Remove(item_to_remove => new { _key = item_to_remove._key }) .Execute(); arangoDatabase.Query().Upsert <T>( arangoDB_item_for_upsert => new { _key = item._key }, _ => item, (_, old) => item) .Execute(); }
public ArrangoDbWriter(string url, string Database, string UserName, string Password) { ArangoDatabase.ChangeSetting(s => { s.Database = Database; s.Url = url; s.Credential = new NetworkCredential(UserName, Password); s.SystemDatabaseCredential = new NetworkCredential(UserName, Password); }); db = ArangoDatabase.CreateWithSetting(); }
public ArangoDBRepositoryTests(ArangoRepositoryTestsFixtureData fixtureData) { var unitOfWork = fixtureData.UnitOfWork; var repository = new BaseRepository <FooArango>(unitOfWork); this._unitOfWork = unitOfWork; this._database = unitOfWork.Database; this._repositoryWriter = repository; this._repositoryReader = repository; this._repositoryWriterAsync = repository; this._repositoryReaderAsync = repository; }
public static void Connect(string collectionName) { if (Collection != null) { throw new TraceStateException("Connection already established."); } ArangoDatabase.ChangeSetting(s => { s.Database = "test"; s.Url = "http://localhost:8529"; // you can set other settings if you need s.Credential = new NetworkCredential("root", ""); s.SystemDatabaseCredential = new NetworkCredential("root", ""); }); client = ArangoDatabase.CreateWithSetting(); //client.CreateDatabase(Dns.GetHostName()); //just to update the description state var databases = client.ListDatabases(); if (client.Connection == null) { throw new TraceStateException("Local db is unreachable."); } //client.CreateCollection("logggs"); Collection = client.Collection(collectionName); Buffers = new LogBuffer[NumberOfBuffers]; for (int i = 0; i < NumberOfBuffers; i++) { Buffers[i] = new LogBuffer(); } Arbiter = new Arbiter2(Buffers); //I create a new delegate in order to call a method with a Conditional Attribute Arbiter.OnAllBuffersFilled += delegate { Flush(); }; timer = new Timer(2000); timer.AutoReset = true; timer.Elapsed += delegate { Timer_Elapsed(null, null); }; timer.Start(); }
public string QueryReplacedWithVariables(IArangoDatabase db) { string query = Query; string[] breakWords = new string[] { "for","filter","and","sort","limit","return","collect","let" ,"remove","update","replace","insert","upsert"}; foreach (var b in breakWords) query = query.Replace(b, Environment.NewLine + b); if(BindVars!=null) for (int i = 0; i < BindVars.Count; i++) query = query.Replace($"@{BindVars[i].Name}", new Serialization.DocumentSerializer(db).SerializeWithoutReader(BindVars[i].Value)); return query; }
public DocumentTracker(IArangoDatabase db) { this.db = db; }
public TestDatabaseSetup() { var sharedSetting = SharedSetting.Value; db = new ArangoDatabase(sharedSetting); }
public DocumentContractResolver(IArangoDatabase db) : base(true) { this.db = db; }
public static string ResolveCollectionName(IArangoDatabase db,Type itemType) { string collectionName = db.SharedSetting.Collection.ResolveCollectionName(itemType); return AddBacktickToName(collectionName); }
public BaseResultAnalyzer(IArangoDatabase db) { this.db = db; }
public static string ResolveMemberName(IArangoDatabase db,MemberInfo memberInfo) { return AddBacktickToName(ResolveMemberNameRaw(db,memberInfo)); }
public static string ResolveMemberNameRaw(IArangoDatabase db, MemberInfo memberInfo) { return ResolvePropertyNameRaw(db.SharedSetting.Collection.ResolvePropertyName(memberInfo.DeclaringType, memberInfo.Name)); }
public JsonContent(IArangoDatabase db,object data) { this.db = db; this.data = data; this.Headers.ContentType = new MediaTypeHeaderValue("application/json"); }
public HttpConnection(IArangoDatabase db) { this.db = db; }
public static JObject CreateJObject(object document,IArangoDatabase db) { return JObject.FromObject(document, new DocumentSerializer(db).CreateJsonSerializer()); }
public static string Serialize(object document, IArangoDatabase db) { return new DocumentSerializer(db).SerializeWithoutReader(document); }
public static void AssertSerialize(object document1,object document2, IArangoDatabase db) { Assert.Equal(Serialize(document1,db), Serialize(document2,db)); }