Beispiel #1
0
        static void Main(string[] args)
        {
            //The Utility class handles all functionality that is not
            //directly related to synchronization, such as holding connection
            //string information, and making changes to the server and client databases.
            Utility util = new Utility();

            //The SampleStatsAndProgress class handles information from the
            //SyncStatistics object that the Synchronize method returns and
            //from SyncAgent events.
            SampleStatsAndProgress sampleStats = new SampleStatsAndProgress();

            //Request a password for the client database, and delete
            //and re-create the database. The client synchronization
            //provider also enables you to create the client database
            //if it does not exist.
            util.SetClientPassword();
            util.RecreateClientDatabase();

            //Initial synchronization. Instantiate the SyncAgent
            //and call Synchronize.
            SampleSyncAgent sampleSyncAgent = new SampleSyncAgent();
            SyncStatistics  syncStatistics  = sampleSyncAgent.Synchronize();

            sampleStats.DisplayStats(syncStatistics, "initial");

            //Make changes on the server and client.
            util.MakeDataChangesOnServer("Customer");
            util.MakeDataChangesOnClient("Customer");

            //Subsequent synchronization.
            syncStatistics = sampleSyncAgent.Synchronize();
            sampleStats.DisplayStats(syncStatistics, "subsequent");

            //Make a change at the client that fails when it is
            //applied at the server.
            util.MakeFailingChangesOnClient();

            //Subsequent synchronization.
            syncStatistics = sampleSyncAgent.Synchronize();
            sampleStats.DisplayStats(syncStatistics, "subsequent");

            //Return server data back to its original state.
            util.CleanUpServer();

            //Exit.
            Console.Write("\nPress Enter to close the window.");
            Console.ReadLine();
        }
Beispiel #2
0
        public SampleSyncAgent()
        {
            //Instantiate a client synchronization provider and specify it
            //as the local provider for this synchronization agent.
            this.LocalProvider = new SampleClientSyncProvider();

            //Instantiate a server synchronization provider and specify it
            //as the remote provider for this synchronization agent.
            this.RemoteProvider = new SampleServerSyncProvider();

            //Create two SyncGroups so that changes to OrderHeader
            //and OrderDetail are made in one transaction. Depending on
            //application requirements, you might include Customer
            //in the same group.
            SyncGroup customerSyncGroup = new SyncGroup("Customer");
            SyncGroup orderSyncGroup    = new SyncGroup("Order");

            //Add each table: specify a synchronization direction of
            //Bidirectional.
            SyncTable customerSyncTable = new SyncTable("Customer");

            customerSyncTable.CreationOption = TableCreationOption.DropExistingOrCreateNewTable;
            customerSyncTable.SyncDirection  = SyncDirection.Bidirectional;
            customerSyncTable.SyncGroup      = customerSyncGroup;
            this.Configuration.SyncTables.Add(customerSyncTable);

            SyncTable orderHeaderSyncTable = new SyncTable("OrderHeader");

            orderHeaderSyncTable.CreationOption = TableCreationOption.DropExistingOrCreateNewTable;
            orderHeaderSyncTable.SyncDirection  = SyncDirection.Bidirectional;
            orderHeaderSyncTable.SyncGroup      = orderSyncGroup;
            this.Configuration.SyncTables.Add(orderHeaderSyncTable);

            SyncTable orderDetailSyncTable = new SyncTable("OrderDetail");

            orderDetailSyncTable.CreationOption = TableCreationOption.DropExistingOrCreateNewTable;
            orderDetailSyncTable.SyncDirection  = SyncDirection.Bidirectional;
            orderDetailSyncTable.SyncGroup      = orderSyncGroup;
            this.Configuration.SyncTables.Add(orderDetailSyncTable);

            //Handle the StateChanged and SessionProgress events, and
            //display information to the console.
            SampleStatsAndProgress sampleStats = new SampleStatsAndProgress();

            this.StateChanged    += new EventHandler <SessionStateChangedEventArgs>(sampleStats.DisplaySessionProgress);
            this.SessionProgress += new EventHandler <SessionProgressEventArgs>(sampleStats.DisplaySessionProgress);
        }