コード例 #1
0
 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.");
     }
 }
コード例 #2
0
        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));
        }