/// <summary> /// Returns after-deploy scripts, ordered by natural sort of file paths inside each package. /// </summary> private List <Script> GetScripts(InstalledPackage package) { string afterDeployFolder = Path.GetFullPath(Path.Combine(package.Folder, "AfterDeploy")); if (!Directory.Exists(afterDeployFolder)) { return new List <Script> { } } ; var files = Directory.GetFiles(afterDeployFolder, "*.*", SearchOption.AllDirectories) .OrderBy(path => CsUtility.GetNaturalSortString(path).Replace(@"\", @" \")); const string expectedExtension = ".sql"; var badFile = files.FirstOrDefault(file => Path.GetExtension(file).ToLower() != expectedExtension); if (badFile != null) { throw new FrameworkException("After-deploy script '" + badFile + "' does not have the expected extension '" + expectedExtension + "'."); } return(files.Select(path => new Script { Package = package, Path = path, Name = GetSimpleName(path, afterDeployFolder) }) .ToList()); }
public void NaturalSortTest_NonNumeric() { var tests = new[] { "", " ", " ", "a", ".", "-" }; foreach (var test in tests) { Assert.AreEqual(test, CsUtility.GetNaturalSortString(test)); } }
public void NaturalSortTest_Simple() { string test = @"0, 1, 9, 10, 11, 100, s1:1\9.9\x, s2:1\9.10\x, s3:1\10.9\x, s4:1\10.10\x, s5:1\11\x, s6:1\11.next\x"; var unsortedList = test.Split(new[] { ", " }, StringSplitOptions.None).Reverse(); Assert.AreNotEqual(test, TestUtility.Dump(unsortedList)); Assert.AreEqual(test, TestUtility.Dump(unsortedList.OrderBy(s => CsUtility.GetNaturalSortString(s)))); }
/// <summary> /// Returns after-deploy scripts, ordered by natural sort of file paths inside each package. /// </summary> private List <AfterDeployScript> GetScripts(InstalledPackage package) { string afterDeployFolderPrefix = "AfterDeploy" + Path.DirectorySeparatorChar; var files = package.ContentFiles.Where(file => file.InPackagePath.StartsWith(afterDeployFolderPrefix, StringComparison.OrdinalIgnoreCase)) .OrderBy(file => CsUtility.GetNaturalSortString(file.InPackagePath).Replace(@"\", @" \").Replace(@"/", @" /")) .ToList(); const string expectedExtension = ".sql"; var badFile = files.FirstOrDefault(file => !string.Equals(Path.GetExtension(file.InPackagePath), expectedExtension, StringComparison.OrdinalIgnoreCase)); if (badFile != null) { throw new FrameworkException("After-deploy script '" + badFile.PhysicalPath + "' does not have expected extension '" + expectedExtension + "'."); } return(files .Select(file => new AfterDeployScript { Name = package.Id + ": " + file.InPackagePath.Substring(afterDeployFolderPrefix.Length), Script = _filesUtility.ReadAllText(file.PhysicalPath) }) .ToList()); }
private static string ComputeOrder(string s) { return(CsUtility.GetNaturalSortString(s).Replace(@"\", @" \").ToLower()); }
protected static string ComputeOrder(string s) { return(CsUtility.GetNaturalSortString(s).Replace(@"\", @" \")); }
private static string ComputeOrderWithinPackage(string path) { return(CsUtility.GetNaturalSortString(path).Replace(@"\", @" \").Replace(@"/", @" /").ToLower()); }