public Script[] GetScripts(ScriptKind kind) { Func<DirectoryInfo, bool> selector; switch (kind) { case ScriptKind.PreMigration: selector = IsPreMigrationFolder; break; case ScriptKind.Migration: selector = IsMigrationFolder; break; case ScriptKind.PostMigration: selector = IsPostMigrationFolder; break; default: throw new ArgumentOutOfRangeException(nameof(kind), kind, null); } var q = from d in _directory.EnumerateDirectories("*") where selector(d) from s in d.GetFiles("*.sql", SearchOption.AllDirectories) let collectionName = Path.GetFileName(d.FullName.Substring(_directory.FullName.Length + 1).Split(Path.PathSeparator).First()) let scriptName = s.FullName.Substring(d.FullName.Length + 1) let content = ReadFile(s.FullName) let checksum = content.Checksum() orderby d.FullName ascending, scriptName ascending select new Script(collectionName, scriptName, content, checksum); var scripts = q.ToArray(); return scripts; }
public static ScriptKind EnsureScriptKind(string fileName, ScriptKind scriptKind) { // Using scriptKind as a condition handles both: // - 'scriptKind' is unspecified and thus it is `null` // - 'scriptKind' is set and it is `Unknown` (0) // If the 'scriptKind' is 'null' or 'Unknown' then we attempt // to get the ScriptKind from the file name. If it cannot be resolved // from the file name then the default 'TS' script kind is returned. var sk = scriptKind != ScriptKind.Unknown ? scriptKind : GetScriptKindFromFileName(fileName); return(sk != ScriptKind.Unknown ? sk : ScriptKind.Ts); }
public string Print(IStatement[] statements, ScriptKind scriptKind) { var astPayload = JsonConvert.SerializeObject(statements); var command = new PrintCommand() { AstPayload = astPayload, ScriptKind = scriptKind }; var response = this.ExecuteCommand(command); var result = JsonConvert.DeserializeObject <PrintCommandResult>(response); return(result.Payload); }
void AddScript(string source, string name, ScriptKind kind, string path, string value = null) { var xname = name; var suffix = 0; while (_scriptlookup.ContainsKey(xname)) { xname = $"{name}-{++suffix}"; } _scriptlookup[xname] = new ScriptInfo { Source = source, Name = xname, Kind = kind, Path = path, Value = value }; }
public IStatement[] Parse(string payload, ScriptKind scriptKind) { var command = new ParseCommand() { Payload = payload, ScriptKind = scriptKind }; var response = this.ExecuteCommand(command); var result = JsonConvert.DeserializeObject <ParseCommandResult>(response); List <IStatement> ast = JsonConvert.DeserializeObject <List <IStatement> >(result.AstPayload, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto, NullValueHandling = NullValueHandling.Ignore, MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead }); return(ast.ToArray()); }
public bool ExecuteScripts(bool whatif, ScriptKind kind) { var scripts = _scriptFileRepository.GetScripts(kind); var maxFolderNameLength = scripts.Select(s => s.Collection.Length).DefaultIfEmpty().Max(); var maxFileNameLength = scripts.Select(s => s.ScriptName.Length).DefaultIfEmpty().Max(); foreach (var script in scripts) { Logger.Info($"[{script.Collection}".PadRight(maxFolderNameLength + 1) + "] "); Logger.Info((script.ScriptName + "... ").PadRight(maxFileNameLength + 4)); try { if (!whatif) { _database.RunInTransaction(script.Content); Logger.Ok(); } } catch (Exception e) { Logger.ErrorLine("ERROR: " + e.Message); return false; } Console.WriteLine(); } return true; }
public bool HasScripts(ScriptKind kind) { var scripts = _scriptFileRepository.GetScripts(kind); return scripts.Any(); }