Пример #1
0
        static void Main(string[] args)
        {
            // connect to the first compact client DB
            SqlCeConnection clientConn = new SqlCeConnection(@"Data Source='C:\dev\SyncTest\SyncSQLServerAndSQLCompact\data\SyncCompactDB.sdf'");

            // create a snapshot of SyncCompactDB and save it to SyncCompactDB2 database
            SqlCeSyncStoreSnapshotInitialization syncStoreSnapshot = new SqlCeSyncStoreSnapshotInitialization();
            syncStoreSnapshot.GenerateSnapshot(clientConn, @"C:\dev\SyncTest\SyncSQLServerAndSQLCompact\data\SyncCompactDB2.sdf");
        }
Пример #2
0
        static void Main(string[] args)
        {
            // connect to the first compact client DB
            SqlCeConnection clientConn = new SqlCeConnection(@"Data Source='C:\dev\SyncTest\SyncSQLServerAndSQLCompact\data\SyncCompactDB.sdf'");

            // create a snapshot of SyncCompactDB and save it to SyncCompactDB2 database
            SqlCeSyncStoreSnapshotInitialization syncStoreSnapshot = new SqlCeSyncStoreSnapshotInitialization();

            syncStoreSnapshot.GenerateSnapshot(clientConn, @"C:\dev\SyncTest\SyncSQLServerAndSQLCompact\data\SyncCompactDB2.sdf");
        }
Пример #3
0
        public void ExportClientDatabase(SqlCeConnection sourceConnection, string destFileName)
        {
            try
            {
                //Configure a CE provider for the source connection and then generate the snapshot from that file
                SqlCeSyncStoreSnapshotInitialization snapshotInit = new SqlCeSyncStoreSnapshotInitialization();
                snapshotInit.GenerateSnapshot(sourceConnection, destFileName);

                MessageBox.Show("Snapshot successfully generated to location " + destFileName, "Snapshot Generation Result", MessageBoxButtons.OK);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString(), "Error in generating Snapshot", MessageBoxButtons.OK);
            }
        }
        static void Main(string[] args)
        {
            //The Utility class handles all functionality that is not
            //directly related to synchronization, such as holding peerConnection
            //string information and making changes to the server database.
            Utility util = new Utility();

            util.RecreateCePeerDatabase(util.Ce1ConnString);
            util.RecreateCePeerDatabase(util.Ce2ConnString);

            //<snippetOCSv2_CS_Basic_PeerWithCe_Synchronize>
            //The SampleStats class handles information from the SyncStatistics
            //object that the Synchronize method returns.
            SampleStats sampleStats = new SampleStats();

            try
            {
                //Initial synchronization. Instantiate the SyncOrchestrator
                //and call Synchronize.
                SampleSyncProvider      sampleSyncProvider = new SampleSyncProvider();
                SyncOrchestrator        sampleSyncAgent;
                SyncOperationStatistics syncStatistics;

                //First session: Synchronize two databases by using two instances
                //of DbSyncProvider.
                sampleSyncAgent = new SampleSyncAgent(
                    sampleSyncProvider.ConfigureDbSyncProvider(util.Peer1ConnString),
                    sampleSyncProvider.ConfigureDbSyncProvider(util.Peer2ConnString));
                syncStatistics = sampleSyncAgent.Synchronize();
                sampleStats.DisplayStats(syncStatistics, "initial");

                //<snippetOCSv2_CS_Basic_PeerWithCe_SnapshotInit>
                //Second session: Synchronize two databases by using one instance of
                //DbSyncProvider and one instance of SqlCeSyncProvider. After the Compact
                //database is initialized, it is copied by using GenerateSnapshot and then
                //used for the third session.
                SqlCeSyncProvider sqlCeSyncProvider1 = sampleSyncProvider.ConfigureCeSyncProvider(util.Ce1ConnString);

                sampleSyncAgent = new SampleSyncAgent(
                    sampleSyncProvider.ConfigureDbSyncProvider(util.Peer1ConnString),
                    sqlCeSyncProvider1);
                syncStatistics = sampleSyncAgent.Synchronize();
                sampleStats.DisplayStats(syncStatistics, "initial");

                //Copy the Compact database and save it as SyncSampleCe2.sdf.
                SqlCeSyncStoreSnapshotInitialization snapshotInit = new SqlCeSyncStoreSnapshotInitialization();
                snapshotInit.GenerateSnapshot(new SqlCeConnection(util.Ce1ConnString), "SyncSampleCe2.sdf");

                //Make a change that is synchronized during the third session.
                util.MakeDataChangesOnPeer(util.Peer1ConnString, "Customer");

                //Third session: Synchronize the new Compact database. The five rows
                //from SyncSampleCe1.sdf are already in SyncSampleCe2.sdf. The new
                //change is now downloaded to bring SyncSampleCe2.sdf up to date.
                //SyncSampleCe2.sdf will get this row during the next round of
                //synchronization sessions.
                sampleSyncAgent = new SampleSyncAgent(
                    sampleSyncProvider.ConfigureDbSyncProvider(util.Peer1ConnString),
                    sampleSyncProvider.ConfigureCeSyncProvider(util.Ce2ConnString));
                syncStatistics = sampleSyncAgent.Synchronize();
                sampleStats.DisplayStats(syncStatistics, "initial");
                //</snippetOCSv2_CS_Basic_PeerWithCe_SnapshotInit>
            }


            catch (DbOutdatedSyncException ex)
            {
                Console.WriteLine("Outdated Knowledge: " + ex.OutdatedPeerSyncKnowledge.ToString() +
                                  " Clean up knowledge: " + ex.MissingCleanupKnowledge.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            //</snippetOCSv2_CS_Basic_PeerWithCe_Synchronize>

            //Make a change in one of the databases.
            util.MakeDataChangesOnPeer(util.Peer2ConnString, "Customer");

            try
            {
                //Subsequent synchronization. Changes are now synchronized between all
                //nodes.
                SampleSyncProvider      sampleSyncProvider = new SampleSyncProvider();
                SyncOrchestrator        sampleSyncAgent;
                SyncOperationStatistics syncStatistics;

                sampleSyncAgent = new SampleSyncAgent(
                    sampleSyncProvider.ConfigureDbSyncProvider(util.Peer1ConnString),
                    sampleSyncProvider.ConfigureDbSyncProvider(util.Peer2ConnString));
                syncStatistics = sampleSyncAgent.Synchronize();
                sampleStats.DisplayStats(syncStatistics, "subsequent");

                sampleSyncAgent = new SampleSyncAgent(
                    sampleSyncProvider.ConfigureDbSyncProvider(util.Peer1ConnString),
                    sampleSyncProvider.ConfigureCeSyncProvider(util.Ce1ConnString));
                syncStatistics = sampleSyncAgent.Synchronize();
                sampleStats.DisplayStats(syncStatistics, "subsequent");

                sampleSyncAgent = new SampleSyncAgent(
                    sampleSyncProvider.ConfigureDbSyncProvider(util.Peer1ConnString),
                    sampleSyncProvider.ConfigureCeSyncProvider(util.Ce2ConnString));
                syncStatistics = sampleSyncAgent.Synchronize();
                sampleStats.DisplayStats(syncStatistics, "subsequent");
            }


            catch (DbOutdatedSyncException ex)
            {
                Console.WriteLine("Outdated Knowledge: " + ex.OutdatedPeerSyncKnowledge.ToString() +
                                  " Clean up knowledge: " + ex.MissingCleanupKnowledge.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            //Return data back to its original state.
            util.CleanUpPeer(util.Peer1ConnString);
            util.CleanUpPeer(util.Peer2ConnString);

            //Exit.
            Console.Write("\nPress Enter to close the window.");
            Console.ReadLine();
        }