/// <summary> /// Runs... /// </summary> /// <param name="thisBatchFile">this batch file.</param> /// <param name="inThisContext">The in this context.</param> /// <param name="withSupplementaryTokenReplacements">with supplementary token replacements.</param> public void Run( ISQLBatchScript thisBatchScript, IConnectionDetail inThisContext, Func <string, string> withSupplementaryTokenReplacements) { It.IsNull(thisBatchScript) .AsGuard <ArgumentNullException>(nameof(thisBatchScript)); It.IsNull(inThisContext) .AsGuard <ArgumentNullException>(nameof(inThisContext)); if (It.IsInRange(thisBatchScript.Type, TypeOfBatchScript.Ignored)) { return; } Emitter.Publish(Indentation.FirstLevel, $"Running: '{thisBatchScript.Description}'"); if (It.IsInRange(thisBatchScript.Type, TypeOfBatchScript.Statement)) { var content = Pseudonyms.ReplaceTokensIn(thisBatchScript.Command, withSupplementaryTokenReplacements); UsingConnection(inThisContext, x => RunCommand(content, x)); return; } var batches = GetSQLOperations(thisBatchScript.Command, withSupplementaryTokenReplacements); Emitter.Publish(Indentation.FirstLevel, $"Batch contains {batches.Count} statement{(batches.Count > 1 ? "s" : string.Empty)}."); Run(batches.AsSafeReadOnlyList(), inThisContext); }
/// <summary> /// Gets the SQL operations... /// </summary> /// <param name="usingThisFile">using this file.</param> /// <param name="withSupplementaryTokenReplacements">with supplementary token replacements.</param> /// <returns> /// a list of batch operations /// </returns> public IReadOnlyCollection <string> GetSQLOperations(string usingThisFile, Func <string, string> withSupplementaryTokenReplacements) { It.IsEmpty(usingThisFile) .AsGuard <ArgumentNullException>(nameof(usingThisFile)); var file = Asset.GetContent(usingThisFile).Result; var content = Pseudonyms.ReplaceTokensIn(file, withSupplementaryTokenReplacements); return(CleanseSQLOperations(content)); }