Ejemplo n.º 1
0
 private void OpenDB()
 {
     if (IsCoverting)
     {
         return;
     }
     if (server != null)
     {
         return;
     }
     try
     {
         var server_config = Db4oClientServer.NewServerConfiguration();
         server_config.Common.AllowVersionUpdates = true;
         server_config.Common.Add(new TransparentActivationSupport());
         if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "do_defragment_backup")))
         {
             DefragmentDB();
             File.Delete(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "do_defragment_backup"));
         }
         server = Db4oClientServer.OpenServer(server_config, db_name, 0);
     }
     catch (Exception ex)
     {
         MessageBox.Show(string.Format("Ошибка открытия файла базы данных {0}.\n{1}\n ", db_name, ex.Message), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
        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);
        }
        /// <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)
                {
                }
            }
        }
Ejemplo n.º 4
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();
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        private static IObjectServer OpenServer(IServerConfiguration configuration)
        {
            IObjectServer server = Db4oClientServer.OpenServer(configuration, DatabaseFileName, PortNumber);

            server.GrantAccess(UserAndPassword, UserAndPassword);
            return(server);
        }
Ejemplo n.º 7
0
        private static IObjectServer StartServer()
        {
            IObjectServer server = Db4oClientServer.OpenServer("In:Memory", Port);

            server.GrantAccess(UserAndPassword, UserAndPassword);
            return(server);
        }
Ejemplo n.º 8
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);
            }
        }
        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());
            }
        }
Ejemplo n.º 10
0
        private static IObjectServer OpenServer()
        {
            IObjectServer server = Db4oClientServer.OpenServer(DatabaseFileName, PortNumber);

            server.GrantAccess(EmbeddedUser, EmbeddedPassword);
            return(server);
        }
Ejemplo n.º 11
0
            public virtual void Open()
            {
                IServerConfiguration config = Db4oClientServer.NewServerConfiguration();

                config.File.Storage = new MemoryStorage();
                _server             = Db4oClientServer.OpenServer(config, string.Empty, 0);
            }
Ejemplo n.º 12
0
        private IObjectServer OpenServer()
        {
            IObjectServer server = Db4oClientServer.OpenServer(Db4oClientServer.NewServerConfiguration
                                                                   (), TempFile(), -1);

            server.GrantAccess(Username, Password);
            return(server);
        }
        /// <exception cref="System.Exception"></exception>
        public virtual void SetUp()
        {
            IServerConfiguration config = Db4oClientServer.NewServerConfiguration();

            config.File.Storage = new MemoryStorage();
            this.server         = Db4oClientServer.OpenServer(config, "InMemory:File", Port);
            this.server.GrantAccess(UsernameAndPassword, UsernameAndPassword);
        }
Ejemplo n.º 14
0
        protected override void Db4oSetupAfterStore()
        {
            var cfg = Db4oClientServer.NewServerConfiguration();

            cfg.File.Storage = new MemoryStorage();
            testDB           = Db4oClientServer.OpenServer(cfg, "No:File:Expected", 0);
            StoreTestData(testDB);
        }
Ejemplo n.º 15
0
        public void TestUpdateDepth()
        {
            System.IO.File.Delete(@"c:\temp\bugzzinga\BDTest.yap");

            var db4oConfig = Db4oClientServer.NewServerConfiguration();

            //db4oConfig.Common.ObjectClass( typeof( Proyecto )).UpdateDepth(10);
            //db4oConfig.Common.ObjectClass( typeof( Proyecto ).FullName ).CascadeOnUpdate( true );
            //db4oConfig.Common.UpdateDepth = 10;

            var servidor = Db4oClientServer.OpenServer(db4oConfig, @"c:\temp\bugzzinga\BDTest.yap", 0);
            //-----------------------------------------------------------------------------------------
            var db = servidor.OpenClient();

            Proyecto proyecto = new Proyecto();

            proyecto.Codigo = "P1";
            proyecto.Nombre = "Proyecto de prueba";

            var tiposItem = HelperInstanciacionItems.GetTiposDeItem("Proyecto de prueba", 2);

            foreach (var item in tiposItem)
            {
                proyecto.AgregarTipoDeItem(item);
            }

            db.Store(proyecto);
            db.Close();
            //-----------------------------------------------------------------------------------------

            db = servidor.OpenClient();

            proyecto = null;
            var proyectoTest = (from Proyecto p in db select p).ToList()[0];

            tiposItem = null;
            var tipoItem = HelperInstanciacionItems.GetTiposDeItem("Proyecto de prueba", 3).ToList()[2];

            proyectoTest.AgregarTipoDeItem(tipoItem);

            db.Store(proyectoTest);

            db.Close();

            //-----------------------------------------------------------------------------------------

            db = servidor.OpenClient();

            proyectoTest = null;
            var proyectoTest2 = (from Proyecto p in db select p).ToList()[0];


            db.Close();

            //-----------------------------------------------------------------------------------------

            servidor.Close();
        }
Ejemplo n.º 16
0
 public static void Main(string[] args)
 {
     using (IObjectServer server = Db4oClientServer.OpenServer("database.db4o", Port))
     {
         server.GrantAccess(UserAndPassword, UserAndPassword);
         GrabSemaphore();
         TryGrabSemaphore();
     }
 }
Ejemplo n.º 17
0
 private static void RegisterForEventsOnTheServer()
 {
     // #example: register for events on the server
     IObjectServer server =
         Db4oClientServer.OpenServer(DatabaseFileName, PortNumber);
     IEventRegistry eventsOnServer =
         EventRegistryFactory.ForObjectContainer(server.Ext().ObjectContainer());
     // #end example
 }
Ejemplo n.º 18
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);
            }
Ejemplo n.º 19
0
        protected override void StartServer()
        {
            string databasePath = InitDatabaseFile();

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

            _server.Ext().Configure().ClientServer().SetMessageRecipient(this);
        }
Ejemplo n.º 20
0
        private static void RunClientServer()
        {
            using (IObjectServer server = Db4oClientServer.OpenServer("database.db4o", 8080))
            {
                server.GrantAccess("user", "password");

                OpenClient();
            }
        }
Ejemplo n.º 21
0
        private IObjectServer GetEmbeddedServer(DB4ODatabaseElement dataBaseData, int retries, HttpContext context)
        {
            IObjectServer database;

            var databaseAlias = dataBaseData.Alias;

            if (_repository.AnyDataBase())
            {
                database = _repository.GetDataBase <IObjectServer>(databaseAlias);

                if (database != null)
                {
                    Debug.WriteLine(String.Format("GetEmbeddedServer ({0}, retry {1}) return cached database from repository", dataBaseData.Alias, retries));

                    return(database);
                }
            }

            if (dataBaseData.ServerType == Db4oServerType.NetworkingServer)
            {
                throw new Exception(String.Format("The server '{0}' is remote and you can´t get a instance of this server", databaseAlias));
            }

            lock (_thisLock)
            {
                var serverConfig = Db4oClientServer.NewServerConfiguration();

                if (dataBaseData.ExistAnyCustomConfiguration())
                {
                    serverConfig = dataBaseData.GetServerConfig <IServerConfiguration>();
                }

                try
                {
                    database = Db4oClientServer.OpenServer(
                        serverConfig, GetAbsolutePath(dataBaseData.FileDb4oPath, context), Embeddedportserver);
                }
                catch (DatabaseFileLockedException)
                {
                    if (retries < dataBaseData.OpenServerRetries)
                    {
                        Debug.WriteLine(String.Format("DatabaseFileLockedException (database: {1}) retry {0}", retries, dataBaseData.Alias));

                        return(GetEmbeddedServer(dataBaseData, retries + 1, context));
                    }

                    throw;
                }

                _repository.AddDataBase(databaseAlias, database);

                Debug.WriteLine(String.Format("AddDataBase (database: '{0}') to Repository", dataBaseData.Alias));
            }

            return(database);
        }
Ejemplo n.º 22
0
        private static void ServerConfiguration()
        {
            // #example: Configure the db4o-server
            IServerConfiguration configuration = Db4oClientServer.NewServerConfiguration();
            // change the configuration...
            IObjectServer server = Db4oClientServer.OpenServer(configuration, "database.db4o", 1337);

            // #end example
            server.Close();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 25
0
 public static void AccessLocalServer()
 {
     using (IObjectServer server = Db4oClientServer.OpenServer(YapFileName, 0))
     {
         using (IObjectContainer client = server.OpenClient())
         {
             // Do something with this client, or open more clients
         }
     }
 }
Ejemplo n.º 26
0
        private void OpenServer()
        {
            IServerConfiguration serverConfig = Db4oClientServer.NewServerConfiguration();

            //serverConfig.Common.ObjectClass(typeof(人员)).MinimumActivationDepth(5);
            //serverConfig.Common.ObjectClass(typeof(人员)).CascadeOnUpdate(true);
            //serverConfig.Common.ObjectClass(typeof(人员)).CascadeOnDelete(true);
            serverConfig.Common.Queries.EvaluationMode(QueryEvaluationMode.Lazy);
            _db4OServer = Db4oClientServer.OpenServer(serverConfig, _dbFilePath, 0);
        }
Ejemplo n.º 27
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);
        }
Ejemplo n.º 28
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
        }
Ejemplo n.º 29
0
 public void Open(string fname, bool clientServer)
 {
     if (clientServer)
     {
         _server    = Db4oClientServer.OpenServer(fname, 0);
         _container = _server.OpenClient();
     }
     else
     {
         _container = Db4oFactory.OpenFile(fname);
     }
 }
        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();
        }