static void Main(string[] args) { if (args.Length != 5) { throw new ArgumentException($"{args.Length} arguments present, only 5 are required: hostname username password port database"); } // Create a new instance of an IOrientDBRecordSerializer of type byte[]. IOrientDBRecordSerializer <byte[]> serializer = new OrientDBRecordCSVSerializer(); // Instantiate and fill in the ServerConnectionOptions. ServerConnectionOptions options = new ServerConnectionOptions { HostName = args[0], UserName = args[1], Password = args[2], Port = int.Parse(args[3]), PoolSize = 1 }; // Create a Server Connection. using (OrientDBBinaryServerConnection serverConnection = new OrientDBBinaryServerConnection(options, serializer)) { // Check if the database exists. if (serverConnection.DatabaseExists(args[4], StorageType.PLocal)) { throw new Exception($"Database {args[4]} already exists!"); } // Create a database. using (OrientDBBinaryConnection databaseConnection = serverConnection.CreateDatabase(args[4], DatabaseType.Graph, StorageType.PLocal)) { // Open database connection. databaseConnection.Open(); } // Drop the database. serverConnection.DropDatabase(args[4], StorageType.PLocal); } }
static void Main(string[] args) { string hostname = args[0]; string username = args[1]; string password = args[2]; int port = int.Parse(args[3]); string database = args[4]; var serverConnectionOptions = new ServerConnectionOptions { HostName = hostname, Password = password, PoolSize = 1, Port = port, UserName = username }; var databaseConnectionOptions = new DatabaseConnectionOptions { Database = database, HostName = hostname, Password = password, PoolSize = 10, Port = port, Type = DatabaseType.Graph, UserName = username }; var serializer = new OrientDBRecordCSVSerializer(); DatabaseUtilities.CreateDatabase(serverConnectionOptions, database, serializer); Console.WriteLine($"Database {database} created."); using (OrientDBBinaryConnection connection = new OrientDBBinaryConnection(databaseConnectionOptions, serializer)) { connection.Open(); connection.CreateCommand().Execute("CREATE CLASS Person"); var transaction = connection.CreateTransaction(); var person1 = new Person { Age = 33, FirstName = "John", LastName = "Doe", FavoriteColors = new[] { "black", "blue" } }; transaction.AddEntity(person1); transaction.AddEntity(new Person { Age = 35, FirstName = "Jane", LastName = "Doe", FavoriteColors = new[] { "red", "blue" } }); transaction.Commit(); transaction = connection.CreateTransaction(); transaction.Remove(person1); transaction.Commit(); } IEnumerable <Person> personCollection = new List <Person>(); IOrientConnection orientConnection = new OrientDBConfiguration() .ConnectWith <byte[]>() .Connect(new BinaryProtocol(hostname, username, password, database, DatabaseType.Graph, 2424)) .SerializeWith.Serializer(new OrientDBRecordCSVSerializer()) .LogWith.Logger(new ConsoleOrientDBLogger()) .CreateFactory().GetConnection(); personCollection = orientConnection.ExecuteQuery <Person>("SELECT * FROM Person"); foreach (var person in personCollection) { Console.WriteLine($"FirstName: {person.FirstName}, LastName: {person.LastName}, Age: {person.Age}, Favorite Colors: {string.Join(",", person.FavoriteColors)}"); } DatabaseUtilities.DeleteDatabase(serverConnectionOptions, database, serializer); Console.WriteLine($"Database {database} deleted."); }