private static void OneWayReplicationExample()
        {
            DeleteDatabases();
            StoreObjectsIn(DesktopDatabaseName);

            //#example: Prepare unidirectional replication
            IObjectContainer desktopDatabase = OpenDatabase(DesktopDatabaseName);
            IObjectContainer mobileDatabase = OpenDatabase(MobileDatabaseName);

            IReplicationProvider dektopReplicationProvider
                = new Db4oEmbeddedReplicationProvider(desktopDatabase);
            IReplicationProvider mobileReplicationProvider
                = new Db4oEmbeddedReplicationProvider(mobileDatabase);

            IReplicationSession replicationSession 
                = Replication.Begin(dektopReplicationProvider, mobileReplicationProvider);
            // set the replication-direction from the desktop database to the mobile database. 
            replicationSession.SetDirection(replicationSession.ProviderA(), replicationSession.ProviderB());
            //#end example

            //#example: One direction replication
            IObjectSet changes = replicationSession.ProviderA().ObjectsChangedSinceLastReplication();
            foreach (object changedObject in changes)
            {
                replicationSession.Replicate(changedObject);
            }
            replicationSession.Commit();
            //#end example

            PrintCars(mobileDatabase);

            CloseDBs(desktopDatabase, mobileDatabase);
        }
        private static void ReplicationConflicts()
        {
            DeleteDatabases();

            IObjectContainer desktopDatabase = OpenDatabase(DesktopDatabaseName);
            desktopDatabase.Store(new Pilot("Max"));
            IObjectContainer mobileDatabase = OpenDatabase(MobileDatabaseName);

            ReplicateBidirectional(desktopDatabase, mobileDatabase);


            UpdateObject(desktopDatabase);
            UpdateObject(mobileDatabase);

            IReplicationProvider desktopRelicationPartner = new Db4oEmbeddedReplicationProvider(desktopDatabase);
            IReplicationProvider mobileRelicationPartner = new Db4oEmbeddedReplicationProvider(mobileDatabase);

            // #example: Deal with conflicts
            IReplicationSession replicationSession =
                Replication.Begin(desktopRelicationPartner, mobileRelicationPartner,
                                    new SimpleConflictResolvingListener());
            // #end example

            ReplicateBidirectional(replicationSession);
            replicationSession.Commit();

            CloseDBs(desktopDatabase, mobileDatabase);
        }
		protected virtual void AssertReplicates(object holder)
		{
			IEmbeddedObjectContainer sourceDb = OpenContainer("source");
			sourceDb.Store(holder);
			sourceDb.Commit();
			IEmbeddedObjectContainer targetDb = OpenContainer("target");
			try
			{
				Db4oEmbeddedReplicationProvider providerA = new Db4oEmbeddedReplicationProvider(sourceDb
					);
				Db4oEmbeddedReplicationProvider providerB = new Db4oEmbeddedReplicationProvider(targetDb
					);
				IReplicationSession replication = Replication.Begin(providerA, providerB);
				IObjectSet changed = replication.ProviderA().ObjectsChangedSinceLastReplication();
				while (changed.HasNext())
				{
					object o = changed.Next();
					if (holder.GetType() == o.GetType())
					{
						replication.Replicate(o);
						break;
					}
				}
				replication.Commit();
			}
			finally
			{
				sourceDb.Close();
				targetDb.Close();
			}
		}
        private static void BiDirectionalReplicationExample()
        {
            DeleteDatabases();
            StoreObjectsIn(DesktopDatabaseName);
            StoreObjectsIn(MobileDatabaseName);

            // #example: Prepare bidirectional replication
            IObjectContainer desktopDatabase = OpenDatabase(DesktopDatabaseName);
            IObjectContainer mobileDatabase = OpenDatabase(MobileDatabaseName);

            IReplicationProvider dektopReplicationProvider
                = new Db4oEmbeddedReplicationProvider(desktopDatabase);
            IReplicationProvider mobileReplicationProvider
                = new Db4oEmbeddedReplicationProvider(mobileDatabase);

            IReplicationSession replicationSession
                = Replication.Begin(dektopReplicationProvider, mobileReplicationProvider);
            // #end example

            //#example: Bidirectional replication
            // First get the changes of the two replication-partners
            IObjectSet changesOnDesktop = replicationSession.ProviderA().ObjectsChangedSinceLastReplication();
            IObjectSet changesOnMobile = replicationSession.ProviderB().ObjectsChangedSinceLastReplication();

            // then iterate over both change-sets and replicate it
            foreach (object changedObjectOnDesktop in changesOnDesktop)
            {
                replicationSession.Replicate(changedObjectOnDesktop);
            }

            foreach (object changedObjectOnMobile in changesOnMobile)
            {
                replicationSession.Replicate(changedObjectOnMobile);
            }

            replicationSession.Commit();
            //#end example

            PrintCars(mobileDatabase);
            PrintCars(desktopDatabase);

            CloseDBs(desktopDatabase, mobileDatabase);
        }
        private static void EventExample()
        {
            DeleteDatabases();
            StoreObjectsIn(DesktopDatabaseName);

            IObjectContainer desktopDatabase = OpenDatabase(DesktopDatabaseName);
            IObjectContainer mobileDatabase = OpenDatabase(MobileDatabaseName);

            IReplicationProvider desktopRelicationPartner
                = new Db4oEmbeddedReplicationProvider(desktopDatabase);
            IReplicationProvider mobileRelicationPartner
                = new Db4oEmbeddedReplicationProvider(mobileDatabase);

            // #example: Register a listener for information about the replication process
            IReplicationSession replicationSession 
                = Replication.Begin(desktopRelicationPartner,mobileRelicationPartner,new LogReplicationListener());
            // #end example
            ReplicateBidirectional(replicationSession);

            replicationSession.Commit();
            CloseDBs(desktopDatabase, mobileDatabase);
        }
 public _IProcedure4_94(Db4oEmbeddedReplicationProvider _enclosing)
 {
     this._enclosing = _enclosing;
 }
        private static void Replicate(IObjectContainer desktopDatabase, IObjectContainer mobileDatabase)
        {
            IReplicationProvider dektopReplicationProvider
                = new Db4oEmbeddedReplicationProvider(desktopDatabase);
            IReplicationProvider mobileReplicationProvider
                = new Db4oEmbeddedReplicationProvider(mobileDatabase);

            IReplicationSession replicationSession
                = Replication.Begin(dektopReplicationProvider, mobileReplicationProvider);
            ReplicateChanges(replicationSession, replicationSession.ProviderA());
            ReplicateChanges(replicationSession, replicationSession.ProviderB());
            replicationSession.Commit();
        }
        private static void DeletionsReplication()
        {
            DeleteDatabases();
            StoreObjectsIn(DesktopDatabaseName);
            IObjectContainer desktopDatabase = OpenDatabase(DesktopDatabaseName);
            IObjectContainer mobileDatabase = OpenDatabase(MobileDatabaseName);

            Replicate(desktopDatabase, mobileDatabase);

            Car carToDelete = desktopDatabase.Query<Car>()[0];
            desktopDatabase.Delete(carToDelete);
            desktopDatabase.Commit();

            PrintCars(mobileDatabase);

            IReplicationProvider dektopReplicationProvider
                = new Db4oEmbeddedReplicationProvider(desktopDatabase);
            IReplicationProvider mobileReplicationProvider
                = new Db4oEmbeddedReplicationProvider(mobileDatabase);

            // #example: Replicate deletions
            IReplicationSession replicationSession
                = Replication.Begin(dektopReplicationProvider, mobileReplicationProvider);

            replicationSession.ReplicateDeletions(typeof (Car));
            replicationSession.Commit();
            // #end example

            PrintCars(mobileDatabase);

            CloseDBs(desktopDatabase, mobileDatabase);
        }
        private static void SelectiveReplicationWithQuery()
        {
            DeleteDatabases();
            StoreObjectsIn(DesktopDatabaseName);

            IObjectContainer desktopDatabase = OpenDatabase(DesktopDatabaseName);
            IObjectContainer mobileDatabase = OpenDatabase(MobileDatabaseName);

            IReplicationProvider dektopReplicationProvider
                = new Db4oEmbeddedReplicationProvider(desktopDatabase);
            IReplicationProvider mobileReplicationProvider
                = new Db4oEmbeddedReplicationProvider(mobileDatabase);

            IReplicationSession replicationSession
                = Replication.Begin(dektopReplicationProvider, mobileReplicationProvider);

            // #example: Selective replication with a query
            IList<Car> changesOnDesktop = 
                desktopDatabase.Query(delegate(Car car) { return car.Name.StartsWith("M"); });

            foreach (Car changedObjectOnDesktop  in changesOnDesktop)
            {
                replicationSession.Replicate(changedObjectOnDesktop);
            }

            replicationSession.Commit();
            // #end example

            // now only the cars which names start with "M" are replicated
            PrintCars(mobileDatabase);

            CloseDBs(desktopDatabase, mobileDatabase);
        }
        private static void SelectiveReplicationWithCondition()
        {
            DeleteDatabases();
            StoreObjectsIn(DesktopDatabaseName);

            IObjectContainer desktopDatabase = OpenDatabase(DesktopDatabaseName);
            IObjectContainer mobileDatabase = OpenDatabase(MobileDatabaseName);

            IReplicationProvider dektopReplicationProvider
                = new Db4oEmbeddedReplicationProvider(desktopDatabase);
            IReplicationProvider mobileReplicationProvider
                = new Db4oEmbeddedReplicationProvider(mobileDatabase);

            IReplicationSession replicationSession
                = Replication.Begin(dektopReplicationProvider, mobileReplicationProvider);

            // #example: Selective replication with a condition
            IObjectSet changesOnDesktop = replicationSession.ProviderA().ObjectsChangedSinceLastReplication();

            foreach (object changedObjectOnDesktop in changesOnDesktop)
            {
                if (changedObjectOnDesktop is Car)
                {
                    if (((Car) changedObjectOnDesktop).Name.StartsWith("M"))
                    {
                        replicationSession.Replicate(changedObjectOnDesktop);
                    }
                }
            }

            replicationSession.Commit();
            // #end example

            // now only the cars which names start with "M" are replicated
            PrintCars(mobileDatabase);

            CloseDBs(desktopDatabase, mobileDatabase);
        }
        private static void SelectiveReplicationByClass()
        {
            DeleteDatabases();
            StoreObjectsIn(DesktopDatabaseName);

            IObjectContainer desktopDatabase = OpenDatabase(DesktopDatabaseName);
            IObjectContainer mobileDatabase = OpenDatabase(MobileDatabaseName);

            IReplicationProvider dektopReplicationProvider
                = new Db4oEmbeddedReplicationProvider(desktopDatabase);
            IReplicationProvider mobileReplicationProvider
                = new Db4oEmbeddedReplicationProvider(mobileDatabase);

            IReplicationSession replicationSession
                = Replication.Begin(dektopReplicationProvider, mobileReplicationProvider);

            // #example: Selective replication by class
            IObjectSet changesOnDesktop = 
                replicationSession.ProviderA().ObjectsChangedSinceLastReplication(typeof (Pilot));

            foreach (object changedObjectOnDesktop in changesOnDesktop)
            {
                replicationSession.Replicate(changedObjectOnDesktop);
            }

            replicationSession.Commit();
            // #end example

            // the car's aren't replicated, only the pilots
            PrintCars(mobileDatabase);
            PrintPilots(mobileDatabase);

            CloseDBs(desktopDatabase, mobileDatabase);
        }
			public _IProcedure4_94(Db4oEmbeddedReplicationProvider _enclosing)
			{
				this._enclosing = _enclosing;
			}
        private static void ReplicationConflictTakeLatestChange()
        {
            DeleteDatabases();

            IObjectContainer desktopDatabase = OpenDatabase(DesktopDatabaseName);
            desktopDatabase.Store(new Pilot("Max"));
            IObjectContainer mobileDatabase = OpenDatabase(MobileDatabaseName);

            ReplicateBidirectional(desktopDatabase, mobileDatabase);


            UpdateObject(desktopDatabase);
            UpdateObject(mobileDatabase);

            IReplicationProvider desktopRelicationPartner
                = new Db4oEmbeddedReplicationProvider(desktopDatabase);
            IReplicationProvider mobileRelicationPartner
                = new Db4oEmbeddedReplicationProvider(mobileDatabase);

            // #example: Take latest change
            IReplicationSession replicationSession =
                Replication.Begin(desktopRelicationPartner, mobileRelicationPartner,
                                   new TakeLatestModificationOnConflictListener());
            // #end example

            ReplicateBidirectional(replicationSession);
            replicationSession.Commit();

            CloseDBs(desktopDatabase, mobileDatabase);
        }
        private static void ReplicateBidirectional(IObjectContainer desktopDatabase, IObjectContainer mobileDatabase)
        {
            IReplicationProvider desktopRelicationPartner
                = new Db4oEmbeddedReplicationProvider(desktopDatabase);
            IReplicationProvider mobileRelicationPartner
                = new Db4oEmbeddedReplicationProvider(mobileDatabase);

            IReplicationSession replicationSession 
                = Replication.Begin(desktopRelicationPartner,mobileRelicationPartner);
            ReplicateBidirectional(replicationSession);
            replicationSession.Commit();
        }
        private static void MigrationOnTheFly()
        {
            DeleteDatabases();

            IObjectContainer desktopDatabaseWithoutUUID = Db4oEmbedded.OpenFile(DesktopDatabaseName);
            desktopDatabaseWithoutUUID.Store(new Car(new Pilot("Max"), "Max's Car"));
            desktopDatabaseWithoutUUID.Store(new Car(new Pilot("Joe"), "Joe's Car"));
            desktopDatabaseWithoutUUID.Commit();
            desktopDatabaseWithoutUUID.Close();

            IObjectContainer desktopDatabase = OpenDatabase(DesktopDatabaseName);
            IObjectContainer mobileDatabase = OpenDatabase(MobileDatabaseName);

            IReplicationProvider desktopRelicationPartner
                = new Db4oEmbeddedReplicationProvider(desktopDatabase);
            IReplicationProvider mobileRelicationPartner
                = new Db4oEmbeddedReplicationProvider(mobileDatabase);

            // #example: Migrate on the fly
            IReplicationSession replicationSession = Replication.Begin(desktopRelicationPartner, mobileRelicationPartner);
            IList<Car> initialReplication = desktopDatabase.Query<Car>();

            foreach (Car changedObjectOnDesktop in initialReplication)
            {
                IObjectInfo infoAboutObject = desktopDatabase.Ext().GetObjectInfo(changedObjectOnDesktop);
                if (null == infoAboutObject.GetUUID())
                {
                    desktopDatabase.Ext().Store(changedObjectOnDesktop, 2);
                }
                replicationSession.Replicate(changedObjectOnDesktop);
            }
            replicationSession.Commit();
            // #end example

            PrintCars(mobileDatabase);

            CloseDBs(desktopDatabase, mobileDatabase);
        }
        private static void ConcurrencyLimitations()
        {
            DeleteDatabases();

            // #example: Lost replication
            IObjectServer serverDatabase = OpenDatabaseServer(DesktopDatabaseName);
            IObjectContainer mobileDatabase = OpenDatabase(MobileDatabaseName);

            {
                IObjectContainer serverDbConnection = 
                    Db4oClientServer.OpenClient(Host, Port, UserName, UserName);
                serverDbConnection.Store(new Pilot("Pilot 1"));
                serverDbConnection.Commit();

                // The replication starts here
                IObjectContainer connectionForReplication = 
                    Db4oClientServer.OpenClient(Host, Port, UserName, UserName);

                IReplicationProvider clientReplication
                    = new Db4oEmbeddedReplicationProvider(connectionForReplication);
                IReplicationProvider mobileRelicationPartner
                    = new Db4oEmbeddedReplicationProvider(mobileDatabase);

                IReplicationSession replicationSession =
                    Replication.Begin(clientReplication, mobileRelicationPartner);
                IObjectSet changesOnDesktop = 
                    replicationSession.ProviderA().ObjectsChangedSinceLastReplication();

                // during the replication other clients store data on the server
                serverDbConnection.Store(new Pilot("Pilot 2"));
                serverDbConnection.Commit();

                foreach (object changedObjectOnDesktop in changesOnDesktop)
                {
                    replicationSession.Replicate(changedObjectOnDesktop);
                }

                replicationSession.Commit();

                serverDbConnection.Store(new Pilot("Pilot 3"));
                serverDbConnection.Commit();
            }

            // Pilot 2 is not replicated
            PrintPilots(mobileDatabase);


            {
                IObjectContainer connectionForReplication =
                    Db4oClientServer.OpenClient(Host, Port, UserName, UserName);

                IReplicationProvider clientRelicationPartner
                    = new Db4oEmbeddedReplicationProvider(connectionForReplication);
                IReplicationProvider mobileRelicationPartner
                    = new Db4oEmbeddedReplicationProvider(mobileDatabase);

                IReplicationSession replicationSession =
                    Replication.Begin(clientRelicationPartner, mobileRelicationPartner);
                IObjectSet changesOnDesktop = 
                    replicationSession.ProviderA().ObjectsChangedSinceLastReplication();
                foreach (object changedOnDesktop in changesOnDesktop)
                {
                    replicationSession.Replicate(changedOnDesktop);
                }
                replicationSession.Commit();
            }

            // Pilot 2 is still not replicated
            PrintPilots(mobileDatabase);
            // #end example

            serverDatabase.Close();
            mobileDatabase.Close();
        }