public void CreateScriptLocation_WhenPathIsRelative_PathFilterShouldBeAbsolute() { var sl = new ScriptLocation { Path = "..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\Temp\\" }; Assert.AreEqual(Expected, sl.AbsolutePath); }
public void CreateScriptLocation_WhenPathIsAbsolute_PathFilterShouldBeSame() { var sl = new ScriptLocation { Path = Expected }; Assert.AreEqual(Expected, sl.AbsolutePath); }
public void Can_Serialize_ScriptLocations() { var xns = new XmlSerializerNamespaces(); xns.Add("", ""); var v = new Variable { Key = "var1", DefaultValue = "somestring" }; var s = new Script { ScriptName = "test" }; s.Variables.Add(v); var sl = new ScriptLocation { Path = "..\\Some\\Path", Recursive = false, RunOnce = true, }; sl.Scripts.Add(s); sl.Scripts.Add(s); sl.Scripts.Add(s); var xs = new XmlSerializer(typeof(ScriptLocation)); var sb = new StringBuilder(); var sw = new StringWriter(sb); xs.Serialize(sw, sl,xns); Debug.WriteLine(sb.ToString()); Assert.AreEqual(strScriptLocationsXml, sb.ToString()); }
/// <summary> /// Checks that the path specified in the <see cref="ScriptLocation"/> contain valid scripts. /// </summary> /// <param name="location">The location.</param> private void LocationCheckPathContents(ScriptLocation location) { if (!location.ContainsSchemaScripts) return; TraceHelper.Verbose("> Schema Script Directory Found"); if (Directory.GetDirectories(location.Path).Any()) { TraceHelper.Warning("> Schema Script Directory contains subdirectories which will be ignored."); } foreach (var filename in Directory.GetFiles(location.Path, "*.sql", SearchOption.TopDirectoryOnly).Select(Path.GetFileName)) { TraceHelper.Verbose("> Validating Schema Script '{0}'", filename); LocationCheckSchemaFile(filename); } }
/// <summary> /// Checks that the path specified in the <see cref="ScriptLocation"/> is valid. /// </summary> /// <param name="location">The location.</param> /// <exception cref="ParachuteException">Aborting. Invalid Script Location.</exception> private void LocationCheckPath(ScriptLocation location) { if (Directory.Exists(location.Path)) return; TraceHelper.Error("Configuration file contains an invalid path '{0}'", location.Path); TraceHelper.Error("Script location paths must be a valid directory."); throw new ParachuteException("Aborting. Invalid Script Location."); }
/// <summary> /// Checks that the custom script variables in the <see cref="ScriptLocation"/> correspond to valid scripts. /// </summary> /// <param name="location">The location.</param> private void LocationCheckCustomScriptVariables(ScriptLocation location) { if(!location.Scripts.Any()) { TraceHelper.Verbose("Location '{0}' contains no custom script variables", location.Path); return; } var files = location.ScriptFiles.ToList(); foreach(var script in location.Scripts) { if(files.Contains(script.ScriptName)) { TraceHelper.Verbose("> Custom Variables found for script '{0}'", script.ScriptName); } else { TraceHelper.Warning("> Custom Variables found for non-existant script '{0}'", script.ScriptName); } } }
/// <summary> /// Prints basic information about the <see cref="ScriptLocation"/> /// </summary> /// <param name="location">The location.</param> private void LocationCheck(ScriptLocation location) { TraceHelper.Info("Validating Location '{0}' ", location.Path); TraceHelper.Verbose("> RunOnce: {0}", location.RunOnce); TraceHelper.Verbose("> Recursive: {0}", location.Recursive); TraceHelper.Verbose("> ContainsSchemaScripts: {0}", location.ContainsSchemaScripts); TraceHelper.Verbose("> Scripts With Variables #: {0}", location.Scripts.Count); }
private void ApplyScriptsToDatabaseRecursiveDirectoryWalk(SchemaVersion currentVersion, ScriptLocation location, string currentDirectoryPath) { foreach (var scriptFile in location.ScriptFiles.OrderBy(s => s)) { var scriptNameToBeLogged = scriptFile.Replace(location.AbsolutePath, string.Empty); if (!location.RunOnce) //Can be run many times { TraceHelper.Info("Applying Script '{0}'", scriptNameToBeLogged); var scripts = IOManager.ReadSqlScripts(scriptFile); var hash = IOManager.GetFileMD5Hash(scriptFile); SqlManager.ExecuteScriptFile(scripts, scriptNameToBeLogged, hash, currentVersion); } else { TraceHelper.Info("Applying Script '{0}'", scriptNameToBeLogged); var scripts = IOManager.ReadSqlScripts(scriptFile); var hash = IOManager.GetFileMD5Hash(scriptFile); SqlManager.ExecuteScriptFile(scripts, scriptNameToBeLogged, hash, currentVersion); } } //foreach file in the location // is directory marked as "runOnce" //if yes //check if file applied before in a previous version. //if no // Apply that file & log it //if yes //skip it //if not //run that file regardless /* if (!location.Recursive) return; //foreach directory in the location foreach(var subDirectoryPath in Directory.GetDirectories(currentDirectoryPath)) { // Recursively repeat. ApplyScriptsToDatabaseRecursiveDirectoryWalk(currentVersion, location, subDirectoryPath); } */ }