ServParam2ClientModelEngine/CodeShowWeb/Index.aspx.cs

95 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CoderEngine;
namespace CodeShowWeb
{
public partial class Index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public string GetCode()
{
string CodeLang = GetLangParam();
string CodeStr = "";
if (CodeLang == "Java")
{
CodeStr = new JavaCodeWrite().ModelToJavaCode("CoderEngine", "A");
}
else if (CodeLang == "Swift")
{
CodeStr = new SwiftCodeWrite().ModelToSwiftCode("CoderEngine", "A");
}
else if (CodeLang == "JavaScript")
{
CodeStr = new AjaxCodeWrite().ModelToAjaxCode("CoderEngine", "A");
}
else if (CodeLang == "CSharp")
{
CodeStr = new CSharpCodeWrite().ModelToCSCode("CoderEngine", "A");
}
//避免类似 List<XXX> 这类的< >被识别为html标签显示异常
CodeStr = CodeStr.Replace("<", "&lt;");
CodeStr = CodeStr.Replace(">", "&gt;");
return CodeStr;
}
public string GetLangParam()
{
var lang = Request.QueryString["Lang"];
if (lang != null && lang != "")
{
return lang;
}
else
return "Java";
}
public string GetLangCodeShowName()
{
string str = GetLangParam();
switch (str)
{
case "Java": return "java";
case "C#": return "C#";
default:return str;
}
}
public string GetCodeStyle()
{
string CodeLang = GetLangParam();
if (CodeLang == "Java")
{
return "androidstudio.css";
}
else if (CodeLang == "Swift")
{
return "xcode.css";
}
else if (CodeLang == "JavaScript")
{
return "codepen-embed.css";
}
else if (CodeLang == "CSharp")
{
return "atelier-plateau-dark.css";
}
return "代码语言尚未支持";
}
}
}