Esempio n. 1
0
        public void Dispose()
        {
            var databases = ArangoClient.ListDatabases(
                Database.Hostname,
                Database.Port,
                Database.IsSecured,
                Database.UserName,
                Database.Password
                );

            if (databases.Contains(Database.TestDatabaseOneTime))
            {
                ArangoClient.DeleteDatabase(
                    Database.Hostname,
                    Database.Port,
                    Database.IsSecured,
                    Database.TestDatabaseOneTime,
                    Database.UserName,
                    Database.Password
                    );
            }

            if (databases.Contains(Database.TestDatabaseGeneral))
            {
                ArangoClient.DeleteDatabase(
                    Database.Hostname,
                    Database.Port,
                    Database.IsSecured,
                    Database.TestDatabaseGeneral,
                    Database.UserName,
                    Database.Password
                    );
            }
        }
Esempio n. 2
0
        static Database()
        {
            TestDatabaseOneTime = "testOneTimeDatabase001xyzLatif";
            TestDatabaseGeneral = "testDatabaseGeneral001xyzLatif";

            TestDocumentCollectionName = "testDocumentCollection001xyzLatif";
            TestEdgeCollectionName     = "testEdgeCollection001xyzLatif";

            Hostname = "127.0.0.1";
            Port     = 8529;
//            Hostname = "192.168.173.6";
//            Port = 8530;
            IsSecured    = false;
            DatabaseName = TestDatabaseGeneral;
            Alias        = "test";
            UserName     = "";
            Password     = "";

            ArangoClient.AddConnection(
                Hostname,
                Port,
                IsSecured,
                DatabaseName,
                Alias,
                UserName,
                Password
                );
        }
Esempio n. 3
0
        public void Init_WithDefaultSettings_ShouldSameAsDefault()
        {
            ArangoClient client = new ArangoClient();

            client.Init();

            Assert.Same(client.Settings, ArangoClientSettings.Default);
        }
		public void Init_WithDefaultSettings_ShouldSameAsDefault()
		{
			ArangoClient client = new ArangoClient();

			client.Init();

			Assert.Same(client.Settings, ArangoClientSettings.Default);
		}
        public TestCaseWithClient()
        {
            LogManager.SetFactory(new ConsoleLoggerFactory());

            Logger = LogManager.GetLogger("Tests");

            Client = new ArangoClient();

            Client.Init();
        }
		public TestCaseWithClient()
		{
			LogManager.SetFactory(new ConsoleLoggerFactory());

			Logger = LogManager.GetLogger("Tests");

			Client = new ArangoClient();

			Client.Init();
		}
Esempio n. 7
0
        public void Dispatch_ThrowExceptionsFalse_NotThrowException()
        {
            using (ArangoClient client = new ArangoClient())
            {
                client.Init();

                var response = client.Database.Drop(ArangoConventions.SystemDatabase);

                response.AssertFail();
            }
        }
		public void Dispatch_ThrowExceptionsFalse_NotThrowException()
		{
			using (ArangoClient client = new ArangoClient())
			{
				client.Init();

				var response = client.Database.Drop(ArangoConventions.SystemDatabase);

				response.AssertFail();
			}
		}
Esempio n. 9
0
        public void Dispatch_ThrowExceptionsTrue_ShouldThrowException()
        {
            using (ArangoClient client = new ArangoClient())
            {
                client.Init(new ArangoClientSettings
                {
                    ThrowExceptions = true
                });

                Assert.Throws <ArangoException>(() => client.Database.Drop(ArangoConventions.SystemDatabase));
            }
        }
		public void Dispatch_ThrowExceptionsTrue_ShouldThrowException()
		{
			using (ArangoClient client = new ArangoClient())
			{
				client.Init(new ArangoClientSettings
				{
					ThrowExceptions = true
				});

				Assert.Throws<ArangoException>(() => client.Database.Drop(ArangoConventions.SystemDatabase));
			}
		}
Esempio n. 11
0
        public static void CreateTestDatabase(string databaseName)
        {
            DeleteTestDatabase(databaseName);

            ArangoClient.CreateDatabase(
                Database.Hostname,
                Database.Port,
                Database.IsSecured,
                databaseName,
                Database.UserName,
                Database.Password
                );
        }
Esempio n. 12
0
        public void Init_WithSpecificSettings_ShouldNotEqual()
        {
            ArangoClient client = new ArangoClient();

            client.Init(new ArangoClientSettings
            {
                Hostname = "localhost",
                Port     = 8529
            });

            Assert.NotSame(ArangoClientSettings.Default, client.Settings);
            Assert.Equal("localhost", client.Settings.Hostname);
            Assert.Equal(8529, client.Settings.Port);
        }
		public void Init_WithSpecificSettings_ShouldNotEqual()
		{
			ArangoClient client = new ArangoClient();

			client.Init(new ArangoClientSettings
			{
				Hostname = "localhost",
				Port = 8529
			});

			Assert.NotSame(ArangoClientSettings.Default, client.Settings);
			Assert.Equal("localhost", client.Settings.Hostname);
			Assert.Equal(8529, client.Settings.Port);
		}
Esempio n. 14
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            //services.AddDbContext<ApplicationDbContext>(options =>
            //    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            //services.AddIdentity<ApplicationUser, IdentityRole>()
            //    .AddEntityFrameworkStores<ApplicationDbContext>()
            //    .AddDefaultTokenProviders();

            ArangoClient.Client().SetDefaultDatabase(new BorderEast.ArangoDB.Client.Database.ClientSettings()
            {
                DatabaseName       = "_system",
                Protocol           = BorderEast.ArangoDB.Client.Database.ProtocolType.HTTP,
                ServerAddress      = "localhost",
                ServerPort         = 8529,
                SystemCredential   = new System.Net.NetworkCredential("root", Environment.GetEnvironmentVariable("USERNAME")),
                DatabaseCredential = new System.Net.NetworkCredential("root", Environment.GetEnvironmentVariable("USERNAME")),
                AutoCreate         = true,
                HTTPClient         = new System.Net.Http.HttpClient(),
                IsDebug            = true
            });

            services.AddSingleton <IArangoClient>(ArangoClient.Client());

            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddArangoDbStores()
            .AddDefaultTokenProviders();

            services.ConfigureApplicationCookie(options =>
            {
                options.CookieName = "Interop";
            });

            services.AddMvc();

            // Add application services.
            services.AddTransient <IEmailSender, AuthMessageSender>();
            services.AddTransient <ISmsSender, AuthMessageSender>();
        }
Esempio n. 15
0
        public static void DeleteTestDatabase(string databaseName)
        {
            var databases = ArangoClient.ListDatabases(
                Database.Hostname,
                Database.Port,
                Database.IsSecured,
                Database.UserName,
                Database.Password
                );

            if (databases.Contains(databaseName))
            {
                ArangoClient.DeleteDatabase(
                    Database.Hostname,
                    Database.Port,
                    Database.IsSecured,
                    databaseName,
                    Database.UserName,
                    Database.Password
                    );
            }
        }
Esempio n. 16
0
        public void Should_create_database_and_return_list_of_all_databases()
        {
            var created = ArangoClient.CreateDatabase(
                Database.Hostname,
                Database.Port,
                Database.IsSecured,
                Database.TestDatabaseOneTime,
                Database.UserName,
                Database.Password
                );

            Assert.AreEqual(true, created);

            var databases = ArangoClient.ListDatabases(
                Database.Hostname,
                Database.Port,
                Database.IsSecured,
                Database.UserName,
                Database.Password
                );

            Assert.AreEqual(true, databases.Contains(Database.TestDatabaseOneTime));
        }
Esempio n. 17
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            ArangoClient.Client().SetDefaultDatabase(new BorderEast.ArangoDB.Client.Database.ClientSettings()
            {
                DatabaseName       = "_system",
                Protocol           = BorderEast.ArangoDB.Client.Database.ProtocolType.HTTP,
                ServerAddress      = "localhost",
                ServerPort         = 8529,
                SystemCredential   = new System.Net.NetworkCredential("root", ""),
                DatabaseCredential = new System.Net.NetworkCredential("root", ""),
                AutoCreate         = true,
                HTTPClient         = new System.Net.Http.HttpClient(),
                IsDebug            = true
            });

            services.AddSingleton(Configuration);
            services.AddSingleton <IArangoClient>(ArangoClient.Client());        // AddSingleton shared with everyone who needs it for lifetime of the application
            services.AddScoped <IContactStore, ArangoContactStore>();            // AddScoped adds it within the scope of a single request
            services.AddAutoMapper();                                            // for doing mappings/custom mappings (resolvers) between Entities and models
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); // for ContactUrlResolver
            services.AddCors();

            services.AddIdentity <ApplicationUser, IdentityRole>(options => {
                options.Cookies.ApplicationCookie.AuthenticationScheme = "ApplicationCookie";
                options.Cookies.ApplicationCookie.CookieName           = "Interop";
            })
            .AddArangoDbStores()
            .AddDefaultTokenProviders();

            services.AddMvc();

            // Add application services.
            services.AddTransient <IEmailSender, AuthMessageSender>(); // AddTransient recreates it everytime
            services.AddTransient <ISmsSender, AuthMessageSender>();
        }
Esempio n. 18
0
        public void Should_create_and_delete_database()
        {
            var created = ArangoClient.CreateDatabase(
                Database.Hostname,
                Database.Port,
                Database.IsSecured,
                Database.TestDatabaseGeneral,
                Database.UserName,
                Database.Password
                );

            Assert.AreEqual(true, created);

            var deleted = ArangoClient.DeleteDatabase(
                Database.Hostname,
                Database.Port,
                Database.IsSecured,
                Database.TestDatabaseGeneral,
                Database.UserName,
                Database.Password
                );

            Assert.AreEqual(true, deleted);
        }
		public void SimpleUsage()
		{
			using (var client = new ArangoClient())
			{
				// Init the client, is possible to define settings like host/port
				client.Init();

				// Create new database
				client.Database.Create("ApiTests");

				// Scope to the recently created database
				using (var db = client.UseDatabase("ApiTests"))
				{
					// Create Station document collection
					db.Collection.Create("Station");

					// Create a station with key ZEK
					var stationZEK = new JObject
					{
						{ "_key", "ZEK" },
						{ "Name", "ZEK" },
						{ "Capacity", 2 }
					};

					// All operations return ArangoResponse generic type
					ArangoResponse<JObject> createResult = db.Document.Create(stationZEK, "Station");

					// By default, this API doesn't throws a Exception if an operation fail, 
					// always is good check the Status.Error property. 
					// This behavior can be configured in ArangoClientSettings.ThrowExceptions
					if (createResult.Status.Error)
					{
						throw new Exception(createResult.Status.ErrorMessage);
					}

					// Or just call the ThrowIfError() method
					createResult.ThrowIfError();

					// Status has other details
					// https://www.arangodb.org/manuals/current/ImplementorManualArangoErrors.html
					int errorNum = createResult.Status.ErrorNum;
					int code = createResult.Status.Code;
					HttpStatusCode httpStatusCode = createResult.Status.StatusCode;
					TimeSpan totalDuration = createResult.Status.TotalDuration;
					TimeSpan serverDuration = createResult.Status.ServerDuration;

					// Each operation have a type of result
					JObject resultOfOperation = createResult.Result;

					// Create the main line of ZEK station
					var lineZEK1 = new JObject
					{
						{"Name", "ZEK1"},
						{"MainLine", true}
					};

					// Is possible to use the SetKey extension method to set the _key
					lineZEK1.SetKey("ZEK1");

					// Are possible to create collections on the fly
					db.Document.Create(lineZEK1, "Line", createCollection: true);

					// Now, we create the edge collection to link Station with Lines
					db.Collection.Create("Station-Line", CollectionType.Edge);

					// Create the edge to link ZEK station with ZEK1 line
					db.Edge.Create("Station-Line", "Station/ZEK", "Line/ZEK1", "ZEK-ZEK1");
				}

				// To finalize the test, drop the database
				client.Database.Drop("ApiTests");
			}
		}
        public void SimpleUsage()
        {
            using (var client = new ArangoClient())
            {
                // Init the client, is possible to define settings like host/port
                client.Init();

                // Create new database
                client.Database.Create("ApiTests");

                // Scope to the recently created database
                using (var db = client.UseDatabase("ApiTests"))
                {
                    // Create Station document collection
                    db.Collection.Create("Station");

                    // Create a station with key ZEK
                    var stationZEK = new JObject
                    {
                        { "_key", "ZEK" },
                        { "Name", "ZEK" },
                        { "Capacity", 2 }
                    };

                    // All operations return ArangoResponse generic type
                    ArangoResponse <JObject> createResult = db.Document.Create(stationZEK, "Station");

                    // By default, this API doesn't throws a Exception if an operation fail,
                    // always is good check the Status.Error property.
                    // This behavior can be configured in ArangoClientSettings.ThrowExceptions
                    if (createResult.Status.Error)
                    {
                        throw new Exception(createResult.Status.ErrorMessage);
                    }

                    // Or just call the ThrowIfError() method
                    createResult.ThrowIfError();

                    // Status has other details
                    // https://www.arangodb.org/manuals/current/ImplementorManualArangoErrors.html
                    int            errorNum       = createResult.Status.ErrorNum;
                    int            code           = createResult.Status.Code;
                    HttpStatusCode httpStatusCode = createResult.Status.StatusCode;
                    TimeSpan       totalDuration  = createResult.Status.TotalDuration;
                    TimeSpan       serverDuration = createResult.Status.ServerDuration;

                    // Each operation have a type of result
                    JObject resultOfOperation = createResult.Result;

                    // Create the main line of ZEK station
                    var lineZEK1 = new JObject
                    {
                        { "Name", "ZEK1" },
                        { "MainLine", true }
                    };

                    // Is possible to use the SetKey extension method to set the _key
                    lineZEK1.SetKey("ZEK1");

                    // Are possible to create collections on the fly
                    db.Document.Create(lineZEK1, "Line", createCollection: true);

                    // Now, we create the edge collection to link Station with Lines
                    db.Collection.Create("Station-Line", CollectionType.Edge);

                    // Create the edge to link ZEK station with ZEK1 line
                    db.Edge.Create("Station-Line", "Station/ZEK", "Line/ZEK1", "ZEK-ZEK1");
                }

                // To finalize the test, drop the database
                client.Database.Drop("ApiTests");
            }
        }
Esempio n. 21
0
        static void Main(string[] args)
        {
            Console.WriteLine(Environment.GetEnvironmentVariable("USERNAME"));
            ArangoClient.Client().SetDefaultDatabase(new BorderEast.ArangoDB.Client.Database.ClientSettings(
                                                         databaseName: "_system",
                                                         protocolType: BorderEast.ArangoDB.Client.Database.ProtocolType.HTTP,
                                                         serverAddress: "localhost",
                                                         serverPort: 8529,
                                                         autoCreate: true,
                                                         isDebug: true,
                                                         systemPassword: Environment.GetEnvironmentVariable("USERNAME"),
                                                         databaseUsername: "******",
                                                         databasePassword: Environment.GetEnvironmentVariable("USERNAME")
                                                         )
            {
                HTTPClient = new System.Net.Http.HttpClient(),
            });

            var client = ArangoClient.Client();


            VelocyStream vs = new VelocyStream();

            vs.Connect("127.0.0.1", 8528);

            var stream = vs.Stream;

            byte[] bytes        = System.Text.Encoding.UTF8.GetBytes("VST/1.0\r\n\r\n");
            byte[] messageBytes = System.Text.Encoding.UTF8.GetBytes("[version: 1, type: 1, requestType 1, request: \"/_admin/echo\", parameter: {a: 1}]");

            //  Segment arraySegment = VPack.ToSegment(messageBytes);

            stream.Write(bytes, 0, bytes.Length);
            stream.Flush();
            stream.Write(messageBytes, 0, messageBytes.Length);
            stream.Flush();

            var    data         = new Byte[256];
            String responseData = String.Empty;



            // Read the first batch of the TcpServer response bytes.
            var inbytes = stream.Read(data, 0, data.Length);

            responseData = System.Text.Encoding.UTF8.GetString(data, 0, inbytes);
            Console.WriteLine("Received: {0}", responseData);

            //Role r = new Role()
            //{
            //    Name = "sysadmin",
            //    Permission = "RW"
            //};
            //Role r2 = new Role()
            //{
            //    Name = "author",
            //    Permission = "RW"
            //};

            //var uR1 = client.DB().InsertAsync<Role>(r).Result;
            //var uR2 = client.DB().InsertAsync<Role>(r2).Result;



            //var juser = new User()
            //{
            //    Username = "******",
            //    Password = "******",
            //    Roles = new List<Role>() { }
            //};


            //JsonSerializerSettings settings = new JsonSerializerSettings
            //{
            //    ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
            //    Formatting = Newtonsoft.Json.Formatting.Indented
            //};

            //string json = JsonConvert.SerializeObject(juser);

            //var s = json;
            ////var u1 = client.DB().InsertAsync<Role>(r2).Result;
            //var users = client.DB().GetAllAsync<User>();

            //var u = client.DB().GetByKeyAsync<User>("");

            //var token = JsonConvert.SerializeObject(juser, Formatting.Indented, new ArangoJsonConverter(typeof(User)));

            //Dictionary<string, object> databases = new Dictionary<string, object>
            //{
            //    { "*", "rw" },
            //    { "temp", 2 }
            //};
            //var json = JsonConvert.SerializeObject(databases);


            //var users = client.DB().GetAllAsync<User>().Result;
            //var users2 = client.DB().GetAllKeysAsync<User>().Result;

            //var result = client.DB().InsertAsync<User>(juser);
            //var user = client.DB().Query<User>("for u in User return u").ToList().Result.First();
            //var user = client.DB().GetByKeyAsync<User>("1312460").Result;
            //var q = client.DB().Query<User>("", new { _key = 1235});

            //var u = client.DB().Query<User>("for r in User return r").ToList().Result;

            // var user = client.DB().GetByKeyAsync<User>("1127162").Result;

            //Console.WriteLine("user = "******"andrew";
            //var user = result.Result.New;
            //user.Password = "******";
            //var updated = client.DB().UpdateAsync("1127162", user).Result;
            //var result2 = client.DB().DeleteAsync<User>("1127162");
            //user = updated.New;

            //Console.WriteLine("user = " + user.Username);

            Console.ReadLine();
        }