コード例 #1
0
 public void GetlogBrowseHeatmap(int bankID)
 {
     using (var db = new HeatMapEntities())
     {
         //记录下载记录
         var logItem = new Logs();
         logItem.PK_ID      = Guid.NewGuid();
         logItem.CreateTime = DateTime.Now;
         logItem.ClientIP   = HostIP.GetHostAddress();
         logItem.TypeID     = 2;//typeID:1-访问页面,2-浏览支行热力图,3-下载支行热力图
         logItem.BankID     = bankID;
         logItem.UserID     = null;
         db.Logs.Add(logItem);
         db.SaveChanges();
     }
 }
コード例 #2
0
        public HttpResponseMessage DownloadImg(string imgUrl, string bankID)
        {
            try
            {
                HttpResponseMessage response = new HttpResponseMessage();
                string filePath = HttpContext.Current.Server.MapPath(imgUrl);

                //以字符流的形式下载文件
                FileStream fs    = new FileStream(filePath, FileMode.Open);
                byte[]     bytes = new byte[(int)fs.Length];
                fs.Read(bytes, 0, bytes.Length);
                fs.Close();

                response.Content = new ByteArrayContent(bytes);
                response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");

                var fileName = DateTime.Now.ToString("yyyyMMddhhmmss") + imgUrl.Substring(imgUrl.LastIndexOf('.'));


                response.Content.Headers.ContentDisposition.FileName = fileName;
                response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                using (var db = new HeatMapEntities())
                {
                    //记录下载记录
                    var logItem = new Logs();
                    logItem.PK_ID      = Guid.NewGuid();
                    logItem.CreateTime = DateTime.Now;
                    logItem.ClientIP   = HostIP.GetHostAddress();
                    logItem.TypeID     = 3;//typeID:1-访问页面,2-浏览支行热力图,3-下载支行热力图
                    logItem.BankID     = Convert.ToInt32(bankID);
                    logItem.UserID     = null;
                    db.Logs.Add(logItem);
                    db.SaveChanges();
                }
                return(response);
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex.StackTrace);
                return(new HttpResponseMessage(HttpStatusCode.NoContent));
            }
        }