ComplianceServer/oldcode/WxService/WxDbUpload.ashx.cs

99 lines
4.3 KiB
C#

using Ninject;
using System;
using System.Configuration;
using System.IO;
using System.Web;
using WX.CRM.Common;
using WX.CRM.IBLL.Wx;
using WX.CRM.Model.Entity;
using WX.CRM.Model.Enum;
using WX.CRM.WebHelper.Infrastructure;
namespace WxService
{
/// <summary>
/// WxDbUpload 的摘要说明
/// </summary>
public class WxDbUpload : IHttpHandler
{
private IWX_DBUPLOADLOG dbpubliclog = NinjectControllerFactory.ninjectKernel.Get<IWX_DBUPLOADLOG>();
private IWX_RCONTACT rcontact = NinjectControllerFactory.ninjectKernel.Get<IWX_RCONTACT>();
public void ProcessRequest(HttpContext context)
{
string username = string.Empty;
try
{
context.Response.ContentType = "text/html";
//LogHelper.Info(string.Format("username:{0},password:{1},copytime:{2},createtime:{3},qunfaclientid{4}", username, password, copytime, createtime, qunfaclientid));
#region
var yearMonth = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString();
var uploadFolder = (ConfigurationManager.AppSettings["dbuploadfile"] ?? "dbuploadfile") + "/" + yearMonth;
//Stream sourceStream = request.FileData;
FileStream targetStream = null;
if (!Directory.Exists(uploadFolder))
{
Directory.CreateDirectory(uploadFolder);
}
username = context.Request.Params["username"];
if (string.IsNullOrEmpty(username))
throw new Exception("username不能为空!");
string password = context.Request.Params["password"];
string copytime = context.Request.Params["copytime"];
string createtime = context.Request.Params["createtime"];
string qunfaclientid = context.Request.Params["qunfaclientid"];
HttpPostedFile file = context.Request.Files[0];
string timejiewei = DateTime.Now.ToString("yyMMddhhmmss");
string fileName = string.Format("{0}-{1}-{2}.db", username, password, timejiewei);
string filePath = Path.Combine(uploadFolder, fileName);
//LogHelper.Info(string.Format("filePath:{0}", filePath));
file.SaveAs(filePath);
WX_DBUPLOADLOG model = new WX_DBUPLOADLOG();
//LogHelper.Info("成功否!");
if (!string.IsNullOrEmpty(copytime))
{
try
{
model.COPYTIME = DateTimeTool.GetTimeFromLinuxTime(Convert.ToInt64(copytime));
}
catch (Exception ex) { LogHelper.Error(ex.ToString()); }
}
model.USERNAME = username;
model.PASSWORD = password;
model.DBFILE = filePath;
long createTimeL = 0;
if (!string.IsNullOrEmpty(copytime))
{
createTimeL = Convert.ToInt64(createtime);
}
DateTime createTimeT = DateTimeTool.GetTimeFromLinuxTime(createTimeL);
bool resu = rcontact.WxDbUploadLog(model, createTimeL, createTimeT, qunfaclientid);
#endregion
//HttpContext.Current.Response.Clear();
if (resu)
HttpContext.Current.Response.Write(Utility.ObjectToJson(new { result = true, retcode = (int)EnumInterfaceErrcode., retmsg = "接收成功" }));
else
HttpContext.Current.Response.Write(Utility.ObjectToJson(new { result = false, retcode = (int)EnumInterfaceErrcode., retmsg = "新增数据失败" }));
}
catch (Exception ex)
{
LogHelper.Error("username:" + username + ";db错误:" + ex.ToString());
//HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(Utility.ObjectToJson(new { result = false, retcode = (int)EnumInterfaceErrcode., retmsg = "接收失败:" + ex.Message }));
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}