Пример #1
0
        /// <summary>
        /// opens the IObjectServer, and waits forever until Close() is called
        /// or a StopServer message is being received.
        /// </summary>
        public void RunServer()
        {
            lock (this)
            {
                IServerConfiguration config = Db4oClientServer.NewServerConfiguration();
                // Using the messaging functionality to redirect all
                // messages to this.processMessage
                config.Networking.MessageRecipient = this;
                IObjectServer db4oServer = Db4oClientServer.OpenServer(config, FILE, PORT);
                db4oServer.GrantAccess(USER, PASS);

                try
                {
                    if (!stop)
                    {
                        // wait forever until Close will change stop variable
                        Monitor.Wait(this);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
                db4oServer.Close();
            }
        }
 public void SetupContext()
 {
     CurrentSessionContext = new ThreadStaticCurrentSessionContext();
     Server = Db4oClientServer.OpenServer(Db4oClientServer.NewServerConfiguration(), "RemoteServerTestDb.yap", Port);
     Server.GrantAccess(Username,Password);
     SessionFactory = new RemoteServerSessionFactory(CurrentSessionContext,Host, Port, Username, Password);
 }
Пример #3
0
        public static void Main(string[] args)
        {
            File.Delete(YapFileName);
            AccessLocalServer();
            File.Delete(YapFileName);
            using (IObjectContainer db = Db4oEmbedded.OpenFile(YapFileName))
            {
                SetFirstCar(db);
                SetSecondCar(db);
            }

            IServerConfiguration config = Db4oClientServer.NewServerConfiguration();

            config.Common.ObjectClass(typeof(Car)).UpdateDepth(3);
            using (IObjectServer server = Db4oClientServer.OpenServer(config,
                                                                      YapFileName, 0))
            {
                QueryLocalServer(server);
                DemonstrateLocalReadCommitted(server);
                DemonstrateLocalRollback(server);
            }

            AccessRemoteServer();
            using (IObjectServer server = Db4oClientServer.OpenServer(Db4oClientServer.NewServerConfiguration(),
                                                                      YapFileName, ServerPort))
            {
                server.GrantAccess(ServerUser, ServerPassword);
                QueryRemoteServer(ServerPort, ServerUser, ServerPassword);
                DemonstrateRemoteReadCommitted(ServerPort, ServerUser, ServerPassword);
                DemonstrateRemoteRollback(ServerPort, ServerUser, ServerPassword);
            }
        }
 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"));
 }
Пример #5
0
        private static IObjectServer OpenServer(IServerConfiguration configuration)
        {
            IObjectServer server = Db4oClientServer.OpenServer(configuration, DatabaseFileName, PortNumber);

            server.GrantAccess(UserAndPassword, UserAndPassword);
            return(server);
        }
Пример #6
0
        private static void UseEventsToRefreshObjects()
        {
            CleanUp();

            using (IObjectServer server = OpenServer())
            {
                server.GrantAccess(UsertNameAndPassword, UsertNameAndPassword);
                StoreJoeOnOtherClient();


                IObjectContainer client = OpenClient();
                RegisterEvent(client);
                List <Person> allPersons = ListAllPersons(client);
                PrintPersons(allPersons);

                UpdateJoeOnOtherClient();

                // the events are asynchronously transported over the network
                // which takes a while
                WaitForALittleWhile();
                PrintPersons(allPersons);


                WaitForALittleWhile();
            }
            CleanUp();
        }
        private void WithDatabase(string file, IFunction4 function)
        {
            Configure();
            IExtObjectContainer objectContainer = Db4oFactory.OpenFile(file).Ext();

            try
            {
                function.Apply(objectContainer);
            }
            finally
            {
                objectContainer.Close();
            }
            IObjectServer server = Db4oFactory.OpenServer(ClientServerFileName(file), -1);

            server.GrantAccess(Username, Password);
            objectContainer = Db4oFactory.OpenClient("localhost", server.Ext().Port(), Username
                                                     , Password).Ext();
            try
            {
                function.Apply(objectContainer);
            }
            finally
            {
                objectContainer.Close();
                server.Close();
            }
        }
 protected virtual void InitializeAccessControl(IObjectServer db4oServer)
 {
     if (!String.IsNullOrEmpty(ClientUsername))
     {
         db4oServer.GrantAccess(ClientUsername, ClientPassword);
     }
 }
Пример #9
0
        private static void RefreshOnDemand()
        {
            CleanUp();

            using (IObjectServer server = OpenServer())
            {
                server.GrantAccess(UsertNameAndPassword, UsertNameAndPassword);
                StoreJoeOnOtherClient();

                IObjectContainer client     = OpenClient();
                IList <Person>   allPersons = ListAllPersons(client);
                PrintPersons(allPersons);

                UpdateJoeOnOtherClient();

                // the persons are not in the most current state
                PrintPersons(allPersons);

                // but you can explicitly refresh the objects
                Refresh(client, allPersons);
                PrintPersons(allPersons);


                WaitForALittleWhile();
            }
            CleanUp();
        }
        /// <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)
                {
                }
            }
        }
Пример #11
0
        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());
            }
        }
Пример #12
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");
		}
        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);
        }
Пример #14
0
        private static IObjectServer StartServer()
        {
            IObjectServer server = Db4oClientServer.OpenServer("In:Memory", Port);

            server.GrantAccess(UserAndPassword, UserAndPassword);
            return(server);
        }
        protected override void StartServer()
        {
            var databasePath = InitDatabaseFile();
            _server = Db4oClientServer.OpenServer(databasePath, Port);
            _server.GrantAccess(USER_NAME, USER_PWD);

            _server.Ext().Configure().ClientServer().SetMessageRecipient(this);
        }
Пример #16
0
        private IObjectServer OpenServer()
        {
            IObjectServer server = Db4oClientServer.OpenServer(Db4oClientServer.NewServerConfiguration
                                                                   (), TempFile(), -1);

            server.GrantAccess(Username, Password);
            return(server);
        }
Пример #17
0
 /// <exception cref="System.Exception"></exception>
 private void OpenServerFor(IDb4oTestCase testInstance)
 {
     _serverConfig = ServerConfigFor(testInstance);
     _server       = _csFactory.OpenServer(AsServerConfiguration(_serverConfig), _file.GetAbsolutePath
                                               (), -1);
     _port = _server.Ext().Port();
     _server.GrantAccess(Username, Password);
 }
			public virtual void Open()
			{
				IServerConfiguration config = Db4oClientServer.NewServerConfiguration();
				config.File.Storage = new MemoryStorage();
				_server = Db4oClientServer.OpenServer(config, string.Empty, Db4oClientServer.ArbitraryPort
					);
				_server.GrantAccess(User, Pass);
			}
Пример #19
0
            public virtual void Open()
            {
                IServerConfiguration config = Db4oClientServer.NewServerConfiguration();

                config.File.Storage = new MemoryStorage();
                _server             = Db4oClientServer.OpenServer(config, string.Empty, Db4oClientServer.ArbitraryPort
                                                                  );
                _server.GrantAccess(User, Pass);
            }
        protected override void StartServer()
        {
            var databasePath = InitDatabaseFile();

            _server = Db4oClientServer.OpenServer(databasePath, Port);
            _server.GrantAccess(USER_NAME, USER_PWD);

            _server.Ext().Configure().ClientServer().SetMessageRecipient(this);
        }
Пример #21
0
        private static void RunClientServer()
        {
            using (IObjectServer server = Db4oClientServer.OpenServer("database.db4o", 8080))
            {
                server.GrantAccess("user", "password");

                OpenClient();
            }
        }
Пример #22
0
 public static void Main(string[] args)
 {
     using (IObjectServer server = Db4oClientServer.OpenServer("database.db4o", Port))
     {
         server.GrantAccess(UserAndPassword, UserAndPassword);
         GrabSemaphore();
         TryGrabSemaphore();
     }
 }
Пример #23
0
        private static IObjectServer CreateInMemoryServer()
        {
            IServerConfiguration config = Db4oClientServer.NewServerConfiguration();

            config.File.Storage = new MemoryStorage();
            IObjectServer server = Db4oClientServer.OpenServer(config, "In:Memory", Port);

            server.GrantAccess(UserAndPassword, UserAndPassword);
            return(server);
        }
Пример #24
0
 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);
 }
		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);
		}
        /// <summary>
        /// Allows configuration of the server and opening to the outside
        /// </summary>
        public HostedServerSessionFactory(ICurrentSessionContext currentSessionContext, IServerConfiguration config, string dbFileName, int port, params Access[] access)
            : base(currentSessionContext)
        {
            _server = Db4oClientServer.OpenServer(config, dbFileName, port);

            foreach(var account in access)
            {
                _server.GrantAccess(account.Username,account.Password);
            }
        }
Пример #27
0
 public bool Start()
 {
     if (IsRunning)
     {
         throw new ArgumentException("Storage server already started.");
     }
     EvaluateConnectionProperties();
     _server = Db4oFactory.OpenServer(Connection.File, Connection.HostPort);
     _server.GrantAccess(Connection.User, Connection.Password);
     return(true);
 }
Пример #28
0
        private static IObjectServer OpenDatabaseServer(string fileName)
        {
            IServerConfiguration configuration = Db4oClientServer.NewServerConfiguration();

            configuration.File.GenerateUUIDs            = ConfigScope.Globally;
            configuration.File.GenerateCommitTimestamps = true;
            IObjectServer srv = Db4oClientServer.OpenServer(configuration, fileName, Port);

            srv.GrantAccess(UserName, UserName);
            return(srv);
        }
        public override void SetUp()
        {
            Db4oPerformanceCounterInstaller.ReInstall();

            var serverConfiguration = Db4oClientServer.NewServerConfiguration();
            serverConfiguration.AddConfigurationItem(new ClientConnectionsMonitoringSupport());
            serverConfiguration.AddConfigurationItem(new ConnectionCloseEventSupport(ClientDisconnected));

            _server = Db4oClientServer.OpenServer(serverConfiguration, TempFile(), Db4oClientServer.ArbitraryPort);
            _server.GrantAccess(UserName, Password);
        }
Пример #30
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
                }
            }
        }
Пример #31
0
        public static void Main(string[] args)
        {
            // #example: Start a db4o server
            using (IObjectServer server = Db4oClientServer.OpenServer("database.db4o", 8080))
            {
                server.GrantAccess("user", "password");

                // Let the server run.
                LetServerRun();
            }
            // #end example
        }
        public override void SetUp()
        {
            Db4oPerformanceCounterInstaller.ReInstall();

            var serverConfiguration = Db4oClientServer.NewServerConfiguration();

            serverConfiguration.AddConfigurationItem(new ClientConnectionsMonitoringSupport());
            serverConfiguration.AddConfigurationItem(new ConnectionCloseEventSupport(ClientDisconnected));

            _server = Db4oClientServer.OpenServer(serverConfiguration, TempFile(), Db4oClientServer.ArbitraryPort);
            _server.GrantAccess(UserName, Password);
        }
Пример #33
0
        public static void Main(string[] args)
        {
            CleanUp();
            using (IObjectServer server = Db4oClientServer.OpenServer(DatabaseFile, 1337))
            {
                server.GrantAccess("sa", "sa");
                StoreData(server);

                ReferenceCacheExample();
                UnitOfWork();
            }
        }
Пример #34
0
        private static IObjectServer StartUpServer()
        {
            // #example: configure a message receiver for the server
            IServerConfiguration configuration = Db4oClientServer.NewServerConfiguration();

            configuration.Networking.MessageRecipient = new ServerMessageReceiver();
            IObjectServer server = Db4oClientServer.OpenServer(configuration, DatabaseFile, PortNumber);

            // #end example
            server.GrantAccess(UserAndPassword, UserAndPassword);
            return(server);
        }
        public virtual void Run()
        {
            //store
            IServerConfiguration conf   = Db4oClientServer.NewServerConfiguration();
            IObjectServer        server = Db4oClientServer.OpenServer(conf, File, Port);

            server.GrantAccess("db4o", "db4o");
            //store
            //update
            //assert
            server.Close();
        }
Пример #36
0
            public object Apply(object config)
            {
                IConfiguration serverConfig = Db4oFactory.NewConfiguration();

                serverConfig.Storage = new MemoryStorage();
                IObjectServer server = this._enclosing.OpenServer(serverConfig, ".", -1);

                server.GrantAccess("user", "password");
                IObjectContainer client = this._enclosing.OpenClient(((IConfiguration)config), "localhost"
                                                                     , server.Ext().Port(), "user", "password");

                return(new _IRunnable_42(client, server));
            }
Пример #37
0
        /// <summary>
        /// opens the IObjectServer, and waits forever until Close() is called
        /// or a StopServer message is being received.
        /// </summary>
        public void RunServer()
        {
            Console.WriteLine("Server starting");
            lock (this)
            {
                // Using the messaging functionality to redirect all
                // messages to this.processMessage
                IConfiguration configuration = Db4oFactory.NewConfiguration();
                configuration.ClientServer().SetMessageRecipient(this);


                configuration.Add(new TransparentActivationSupport());
                configuration.Add(new TransparentPersistenceSupport());


                server = Db4oFactory.OpenServer(configuration, FileName, Port);
                server.GrantAccess(User, Password);
                server.GrantAccess("server", "serverpass");

                Console.WriteLine("Server started");
                client = Db4oFactory.OpenClient(Host, Port, "server", "serverpass");
                try
                {
                    if (!stop)
                    {
                        // wait forever until Close will change stop variable
                        Console.WriteLine("Server waiting...");
                        Monitor.Wait(this);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
                server.Close();
                Console.WriteLine("Server closed");
            }
        }
Пример #38
0
		private IObjectContainer OpenContainer()
		{
			string user = "******";
			string password = "******";
			_server = Db4oClientServer.OpenServer(((IServerConfiguration)Configure(Db4oClientServer
				.NewServerConfiguration(), "db4o server(" + DatabaseFileName + ")")), DatabaseFileName
				, Db4oClientServer.ArbitraryPort);
			_server.GrantAccess(user, password);
			return Db4oClientServer.OpenClient(((IClientConfiguration)Configure(Db4oClientServer
				.NewClientConfiguration(), "db4o client(localhost:" + _server.Ext().Port() + ")"
				)), "localhost", _server.Ext().Port(), user, password);
			return Db4oEmbedded.OpenFile(((IEmbeddedConfiguration)Configure(Db4oEmbedded.NewConfiguration
				(), "db4o(" + DatabaseFileName + ")")), DatabaseFileName);
		}
Пример #39
0
        /// <summary>
        /// Starts the server.
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown if the server has already been started.</exception>
        /// <exception cref="ObjectDisposedException">Thrown if the server has been disposed.</exception>
        /// <exception cref="AmbienceException">Thrown if the operation failed.</exception>
        public void Start()
        {
            ThrowIfDisposed();

            Directory.CreateDirectory(Path.GetDirectoryName(databasePath));

            try
            {
                IConfiguration db4oConfig = Db4oFactory.NewConfiguration();
                db4oServer = Db4oFactory.OpenServer(db4oConfig, databasePath, configuration.Port);
                db4oServer.GrantAccess(configuration.Credential.UserName, configuration.Credential.Password);
            }
            catch (Db4oException ex)
            {
                throw new AmbienceException("An error occurred while starting the server.", ex);
            }
        }
Пример #40
0
 public void StartServer()
 {
     _databaseInstance = Db4oFactory.OpenServer(_databaseFile, _databasePort);
     _databaseInstance.GrantAccess(_databaseUser, _databasePassword);
     _databaseUp = true;
 }
Пример #41
0
		/// <exception cref="System.Exception"></exception>
		private void OpenServerFor(IDb4oTestCase testInstance)
		{
			_serverConfig = ServerConfigFor(testInstance);
			_server = _csFactory.OpenServer(AsServerConfiguration(_serverConfig), _file.GetAbsolutePath
				(), -1);
			_port = _server.Ext().Port();
			_server.GrantAccess(Username, Password);
		}
Пример #42
0
 protected virtual void InitializeAccessControl(IObjectServer db4oServer)
 {
     if (!String.IsNullOrEmpty(ClientUsername))
         db4oServer.GrantAccess(ClientUsername, ClientPassword);
 }
Пример #43
0
 /// <summary>
 /// Opens a connection to the database file.
 /// </summary>
 /// <remarks>The <c>Open</c> method assumes that the connection string will
 /// contain user credentials which are used when calling the 
 /// <see cref="Db4objects.Db4o.CS.Db4oClientServer"/> <c>GrantAccess</c> method.</remarks>
 /// <exception cref="System.Exception">Throws when the singleton
 /// is already initialized.</exception>
 public void Open()
 {
     if (_databaseServer != null)
     {
         throw new Exception("Server is running");
     }
     var userInfo = _connectionString.UserInfo.Split(new char[] { ':' });
     _user = new GenericIdentity(userInfo[0]);
     _config = Db4oClientServer.NewServerConfiguration();
     _databaseServer = Db4oClientServer.OpenServer(_connectionString.AbsolutePath,
         _connectionString.Port);
     _databaseServer.GrantAccess(userInfo[0], userInfo[1]);
 }