private void DesaprovicionarServidor(IDbConnection sqlConnection) { SqlSyncScopeDeprovisioning DesaprovicionadorDeAmbito = new SqlSyncScopeDeprovisioning((SqlConnection)sqlConnection) { ObjectSchema = _esquemaMetadataSyncFramework, ObjectPrefix = _prefijoMetadataSyncFramework }; try { Loguear("Se va a desaprovicionar el servidor entero " + sqlConnection.Database); DesaprovicionadorDeAmbito.DeprovisionStore(); Loguear("Se desaproviciono el servidor entero " + sqlConnection.Database); } catch (Exception e) { Loguear(e.Message); } }
private void removeScopeToolStripMenuItem_Click(object sender, EventArgs e) { #if (DEBUG) SqlConnection clientConn = new SqlConnection(Program.str_debug_clientConn); #else SqlConnection clientConn = new SqlConnection(Program.str_release_clientConn); #endif SqlConnection serverConn = new SqlConnection(Program.str_serverConn); SqlSyncScopeDeprovisioning objDeprovisioning1 = new SqlSyncScopeDeprovisioning(serverConn); objDeprovisioning1.DeprovisionStore(); SqlSyncScopeDeprovisioning objDeprovisioning2 = new SqlSyncScopeDeprovisioning(clientConn); objDeprovisioning2.DeprovisionStore(); DialogResult result = DotNetPerls.BetterDialog.ShowDialog( "Trans2Summa3060", //titleString "Client and Server Successfully DeProvisioned.", //bigString null, //smallString null, //leftButton "OK", //rightButton global::Trans2Summa3060.Properties.Resources.Message_info); //iconSet }
public void Deprovision2() { try { SqlConnection serverConn = new SqlConnection(sServerConnection); // Connection to SQL client SqlConnection clientConn = new SqlConnection(sClientConnection); // Create Scope Deprovisioning for Sql Server and SQL client. SqlSyncScopeDeprovisioning serverSqlDepro = new SqlSyncScopeDeprovisioning(serverConn); SqlSyncScopeDeprovisioning clientSqlDepro = new SqlSyncScopeDeprovisioning(clientConn); // Remove the scope from SQL Server remove all synchronization objects. serverSqlDepro.DeprovisionScope(sScope); serverSqlDepro.DeprovisionStore(); // Remove the scope from SQL client and remove all synchronization objects. clientSqlDepro.DeprovisionScope(sScope); clientSqlDepro.DeprovisionStore(); // Shut down database connections. serverConn.Close(); serverConn.Dispose(); clientConn.Close(); clientConn.Dispose(); } catch (SqlException ex) { } catch (Microsoft.Synchronization.Data.DbVersionException ex) { } catch (Exception ex) { } }
private static void DeprovisionStore(SelectedConfigSections selectedConfig, bool script, DirectoryInfo workingDirectory) { try { SqlSyncScopeDeprovisioning deprov = new SqlSyncScopeDeprovisioning(new SqlConnection(selectedConfig.SelectedTargetDatabase.GetConnectionString())); Log("Deprovisioning Store Database {0} ...", selectedConfig.SelectedTargetDatabase.Name); if (!script) { deprov.DeprovisionStore(); } else { SaveScript("deprovisionstore.sql", deprov.ScriptDeprovisionStore(), workingDirectory); } } catch (Exception e) { throw new InvalidOperationException( "Unexpected error when executing the Deprovisioning command. See inner exception for details.", e); } }
public static void ServerDeprovision() { SqlSyncScopeDeprovisioning clientSqlCeDepro = new SqlSyncScopeDeprovisioning(serverConn); clientSqlCeDepro.DeprovisionStore(); }
public override void DeProvisionStore() { SqlSyncScopeDeprovisioning serverDeprovision = CreateScopeDeProvision(); serverDeprovision.DeprovisionStore(); }
private void DesaprovicionarServidor(SqlConnection conexionSql ) { SqlSyncScopeDeprovisioning DesaprovicionadorDeAmbito = new SqlSyncScopeDeprovisioning(conexionSql); DesaprovicionadorDeAmbito.ObjectSchema = this.esquemaMetadataSyncFramework; DesaprovicionadorDeAmbito.ObjectPrefix = this.prefijoMetadataSyncFramework; try { this.loguear("Se va a desaprovicionar el servidor entero " + conexionSql.Database + " Inicio:\t" + DateTime.Now); DesaprovicionadorDeAmbito.DeprovisionStore(); this.loguear("Se desaprovicio el servidor entero " + conexionSql.Database + " fin:\t" + DateTime.Now); } catch (Exception e) { this.loguear(e.Message); } }
private static void ProcessConfigFile(ArgsParser parser) { DbSyncScopeDescription scopeDescription; Dictionary <string, Dictionary <string, string> > tablesToColumnMappingsInfo = new Dictionary <string, Dictionary <string, string> >(); if (string.IsNullOrEmpty(parser.ConfigFile)) { LogArgsError("Required argument /scopeconfig is not specified."); return; } if (!System.IO.File.Exists(parser.ConfigFile)) { LogArgsError("Unable to find scopeconfig file '" + parser.ConfigFile + "'"); return; } System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap() { ExeConfigFilename = parser.ConfigFile }, ConfigurationUserLevel.None); Log("Reading specified config file..."); SyncConfigurationSection syncConfig = config.GetSection(Constants.SyncConfigurationSectionName) as SyncConfigurationSection; // ValidateConfigFile the config and the passed in input parameters ValidateConfigFile(parser, syncConfig); // Fill in the defaults value for the parser. SelectedConfigSections selectedConfig = FillDefaults(parser, syncConfig); Log("Generating DbSyncScopeDescription for scope {0}...", selectedConfig.SelectedSyncScope.Name); scopeDescription = GetDbSyncScopeDescription(selectedConfig); tablesToColumnMappingsInfo = BuildColumnMappingInfo(selectedConfig); switch (parser.OperationMode) { case OperationMode.Provision: try { SqlSyncScopeProvisioning prov = new SqlSyncScopeProvisioning(new SqlConnection(selectedConfig.SelectedTargetDatabase.GetConnectionString()), scopeDescription, selectedConfig.SelectedSyncScope.IsTemplateScope ? SqlSyncScopeProvisioningType.Template : SqlSyncScopeProvisioningType.Scope); // Note: Deprovisioning does not work because of a bug in the provider when you set the ObjectSchema property to “dbo”. // The workaround is to not set the property (it internally assumes dbo in this case) so that things work on deprovisioning. if (!String.IsNullOrEmpty(selectedConfig.SelectedSyncScope.SchemaName)) { prov.ObjectSchema = selectedConfig.SelectedSyncScope.SchemaName; } foreach (SyncTableConfigElement tableElement in selectedConfig.SelectedSyncScope.SyncTables) { // Check and set the SchemaName for individual table if specified if (!string.IsNullOrEmpty(tableElement.SchemaName)) { prov.Tables[tableElement.GlobalName].ObjectSchema = tableElement.SchemaName; } prov.Tables[tableElement.GlobalName].FilterClause = tableElement.FilterClause; foreach (FilterColumnConfigElement filterCol in tableElement.FilterColumns) { prov.Tables[tableElement.GlobalName].FilterColumns.Add(scopeDescription.Tables[tableElement.GlobalName].Columns[filterCol.Name]); } foreach (FilterParameterConfigElement filterParam in tableElement.FilterParameters) { CheckFilterParamTypeAndSize(filterParam); prov.Tables[tableElement.GlobalName].FilterParameters.Add(new SqlParameter(filterParam.Name, (SqlDbType)Enum.Parse(typeof(SqlDbType), filterParam.SqlType, true))); prov.Tables[tableElement.GlobalName].FilterParameters[filterParam.Name].Size = filterParam.DataSize; } } // enable bulk procedures. prov.SetUseBulkProceduresDefault(selectedConfig.SelectedSyncScope.EnableBulkApplyProcedures); // Create a new set of enumeration stored procs per scope. // Without this multiple scopes share the same stored procedure which is not desirable. prov.SetCreateProceduresForAdditionalScopeDefault(DbSyncCreationOption.Create); if (selectedConfig.SelectedSyncScope.IsTemplateScope) { if (!prov.TemplateExists(selectedConfig.SelectedSyncScope.Name)) { Log("Provisioning Database {0} for template scope {1}...", selectedConfig.SelectedTargetDatabase.Name, selectedConfig.SelectedSyncScope.Name); prov.Apply(); } else { throw new InvalidOperationException(string.Format("Database {0} already contains a template scope {1}. Please deprovision the scope and retry.", selectedConfig.SelectedTargetDatabase.Name, selectedConfig.SelectedSyncScope.Name)); } } else { if (!prov.ScopeExists(selectedConfig.SelectedSyncScope.Name)) { Log("Provisioning Database {0} for scope {1}...", selectedConfig.SelectedTargetDatabase.Name, selectedConfig.SelectedSyncScope.Name); prov.Apply(); } else { throw new InvalidOperationException(string.Format("Database {0} already contains a scope {1}. Please deprovision the scope and retry.", selectedConfig.SelectedTargetDatabase.Name, selectedConfig.SelectedSyncScope.Name)); } } } catch (ConfigurationErrorsException) { throw; } catch (InvalidOperationException) { throw; } catch (Exception e) { throw new InvalidOperationException("Unexpected error when executing the Provisioning command. See inner exception for details.", e); } break; case OperationMode.Deprovision: try { SqlSyncScopeDeprovisioning deprov = new SqlSyncScopeDeprovisioning(new SqlConnection(selectedConfig.SelectedTargetDatabase.GetConnectionString())); // Set the ObjectSchema property. if (!String.IsNullOrEmpty(selectedConfig.SelectedSyncScope.SchemaName)) { deprov.ObjectSchema = selectedConfig.SelectedSyncScope.SchemaName; } Log("Deprovisioning Database {0} for scope {1}...", selectedConfig.SelectedTargetDatabase.Name, selectedConfig.SelectedSyncScope.Name); if (selectedConfig.SelectedSyncScope.IsTemplateScope) { deprov.DeprovisionTemplate(selectedConfig.SelectedSyncScope.Name); } else { deprov.DeprovisionScope(selectedConfig.SelectedSyncScope.Name); } } catch (Exception e) { throw new InvalidOperationException("Unexpected error when executing the Deprovisioning command. See inner exception for details.", e); } break; case OperationMode.Deprovisionstore: try { SqlSyncScopeDeprovisioning deprov = new SqlSyncScopeDeprovisioning(new SqlConnection(selectedConfig.SelectedTargetDatabase.GetConnectionString())); Log("Deprovisioning Store Database {0} ...", selectedConfig.SelectedTargetDatabase.Name); deprov.DeprovisionStore(); } catch (Exception e) { throw new InvalidOperationException("Unexpected error when executing the Deprovisioning command. See inner exception for details.", e); } break; case OperationMode.Codegen: Log("Generating files..."); EntityGenerator generator = EntityGeneratorFactory.Create(parser.CodeGenMode, selectedConfig.SelectedSyncScope.SchemaName); generator.GenerateEntities(parser.GeneratedFilePrefix, string.IsNullOrEmpty(parser.Namespace) ? string.IsNullOrEmpty(parser.GeneratedFilePrefix) ? scopeDescription.ScopeName : parser.GeneratedFilePrefix : parser.Namespace, scopeDescription, tablesToColumnMappingsInfo, parser.WorkingDirectory, parser.Language, null /*serviceUri*/); break; default: break; } }
private static void ProcessConfigFile(ArgsParser parser) { DbSyncScopeDescription scopeDescription; Dictionary<string, Dictionary<string, string>> tablesToColumnMappingsInfo = new Dictionary<string, Dictionary<string, string>>(); if (string.IsNullOrEmpty(parser.ConfigFile)) { LogArgsError("Required argument /scopeconfig is not specified."); return; } if (!System.IO.File.Exists(parser.ConfigFile)) { LogArgsError("Unable to find scopeconfig file '" + parser.ConfigFile + "'"); return; } System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap() { ExeConfigFilename = parser.ConfigFile }, ConfigurationUserLevel.None); Log("Reading specified config file..."); SyncConfigurationSection syncConfig = config.GetSection(Constants.SyncConfigurationSectionName) as SyncConfigurationSection; // ValidateConfigFile the config and the passed in input parameters ValidateConfigFile(parser, syncConfig); // Fill in the defaults value for the parser. SelectedConfigSections selectedConfig = FillDefaults(parser, syncConfig); Log("Generating DbSyncScopeDescription for scope {0}...", selectedConfig.SelectedSyncScope.Name); scopeDescription = GetDbSyncScopeDescription(selectedConfig); tablesToColumnMappingsInfo = BuildColumnMappingInfo(selectedConfig); switch (parser.OperationMode) { case OperationMode.Provision: try { SqlSyncScopeProvisioning prov = new SqlSyncScopeProvisioning(new SqlConnection(selectedConfig.SelectedTargetDatabase.GetConnectionString()), scopeDescription, selectedConfig.SelectedSyncScope.IsTemplateScope ? SqlSyncScopeProvisioningType.Template : SqlSyncScopeProvisioningType.Scope); // Note: Deprovisioning does not work because of a bug in the provider when you set the ObjectSchema property to “dbo”. // The workaround is to not set the property (it internally assumes dbo in this case) so that things work on deprovisioning. if (!String.IsNullOrEmpty(selectedConfig.SelectedSyncScope.SchemaName)) { prov.ObjectSchema = selectedConfig.SelectedSyncScope.SchemaName; } foreach (SyncTableConfigElement tableElement in selectedConfig.SelectedSyncScope.SyncTables) { // Check and set the SchemaName for individual table if specified if (!string.IsNullOrEmpty(tableElement.SchemaName)) { prov.Tables[tableElement.GlobalName].ObjectSchema = tableElement.SchemaName; } prov.Tables[tableElement.GlobalName].FilterClause = tableElement.FilterClause; foreach (FilterColumnConfigElement filterCol in tableElement.FilterColumns) { prov.Tables[tableElement.GlobalName].FilterColumns.Add(scopeDescription.Tables[tableElement.GlobalName].Columns[filterCol.Name]); } foreach (FilterParameterConfigElement filterParam in tableElement.FilterParameters) { CheckFilterParamTypeAndSize(filterParam); prov.Tables[tableElement.GlobalName].FilterParameters.Add(new SqlParameter(filterParam.Name, (SqlDbType)Enum.Parse(typeof(SqlDbType), filterParam.SqlType, true))); prov.Tables[tableElement.GlobalName].FilterParameters[filterParam.Name].Size = filterParam.DataSize; } } // enable bulk procedures. prov.SetUseBulkProceduresDefault(selectedConfig.SelectedSyncScope.EnableBulkApplyProcedures); // Create a new set of enumeration stored procs per scope. // Without this multiple scopes share the same stored procedure which is not desirable. prov.SetCreateProceduresForAdditionalScopeDefault(DbSyncCreationOption.Create); if (selectedConfig.SelectedSyncScope.IsTemplateScope) { if (!prov.TemplateExists(selectedConfig.SelectedSyncScope.Name)) { Log("Provisioning Database {0} for template scope {1}...", selectedConfig.SelectedTargetDatabase.Name, selectedConfig.SelectedSyncScope.Name); prov.Apply(); } else { throw new InvalidOperationException(string.Format("Database {0} already contains a template scope {1}. Please deprovision the scope and retry.", selectedConfig.SelectedTargetDatabase.Name, selectedConfig.SelectedSyncScope.Name)); } } else { if (!prov.ScopeExists(selectedConfig.SelectedSyncScope.Name)) { Log("Provisioning Database {0} for scope {1}...", selectedConfig.SelectedTargetDatabase.Name, selectedConfig.SelectedSyncScope.Name); prov.Apply(); } else { throw new InvalidOperationException(string.Format("Database {0} already contains a scope {1}. Please deprovision the scope and retry.", selectedConfig.SelectedTargetDatabase.Name, selectedConfig.SelectedSyncScope.Name)); } } } catch (ConfigurationErrorsException) { throw; } catch (InvalidOperationException) { throw; } catch (Exception e) { throw new InvalidOperationException("Unexpected error when executing the Provisioning command. See inner exception for details.", e); } break; case OperationMode.Deprovision: try { SqlSyncScopeDeprovisioning deprov = new SqlSyncScopeDeprovisioning(new SqlConnection(selectedConfig.SelectedTargetDatabase.GetConnectionString())); // Set the ObjectSchema property. if (!String.IsNullOrEmpty(selectedConfig.SelectedSyncScope.SchemaName)) { deprov.ObjectSchema = selectedConfig.SelectedSyncScope.SchemaName; } Log("Deprovisioning Database {0} for scope {1}...", selectedConfig.SelectedTargetDatabase.Name, selectedConfig.SelectedSyncScope.Name); if (selectedConfig.SelectedSyncScope.IsTemplateScope) { deprov.DeprovisionTemplate(selectedConfig.SelectedSyncScope.Name); } else { deprov.DeprovisionScope(selectedConfig.SelectedSyncScope.Name); } } catch (Exception e) { throw new InvalidOperationException("Unexpected error when executing the Deprovisioning command. See inner exception for details.", e); } break; case OperationMode.Deprovisionstore: try { SqlSyncScopeDeprovisioning deprov = new SqlSyncScopeDeprovisioning(new SqlConnection(selectedConfig.SelectedTargetDatabase.GetConnectionString())); Log("Deprovisioning Store Database {0} ...", selectedConfig.SelectedTargetDatabase.Name); deprov.DeprovisionStore(); } catch (Exception e) { throw new InvalidOperationException("Unexpected error when executing the Deprovisioning command. See inner exception for details.", e); } break; case OperationMode.Codegen: Log("Generating files..."); EntityGenerator generator = EntityGeneratorFactory.Create(parser.CodeGenMode, selectedConfig.SelectedSyncScope.SchemaName); generator.GenerateEntities(parser.GeneratedFilePrefix, string.IsNullOrEmpty(parser.Namespace) ? string.IsNullOrEmpty(parser.GeneratedFilePrefix) ? scopeDescription.ScopeName : parser.GeneratedFilePrefix : parser.Namespace, scopeDescription, tablesToColumnMappingsInfo, parser.WorkingDirectory, parser.Language, null/*serviceUri*/); break; default: break; } }
public override void DeProvisionStore() { SqlSyncScopeDeprovisioning clientDeprovision = CreateScopeDeProvision(); clientDeprovision.DeprovisionStore(); }