private string FormatTSqlWithFormatter(string inputString, PoorMansTSqlFormatterRedux.Interfaces.ISqlTreeFormatter formatter) { if (this.HttpContext.IsLocalRequest()) { PoorMansTSqlFormatterRedux.SqlFormattingManager fullFormatter = new PoorMansTSqlFormatterRedux.SqlFormattingManager(new PoorMansTSqlFormatterRedux.Formatters.HtmlPageWrapper(formatter)); return(fullFormatter.Format(inputString)); } else { return("Sorry, this web service can only be called from code hosted at localhost."); } }
public string FormatTSqlWithOptions(Options options) { PoorMansTSqlFormatterRedux.Interfaces.ISqlTreeFormatter formatter = null; if (options.reFormat.Value) { formatter = new PoorMansTSqlFormatterRedux.Formatters.TSqlStandardFormatter(new PoorMansTSqlFormatterRedux.Formatters.TSqlStandardFormatterOptions { IndentString = options.indent, SpacesPerTab = options.spacesPerTab.Value, MaxLineWidth = options.maxLineWidth.Value, NewStatementLineBreaks = options.statementBreaks.Value, NewClauseLineBreaks = options.clauseBreaks.Value, ExpandCommaLists = options.expandCommaLists.Value, TrailingCommas = options.trailingCommas.Value, SpaceAfterExpandedComma = options.spaceAfterExpandedComma.Value, ExpandBooleanExpressions = options.expandBooleanExpressions.Value, ExpandCaseStatements = options.expandCaseStatements.Value, ExpandBetweenConditions = options.expandBetweenConditions.Value, BreakJoinOnSections = options.breakJoinOnSections.Value, UppercaseKeywords = options.uppercaseKeywords.Value, HTMLColoring = options.coloring.Value, KeywordStandardization = options.keywordStandardization.Value, ExpandInLists = options.expandInLists.Value }); } else if (options.obfuscate.Value) { formatter = new PoorMansTSqlFormatterRedux.Formatters.TSqlObfuscatingFormatter( options.randomizeKeywordCase.Value, options.randomizeColor.Value, options.randomizeLineLengths.Value, options.preserveComments.Value, options.enableKeywordSubstitution.Value ); } else { formatter = new PoorMansTSqlFormatterRedux.Formatters.TSqlIdentityFormatter(options.coloring.Value); } if (options.useParseErrorPlaceholder.Value) { formatter.ErrorOutputPrefix = "{PARSEERRORPLACEHOLDER}"; } PoorMansTSqlFormatterRedux.Interfaces.ISqlTreeFormatter wrapper = formatter; if (string.Equals("html", options.format, System.StringComparison.OrdinalIgnoreCase)) { wrapper = new PoorMansTSqlFormatterRedux.Formatters.HtmlPageWrapper(formatter); } PoorMansTSqlFormatterRedux.SqlFormattingManager fullFormatter = new PoorMansTSqlFormatterRedux.SqlFormattingManager(wrapper); return(fullFormatter.Format(options.inputString)); }
public string FormatTSqlWithOptions([FromBody] FormatTSqlModel model) { PoorMansTSqlFormatterRedux.Interfaces.ISqlTreeFormatter formatter = null; if (model.ReFormat) { formatter = new PoorMansTSqlFormatterRedux.Formatters.TSqlStandardFormatter(new PoorMansTSqlFormatterRedux.Formatters.TSqlStandardFormatterOptions { IndentString = model.Indent, SpacesPerTab = model.SpacesPerTab, MaxLineWidth = model.MaxLineWidth, NewStatementLineBreaks = model.StatementBreaks, NewClauseLineBreaks = model.ClauseBreaks, ExpandCommaLists = model.ExpandCommaLists, TrailingCommas = model.TrailingCommas, SpaceAfterExpandedComma = model.SpaceAfterExpandedComma, ExpandBooleanExpressions = model.ExpandBooleanExpressions, ExpandCaseStatements = model.ExpandCaseStatements, ExpandBetweenConditions = model.ExpandBetweenConditions, BreakJoinOnSections = model.BreakJoinOnSections, UppercaseKeywords = model.UppercaseKeywords, HTMLColoring = model.Coloring, KeywordStandardization = model.KeywordStandardization, ExpandInLists = model.ExpandInLists }); } else if (model.Obfuscate) { formatter = new PoorMansTSqlFormatterRedux.Formatters.TSqlObfuscatingFormatter( model.RandomizeKeywordCase, model.RandomizeColor, model.RandomizeLineLengths, model.PreserveComments, model.EnableKeywordSubstitution ); } else { formatter = new PoorMansTSqlFormatterRedux.Formatters.TSqlIdentityFormatter(model.Coloring); } if (model.UseParseErrorPlaceholder) { formatter.ErrorOutputPrefix = "{PARSEERRORPLACEHOLDER}"; } return(FormatTSqlWithFormatter(model.InputString, formatter)); }