コード例 #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.");
            }
            //}
        }
コード例 #3
0
			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"));
     }
 }
コード例 #5
0
 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();
        }
コード例 #7
0
 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"));
 }
コード例 #10
0
        /// <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
ファイル: StoreFactory.cs プロジェクト: kouweizhong/Sop
 // 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
ファイル: ClientServerExample.cs プロジェクト: superyfwy/db4o
 public static void QueryLocalServer(IObjectServer server)
 {
     using(IObjectContainer client = server.OpenClient())
     {
         ListResult(client.QueryByExample(new Car(null)));
     }
 }
コード例 #17
0
ファイル: ClientServerExample.cs プロジェクト: pondyond/db4o
        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
ファイル: ConnectionPoolExamples.cs プロジェクト: yuuhhe/db4o
        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
ファイル: TestConnectionPool.cs プロジェクト: superyfwy/db4o
 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);
            }
コード例 #26
0
 protected virtual void InitializeAccessControl(IObjectServer db4oServer)
 {
     if (!String.IsNullOrEmpty(ClientUsername))
     {
         db4oServer.GrantAccess(ClientUsername, ClientPassword);
     }
 }
コード例 #27
0
ファイル: ReferenceCacheExamples.cs プロジェクト: yuuhhe/db4o
 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);
 }
コード例 #33
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());
            }
        }
コード例 #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));
        }
コード例 #35
0
        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();
            }
        }
コード例 #36
0
        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);
        }
コード例 #37
0
        protected override void StartServer()
        {
            var databasePath = InitDatabaseFile();
            _server = Db4oClientServer.OpenServer(databasePath, Port);
            _server.GrantAccess(USER_NAME, USER_PWD);

            _server.Ext().Configure().ClientServer().SetMessageRecipient(this);
        }
コード例 #38
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);
			}
コード例 #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
ファイル: MonitoringDemo.cs プロジェクト: Galigator/db4o
		private void Close(IObjectContainer objectContainer)
		{
			objectContainer.Close();
			if (_server != null)
			{
				_server.Close();
				_server = null;
			}
		}
コード例 #41
0
ファイル: Sessionfactory.cs プロジェクト: Itslet/Inventory
        public static ISession CreateSession()
        {
            if (_server == null)
            {
                _server = Db4oFactory.OpenServer( @"c:\temp\inventoryDb", 0);
            }

            return new Db4oSession(_server);
        }
コード例 #42
0
        /// <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;
		}
コード例 #44
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);
		}
コード例 #45
0
        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);
        }
コード例 #46
0
        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);
     }
 }
コード例 #49
0
		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
ファイル: MonitoringDemo.cs プロジェクト: Galigator/db4o
		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
ファイル: BeekDataAccess.cs プロジェクト: boriscallens/Beek
        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
ファイル: SessionSource.cs プロジェクト: zam17/lean-planner
        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);
            }
        }