📄 ajax.cs
字号:
namespace PowerEasy.WebSite.Admin.Collection
{
using PowerEasy.Collection;
using PowerEasy.Common;
using PowerEasy.Enumerations;
using PowerEasy.Model.Collection;
using PowerEasy.Web.UI;
using System;
using System.Collections;
using System.IO;
using System.Text;
using System.Web;
using System.Xml;
public class Ajax : BasePage
{
private static string CommonFilter(string filterRuleId, string filter, CollectionCommon collectionCommon, string testContent)
{
if (filterRuleId.IndexOf(',') > 0)
{
foreach (string str in filterRuleId.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries))
{
testContent = FilterRule(DataConverter.CLng(str), collectionCommon, testContent);
}
}
else
{
testContent = FilterRule(DataConverter.CLng(filterRuleId), collectionCommon, testContent);
}
testContent = StringHelper.FilterScript(testContent, filter);
return testContent;
}
private static string FilterRule(int filterRuleId, CollectionCommon collectionCommon, string testContent)
{
if (filterRuleId > 0)
{
CollectionFilterRuleInfo infoById = CollectionFilterRules.GetInfoById(filterRuleId);
if (!infoById.IsNull)
{
switch (infoById.FilterType)
{
case 1:
testContent = testContent.Replace(infoById.BeginCode, infoById.Replace);
return testContent;
case 2:
testContent = collectionCommon.GetInterceptionString(testContent, infoById.BeginCode, infoById.EndCode);
return testContent;
}
}
}
return testContent;
}
protected void Page_Load(object sender, EventArgs e)
{
XmlDocument ixml = new XmlDocument();
try
{
ixml.Load(base.Request.InputStream);
}
catch (XmlException exception)
{
string path = "~/Temp/ajaxnote.txt";
path = HttpContext.Current.Server.MapPath(path);
if (File.Exists(path))
{
base.Response.Write(File.ReadAllText(path));
}
else
{
base.Response.Write(exception.Message);
}
return;
}
base.Response.Clear();
base.Response.Buffer = true;
base.Response.Charset = "utf-8";
base.Response.AddHeader("contenttype", "text/xml");
base.Response.ContentEncoding = Encoding.GetEncoding("utf-8");
base.Response.ContentType = "text/xml";
if (ixml.HasChildNodes)
{
string str2 = (ixml.DocumentElement.SelectSingleNode("//type") == null) ? "" : ixml.DocumentElement.SelectSingleNode("//type").InnerText.Trim();
switch (str2)
{
case "testList":
this.TestList(ixml);
goto Label_01E6;
case "testLink":
this.TestLink(ixml);
goto Label_01E6;
case "testPaing":
this.TestPaing(ixml);
goto Label_01E6;
case "testPaing2":
this.TestPaing2(ixml);
goto Label_01E6;
case "testShowContent":
this.TestShowContent(ixml);
goto Label_01E6;
case "testField":
this.TestField(ixml);
goto Label_01E6;
default:
if (!string.IsNullOrEmpty(str2))
{
goto Label_01E6;
}
this.PutErrMessage("没有要测试的采集类型!");
return;
}
return;
}
Label_01E6:
base.Response.End();
}
private void PutErrMessage(string message)
{
XmlTextWriter writer = new XmlTextWriter(HttpContext.Current.Response.OutputStream, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.WriteStartDocument();
writer.WriteStartElement("root", "");
writer.WriteElementString("status", "err");
writer.WriteElementString("body", message);
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
}
private void TestField(XmlDocument ixml)
{
string uriString = (ixml.DocumentElement.SelectSingleNode("//url") == null) ? "" : ixml.DocumentElement.SelectSingleNode("//url").InnerText.Trim();
string coding = (ixml.DocumentElement.SelectSingleNode("//codeType") == null) ? "" : ixml.DocumentElement.SelectSingleNode("//codeType").InnerText.Trim();
string startStr = (ixml.DocumentElement.SelectSingleNode("//listBegin") == null) ? "" : ixml.DocumentElement.SelectSingleNode("//listBegin").InnerText.Trim();
string overStr = (ixml.DocumentElement.SelectSingleNode("//listEnd") == null) ? "" : ixml.DocumentElement.SelectSingleNode("//listEnd").InnerText.Trim();
string input = (ixml.DocumentElement.SelectSingleNode("//keyword") == null) ? "" : ixml.DocumentElement.SelectSingleNode("//keyword").InnerText.Trim();
string filterRuleId = (ixml.DocumentElement.SelectSingleNode("//filterRuleId") == null) ? "" : ixml.DocumentElement.SelectSingleNode("//filterRuleId").InnerText.Trim();
string filter = (ixml.DocumentElement.SelectSingleNode("//filter") == null) ? "" : ixml.DocumentElement.SelectSingleNode("//filter").InnerText.Trim();
string str8 = (ixml.DocumentElement.SelectSingleNode("//fieldType") == null) ? "" : ixml.DocumentElement.SelectSingleNode("//fieldType").InnerText.Trim();
CollectionCommon collectionCommon = new CollectionCommon();
Uri url = new Uri(uriString);
string httpPage = collectionCommon.GetHttpPage(url, coding);
string testContent = collectionCommon.GetInterceptionString(httpPage, startStr, overStr);
FieldType none = FieldType.None;
if (Enum.IsDefined(typeof(FieldType), str8))
{
none = (FieldType) Enum.Parse(typeof(FieldType), str8);
}
switch (none)
{
case FieldType.TextType:
case FieldType.ListBoxType:
case FieldType.LookType:
case FieldType.CountType:
case FieldType.ColorType:
case FieldType.TemplateType:
case FieldType.AuthorType:
case FieldType.SourceType:
case FieldType.OperatingType:
case FieldType.Producer:
case FieldType.Trademark:
case FieldType.TitleType:
if (testContent.Length > 0xff)
{
testContent = testContent.Substring(0, 0xff);
}
testContent = CommonFilter(filterRuleId, filter, collectionCommon, testContent);
break;
case FieldType.NumberType:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -