예제 #1
0
        private void CloseDb4OContainer()
        {
            if (!UseClient && _emmbededServer == null)
            {
                return;
            }

            if (UseClient && _embeddedContainer == null)
            {
                return;
            }

            if (!UseClient)
            {
                _emmbededServer.Close();
                _emmbededServer.Dispose();
                _emmbededServer = null;
            }
            else
            {
                _embeddedContainer.Close();
                _embeddedContainer.Dispose();
                _embeddedContainer = null;
            }

            _isDb4OInitiated = false;
        }
예제 #2
0
        /// <summary>
        /// Opens the db4o object container.
        /// </summary>
        public void OpenContainer()
        {
            //using (LogGroup logGroup = LogGroup.StartDebug("Opening db4o data container."))
            //{
            LogWriter.Debug("${db4o.OpenContainer:" + Name + "}");

            string fileName = Name;

            string fullName = GetStoreFileName();

            //	LogWriter.Debug("Full file name: " + fullName);

            // Get the server (this activates JIT loading if necessary)
            IObjectServer server = ObjectServer;

            if (!Directory.Exists(Path.GetDirectoryName(fullName)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(fullName));
            }

            // This info should come after the JIT loading of the object server (to make them show up in the right order in the logs)
            //	LogWriter.Debug("Opening db4o object container: " + Name);

            if (server != null)
            {
                ObjectContainer = server.OpenClient();
            }
            else
            {
                LogWriter.Error("Can't open container because server is not initialized.");
            }
            //}
        }
			internal void Verify(IServerConfiguration config, IObjectServer server)
			{
				Assert.AreSame(config, this._config);
				Assert.AreSame(server, this._server);
				Assert.AreEqual(1, this._prepareCount);
				Assert.AreEqual(1, this._applyCount);
			}
예제 #4
0
 private static void StoreData(IObjectServer server)
 {
     using (IObjectContainer container = server.OpenClient())
     {
         container.Store(new Person("Joe"));
     }
 }
 internal void Verify(IServerConfiguration config, IObjectServer server)
 {
     Assert.AreSame(config, _config);
     Assert.AreSame(server, _server);
     Assert.AreEqual(1, _prepareCount);
     Assert.AreEqual(1, _applyCount);
 }
예제 #6
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 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);
 }
예제 #8
0
 public Db4oBeekRepository(IObjectServer beekServer)
 {
     server = beekServer;
     client = server.OpenClient();
     genreLock = new object();
     beekLock = new object();
 }
예제 #9
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"));
 }
        /// <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
        /// <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();
            }
        }
예제 #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");
		}
예제 #13
0
        private static IObjectServer OpenServer(IServerConfiguration configuration)
        {
            IObjectServer server = Db4oClientServer.OpenServer(configuration, DatabaseFileName, PortNumber);

            server.GrantAccess(UserAndPassword, UserAndPassword);
            return(server);
        }
예제 #14
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);
     }
 }
예제 #15
0
 // todo: future task, move this into the core... (when Server is disposed, its Stores should auto-remove themselves from OpenedStores).
 internal static void RemoveServerStoresInMru(IObjectServer server)
 {
     Mru.Generic.ConcurrentMruManager <string, SpecializedStoreBase> openedStores =
         (Mru.Generic.ConcurrentMruManager <string, SpecializedStoreBase>)OpenedStores;
     lock (openedStores.Locker)
     {
         if (!openedStores.MruManager.CacheCollection.MoveFirst())
         {
             return;
         }
         List <KeyValuePair <string, ISortedDictionaryOnDisk> > storesForDispose =
             new List <KeyValuePair <string, ISortedDictionaryOnDisk> >(openedStores.Count);
         do
         {
             if (openedStores.MruManager.CacheCollection.CurrentValue.Value.Collection.File.Server != server)
             {
                 continue;
             }
             storesForDispose.Add(
                 new KeyValuePair <string, ISortedDictionaryOnDisk>(
                     openedStores.MruManager.CacheCollection.CurrentKey,
                     openedStores.MruManager.CacheCollection.CurrentValue.Value.Collection));
         } while (openedStores.MruManager.CacheCollection.MoveNext());
         // remove Stores identified to belong to the server received as parameter...
         foreach (var kvp in storesForDispose)
         {
             openedStores.MruManager.Remove(kvp.Key);
         }
     }
 }
예제 #16
0
 public static void QueryLocalServer(IObjectServer server)
 {
     using(IObjectContainer client = server.OpenClient())
     {
         ListResult(client.QueryByExample(new Car(null)));
     }
 }
예제 #17
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);
            }
        }
예제 #18
0
        private static IObjectServer StartServer()
        {
            IObjectServer server = Db4oClientServer.OpenServer("In:Memory", Port);

            server.GrantAccess(UserAndPassword, UserAndPassword);
            return(server);
        }
예제 #19
0
            public object Apply(object config)
            {
                IObjectServer server = this._enclosing.OpenServer(((IConfiguration)config), ".",
                                                                  0);

                return(new _IRunnable_33(server));
            }
예제 #20
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();
        }
예제 #21
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();
        }
예제 #22
0
파일: CSMonitoring.cs 프로젝트: yuuhhe/db4o
 public static void Main(string[] args)
 {
     using (IObjectServer server = StartServer())
     {
         RunClient();
     }
 }
예제 #23
0
 public void Setup()
 {
     server = CreateInMemoryServer();
     StoreTestObjects();
     assertConnectionFactory = NewFactory();
     toTest = new ConnectionPool(assertConnectionFactory.Connect);
 }
예제 #24
0
        public virtual void Test()
        {
            Collection4 expected = new Collection4(new object[] { "PING", true, 42 });

            MessagingTestCaseBase.MessageCollector recipient = new MessagingTestCaseBase.MessageCollector
                                                                   ();
            IObjectServer server = OpenServerWith(recipient);

            try
            {
                IObjectContainer client = OpenClient("client", server);
                try
                {
                    IMessageSender sender = MessageSender(client);
                    SendAll(expected, sender);
                }
                finally
                {
                    client.Close();
                }
            }
            finally
            {
                server.Close();
            }
            Assert.AreEqual(expected.ToString(), recipient.messages.ToString());
        }
예제 #25
0
            public virtual void Open()
            {
                IServerConfiguration config = Db4oClientServer.NewServerConfiguration();

                config.File.Storage = new MemoryStorage();
                _server             = Db4oClientServer.OpenServer(config, string.Empty, 0);
            }
 protected virtual void InitializeAccessControl(IObjectServer db4oServer)
 {
     if (!String.IsNullOrEmpty(ClientUsername))
     {
         db4oServer.GrantAccess(ClientUsername, ClientPassword);
     }
 }
예제 #27
0
 private static void StoreData(IObjectServer server)
 {
     using (IObjectContainer container = server.OpenClient())
     {
         container.Store(new Person("Joe"));
     }
 }
예제 #28
0
 public static void QueryLocalServer(IObjectServer server)
 {
     using (IObjectContainer client = server.OpenClient())
     {
         ListResult(client.QueryByExample(new Car(null)));
     }
 }
예제 #29
0
        private void AddItems(IObjectServer server)
        {
            IStoreFactory sf          = new StoreFactory();
            var           PeopleStore = sf.Get <long, Person>(server.SystemFile.Store, "People");
            const int     batchSize   = 1000;

            KeyValuePair <long, Person>[] batch = new KeyValuePair <long, Person> [batchSize];
            for (int i = 0; i < ItemCount;)
            {
                for (int ii = 0; ii < batchSize; ii++, i++)
                {
                    var id = PeopleStore.GetNextSequence();
                    batch[ii] = new KeyValuePair <long, Person>(id,
                                                                new Person
                    {
                        PersonId    = id,
                        FirstName   = string.Format("Joe{0}", id),
                        LastName    = string.Format("Petit{0}", id),
                        PhoneNumber = "555-999-4444"
                    });
                }
                PeopleStore.Locker.Invoke(() => { PeopleStore.Add(batch); });
                Console.WriteLine("{0}: Wrote a batch of {1} items.", DateTime.Now, batchSize);
                System.Threading.Thread.Sleep(1);
            }
            PeopleStore = null;
        }
예제 #30
0
        private static void EventsClientServer()
        {
            CleanUp();
            StoreJoe();

            using (IObjectServer server = OpenServer())
            {
                IEventRegistry eventsOnServer = EventRegistryFactory.ForObjectContainer(server.Ext().ObjectContainer());
                RegisterAFewEvents(eventsOnServer, "db4o server");

                IObjectContainer client1         = OpenClient();
                IEventRegistry   eventsOnClient1 = EventRegistryFactory.ForObjectContainer(client1);
                RegisterAFewEvents(eventsOnClient1, "db4o client 1");
                RunOperations(client1);


                IObjectContainer client2         = OpenClient();
                IEventRegistry   eventsOnClient2 = EventRegistryFactory.ForObjectContainer(client2);
                RegisterAFewEvents(eventsOnClient2, "db4o client 2");

                SleepForAWhile();
                client1.Dispose();
                client2.Dispose();
            }

            CleanUp();
        }
예제 #31
0
        private static IObjectServer OpenServer()
        {
            IObjectServer server = Db4oClientServer.OpenServer(DatabaseFileName, PortNumber);

            server.GrantAccess(EmbeddedUser, EmbeddedPassword);
            return(server);
        }
예제 #32
0
 public void Setup()
 {
     server = CreateInMemoryServer();
     StoreTestObjects();
     assertConnectionFactory = NewFactory();
     toTest = new ConnectionPool(assertConnectionFactory.Connect);
 }
        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());
            }
        }
예제 #34
0
        internal static void Initialize()
        {
            //TODO: Obtain addresses from some form of configuration...

            m_ObjectServer   = (IObjectServer)RemotingClient.GetServerObject(IPAddress.Loopback, 40001, "ObjectServer", typeof(IObjectServer));
            m_RedirectServer = (IRedirectServer)RemotingClient.GetServerObject(IPAddress.Loopback, 40004, "RedirectServer", typeof(IRedirectServer));
        }
        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();
            }
        }
        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);
        }
        protected override void StartServer()
        {
            var databasePath = InitDatabaseFile();
            _server = Db4oClientServer.OpenServer(databasePath, Port);
            _server.GrantAccess(USER_NAME, USER_PWD);

            _server.Ext().Configure().ClientServer().SetMessageRecipient(this);
        }
			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);
			}
예제 #39
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);
 }
예제 #40
0
		private void Close(IObjectContainer objectContainer)
		{
			objectContainer.Close();
			if (_server != null)
			{
				_server.Close();
				_server = null;
			}
		}
예제 #41
0
        public static ISession CreateSession()
        {
            if (_server == null)
            {
                _server = Db4oFactory.OpenServer( @"c:\temp\inventoryDb", 0);
            }

            return new Db4oSession(_server);
        }
        /// <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);
            }
        }
		public static PerformanceCounter CounterForNetworkingClientConnections(IObjectServer server)
		{
			PerformanceCounter clientConnections = NewDb4oCounter(PerformanceCounterSpec.NetClientConnections.Id, false);
			
			IObjectServerEvents serverEvents = (IObjectServerEvents) server;
			serverEvents.ClientConnected += delegate { clientConnections.Increment(); };
			serverEvents.ClientDisconnected += delegate { clientConnections.Decrement(); };

			return clientConnections;
		}
		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 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);
        }
        protected override void DoDisposal()
        {
            if(_server == null)
            {
                return;
            }

            _server.Close();
            _server.Dispose();
            _server = null;
        }
예제 #47
0
 public Db4oUserRepository(string db4oFilePath)
 {
     FileInfo file = new FileInfo(db4oFilePath);
     if (file.Directory != null && !file.Directory.Exists)
     {
         file.Directory.Create();
     }
     server = Db4oClientServer.OpenServer(db4oFilePath, 0);
     client = server.OpenClient();
     userLock = new object();
 }
예제 #48
0
 public void Open(string fname, bool clientServer)
 {
     if (clientServer)
     {
         _server = Db4oClientServer.OpenServer(fname, 0);
         _container = _server.OpenClient();
     }
     else
     {
         _container = Db4oFactory.OpenFile(fname);
     }
 }
		public void Apply(IObjectServer server)
		{
			PerformanceCounter clientConnections = null;

			ObjectContainerBase container = (ObjectContainerBase) server.Ext().ObjectContainer();
			container.WithEnvironment(delegate
			{
				clientConnections = Db4oClientServerPerformanceCounters.CounterForNetworkingClientConnections(server);
			});

			ServerEventsFor(server).Closed += delegate { clientConnections.RemoveInstance();};
		}
예제 #50
0
		public virtual void ApplyConfigurationItems(IObjectServer server)
		{
			if (_configItems == null)
			{
				return;
			}
			for (IEnumerator configItemIter = _configItems.GetEnumerator(); configItemIter.MoveNext
				(); )
			{
				IServerConfigurationItem configItem = ((IServerConfigurationItem)configItemIter.Current
					);
				configItem.Apply(server);
			}
		}
예제 #51
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);
		}
예제 #52
0
 public void Dispose()
 {
     if (null != _container)
     {
         _container.Close();
         _container = null;
     }
     if (null != _server)
     {
         _server.Close();
         _server = null;
     }
     // MAGIC: give some time for the db4o background threads to exit
     System.Threading.Thread.Sleep(1000);
 }
예제 #53
0
        private Db4oBeekRepository(string db4oFilePath)
        {
            db4oFilePath = EnsureDb4OFilePath(db4oFilePath);
            lock (servers)
            {
                if (!servers.ContainsKey(db4oFilePath))
                {
                    server = Db4oClientServer.OpenServer(db4oFilePath, 0);
                    servers.Add(db4oFilePath, server);
                }
            }

            server = servers[db4oFilePath];
            client = server.OpenClient();
            genreLock = new object();
            beekLock = new object();
        }
예제 #54
0
 public static void DemonstrateLocalReadCommitted(IObjectServer server)
 {
     //using (IObjectContainer client1 = server.OpenClient(),
     //    client2 = server.OpenClient())
     //{
     //    Pilot pilot = new Pilot("David Coulthard", 98);
     //    IObjectSet result = client1.QueryByExample(new Car("BMW"));
     //    Car car = (Car)result.Next();
     //    car.Pilot = pilot;
     //    client1.Store(car);
     //    ListResult(client1.QueryByExample(new Car(null)));
     //    ListResult(client2.QueryByExample(new Car(null)));
     //    client1.Commit();
     //    ListResult(client1.QueryByExample(typeof(Car)));
     //    ListRefreshedResult(client2, client2.QueryByExample(typeof(Car)), 2);
     //}
 }
예제 #55
0
 public static void DemonstrateLocalRollback(IObjectServer server)
 {
     //using (IObjectContainer client1 = server.OpenClient(),
     //    client2 = server.OpenClient())
     //{
     //    IObjectSet result = client1.QueryByExample(new Car("BMW"));
     //    Car car = (Car)result.Next();
     //    car.Pilot = new Pilot("Someone else", 0);
     //    client1.Store(car);
     //    ListResult(client1.QueryByExample(new Car(null)));
     //    ListResult(client2.QueryByExample(new Car(null)));
     //    client1.Rollback();
     //    client1.Ext().Refresh(car, 2);
     //    ListResult(client1.QueryByExample(new Car(null)));
     //    ListResult(client2.QueryByExample(new Car(null)));
     //}
 }
예제 #56
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);
            }
        }
예제 #57
0
        public BeekDataAccess()
        {
            string beekPath = IOHelper.MakeAbsolute(ConfigurationManager.AppSettings["beekRepository.path.db4o"]);
            string userPath = IOHelper.MakeAbsolute(ConfigurationManager.AppSettings["userRepository.path.db4o"]);
            if (!File.Exists(beekPath))
            {
                new FileInfo(beekPath).Directory.Create();
            }
            if (!File.Exists(userPath))
            {
                new FileInfo(userPath).Directory.Create();
            }

            beekServer = beekServer ?? Db4oClientServer.OpenServer(beekPath, 0);
            userServer = beekServer ?? Db4oClientServer.OpenServer(userPath, 0);
            beekRepos = new Db4oBeekRepository(beekServer);
            userRepository = new Db4oUserRepository(userServer);
        }
예제 #58
0
        public void Initialise()
        {
            _log.Debug("Loading " + Name);

            try
            {
                IConfiguration config = Db4oFactory.CloneConfiguration();
                config.LockDatabaseFile(false);
                config.UpdateDepth(2);

                // open the database connection
                _theDatabase = Db4oFactory.OpenServer(config, Db4oServiceConstants.DB_FILE_NAME, 0);
            }
            catch (Db4oException e)
            {
                throw new InitialisationException("Problem loading " + Name, e);
            }
        }
예제 #59
0
        public void Start(object coreRef)
        {
            _log.Debug("Loading " + Identify());
            _theCore = coreRef as PropagandaCore;

            try
            {
                IConfiguration config = Db4oFactory.CloneConfiguration();
                config.LockDatabaseFile(false);
                config.UpdateDepth(2);

                // open the database connection
                _theDatabase = Db4oFactory.OpenServer(config, DBServiceConstants.DB_FILE_NAME, 0);
            }
            catch (Db4oException e)
            {
                throw new InitialisationException("Problem loading " + Identify(), e);
            }
        }
예제 #60
0
        private void EnsureServer()
        {
            if (_server == null)
            {
                var dbPath = System.Configuration.ConfigurationManager
                    .ConnectionStrings["ObjectStore"].ConnectionString;

                if (dbPath.Contains("|DataDirectory|"))
                {
                    dbPath = dbPath.Replace("|DataDirectory|", "");
                    var appDir = HttpContext.Current.Server.MapPath("~/App_Data/");
                    dbPath = Path.Combine(appDir, dbPath);
                }

                var configuration = Db4oClientServer.NewServerConfiguration();
                configuration.Common.Add(new TransparentPersistenceSupport());
                configuration.Common.Add(new TransparentActivationSupport());
                _server = Db4oClientServer.OpenServer(configuration, dbPath, 0);
            }
        }