/// <summary>删除记录</summary> /// <param name="id">标识</param> public void Delete(string id) { if (string.IsNullOrEmpty(id)) { return; } // 01.删除物理文件信息 IAttachmentFileInfo file = FindOne(id); if (file != null) { string path = file.VirtualPath.Replace("{uploads}", AttachmentStorageConfigurationView.Instance.PhysicalUploadFolder); if (File.Exists(path)) { File.Delete(path); } } // 02.删除数据库信息 Dictionary <string, object> args = new Dictionary <string, object>(); args.Add("WhereClause", string.Format(" Id IN ('{0}') ", StringHelper.ToSafeSQL(id).Replace(",", "','"))); this.ibatisMapper.Delete(StringHelper.ToProcedurePrefix(string.Format("{0}_Delete", this.tableName)), args); // 03.删除分布式文件数据 DistributedFileStorage.Delete(id); }
/// <summary>下载</summary> /// <param name="doc">Xml 文档对象</param> /// <returns>返回操作结果</returns> public ActionResult Download(string options) { JsonData request = JsonMapper.ToObject(options == null ? "{}" : options); // 实体数据标识 string id = !request.Keys.Contains("id") ? string.Empty : request["id"].ToString(); IAttachmentFileInfo param = AttachmentStorageContext.Instance.AttachmentFileService[id]; if (param == null) { KernelContext.Log.Info("file not found id:" + id); ApplicationError.Write(404); } else { if (param != null && param.FileData == null) { KernelContext.Log.Info("file data is null id:" + id); // 下载分布式文件数据 param.FileData = DistributedFileStorage.Download(param); } // [容错] 由于人为原因将服务器上的文件删除。 if (param.FileData == null) { ApplicationError.Write(404); } Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment;filename=" + EncodeFileName(param.AttachmentName)); Response.BinaryWrite(param.FileData); } Response.End(); return(Content(string.Empty)); }
/// <summary>获取分页内容</summary> /// <param name="doc">Xml 文档对象</param> /// <returns>返回操作结果</returns> public string Download(XmlDocument doc) { this.ProcessRequest(HttpContext.Current); string id = HttpContext.Current.Request.QueryString["id"]; IAttachmentFileInfo param = AttachmentStorageContext.Instance.AttachmentFileService[id]; if (param == null) { ApplicationError.Write(404); } else { if (param != null && param.FileData == null) { // 下载分布式文件数据 param.FileData = DistributedFileStorage.Download(param); } // [容错] 由于人为原因将服务器上的文件删除。 if (param.FileData == null) { ApplicationError.Write(404); } HttpContext.Current.Response.ContentType = "application/octet-stream"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + EncodeFileName(param.AttachmentName)); HttpContext.Current.Response.BinaryWrite(param.FileData); } HttpContext.Current.Response.End(); return(string.Empty); }