Пример #1
0
        /// <summary>
        /// Returns x sandwiched between open and shut code tags.
        ///
        /// If encode is true, first HTML encode x.
        ///
        /// Returns an empty string if x is trivial.
        /// </summary>
        /// <param name="x">The text to sandwich</param>
        /// <param name="encode">If true HTML encode x</param>
        public static string code(string x, bool encode)
        {
            if (StringTools.IsTrivial(x))
            {
                return("");
            }

            x = encode ? StringTools.HtmlEncode(x) : x;

            return(open_code + x + shut_code);
        }
Пример #2
0
        /*
         * Provide error content to the HttpContext Response object.
         *
         * The embeddedUrl is the url that was being processed.
         *
         * The message is any additional information  to provide.
         */
        void ProcessRequestError
            (HttpContext context, string embeddedUrl, string message)
        {
            context.Response.Write("<!DOCTYPE html>\n");
            context.Response.Write("<html>\n");
            context.Response.Write("<head><title>SimpleProxy</title></head>\n");
            context.Response.Write("<body><h1>SimpleProxy Error</h1>\n");

            if (StringTools.IsTrivial(embeddedUrl))
            {
                context.Response.Write("<h2>Needs an embedded Url in the query string</h2>\n");

                context.Response.Write("<pre style='color: blue; font-size: 150%; margin-left: 5%'><b>");
                context.Response.Write("?url=\"...\"");
                context.Response.Write("</b></pre>\n");

                context.Response.Write("<h2>where ... is the url embedded between the delimiters.</h2>");
                context.Response.Write("<h2>The delimiters may be single quote, double quote, or vertical bar.</h2>");

                context.Response.Write("<h2>Documentation is <a href=");
                context.Response.Write("'http://net4.ccs.neu.edu/home/rasala/simpleproxy/'");
                context.Response.Write(" target='_blank' style='text-decoration: none'>here</a>.</h2>\n");
            }
            else
            {
                context.Response.Write("<h2>Embedded Url:</h2>\n");

                embeddedUrl = StringTools.HtmlEncode(embeddedUrl);

                context.Response.Write("<pre style='color: blue; font-size: 150%; margin-left: 5%'><b>");
                context.Response.Write(embeddedUrl);
                context.Response.Write("</b></pre>\n");
            }

            if (!StringTools.IsTrivial(message))
            {
                context.Response.Write("<div>");
                context.Response.Write(message);
                context.Response.Write("</div>\n");
            }

            context.Response.Write("</body>\n");
            context.Response.Write("</html>\n");
        }
Пример #3
0
        /// <summary>
        /// Adds x sandwiched between open and shut code tags
        /// to the given StringBuilder builder.
        ///
        /// If encode is true, first HTML encode x.
        ///
        /// Does nothing if x is trivial.
        /// </summary>
        /// <param name="builder">The builder to collect the markup</param>
        /// <param name="x">The text to sandwich</param>
        /// <param name="encode">If true HTML encode x</param>
        public static void code
            (StringBuilder builder, string x, bool encode)
        {
            if (StringTools.IsTrivial(x))
            {
                return;
            }

            builder.Append(open_code);

            if (encode)
            {
                x = StringTools.HtmlEncode(x);
            }

            builder.Append(x);

            builder.Append(shut_code);
        }
Пример #4
0
        /// <summary>
        /// Adds feedback data markup constructed as follows
        /// to the given StringBuilder builder.
        ///
        /// If the feedback data is non-trivial then the
        /// data is HTML encoded and inserted in a pre-tag
        /// with CSS class 'feedback'.
        ///
        /// If the feedback data is null then the constant
        /// string
        ///
        ///   data is null
        ///
        /// is inserted in a pre-tag with CSS class 'feedback'
        /// and with color styled as red.
        ///
        /// If the feedback data is empty then the constant
        /// string
        ///
        ///   data is empty
        ///
        /// is inserted in a pre-tag with CSS class 'feedback'
        /// and with color styled as red.
        ///
        /// See the const string FeedbackCSS.
        /// </summary>
        /// <param name="builder">The builder to collect the markup</param>
        /// <param name="data">The feedback data</param>
        public static void FeedbackData
            (StringBuilder builder, string data)
        {
            if (StringTools.IsTrivial(data))
            {
                builder.Append(open_pre_feedback_red);

                if (data == null)
                {
                    builder.Append("data is null");
                }
                else
                {
                    builder.Append("data is empty");
                }
            }
            else
            {
                builder.Append(open_pre_feedback);
                builder.Append(StringTools.HtmlEncode(data));
            }

            builder.Append(shut_pre);
        }