/// <summary> /// Check to see if the passed in SqlSyncProvider needs Schema from server /// </summary> /// <param name="localProvider"></param> private void CheckIfProviderNeedsSchema(SqlSyncProvider localProvider) { if (localProvider != null) { SqlConnection conn = (SqlConnection)localProvider.Connection; SqlSyncScopeProvisioning sqlConfig = new SqlSyncScopeProvisioning(conn); string scopeName = localProvider.ScopeName; //if the scope does not exist in this store if (!sqlConfig.ScopeExists(scopeName)) { //create a reference to the server proxy SqlSyncProviderProxy serverProxy = new SqlSyncProviderProxy("CardsScope", connString); //retrieve the scope description from the server DbSyncScopeDescription scopeDesc = serverProxy.GetScopeDescription(); serverProxy.Dispose(); //use scope description from server to intitialize the client sqlConfig.PopulateFromScopeDescription(scopeDesc); sqlConfig.Apply(); } } }
public bool Synchronize(string scopeName, string localConnectionString, string remoteConnectionString) { try { _localSqlSyncProvider = new SqlSyncProvider() { ScopeName = scopeName, Connection = new SqlConnection(localConnectionString), MemoryDataCacheSize = _batchSize, BatchingDirectory = _batchFolder, } ; _remoteSqlSyncProvider = new SqlSyncProviderProxy(scopeName, remoteConnectionString) { BatchingDirectory = _batchFolder, }; var stats = SynchronizeProviders(_localSqlSyncProvider, _remoteSqlSyncProvider); } catch (Exception e) { return(false); } return(true); }
/// <summary> /// Check to see if the passed in SQL provider needs Schema from server. /// This method assumes the provider is remote and uses a proxy instead /// of directly leveraging a provider. /// </summary> /// <param name="localProvider"></param> private void CheckIfProviderNeedsSchema(string scopeName, string clientConnectionString, string serverConnectionString, SqlSyncProviderProxy remoteProxy) { if (remoteProxy != null && remoteProxy.NeedsScope(scopeName, clientConnectionString)) { SqlSyncProviderProxy serverProxy = new SqlSyncProviderProxy(scopeName, serverConnectionString); DbSyncScopeDescription scopeDesc = serverProxy.GetScopeDescription(scopeName, serverConnectionString); serverProxy.Dispose(); remoteProxy.CreateScopeDescription(scopeDesc); } }
//public void Synchronization(SqlConnection clientConn, SqlConnection serverConn) //{ // SqlSyncProvider sqlSyncProvider = new SqlSyncProvider("CardsScope",clientConn); // SqlSyncProvider sqlSyncProvider1 = new SqlSyncProvider("CardsScope", serverConn); // SyncOrchestrator syncOrchestrator = new SyncOrchestrator(); // syncOrchestrator.LocalProvider = sqlSyncProvider; // syncOrchestrator.RemoteProvider = sqlSyncProvider1; // syncOrchestrator.Direction = SyncDirectionOrder.UploadAndDownload; // syncStatistics = syncOrchestrator.Synchronize(); // Console.WriteLine("Start Time: " + syncStatistics.SyncStartTime); // Console.WriteLine("Total Changes Uploaded: " + syncStatistics.UploadChangesTotal); // Console.WriteLine("Total Changes Downloaded: " + syncStatistics.DownloadChangesTotal); // Console.WriteLine("Complete Time: " + syncStatistics.SyncEndTime); // Console.WriteLine(String.Empty); //} public bool Synchronization(string syncString) { try { SqlSyncProvider srcProvider = new SqlSyncProvider("CardsScope", new SqlConnection(connString)); SqlSyncProvider destinationProvider = new SqlSyncProvider("CardsScope", new SqlConnection(connString)); string hostName = ((SqlConnection)destinationProvider.Connection).DataSource; SqlSyncProviderProxy destinationProxy = new SqlSyncProviderProxy( "CardsScope", syncString); ////Set memory data cache size property. 0 represents non batched mode //srcProvider.MemoryDataCacheSize = this._batchSize; ////No need to set memory cache size for Proxy as since the source is enabled for batching, both upload and download will ////be batched. ////Set batch spool location. Default value if not set is %Temp% directory. //if (!string.IsNullOrEmpty(this.batchSpoolLocation.Text)) //{ // srcProvider.BatchingDirectory = this.batchSpoolLocation.Text; // destinationProxy.BatchingDirectory = this.batchSpoolLocation.Text; //} //string remoteUri = @"http://*****:*****@"http://localhost:8733/Design_Time_Addresses/RemoteProvider/RemotePeerSyncContract/"; SynchronizationHelper synchronizationHelper = new SynchronizationHelper(); SyncOperationStatistics stats = synchronizationHelper.SynchronizeProviders(srcProvider, destinationProxy); Console.WriteLine("Start synchronization session with server: {0}", syncString); logger.Info("Start synchronization session with server: {0}", syncString); Console.WriteLine("Start Time: " + stats.SyncStartTime); logger.Info("Start Time: " + stats.SyncStartTime); Console.WriteLine("Total Changes Uploaded: " + stats.UploadChangesTotal); logger.Info("Total Changes Uploaded: " + stats.UploadChangesTotal); Console.WriteLine("Total Changes Downloaded: " + stats.DownloadChangesTotal); logger.Info("Total Changes Downloaded: " + stats.DownloadChangesTotal); Console.WriteLine("Complete Time: " + stats.SyncEndTime); logger.Info("Complete Time: " + stats.SyncEndTime); Console.WriteLine("End synchronization session."); logger.Info("End synchronization session."); Console.WriteLine(String.Empty); return(true); } catch (Exception exc) { Console.WriteLine(exc.ToString()); logger.Error(exc.ToString()); return(false); } }
/// <summary> /// Check to see if the passed in SQL provider needs Schema from server. /// This method assumes the provider is remote and uses a proxy instead /// of directly leveraging a provider. /// </summary> /// <param name="localProvider"></param> private void CheckIfProviderNeedsSchema(SqlSyncProviderProxy remoteProxy) { if (remoteProxy != null && remoteProxy.NeedsScope()) { //create a reference to the server proxy SqlSyncProviderProxy serverProxy = new SqlSyncProviderProxy("CardsScope", connString); //retrieve the scope description from the server DbSyncScopeDescription scopeDesc = serverProxy.GetScopeDescription(); serverProxy.Dispose(); //intitialize remote store based on scope description from the server remoteProxy.CreateScopeDescription(scopeDesc); } }
/// <summary> /// Check to see if the passed in SQL provider needs Schema from server. /// This method assumes the provider is remote and uses a proxy instead /// of directly leveraging a provider. /// </summary> /// <param name="localProvider"></param> private void CheckIfProviderNeedsSchema(SqlSyncProviderProxy remoteProxy) { if (remoteProxy != null && remoteProxy.NeedsScope()) { //create a reference to the server proxy SqlSyncProviderProxy serverProxy = new SqlSyncProviderProxy(SyncUtils.ScopeName, SyncUtils.GenerateSqlConnectionString(this.serverHostName, SyncUtils.FirstPeerDBName, null, null, true)); //retrieve the scope description from the server DbSyncScopeDescription scopeDesc = serverProxy.GetScopeDescription(); serverProxy.Dispose(); //intitialize remote store based on scope description from the server remoteProxy.CreateScopeDescription(scopeDesc); } }
private void synchronizeBtn_Click(object sender, EventArgs e) { //Before calling synchronize, save any changes made to any of the peer tables foreach (TabPage page in this.peerTabsControl.TabPages) { if (page != null) { ((TablesViewControl)page.Controls["TablesViewCtrl"]).UpdateValues(); } } SqlSyncProvider srcProvider = providersCollection[this.srcProviderComboBox.SelectedItem.ToString()]; SqlSyncProvider destinationProvider = providersCollection[this.destProviderComboBox.SelectedItem.ToString()]; string hostName = ((SqlConnection)destinationProvider.Connection).DataSource; SqlSyncProviderProxy destinationProxy = new SqlSyncProviderProxy( SyncUtils.ScopeName, ((SqlConnection)destinationProvider.Connection).ConnectionString); //Set memory data cache size property. 0 represents non batched mode srcProvider.MemoryDataCacheSize = this._batchSize; //No need to set memory cache size for Proxy as since the source is enabled for batching, both upload and download will //be batched. //Set batch spool location. Default value if not set is %Temp% directory. if (!string.IsNullOrEmpty(this.batchSpoolLocation.Text)) { srcProvider.BatchingDirectory = this.batchSpoolLocation.Text; destinationProxy.BatchingDirectory = this.batchSpoolLocation.Text; } SyncOperationStatistics stats = synchronizationHelper.SynchronizeProviders(srcProvider, destinationProxy); TimeSpan diff = stats.SyncEndTime.Subtract(stats.SyncStartTime); destinationProxy.Dispose(); //Print Sync stats object this.syncStats.Text = string.Format("Batching: {4} - Total Time To Synchronize = {0}:{1}:{2}:{3}", diff.Hours, diff.Minutes, diff.Seconds, diff.Milliseconds, (this._batchSize > 0) ? "Enabled" : "Disabled"); this.ReadTableValuesForSelectedTab(); }
/// <summary> /// Check to see if the passed in SqlSyncProvider needs Schema from server /// </summary> /// <param name="localProvider"></param> private void CheckIfProviderNeedsSchema(SqlSyncProvider localProvider, string serverConnectionString) { if (localProvider != null) { SqlConnection conn = (SqlConnection)localProvider.Connection; SqlSyncScopeProvisioning sqlConfig = new SqlSyncScopeProvisioning(conn); string scopeName = localProvider.ScopeName; if (!sqlConfig.ScopeExists(scopeName)) { SqlSyncProviderProxy serverProxy = new SqlSyncProviderProxy(scopeName, serverConnectionString); DbSyncScopeDescription scopeDesc = serverProxy.GetScopeDescription(scopeName, serverConnectionString); serverProxy.Dispose(); sqlConfig.PopulateFromScopeDescription(scopeDesc); sqlConfig.Apply(); } } }