private static void Provision(SqlConnection server, SqlConnection client, string tablename, string direction) { try { Provisioning.ProvisionTable(server, client, tablename); } catch (SyncConstraintConflictNotAllowedException) { Console.ForegroundColor = ConsoleColor.Red; string message = string.Format("Scope called {0} already exists. Please use --deprovision first", tablename); Console.Error.WriteLine(message); Console.ResetColor(); } Console.WriteLine("Provision complete"); if (server.ConnectionString != client.ConnectionString) { if (client.State == System.Data.ConnectionState.Closed) { client.Open(); } Console.WriteLine("Adding to scopes table on client"); Provisioning.AddScopeToScopesTable(client, tablename, utils.StringToEnum <SyncDirectionOrder>(direction)); } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Complete"); Console.ResetColor(); }
/// <summary> /// Sync a single scope from the client to the server. /// </summary> /// <param name="server">Provider for the server.</param> /// <param name="client">Provider for the client.</param> /// <param name="tablename">The able name to sync.</param> public static SyncOperationStatistics syncscope(SqlConnection server, SqlConnection client, string scope, SyncDirectionOrder order, Action <object, DbApplyingChangesEventArgs> callback, Action <object, DbApplyingChangesEventArgs> mastercallback) { // If we are only doing a download and the scope on the database // is out of date then we need to reprovision the data, but for now just // error. if (order == SyncDirectionOrder.Download && ScopesDiffer(server, client, scope)) { ProgressUpdate("Scope has changed on server. Reprovisoning client"); Provisioning.ProvisionTable(server, client, scope, true); } else if (order != SyncDirectionOrder.Download && ScopesDiffer(server, client, scope)) { throw new DbSyncException("Can not sync twoway tables with changed scopes"); } using (SqlSyncProvider masterProvider = new SqlSyncProvider(scope, server), slaveProvider = new SqlSyncProvider(scope, client)) { SyncOrchestrator orchestrator = new SyncOrchestrator { LocalProvider = slaveProvider, RemoteProvider = masterProvider, Direction = order }; slaveProvider.ApplyingChanges += new EventHandler <DbApplyingChangesEventArgs>(callback); masterProvider.ApplyingChanges += new EventHandler <DbApplyingChangesEventArgs>(mastercallback); slaveProvider.ApplyChangeFailed += slaveProvider_ApplyChangeFailed; return(orchestrator.Synchronize()); } }