Example #1
0
        //
        // Synchronize Call
        //
        private void buttonSynchronize_Click(object sender, EventArgs e)
        {
            try
            {
                //
                // 1. Create instance of the sync components (peer, agent, peer)
                // This demo illustrates direct connection to server database. In this scenario,
                // all sync components reside in the sample process.
                //
                DbSyncProvider localProvider  = new DbSyncProvider();
                DbSyncProvider remoteProvider = new DbSyncProvider();

                localProvider = SetupSyncProvider(GetFromPeerConnectionString(), localProvider);
                localProvider.SyncProviderPosition = SyncProviderPosition.Local;
                localProvider.ChangesSelected     += new EventHandler <DbChangesSelectedEventArgs>(ChangesSelected);

                remoteProvider = SetupSyncProvider(GetToPeerConnectionString(), remoteProvider);
                remoteProvider.SyncProviderPosition = SyncProviderPosition.Remote;
                remoteProvider.ChangesApplied      += new EventHandler <DbChangesAppliedEventArgs>(ChangesApplied);

                SyncOrchestrator syncOrchestrator = new SyncOrchestrator();
                // sync direction : local -> remote
                syncOrchestrator.LocalProvider  = localProvider;
                syncOrchestrator.RemoteProvider = remoteProvider;
                syncOrchestrator.Direction      = SyncDirectionOrder.Upload;

                _progressForm = new ProgressForm();
                _progressForm.Show();
                SyncOperationStatistics syncStats = syncOrchestrator.Synchronize();

                _progressForm.ShowStatistics(syncStats);
                // Update the UI
                _progressForm.EnableClose();
                _progressForm = null;
            }
            catch (DbOutdatedSyncException ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show("Outdated Knowledge: " + ex.OutdatedPeerSyncKnowledge.ToString() + " Clean up knowledge: " + ex.MissingCleanupKnowledge.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                if (_progressForm != null)
                {
                    _progressForm.EnableClose();
                    _progressForm = null;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Utility function that will create a SyncOrchestrator and synchronize the two passed in providers
        /// </summary>
        /// <param name="localProvider">Local store provider</param>
        /// <param name="remoteProvider">Remote store provider</param>
        /// <returns></returns>
        public SyncOperationStatistics SynchronizeProviders(KnowledgeSyncProvider localProvider, KnowledgeSyncProvider remoteProvider)
        {
            SyncOrchestrator orchestrator = new SyncOrchestrator();

            orchestrator.LocalProvider  = localProvider;
            orchestrator.RemoteProvider = remoteProvider;
            orchestrator.Direction      = SyncDirectionOrder.UploadAndDownload;

            progressForm = new ProgressForm();
            progressForm.Show();

            //Check to see if any provider is a Sql provider and if it needs schema
            CheckIfProviderNeedsSchema(localProvider as SqlSyncProvider);
            CheckIfProviderNeedsSchema(remoteProvider as SqlSyncProvider);

            SyncOperationStatistics stats = orchestrator.Synchronize();

            progressForm.ShowStatistics(stats);
            progressForm.EnableClose();
            return(stats);
        }
Example #3
0
        //
        // Synchronize Call
        //
        private void buttonSynchronize_Click(object sender, EventArgs e)
        {
            try
            {

                //
                // 1. Create instance of the sync components (peer, agent, peer)
                // This demo illustrates direct connection to server database. In this scenario,
                // all sync components reside in the sample process.
                //
                DbSyncProvider localProvider = new DbSyncProvider();
                DbSyncProvider remoteProvider = new DbSyncProvider();

                localProvider = SetupSyncProvider(GetFromPeerConnectionString(), localProvider);
                localProvider.SyncProviderPosition = SyncProviderPosition.Local;

                remoteProvider = SetupSyncProvider(GetToPeerConnectionString(), remoteProvider);
                remoteProvider.SyncProviderPosition = SyncProviderPosition.Remote;

                SyncOrchestrator syncOrchestrator = new SyncOrchestrator();
                // syncdirection: local->remote
                syncOrchestrator.LocalProvider = localProvider;
                syncOrchestrator.RemoteProvider = remoteProvider;
                syncOrchestrator.Direction = SyncDirectionOrder.Upload;
                syncOrchestrator.SessionProgress += new EventHandler<SyncStagedProgressEventArgs>(ProgressChanged);

                _progressForm = new ProgressForm();
                _progressForm.Show();
                SyncOperationStatistics syncStats = syncOrchestrator.Synchronize();

                _progressForm.ShowStatistics(syncStats);
                // Update the UI
                _progressForm.EnableClose();
                _progressForm = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                if (_progressForm != null)
                {
                    _progressForm.EnableClose();
                    _progressForm = null;
                }
            }
        }