public void Should_create_and_clear_and_delete_collection() { Database.DeleteTestCollection(Database.TestDocumentCollectionName); ArangoDatabase db = Database.GetTestDatabase(); // set collection data ArangoCollection collection = new ArangoCollection(); collection.Name = Database.TestDocumentCollectionName; // create collection in database db.Collection.Create(collection); // clear collection data var isCleared = db.Collection.Clear(Database.TestDocumentCollectionName); Assert.AreEqual(true, isCleared); // delete collection from database bool isDeleted = db.Collection.Delete(collection.Name); // check if the collection was deleted from database Assert.AreEqual(true, isDeleted); }
public async Task Clear() { using (var db = ArangoDatabase.CreateWithSetting(this.settingsService.DatabaseName)) { await Helper.Clear(db, nameof(Neuron)); var lgs = await db.ListGraphsAsync(); if (lgs.Any(a => a.Id == "_graphs/" + Constants.GraphName)) { await db.Graph(Constants.GraphName).DropAsync(true); } await db.Graph(Constants.GraphName).CreateAsync(new List <EdgeDefinitionTypedData> { new EdgeDefinitionTypedData() { Collection = typeof(Terminal), From = new List <Type> { typeof(Neuron) }, To = new List <Type> { typeof(Neuron) } } }); } }
public async Task Clear() { using (var db = ArangoDatabase.CreateWithSetting(this.settingsService.DatabaseName)) { await Helper.Clear(db, nameof(Terminal), CollectionType.Edge); } }
public async Task Save(Settings dto, CancellationToken cancellationToken = default(CancellationToken)) { if (dto.Id != Guid.Empty.ToString()) { throw new ArgumentException("Invalid 'Settings' document id."); } using (var db = ArangoDatabase.CreateWithSetting(this.settingsService.DatabaseName)) { if (!db.ListCollections().Any(c => c.Name == nameof(Settings))) { throw new InvalidOperationException( $"Collection '{nameof(Settings)}' not initialized." ); } if (await db.DocumentAsync <Settings>(dto.Id) == null) { await db.InsertAsync <Settings>(dto); } else { await db.ReplaceByIdAsync <Settings>(dto.Id, dto); } } }
public async Task Clear() { using (var db = ArangoDatabase.CreateWithSetting(this.settingsService.DatabaseName)) { await Helper.Clear(db, nameof(Settings)); } }
private async Task UpdateUser(User userToUpdate) { using (var db = ArangoDatabase.CreateWithSetting()) { await db.UpdateByIdAsync <User>(userToUpdate.Id, userToUpdate); } }
public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { this.Log = providerRuntime.GetLogger(nameof(ArangoStorageProvider)); this.Name = name; var databaseName = config.GetProperty("DatabaseName", "Orleans"); var url = config.GetProperty("Url", "http://localhost:8529"); var username = config.GetProperty("Username", "root"); var password = config.GetProperty("Password", ""); var waitForSync = config.GetBoolProperty("WaitForSync", true); collectionName = config.GetProperty("CollectionName", null); var serializationManager = providerRuntime.ServiceProvider.GetRequiredService <SerializationManager>(); var grainRefConverter = new GrainReferenceConverter(serializationManager, providerRuntime.GrainFactory); ArangoDatabase.ChangeSetting(s => { s.Database = databaseName; s.Url = url; s.Credential = new NetworkCredential(username, password); s.DisableChangeTracking = true; s.WaitForSync = waitForSync; s.Serialization.Converters.Add(grainRefConverter); }); jsonSerializerSettings = new JsonSerializer(); jsonSerializerSettings.Converters.Add(grainRefConverter); this.Database = new ArangoDatabase(); return(Task.CompletedTask); }
public async Task <ActionResult> GetUserInfo(string userId) { using (var db = ArangoDatabase.CreateWithSetting()) { var user = await(from u in db.Query <User>() where u.Key == userId select new { u.Username, u.RealName, u.Email, u.Description, u.Birthday, u.Occupation, u.Key }) .FirstOrDefaultAsync(); if (user == null) { return(NotFound()); } return(Ok(new { user.Username, user.RealName, user.Email, user.Description, user.Birthday, user.Occupation, user.Key, ProfilePicture = $"{Configuration["AppSettings:DefaultURL"]}/api/users/{user.Key}/profile.jpeg" })); } }
public async Task <Terminal> Get(Guid guid, Graph.Common.NeuronQuery neuronQuery, CancellationToken cancellationToken = default(CancellationToken)) { Terminal result = null; NeuronRepository.FillWithDefaults(neuronQuery, this.settingsService); using (var db = ArangoDatabase.CreateWithSetting(this.settingsService.DatabaseName)) { AssertionConcern.AssertStateTrue(await Helper.GraphExists(db), Constants.Messages.Error.GraphNotInitialized); var t = await db.DocumentAsync <Terminal>(guid.ToString()); if ( t != null && ( neuronQuery.TerminalActiveValues.Value.HasFlag(Graph.Common.ActiveValues.All) || ( Helper.TryConvert(neuronQuery.TerminalActiveValues.Value, out bool activeValue) && t.Active == activeValue ) ) ) { result = t.CloneExcludeSynapticPrefix(); } } return(result); }
static void Main(string[] args) { var creds = new NetworkCredential("root", "123456"); ArangoDatabase.ChangeSetting(s => { s.Database = "IdentityTest"; s.Url = "http://localhost:8529/"; s.Credential = creds; s.SystemDatabaseCredential = creds; }); // Keys must be saved without encoding but // retrieved with UrlEncoding. // using (var database = ArangoDatabase.CreateWithSetting()) { database.Collection("Hello").Insert(new Hello { Key = ToBase64UrlFromString("hello/world"), Text = "Hello world" }); var data = database.Collection("Hello").Document <Hello>(ToBase64UrlFromString("hello/world")); //var grant = database.Collection("PersistedGrants").Document<PersistedGrants>(WebUtility.UrlEncode("gmzAS+Gw3zjqPNU0sFvRBC9AGkZqXyNxRx+HQhPiUvs=")); //Console.WriteLine(grant.Key); } }
public ActionResult Save(String nombre, String usuario, String contrasenia) { using (ArangoDB.Client.ArangoDatabase db = new ArangoDatabase(url: "http://52.32.98.159:8529", database: "Expedia")) { string id = Guid.NewGuid().ToString(); var usuarios = new Usuarios { _key = id, nombre = nombre, usuario = usuario, contrasenia = contrasenia }; var query = (from User in db.Query <Usuarios>() where User.usuario == usuario select new { User.usuario }).ToList(); if (query.Count == 0) { db.Insert <Usuarios>(usuarios); return(View("Detail", usuarios)); } else { return(View("Create", usuarios)); } } }
internal async static Task Remove(object value, string collectionName, string databaseName) { using (var db = ArangoDatabase.CreateWithSetting(databaseName)) { AssertionConcern.AssertStateTrue(await Helper.GraphExists(db), Constants.Messages.Error.GraphNotInitialized); var txnParams = new List <object> { value }; string[] collections = new string[] { collectionName }; // https://docs.arangodb.com/3.1/Manual/Appendix/JavaScriptModules/ArangoDB.html // This 'ArangoDB' module should not be confused with the arangojs JavaScript driver. var r = await db.ExecuteTransactionAsync <object>( new TransactionData() { Collections = new TransactionCollection() { Read = collections, Write = collections }, Action = $@" function (params) {{ const db = require('@arangodb').db; if (db.{collectionName}.exists(params[0])) {{ db.{collectionName}.remove(params[0]); }} }}", Params = txnParams } ); } }
[SetUp()] public void Init() { Database.CreateTestDatabase(Database.TestDatabaseGeneral); db = Database.GetTestDatabase(); List <ArangoGraphEdgeDefinition> eds = new List <ArangoGraphEdgeDefinition>(); ed1 = new ArangoGraphEdgeDefinition( edgeCol1, new List <String> { fromCol1, fromCol2 }, new List <String> { toCol1, toCol2 } ); eds.Add(ed1); ed2 = new ArangoGraphEdgeDefinition( edgeCol2, new List <String> { fromCol2, fromCol3 }, new List <String> { toCol2, toCol3 } ); eds.Add(ed2); List <String> vertexCollections = new List <String>(); vertexCollections.Add(vertexCol1); vertexCollections.Add(vertexCol2); vertexCollections.Add(vertexCol3); g = db.Graph.Create(graphName, eds, vertexCollections); }
public ConfigDbContext(IOptions <ConfigDbSettings> options) { var configDbSettings = options.Value; ArangoDatabase.ChangeSetting(s => { s.Database = configDbSettings.DbName; s.Url = configDbSettings.Url; s.Credential = new NetworkCredential(configDbSettings.UserName, configDbSettings.Password); s.SystemDatabaseCredential = new NetworkCredential(configDbSettings.UserName, configDbSettings.Password); }); using (var db = ArangoDatabase.CreateWithSetting()) { Versions = db.Document <DbVersions>(configDbSettings.BaseVersion); AppDefaults = db.Document <DbAppDefaults>(Versions.AppDefaults); UserDefaults = db.Document <DbUserDefaults>(Versions.UserDefaults); Cakes = db.Document <DbCakes>(Versions.Cakes); Avatars = db.Document <DbAvatars>(Versions.Avatars); Buildings = db.Document <DbBuildings>(Versions.Buildings); Store = db.Document <DbStore>(Versions.Store); } }
public async Task StoreAsync(PersistedGrant grant) { using (var database = ArangoDatabase.CreateWithSetting()) { var collection = database.Collection(_arangoDBConfig.Collections.PersistedGrants); var encodedKey = ToBase64UrlFromString(grant.Key); if (await collection.ExistsAsync(encodedKey)) { return; } await collection .InsertAsync( new ArangoDBPersistedGrant { Key = encodedKey, GrantKey = grant.Key, ClientId = grant.ClientId, CreationTime = grant.CreationTime, Data = grant.Data, Expiration = grant.Expiration, SubjectId = grant.SubjectId, Type = grant.Type } ); } }
public void Should_create_and_get_and_delete_collection() { Database.DeleteTestCollection(Database.TestDocumentCollectionName); ArangoDatabase db = Database.GetTestDatabase(); // set collection data ArangoCollection collection = new ArangoCollection(); collection.Name = Database.TestDocumentCollectionName; // create collection in database db.Collection.Create(collection); // get collection from database ArangoCollection returnedCollection = db.Collection.Get(Database.TestDocumentCollectionName); // check collection data retrieved from server Assert.AreEqual(collection.Id, returnedCollection.Id); Assert.AreEqual(collection.Name, returnedCollection.Name); Assert.AreEqual(collection.Type, returnedCollection.Type); Assert.AreEqual(collection.Status, returnedCollection.Status); // delete collection from database bool isDeleted = db.Collection.Delete(collection.Name); // check if the collection was deleted from database Assert.AreEqual(true, isDeleted); }
public void Should_create_and_delete_collection() { Database.DeleteTestCollection(Database.TestEdgeCollectionName); ArangoDatabase db = Database.GetTestDatabase(); // set collection data ArangoCollection collection = new ArangoCollection(); collection.Name = Database.TestEdgeCollectionName; collection.Type = ArangoCollectionType.Edge; collection.WaitForSync = true; // create collection in database db.Collection.Create(collection); // check collection data retrieved from server Assert.AreEqual(false, string.IsNullOrEmpty(collection.Id)); Assert.AreEqual(Database.TestEdgeCollectionName, collection.Name); Assert.AreEqual(ArangoCollectionType.Edge, collection.Type); Assert.AreEqual(ArangoCollectionStatus.Loaded, collection.Status); Assert.AreEqual(true, collection.WaitForSync); Assert.AreEqual(false, collection.IsSystem); Assert.AreEqual(false, collection.IsVolatile); // delete collection from database bool isDeleted = db.Collection.Delete(collection.Name); // check if the collection was deleted from database Assert.AreEqual(true, isDeleted); }
public ActionResult AddThingsToDo(Int64 key) { if (Session["userKey"] != null) { using (ArangoDatabase db = new ArangoDatabase(url: "http://52.32.98.159:8529", database: "Expedia")) { var query = from thingsToDo in db.Query <ThingsToDo>() where thingsToDo._key == key select new { thingsToDo.FechaDeFin, thingsToDo.FechaDeInicio }; // ViewData["FechaDeFin"] = query.First().FechaDeFin; } using (WebClient wc = new WebClient()) { //TTD var jsonttd = wc.DownloadString("http://52.32.98.159:8529/_db/Expedia/_api/document/ThingsToDo/" + key); System.Web.Script.Serialization.JavaScriptSerializer jsSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); ThingsToDo thingsToDo = jsSerializer.Deserialize <ThingsToDo>(jsonttd); //Usuario var jsonU = wc.DownloadString("http://52.32.98.159:8529/_db/Expedia/_api/document/ThingsToDo/" + key); System.Web.Script.Serialization.JavaScriptSerializer jsSerializerU = new System.Web.Script.Serialization.JavaScriptSerializer(); ThingsToDo thingsTo = jsSerializerU.Deserialize <ThingsToDo>(jsonU); } // usuario.thingsToDo.Add(thingToDo); // db.Update<Usuarios>(usuario); } return(null); }
public async Task <IActionResult> GetUsersOfChat(string chatId) { using (var db = ArangoDatabase.CreateWithSetting()) { var group = await db.Query <Chat>() .Where(c => c.Key == chatId) .Select(c => c).FirstOrDefaultAsync(); if (group == null) { return(NotFound()); } var traversalResult = await db.TraverseAsync <User, Chat>(new TraversalConfig { StartVertex = group.Id, GraphName = "ChatUsersGraph", Direction = EdgeDirection.Outbound, MinDepth = 1, MaxDepth = 1 }); var chats = traversalResult.Visited.Vertices; var users = chats.Select(u => new { u.Key, u.Username }); return(Ok(users)); } }
public void deleteDB(string name) { this.connect(); using (var db = ArangoDatabase.CreateWithSetting()) { db.DropDatabase(name); } }
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 async Task RemoveAsync(string key) { using (var database = ArangoDatabase.CreateWithSetting()) { var encodedKey = WebUtility.UrlEncode(key); await database.Collection(_arangoDBConfig.Collections.PersistedGrants) .RemoveByIdAsync(encodedKey); } }
public Task Close(CancellationToken ct) { if (Database != null) { Database.Dispose(); Database = null; } return(Task.CompletedTask); }
public async Task <bool> CreateAsync(ArangoDatabase database, CancellationToken cancellationToken = default) { database.Name = RealmPrefix(database.Name); var res = await SendAsync <ArangoVoid>(null, HttpMethod.Post, ApiPath("_system", "database"), database, false, cancellationToken : cancellationToken); return(res != null); }
private async Task <User> GetUserWithId(string userId) { using (var db = ArangoDatabase.CreateWithSetting()) { var selectedUser = await(from u in db.Query <Models.Users.User>() where u.Key == userId select u).FirstOrDefaultAsync(); return(selectedUser); } }
public DatabaseManager() { DatabaseSharedSetting setting = new DatabaseSharedSetting(); setting.Credential.Password = "******"; setting.Credential.UserName = "******"; setting.Database = "test"; setting.Url = "http://95.213.191.243:8529"; Database = new ArangoDatabase(setting); }
public ArangoConnection(ArangoOptions options) { ArangoDatabase.ChangeSetting(ArangoID, a => { a.Url = options.Url; a.Credential = options.Credential; a.SystemDatabaseCredential = options.SystemCredential; a.Database = options.Database; }); }
public void SimpleSetting() { // you can setup a database-setting with just url and database-name using (IArangoDatabase db = new ArangoDatabase(url: "http://localhost:8529", database: "ExampleDB")) { Assert.Equal(db.SharedSetting.Database, "ExampleDB"); Assert.Equal(db.SharedSetting.Url, "http://localhost:8529/"); } }
public async Task RemoveAllAsync(string subjectId, string clientId, string type) { using (var database = ArangoDatabase.CreateWithSetting()) { await database.Query <ArangoDBPersistedGrant>() .Where(pg => pg.SubjectId == subjectId && pg.ClientId == clientId && pg.Type == type) .Remove() .ToListAsync(); } }
public void createDB(string name) { this.connect(); using (var db = ArangoDatabase.CreateWithSetting()) { db.CreateDatabase(name); //var currentDatabaseInfo = db.CurrentDatabaseInformation(); //Console.WriteLine(currentDatabaseInfo.Path); } }
public void ParseBatchList() { using (var reader = GenerateReader(JsonSample.ListResult)) { var db = new ArangoDatabase(); var documentParser = new DocumentParser(db); BaseResult baseResult = null; var personList = documentParser.ParseBatchResult<Person>(reader, out baseResult); Assert.Equal(personList.Count, 2); Assert.Equal(personList[0].Age, 27); Assert.Equal(personList[0].Fullname, "raoof hojat"); Assert.Equal(personList[0].Height, 172); Assert.Equal(personList[1].Age, 7); Assert.Equal(personList[1].Fullname, "hojat raoof"); Assert.Equal(personList[1].Height, 721); var info1 = db.FindDocumentInfo(personList[0]); Assert.NotNull(info1.Document); Assert.Equal(info1.Id, "Person/KEY1"); Assert.Equal(info1.Key, "KEY1"); Assert.Equal(info1.Rev, "REV1"); var info2 = db.FindDocumentInfo(personList[1]); Assert.NotNull(info2.Document); Assert.Equal(info2.Id, "Person/KEY2"); Assert.Equal(info2.Key, "KEY2"); Assert.Equal(info2.Rev, "REV2"); Assert.Equal(baseResult.Code, 200); Assert.Equal(baseResult.Error, false); } }
public void ParseBatchErrorDocumentWithNotThrowing() { using (var reader = GenerateReader(JsonSample.Error)) { var db = new ArangoDatabase(); db.Setting.ThrowForServerErrors = false; var documentParser = new DocumentParser(db); BaseResult baseResult = null; var list = documentParser.ParseBatchResult<Person>(reader, out baseResult); Assert.Equal(list.Count, 0); Assert.Equal(baseResult.Error, true); Assert.Equal(baseResult.Code, 400); Assert.Equal(baseResult.ErrorMessage, "ERROR"); Assert.Equal(baseResult.ErrorNum, 1202); } }