Пример #1
0
        protected void DisplayCode()
        {
            string File = this.Page.Server.MapPath(this.ResolveUrl(this.CodeFile));

            File = File.ToLower();

            // Allow only source and aspx files
            string extension = Path.GetExtension(File).ToLower();

            if (!",.cs,.vb,.aspx,.asmx,.js,.ashx,".Contains("," + extension + ","))
            {
                this.Output = "Invalid Filename specified...";
                return;
            }

            if (System.IO.File.Exists(File))
            {
                StreamReader sr         = new StreamReader(File);
                string       FileOutput = sr.ReadToEnd();
                sr.Close();

                if (File.ToLower().EndsWith(".cs") || File.ToLower().EndsWith(".asmx") || File.ToLower().EndsWith(".ashx"))
                {
                    JavaFormat Format = new JavaFormat();
                    this.Output = "<div class='showcode'>" + Format.FormatCode(FileOutput) + "</div>";
                }
                else if (File.ToLower().EndsWith(".js"))
                {
                    JavaScriptFormat Format = new JavaScriptFormat();
                    this.Output = "<div class='showcode'>" + Format.FormatCode(FileOutput) + "</div>";
                }
                else
                {
                    HtmlFormat Format = new HtmlFormat();
                    this.Output = "<div class='showcode'>" + Format.FormatCode(FileOutput) + "</div>";
                }

                //this.txtOutput.Text = "<pre>" + Server.HtmlEncode(FileOutput) + "</pre>";

                this.Page.ClientScript.RegisterStartupScript(typeof(ViewSourceControl), "scroll",
                                                             "var codeContainer = document.getElementById('" + this.btnShowCode.ClientID + "');codeContainer.focus();setTimeout(function() { window.scrollBy(0,200);},100);", true);
            }

            this.btnShowCode.Visible = true;
        }
Пример #2
0
        public static void Main(string[] args)
        {
            SourceFormat sourceFormat = null;

            bool lineNumbers = false;

            bool alternate = false;

            bool embedStyleSheet = false;

            string title = null;

            foreach (string arg in args)
            {
                String s = arg.ToLower();
                if (s.Equals("-csharp"))
                {
                    sourceFormat = new CSharpFormat();
                }
                else if (s.Equals("-java"))
                {
                    sourceFormat = new JavaFormat();
                }
                else if (s.StartsWith("-line"))
                {
                    lineNumbers = true;
                }
                else if (s.StartsWith("-alt"))
                {
                    alternate = true;
                }
                else if (s.StartsWith("-embed"))
                {
                    embedStyleSheet = true;
                }
                else if (s.StartsWith("-title:"))
                {
                    title = arg.Substring(7);
                }
                else
                {
                    Console.WriteLine("ERROR: Invalid argument: " + arg);
                    Environment.Exit(1);
                }
            }

            if (sourceFormat == null)
            {
                Console.WriteLine("ERROR: Missing language argument");
                Environment.Exit(1);
            }

            if (lineNumbers)
            {
                sourceFormat.LineNumbers = true;
            }

            if (alternate)
            {
                sourceFormat.Alternate = true;
            }

            if (embedStyleSheet)
            {
                sourceFormat.EmbedStyleSheet = true;
            }

            if (title != null)
            {
                sourceFormat.Title = title;
            }

            Console.Write(sourceFormat.FormatCode(Console.In.ReadToEnd()));
        }
Пример #3
0
        protected void DisplayCode()
        {
            string File = this.Page.Server.MapPath(this.ResolveUrl(this.CodeFile));
            File = File.ToLower();

            // Allow only source and aspx files
            string extension = Path.GetExtension(File).ToLower();

            if ( !",.cs,.vb,.aspx,.asmx,.js,.ashx,".Contains("," + extension + ",") )
            {
                this.Output = "Invalid Filename specified...";
                return;
            }

            if (System.IO.File.Exists(File))
            {
                StreamReader sr = new StreamReader(File);
                string FileOutput = sr.ReadToEnd();
                sr.Close();

                if (File.ToLower().EndsWith(".cs") || File.ToLower().EndsWith(".asmx") || File.ToLower().EndsWith(".ashx"))
                {
                    JavaFormat Format = new JavaFormat();
                    this.Output = "<div class='showcode'>" + Format.FormatCode(FileOutput) + "</div>";
                }
                else if (File.ToLower().EndsWith(".js"))
                {
                    JavaScriptFormat Format = new JavaScriptFormat();
                    this.Output = "<div class='showcode'>" + Format.FormatCode(FileOutput) + "</div>";
                }
                else
                {
                    HtmlFormat Format = new HtmlFormat();
                    this.Output = "<div class='showcode'>" + Format.FormatCode(FileOutput) + "</div>";
                }

                //this.txtOutput.Text = "<pre>" + Server.HtmlEncode(FileOutput) + "</pre>";

                this.Page.ClientScript.RegisterStartupScript(typeof(ViewSourceControl), "scroll",
                    "var codeContainer = document.getElementById('" + this.btnShowCode.ClientID + "');codeContainer.focus();setTimeout(function() { window.scrollBy(0,200);},100);", true);
            }
            
            this.btnShowCode.Visible = true;
            
        }