public override void Execute(IScriptExecutionContext context) { // The script to be executed. String script = Parameters["script"]; // Connection string to target DB String connectionString = Parameters["connectionString"]; // Treat the 'script' parameter as a script containing the script to be executed or as the script itself. Boolean useAsFile = Parameters.ContainsKey("useAsFile") ? Boolean.Parse(Parameters["useAsFile"]) : false; // Expressed in seconds. int commandTimeout = Parameters.ContainsKey("timeout") ? Int32.Parse(Parameters["timeout"]) : 30; if (useAsFile) script = File.ReadAllText(script); using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); using (SqlCommand command = connection.CreateCommand()) { command.CommandText = script; command.CommandType = System.Data.CommandType.Text; command.CommandTimeout = commandTimeout; command.ExecuteNonQuery(); } } }
public override void Execute(IScriptExecutionContext context) { FileInfo sourceFile = new FileInfo(Parameters["source"]); FileInfo target = new FileInfo(Parameters["target"]); bool targetIsDirectory = Boolean.Parse(Parameters["targetIsDirectory"]); bool overwriteTarget = Parameters.ContainsKey("overwrite") ? Boolean.Parse(Parameters["overwrite"]) : false; if (!sourceFile.Exists) throw new Exception(String.Format("Source file '{0}' does not exists!", sourceFile.FullName)); if (IsDirectory(sourceFile)) throw new Exception(String.Format("Source file '{0}' points to a directory and should point to a file instead!", sourceFile.FullName)); if (targetIsDirectory) { if (!target.Exists) Directory.CreateDirectory(target.FullName); target = new FileInfo(Path.Combine(target.FullName, Path.GetFileName(sourceFile.FullName))); } else { if (!Directory.Exists(Path.GetDirectoryName(target.FullName))) Directory.CreateDirectory(Path.GetDirectoryName(target.FullName)); } if (target.Exists && !overwriteTarget) throw new Exception(String.Format("Target '{0}' already exists and overwrite was not requested!", target.FullName)); File.Copy(sourceFile.FullName, target.FullName, overwriteTarget); }
public override void Execute(IScriptExecutionContext context) { IDictionary environment = Environment.GetEnvironmentVariables(); foreach (Object key in environment.Keys) { Console.WriteLine(String.Format("{0} => {1}", key, environment[key])); } }
public override void Execute(IScriptExecutionContext context) { Console.WriteLine(FirstParameter); }
public DefaultScriptRunner(IScriptExecutionContext context) : base(context) { }
public override void Execute(IScriptExecutionContext context) { throw new Exception(FirstParameter); }
public void Execute(IScriptExecutionContext context) { task.Execute(context); }
public abstract void Execute(IScriptExecutionContext context);
public AbstractScriptRunner(IScriptExecutionContext context) { this.context = context; }