TaskStatus.ashx:
using System;
using System.Collections.Generic;using System.Linq;
using System.Web;
using System.Data;
using System.IO;
namespace iCare.VQD.Workbench.Web
{
/// <summary>
/// Summary description for TaskStatus
/// </summary>
public class TaskStatus : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string result = string.Empty;
Response response = new Response();
response.Command = "taskstatus";
response.ErrorCode = 500;
string id = context.Request.QueryString["id"];
string status=context.Request.QueryString["status"];
string sql="update TaskExecLog set EndTime=getdate(),status={0} where ID ={1}";
if (string.IsNullOrEmpty(id)) //判断id是否为空
{
response.ErrorCode=501;
}
else if (!string.IsNullOrEmpty(status )) //判断status是否为空
{
response.ErrorCode = 501;
}
int intId;
if (!int.TryParse(id,out intId) || intId <= 0) //判断id的格式是够是int类型
{
response.ErrorCode = 502;
}
bool boolStatus;
if (!bool.TryParse(status,out boolStatus)) //判断status的格式是够是bool类型
{
response.ErrorCode = 502;
}
if (response.ErrorCode == 500)
{
sql = string.Format(sql,boolStatus ? 1 : 36,intId);
DBManager dbManager = null;
try
{
dbManager = new DBManager(VQDUtil.GetConnectionString(),VQDUtil.GetDbProviderType());
dbManager.ExecuteNonQuery(sql,CommandType.Text);
}
catch (Exception ex)
{
logger.Debug("更新数据异常",ex);
}
}
result = XMLHelper.ToXmlString<Response>(response);
context.Response.ContentType = "text/xml";
Stream outStream = context.Response.OutputStream;
using (StreamWriter writter = new StreamWriter(outStream))
{
writter.WriteLine(result);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
XMLHelper:
public static string ToXmlString<ITEM>(ITEM item)
{
XmlSerializer serializer = new XmlSerializer(typeof(ITEM));
using (MemoryStream memStream = new MemoryStream())
{
XmlWriterSettings setting = new XmlWriterSettings();
setting.Encoding = Encoding.UTF8;
using (XmlWriter writer = XmlWriter.Create(memStream,setting))
{
serializer.Serialize(writer,item);
writer.Flush();
writer.Close();
memStream.Position = 0;
using (StreamReader reader = new StreamReader(memStream))
{
return reader.ReadToEnd();
}
}
}
}
<response command="xxxx">
<errorcode>0</errorcode>
</response>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Xml.Serialization; namespace iCare.VQD.Workbench.Web.Models.Shared.Http { [XmlRoot("response")] public class Response { [XmlAttribute("command")] public string Command { get; set; } [XmlElement("errorcode")] public int ErrorCode { get; set; } } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。