/// <exception cref="System.Exception"></exception>
        public virtual void Test()
        {
            IObjectServer server = Db4oClientServer.OpenServer(TempFile(), Db4oClientServer.ArbitraryPort
                                                               );

            server.GrantAccess(string.Empty, string.Empty);
            IObjectContainer client = Db4oClientServer.OpenClient("localhost", ((ObjectServerImpl
                                                                                 )server).Port(), string.Empty, string.Empty);
            IObjectContainer client2 = Db4oClientServer.OpenClient("localhost", ((ObjectServerImpl
                                                                                  )server).Port(), string.Empty, string.Empty);

            client.Commit();
            client2.Commit();
            try
            {
                server.Close();
            }
            finally
            {
                try
                {
                    client.Close();
                    client2.Close();
                }
                catch (Db4oException)
                {
                }
            }
        }
Beispiel #2
0
        public virtual void TestMissingClassesInServer()
        {
            IList serverMissedClasses = new ArrayList();
            IList clientMissedClasses = new ArrayList();
            var   serverConfig        = Db4oClientServer.NewServerConfiguration();

            PrepareHost(serverConfig.File, serverConfig.Common, serverMissedClasses);
            ExcludeClasses(serverConfig.Common, new[]
            {
                typeof(Pilot
                       ),
                typeof(Car)
            });
            var server = Db4oClientServer.OpenServer(serverConfig, DbUri, Port);

            server.GrantAccess(User, Password);
            try
            {
                var clientConfig = Db4oClientServer.NewClientConfiguration();
                PrepareCommon(clientConfig.Common, clientMissedClasses);
                var client = Db4oClientServer.OpenClient(clientConfig, "localhost",
                                                         Port, User, Password);
                client.Query(new AcceptAllPredicate());
                client.Close();
            }
            finally
            {
                server.Close();
            }
            AssertPilotAndCarMissing(serverMissedClasses);
            Assert.AreEqual(0, clientMissedClasses.Count);
        }
Beispiel #3
0
        private static void SimpleMessagingExample()
        {
            IObjectServer server = StartUpServer();

            // #example: configure a message receiver for a client
            IClientConfiguration configuration = Db4oClientServer.NewClientConfiguration();

            configuration.Networking.MessageRecipient = new ClientMessageReceiver();
            // #end example

            // #example: Get the message sender and use it
            IMessageSender sender = configuration.MessageSender;

            using (IObjectContainer container = Db4oClientServer.OpenClient(configuration, "localhost",
                                                                            PortNumber, UserAndPassword,
                                                                            UserAndPassword))
            {
                sender.Send(new HelloMessage("Hi Server!"));
                WaitForAWhile();
            }
            // #end example


            server.Close();
        }
        public virtual void TestClientServerApi()
        {
            IServerConfiguration config = Db4oClientServer.NewServerConfiguration();
            IObjectServer        server = Db4oClientServer.OpenServer(config, TempFile(), unchecked (
                                                                          (int)(0xdb40)));

            try
            {
                server.GrantAccess("user", "password");
                IClientConfiguration clientConfig = Db4oClientServer.NewClientConfiguration();
                IObjectContainer     client1      = Db4oClientServer.OpenClient(clientConfig, "localhost",
                                                                                unchecked ((int)(0xdb40)), "user", "password");
                try
                {
                }
                finally
                {
                    Assert.IsTrue(client1.Close());
                }
            }
            finally
            {
                Assert.IsTrue(server.Close());
            }
        }
 public static void QueryRemoteServer(int port, string user, string password)
 {
     using (IObjectContainer client = Db4oClientServer.OpenClient("localhost", port, user, password))
     {
         ListResult(client.QueryByExample(new Car(null)));
     }
 }
Beispiel #6
0
 protected virtual IObjectContainer OpenClient(string clientId, IObjectServer server
                                               )
 {
     server.GrantAccess(clientId, "p");
     return(Db4oClientServer.OpenClient(MultithreadedClientConfig(), "127.0.0.1", server
                                        .Ext().Port(), clientId, "p"));
 }
Beispiel #7
0
        /// <summary>
        /// stops a db4o Server started with StartServer.
        /// </summary>
        /// <exception cref="Exception" />
        public static void Main(string[] args)
        {
            IObjectContainer IObjectContainer = null;

            try
            {
                // connect to the server
                IObjectContainer = Db4oClientServer.OpenClient(Db4oClientServer.NewClientConfiguration(),
                                                               HOST, PORT, USER, PASS);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            if (IObjectContainer != null)
            {
                // get the messageSender for the IObjectContainer
                IMessageSender messageSender = IObjectContainer.Ext()
                                               .Configure().ClientServer().GetMessageSender();

                // send an instance of a StopServer object
                messageSender.Send(new StopServer());

                // close the IObjectContainer
                IObjectContainer.Close();
            }
        }
Beispiel #8
0
        //Container/Client Staff

        private IObjectContainer GetContainerFromConfig(DB4ODatabaseElement dataBaseData, HttpContext context)
        {
            Debug.WriteLine(String.Format("GetContainerFromConfig (database: {0})", dataBaseData.Alias));

            IObjectContainer container;

            switch (dataBaseData.ServerType)
            {
            case Db4oServerType.NetworkingServer:

                var clientConfig = Db4oClientServer.NewClientConfiguration();

                if (dataBaseData.ExistAnyCustomConfiguration())
                {
                    clientConfig = dataBaseData.GetServerConfig <IClientConfiguration>();
                }

                container = Db4oClientServer.OpenClient(clientConfig, dataBaseData.RemoteHost, dataBaseData.RemotePort,
                                                        dataBaseData.RemoteUser, dataBaseData.RemotePassWord);

                break;

            case Db4oServerType.EmbeddedServer:
            default:

                var server = GetEmbeddedServer(dataBaseData, 0, context);
                container = server.OpenClient();

                break;
            }

            BindContainerEvents(container, dataBaseData);

            return(container);
        }
        public virtual void TestMissingClassesInClient()
        {
            IList serverMissedClasses         = new ArrayList();
            IList clientMissedClasses         = new ArrayList();
            IServerConfiguration serverConfig = Db4oClientServer.NewServerConfiguration();

            PrepareHost(serverConfig.File, serverConfig.Common, serverMissedClasses);
            IObjectServer server = Db4oClientServer.OpenServer(serverConfig, DbUri, Port);

            server.GrantAccess(User, Password);
            try
            {
                IClientConfiguration clientConfig = Db4oClientServer.NewClientConfiguration();
                PrepareCommon(clientConfig.Common, clientMissedClasses);
                ExcludeClasses(clientConfig.Common, new Type[] { typeof(MissingClassDiagnosticsTestCase.Pilot
                                                                        ), typeof(MissingClassDiagnosticsTestCase.Car) });
                IObjectContainer client = Db4oClientServer.OpenClient(clientConfig, "localhost",
                                                                      Port, User, Password);
                IObjectSet result = client.Query(new MissingClassDiagnosticsTestCase.AcceptAllPredicate
                                                     ());
                IterateOver(result);
                client.Close();
            }
            finally
            {
                server.Close();
            }
            Assert.AreEqual(0, serverMissedClasses.Count);
            AssertPilotAndCarMissing(clientMissedClasses);
        }
Beispiel #10
0
        private static IObjectContainer  ConnectClient()
        {
            IClientConfiguration config = Db4oClientServer.NewClientConfiguration();

            ConfigureCommon(config.Common);
            return(Db4oClientServer.OpenClient(config, conn.Host, conn.Port, conn.UserName, conn.PassWord));
        }
Beispiel #11
0
        /// <summary></summary>
        public DummyLocalConnectedClient(int port)
        {
            IClientConfiguration config = Db4oClientServer.NewClientConfiguration();

            config.Common.StringEncoding = StringEncodings.Utf8();
            Client = Db4oClientServer.OpenClient(config, "127.0.0.1", port, User, Password);
        }
        private void Connect()
        {
            const int retryCount = 20; // With 20 retries we'll wait at most 11 seconds until fail.
            var       exceptions = new Stack <Exception>();

            _client = null;
            long timeToWait = 100;

            for (var i = 0; i < retryCount; ++i)
            {
                try
                {
                    var clientConfiguration = Db4oClientServerLegacyConfigurationBridge.AsClientConfiguration(Config());
                    _client = Db4oClientServer.OpenClient(clientConfiguration, "localhost", Port, USER_NAME, USER_PWD);
                    return;
                }
                catch (Exception e)
                {
                    if (NotTheSameAsLast(e, exceptions))
                    {
                        exceptions.Push(e);
                    }
                }
                Runtime4.Sleep(timeToWait);
                if (i == 10)
                {
                    timeToWait = 1000;
                }
            }

            FailConnect(retryCount, exceptions);
        }
        private IObjectContainer OpenClient(int port)
        {
            var config = Db4oClientServer.NewClientConfiguration();

            config.PrefetchIDCount = PrefetchIdCount;
            return(Db4oClientServer.OpenClient(config, "localhost", port, User, Password));
        }
Beispiel #14
0
        private ClientObjectContainer OpenClient(int port)
        {
            ClientObjectContainer client = (ClientObjectContainer)Db4oClientServer.OpenClient
                                               (Db4oClientServer.NewClientConfiguration(), "localhost", port, Username, Password
                                               );

            return(client);
        }
Beispiel #15
0
        private static IObjectContainer CreateClientConnection()
        {
            // #example: Open clients for the pool
            IObjectContainer client = Db4oClientServer.OpenClient("localhost",
                                                                  Port, UserAndPassword, UserAndPassword);

            // #end example
            return(client);
        }
Beispiel #16
0
        private static void EnableBatchMode()
        {
            // #example: enable or disable batch mode
            IClientConfiguration configuration = Db4oClientServer.NewClientConfiguration();

            configuration.Networking.BatchMessages = true;
            // #end example
            IObjectContainer container = Db4oClientServer.OpenClient(configuration, "localhost", 1337, "sa", "sa");
        }
Beispiel #17
0
        private static void ReplaceClientServerFactory()
        {
            // #example: exchange the way a client or server is created
            IClientConfiguration configuration = Db4oClientServer.NewClientConfiguration();

            configuration.Networking.ClientServerFactory = new StandardClientServerFactory();
            // #end example
            IObjectContainer container = Db4oClientServer.OpenClient(configuration, "localhost", 1337, "sa", "sa");
        }
Beispiel #18
0
        private static void MaxBatchQueueSize()
        {
            // #example: change the maximum batch queue size
            IClientConfiguration configuration = Db4oClientServer.NewClientConfiguration();

            configuration.Networking.MaxBatchQueueSize = 1024;
            // #end example
            IObjectContainer container = Db4oClientServer.OpenClient(configuration, "localhost", 1337, "sa", "sa");
        }
Beispiel #19
0
        private static void SingleThreadedClient()
        {
            // #example: single threaded client
            IClientConfiguration configuration = Db4oClientServer.NewClientConfiguration();

            configuration.Networking.SingleThreadedClient = true;
            // #end example
            IObjectContainer container = Db4oClientServer.OpenClient(configuration, "localhost", 1337, "sa", "sa");
        }
Beispiel #20
0
        private static void PluggableSocket()
        {
            // #example: Exchange the socket-factory
            IClientConfiguration configuration = Db4oClientServer.NewClientConfiguration();

            configuration.Networking.SocketFactory = new StandardSocket4Factory();
            // #end example
            IObjectContainer container = Db4oClientServer.OpenClient(configuration, "localhost", 1337, "sa", "sa");
        }
Beispiel #21
0
 public static void main(string[] args)
 {
     // #example: Connect to the server
     using (IObjectContainer container
                = Db4oClientServer.OpenClient("localhost", 8080, "user", "password"))
     {
         // Your operations
     }
     // #end example
 }
Beispiel #22
0
 private static void OpenClient()
 {
     // #example: Using the client
     using (IObjectContainer container
                = Db4oClientServer.OpenClient("localhost", 8080, "user", "password"))
     {
         // Use the client object container as usual
     }
     // #end example
 }
Beispiel #23
0
        private static void ClientConfiguration()
        {
            // #example: Configure a client object container
            IClientConfiguration configuration = Db4oClientServer.NewClientConfiguration();
            // change the configuration...
            IObjectContainer container = Db4oClientServer.OpenClient(configuration, "localhost", 1337, "user", "pwd");

            // #end example
            container.Close();
        }
 public override void Open()
 {
     Config().MessageLevel(-1);
     _server = Db4oClientServer.OpenServer(Db4oClientServerLegacyConfigurationBridge.AsServerConfiguration
                                               (CloneConfiguration()), testFile.GetPath(), _port);
     _server.GrantAccess(Username, Password);
     _db = Db4oClientServer.OpenClient(Db4oClientServerLegacyConfigurationBridge.AsClientConfiguration
                                           (CloneConfiguration()), Host, _port, Username, Password).Ext();
     _provider = Db4oProviderFactory.NewInstance(_db, _name);
 }
Beispiel #25
0
        public static void ConnectionTimeOut()
        {
            // #example: Configure the timeout
            IClientConfiguration configuration = Db4oClientServer.NewClientConfiguration();

            configuration.TimeoutClientSocket = (1 * 60 * 1000);
            // #end example
            IObjectContainer container = Db4oClientServer.OpenClient(configuration, "localhost", 1337, "user", "password");

            container.Close();
        }
Beispiel #26
0
        public static void PrefetchIDCount()
        {
            // #example: Configure the prefetch id count
            IClientConfiguration configuration = Db4oClientServer.NewClientConfiguration();

            configuration.PrefetchSlotCacheSize = 128;
            // #end example
            IObjectContainer container = Db4oClientServer.OpenClient(configuration, "localhost", 1337, "user", "password");

            container.Close();
        }
Beispiel #27
0
        public static void PrefetchDepth()
        {
            // #example: Configure the prefetch depth
            IClientConfiguration configuration = Db4oClientServer.NewClientConfiguration();

            configuration.PrefetchDepth = 5;
            // #end example
            IObjectContainer container = Db4oClientServer.OpenClient(configuration, "localhost", 1337, "user", "password");

            container.Close();
        }
Beispiel #28
0
        private static void RunClient()
        {
            IClientConfiguration configuration = Db4oClientServer.NewClientConfiguration();

            configuration.Common.Add(new NetworkingMonitoringSupport());
            using (IObjectContainer client = Db4oClientServer.OpenClient(configuration,
                                                                         "localhost", PortNumber, User, Password))
            {
                DoOperationsOnClient(client);
            }
        }
Beispiel #29
0
        public static void AccessRemoteServer()
        {
            using (IObjectServer server = Db4oClientServer.OpenServer(YapFileName, ServerPort))
            {
                server.GrantAccess(ServerUser, ServerPassword);

                using (IObjectContainer client = Db4oClientServer.OpenClient("localhost", ServerPort, ServerUser, ServerPassword))
                {
                    // Do something with this client, or open more clients
                }
            }
        }
        /// <exception cref="System.Exception"></exception>
        public virtual void SetUp()
        {
            var serverConfiguration = Db4oClientServer.NewServerConfiguration
                                          ();

            serverConfiguration.File.Storage = new MemoryStorage();
            _server = Db4oClientServer.OpenServer(serverConfiguration, string.Empty, Db4oClientServer
                                                  .ArbitraryPort).Ext();
            _server.GrantAccess(Username, Password);
            _networkingClient = Db4oClientServer.OpenClient("localhost", _server.Port(), Username
                                                            , Password).Ext();
            _embeddedClient = ((ObjectContainerSession)_server.OpenClient().Ext());
        }