public async Task LocalServer(DBusDaemonProtocol protocol)
        {
            if (!File.Exists("dbus-daemon"))
            {
                throw new SkipTestException("dbus-daemon not present");
            }
            string service       = "any.service";
            string listenAddress = null;

            switch (protocol)
            {
            case DBusDaemonProtocol.Tcp:
                listenAddress = "tcp:host=localhost";
                break;

            case DBusDaemonProtocol.Unix:
                listenAddress = $"unix:path={Path.GetTempPath()}/{Path.GetRandomFileName()}";
                break;

            case DBusDaemonProtocol.UnixAbstract:
                listenAddress = $"unix:abstract={Guid.NewGuid()}";
                break;
            }

            throw new NotImplementedException();
#if false
            // server
            var server = new ServerConnectionOptions();
            using (var connection = new Connection(server))
            {
                await connection.RegisterObjectAsync(new PingPong());

                var boundAddress = await server.StartAsync(listenAddress);

                for (int i = 0; i < 2; i++)
                {
                    // client
                    using (var client = new Connection(boundAddress))
                    {
                        // method
                        await client.ConnectAsync();

                        var proxy  = client.CreateProxy <IPingPong>(service, PingPong.Path);
                        var echoed = await proxy.EchoAsync("test");

                        Assert.Equal("test", echoed);

                        // signal
                        var tcs = new TaskCompletionSource <string>();
                        await proxy.WatchPongAsync(message => tcs.SetResult(message));

                        await proxy.PingAsync("hello world");

                        var reply = await tcs.Task;
                        Assert.Equal("hello world", reply);
                    }
                }
            }
#endif
        }
 public DatabaseExistsOperation(string database, StorageType storageType, ConnectionMetaData metaData, ServerConnectionOptions options)
 {
     _database    = database;
     _metaData    = metaData;
     _options     = options;
     _storageType = storageType;
 }
Beispiel #3
0
        public static async Task Setup()
        {
            var server = new ServerConnectionOptions();

            using var connection = new Connection(server);

            await connection.RegisterObjectAsync(new InstanceActivator());

            try
            {
                var boundAddress = await server.StartAsync(TcpAddress);

                Log.Information($"SingleInstanceWatcher: Server listening at {boundAddress}");
                return;
            }
            catch (Exception e)
            {
                Log.Information($"SingleInstanceWatcher: Unable to register server: {e.Message}. Attempting to connect to existing instance...");
            }

            var clientOptions = new ClientConnectionOptions(TcpAddress);

            using var client = new Connection(clientOptions);
            try
            {
                await client.ConnectAsync();
            }
            catch (Exception e)
            {
                Log.Warning($"SingleInstanceWatcher: Unable to connect to interface: {e.Message}");
                Log.Warning($"SingleInstanceWatcher: Continuing without any instance restrictions. This can cause Bluetooth issues since only one app can interact with the earbuds at a time.");
                return;
            }

            Log.Information("SingleInstanceWatcher: Client connected to active instance");
            try
            {
                var proxy = client.CreateProxy <IInstanceActivator>("any.service", InstanceActivator.Path);
                await proxy.ActivateAsync();

                Log.Information(
                    "SingleInstanceWatcher: Activation request to other instance sent. Shutting down now.");
                Environment.Exit(0);
                return;
            }
            catch (Exception e)
            {
                Log.Warning($"SingleInstanceWatcher: Unable to invoke activation method via proxy: {e.Message}");
                Log.Warning($"SingleInstanceWatcher: Continuing without any instance restrictions. This can cause Bluetooth issues since only one app can interact with the earbuds at a time.");
                return;
            }
        }
Beispiel #4
0
        public static void CreateDatabase(ServerConnectionOptions serverConnectionOptions, string database, IOrientDBRecordSerializer <byte[]> serializer)
        {
            using (OrientDBBinaryServerConnection serverConnection = new OrientDBBinaryServerConnection(serverConnectionOptions, serializer))
            {
                serverConnection.Open();

                if (serverConnection.DatabaseExists(database, StorageType.PLocal))
                {
                    serverConnection.DropDatabase(database, StorageType.PLocal);
                }

                var databaseConnection = serverConnection.CreateDatabase(database, DatabaseType.Graph, StorageType.PLocal);
            }
        }
Beispiel #5
0
        public static void DeleteDatabase(ServerConnectionOptions serverConnectionOptions, string database, IOrientDBRecordSerializer <byte[]> serializer)
        {
            using (OrientDBBinaryServerConnection serverConnection = new OrientDBBinaryServerConnection(serverConnectionOptions, serializer))
            {
                serverConnection.Open();

                if (!serverConnection.DatabaseExists(database, StorageType.PLocal))
                {
                    return;
                }

                serverConnection.DropDatabase(database, StorageType.PLocal);
            }
        }
Beispiel #6
0
        public DatabaseCreateOperation(string databaseName, DatabaseType databaseType, StorageType storageType, ConnectionMetaData metaData, ServerConnectionOptions options, IOrientDBRecordSerializer <byte[]> serializer, ILogger logger)
        {
            if (string.IsNullOrWhiteSpace(databaseName))
            {
                throw new ArgumentException($"{nameof(databaseName)} cannot be zero length or null.");
            }
            _metaData   = metaData ?? throw new ArgumentNullException($"{nameof(metaData)} cannot be null.");
            _options    = options ?? throw new ArgumentNullException($"{nameof(options)} cannot be null.");
            _serializer = serializer ?? throw new ArgumentNullException($"{nameof(serializer)} cannot be null.");
            _logger     = logger ?? throw new ArgumentNullException($"{nameof(logger)} cannot be null");

            _databaseName = databaseName;
            _databaseType = databaseType;
            _storageType  = storageType;
        }
Beispiel #7
0
        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 serializer = new OrientDBRecordCSVSerializer();

            DatabaseUtilities.CreateDatabase(serverConnectionOptions, database, serializer);
            Console.WriteLine($"Database {database} created.");

            IOrientConnection connection = CreateConnection(hostname, username, password, database, port, serializer);

            connection.ExecuteCommand("CREATE CLASS Persons");
            Console.WriteLine("CREATE CLASS Persons executed.");

            connection.ExecuteCommand("INSERT INTO Persons (FirstName, LastName, FavoriteColors, Age) VALUES ('Joe', 'Tester', ['red', 'blue'], 25)");
            Console.WriteLine("INSERT INTO Persons (FirstName, LastName, FavoriteColors, Age) VALUES ('Joe', 'Tester', ['red', 'blue'], 25) executed.");

            var persons = connection.ExecuteQuery <Person>("SELECT * FROM Persons");

            Console.WriteLine($"SELECT * FROM Persons executed with {persons.Count()} results.");

            foreach (var person in persons)
            {
                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.");
        }
Beispiel #8
0
        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);
            }
        }
 public BinaryProtocol(ServerConnectionOptions options)
 {
     _options = options;
 }
Beispiel #10
0
 public UnsupportedServerVersionException(ServerConnectionOptions connection) :
     base($"The debug server on host {connection} is out of date and missing critical features. Please update it to the latest available version.")
 {
 }
Beispiel #11
0
 public ConnectionRefusedException(ServerConnectionOptions connection) :
     base($"Unable to establish connection to the debug server at host {connection}")
 {
 }
 public ServerOpenOperation(ServerConnectionOptions _options, ConnectionMetaData connectionMetaData)
 {
     this._options            = _options;
     this._connectionMetaData = connectionMetaData;
 }
Beispiel #13
0
        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.");
        }