void IScriptExecuteCallback.ExecutionStarting(ScriptStepCollection script) { lock (this) { executingScript = script; lastReportedStep = -1; } }
/// <summary> /// callback from worker thread when it went OK /// </summary> /// <param name="script"></param> private void ScriptComplete(ScriptStepCollection script) { if (script != null) { WriteScriptToWindow(script); } progressBar.Value = progressBar.Maximum; ViewModeSet(ViewMode.Normal); }
private void WriteScriptToWindow(ScriptStepCollection script) { feedbackL.Clear(); foreach (ScriptStep step in script) { feedbackL.AppendText(step.CommandText); feedbackL.AppendText("\n\nGO\n\n"); } }
///look in the assembly manifest resources for the script files ///get the ones that are SQL scripts and order them private ScriptStepCollection LoadScript(Version serverVersion, string database, bool dropAllConstraints, string collation, FullTextLanguage language, bool setSingleUser) { string[] resources; Assembly thisAssembly; ScriptStepCollection script = new ScriptStepCollection(); thisAssembly = this.GetType().Assembly; resources = thisAssembly.GetManifestResourceNames(); int lcid = language==null ? int.MinValue : language.Lcid; string dropAllConstraintsText = dropAllConstraints ? "1" : "0"; string setSingleUserText = setSingleUser ? "1" : "0"; object[] formatArgs = new object[] { database, collation, dropAllConstraintsText, lcid, setSingleUserText }; //first get a list or resources ArrayList resourceNames = new ArrayList(); foreach (string resource in resources) { if (string.Compare(resource.Substring(resource.Length - 4), ".sql", true, CultureInfo.InvariantCulture) == 0) { //we want this script... //lets see if it is specific to a version of sql server string versionText = resource.Substring(resource.Length - 9, 5); if (versionText == ".2000") { if (serverVersion.Major <= 8) { resourceNames.Add(resource); } } else if (versionText == ".2005") { if (serverVersion.Major >= 9) { resourceNames.Add(resource); } } else { resourceNames.Add(resource); } } } resourceNames.Sort(); foreach (string resource in resourceNames) { script.Add(new ScriptStepResource(resource, formatArgs)); } return script; }
///look in the assembly manifest resources for the script files ///get the ones that are SQL scripts and order them private ScriptStepCollection LoadScript(Version serverVersion, string database, bool dropAllConstraints, string collation, FullTextLanguage language, bool setSingleUser) { string[] resources; Assembly thisAssembly; ScriptStepCollection script = new ScriptStepCollection(); thisAssembly = this.GetType().Assembly; resources = thisAssembly.GetManifestResourceNames(); int lcid = language == null ? int.MinValue : language.Lcid; string dropAllConstraintsText = dropAllConstraints ? "1" : "0"; string setSingleUserText = setSingleUser ? "1" : "0"; object[] formatArgs = new object[] { database, collation, dropAllConstraintsText, lcid, setSingleUserText }; //first get a list or resources ArrayList resourceNames = new ArrayList(); foreach (string resource in resources) { if (string.Compare(resource.Substring(resource.Length - 4), ".sql", true, CultureInfo.InvariantCulture) == 0) { //we want this script... //lets see if it is specific to a version of sql server string versionText = resource.Substring(resource.Length - 9, 5); if (versionText == ".2000") { if (serverVersion.Major <= 8) { resourceNames.Add(resource); } } else if (versionText == ".2005") { if (serverVersion.Major >= 9) { resourceNames.Add(resource); } } else { resourceNames.Add(resource); } } } resourceNames.Sort(); foreach (string resource in resourceNames) { script.Add(new ScriptStepResource(resource, formatArgs)); } return(script); }
protected override void ExecuteCommand(SqlCommand command) { script = new ScriptStepCollection(); SqlDataReader reader = command.ExecuteReader(); try { //this only selects the value in the first column while (reader.Read()) script.Add(new ScriptStep(reader.GetString(0))); } finally { reader.Close(); } }
private void ScriptThreadProc() { //WorkerThreadArguments arguments = (WorkerThreadArguments)threadArguments; CollationChanger collationChanger = new CollationChanger(); ScriptStepCollection script = null; SqlConnection connection = null; try { script = collationChanger.GenerateScript(workerThreadArguments.Callback, workerThreadArguments.Server, workerThreadArguments.UserId, workerThreadArguments.Password, workerThreadArguments.Database, workerThreadArguments.DropAllConstraints, workerThreadArguments.Collation, workerThreadArguments.Language, workerThreadArguments.SetSingleUser); if (script != null) { if (workerThreadArguments.ScriptOnly) { BeginInvoke(new ScriptCompleteCallback(ScriptComplete), new object[] { script }); } else { connection = new SqlConnection(Utils.ConnectionString(workerThreadArguments.Server, workerThreadArguments.UserId, workerThreadArguments.Password)); connection.Open(); script.Execute(connection, workerThreadArguments.Callback); BeginInvoke(new ExecuteCompleteCallback(ExecuteComplete)); } } else { BeginInvoke(new ScriptCompleteCallback(ScriptComplete), new object[] { null }); } } catch (ThreadAbortException) { throw; } catch (Exception ex) { BeginInvoke(new ScriptCompleteErrorCallback(ScriptComplete), new object[] { ex }); } finally { if (connection != null) { connection.Dispose(); } } lock (this) { workerThread = null; } }
protected override void ExecuteCommand(SqlCommand command) { script = new ScriptStepCollection(); SqlDataReader reader = command.ExecuteReader(); try { //this only selects the value in the first column while (reader.Read()) { script.Add(new ScriptStep(reader.GetString(0))); } } finally { reader.Close(); } }
public ScriptStepCollection GenerateScript(IScriptExecuteCallback callback, string server, string userId, string password, string database, bool dropAllConstraints, string collation, FullTextLanguage language, bool setSingleUser) { SqlConnection connection = new SqlConnection(); connection.ConnectionString = Utils.ConnectionString(server, userId, password); try { connection.Open(); ScriptStepCollection script = LoadScript(new Version(connection.ServerVersion), database, dropAllConstraints, collation, language, setSingleUser); //now get the last script entry and replace it with //a special component that will return out ScriptStepGenerateScript generator = new ScriptStepGenerateScript(script[script.Count - 1]); script[script.Count - 1] = generator; script.Execute(connection, callback); return(generator.Script); } finally { connection.Dispose(); } }
void IScriptExecuteCallback.ExecutionStarting(ScriptStepCollection script) { lock(this) { executingScript = script; lastReportedStep = -1; } }
/// <summary> /// callback from worker thread when it went OK /// </summary> /// <param name="script"></param> private void ScriptComplete(ScriptStepCollection script) { if (script!=null) WriteScriptToWindow(script); progressBar.Value = progressBar.Maximum; ViewModeSet(ViewMode.Normal); }