|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
另外,小型软件代码重用价值低,没有必要跨平台;大型软件,有严格的规划、部署,不可以随意跨平台。asp.net|技能|哀求 目标,把远程服务器传回的Html,剖析到类内里,为GridView等供应数据源
1、向远程服务器Post数据
publicintPostData(stringurl,stringdata,outstringinfo)
{
info="";
CookieContainercc=newCookieContainer();
HttpWebRequestrequest=WebRequest.Create(url)asHttpWebRequest;
request.CookieContainer=cc;
request.Method="POST";
request.ContentType="application/x-www-form-urlencoded";
StreamrequestStream=request.GetRequestStream();
byte[]byteArray=Encoding.UTF8.GetBytes(data);
requestStream.Write(byteArray,0,byteArray.Length);
requestStream.Close();
HttpWebResponseresponse=request.GetResponse()asHttpWebResponse;
UriresponseUri=response.ResponseUri;
StreamreceiveStream=response.GetResponseStream();
Encodingencode=System.Text.Encoding.GetEncoding("utf-8");
StreamReaderreadStream=newStreamReader(receiveStream,encode);
stringresult=readStream.ReadToEnd();
info=result;
return0;
}
2、剖析前往的html,有省略
publicClassInfo[]GetClass(stringhtml)
{
ArrayListar=newArrayList();
ArrayListarr=newArrayList();
stringtable="";
Regexregtable=newRegex(@"(?<=<table.*>).*?(?=</table>)",RegexOptions.Singleline);
Matchma=regtable.Match(html);
while(ma.Success)
{
if(ma.Value.Trim()!="")
{
arr.Add(HttpUtility.HtmlDecode(ma.Value));
}
ma=ma.NextMatch();
}
for(inti=0;i<arr.Count;i++)
{
table=arr.ToString()+table;
}
Regexreg=newRegex(@"(?<=<.*?>).*?(?=<.*?>)",RegexOptions.Singleline);
Matchm=reg.Match(table);
while(m.Success)
{
if(m.Value.Trim()!="")
{
ar.Add(HttpUtility.HtmlDecode(m.Value));
}
m=m.NextMatch();
}
ClassInfo[]ci=newClassInfo[classno];
for(inti=0;i<classno;i++)
{
ci=newClassInfo();
ci.RegisterDate=(ar[i*8+0]).ToString();
ci.LoginDate=(ar[i*8+1]).ToString();
ci.LogoutDate=(ar[i*8+2]).ToString();
ci.UseMin=ar[i*8+3].ToString();
ci.ClassName=ar[i*8+5].ToString();
ci.ClassType=ar[i*8+6].ToString();
ci.Percent=ar[i*8+7].ToString();
}
returnci;
}
3、界说ClassInfo类(课程类),用CodeSmith天生
publicclassClassInfo
{
MemberVariables#regionMemberVariables
protectedstring_loginDate;
protectedstring_logoutDate;
protectedstring_registerDate;
protectedstring_useMin;
protectedstring_className;
protectedstring_classType;
protectedstring_percent;
//protectedstring_nouse;
#endregion
Constructors#regionConstructors
publicClassInfo(){}
publicClassInfo(stringloginDate,stringlogoutDate,stringregisterDate,stringuseMin,stringclassName,stringclassType,stringpercent)
{
this._loginDate=loginDate;
this._logoutDate=logoutDate;
this._registerDate=registerDate;
this._useMin=useMin;
this._className=className;
this._classType=classType;
this._percent=percent;
}
#endregion
PublicProperties#regionPublicProperties
//publicstringNoUse
//{
//get{return_nouse;}
//set{_nouse=value;}
//}
publicstringLoginDate
{
get{return_loginDate;}
set{_loginDate=value;}
}
publicstringLogoutDate
{
get{return_logoutDate;}
set{_logoutDate=value;}
}
publicstringRegisterDate
{
get{return_registerDate;}
set{_registerDate=value;}
}
publicstringUseMin
{
get{return_useMin;}
set{_useMin=value;}
}
publicstringClassName
{
get{return_className;}
set
{
if(value!=null&&value.Length>50)
thrownewArgumentOutOfRangeException("InvalidvalueforClassName",value,value.ToString());
_className=value;
}
}
publicstringClassType
{
get{return_classType;}
set
{
if(value!=null&&value.Length>50)
thrownewArgumentOutOfRangeException("InvalidvalueforClassType",value,value.ToString());
_classType=value;
}
}
publicstringPercent
{
get{return_percent;}
set
{
if(value!=null&&value.Length>50)
thrownewArgumentOutOfRangeException("InvalidvalueforPercent",value,value.ToString());
_percent=value;
}
}
#endregion
}
中间码是基于一个虚拟机器。源代码是最高层的,理论上从源代码开始直接编译成本地码能提供最大优化的。而中间码只能是转译成本地码,效率上难免受到损耗。根据虚拟机器所设定的体系结构的特点,和本地机器的差异的多少。 |
|