/// <summary> /// 执行命令并返回结果 /// </summary> /// <param name="connection"></param> /// <param name="commandInfo"></param> public void ExecuteCommand(IConnection connection, AsyncBinaryCommandInfo commandInfo) { if (commandInfo.Buffer == null || commandInfo.Buffer.Length == 0) { Console.WriteLine("数据为空"); return; } var form = Container as MainForm; string content = System.Text.Encoding.Default.GetString(commandInfo.Buffer); UpdateFileModel file = Util.Json.ToObject <UpdateFileModel>(content); if (file == null) { form.DisplayMsg(string.Format("请求更新文件出现错误,session Id:{0}", connection.ConnectionID)); } form.DisplayMsg(string.Format("{0} 正在下载文件{1}", connection.ConnectionID, file.FileName)); FileStream fs = new FileStream(file.FilePath, FileMode.Open); byte[] fileblock = new byte[4096]; while (fs.Read(fileblock, 0, 4096) != 0) { form.DisplayMsg(string.Format("正在下载文件{0}", file.FileName)); commandInfo.Reply(connection, fileblock); } }
public ActionResult UpdateFile(int id) { //get details of file to be updated var file = db.Document_Repository.Where(f => f.Document_Seq.Equals(id)).FirstOrDefault(); //create the viewmodel to be passed UpdateFileModel a = new UpdateFileModel { Document_Name = file.Document_Name, Document_Type_ID = file.Document_Type_ID, Category_ID = file.Category_ID, Description = file.Description, Document_Seq = file.Document_Seq, }; //populate select lists for drop downs ViewBag.Category_ID = new SelectList(db.Document_Category, "Category_ID", "Category_Name"); ViewBag.Document_Type_ID = new SelectList(db.Document_Type, "Document_Type_ID", "Document_Type_Name"); return(View(a)); }
public ActionResult UpdateFile(UpdateFileModel model) { if (ModelState.IsValid) { //get instance of the file to be updated var updatedfile = db.Document_Repository.Where(f => f.Document_Seq.Equals(model.Document_Seq)).FirstOrDefault(); //update the entries details updatedfile.Document_Name = model.Document_Name; updatedfile.Description = model.Description; updatedfile.Category_ID = model.Category_ID; updatedfile.Document_Type_ID = model.Document_Type_ID; //check if a new file has been uploaded if (model.uploadFile != null) { //get uploaded file filename var filename = Path.GetFileName(model.uploadFile.FileName); //get uploaded file path var path = Path.Combine(Server.MapPath("~/App_Data/Uploads"), filename); //determine the uploaded file extension var extension = Path.GetExtension(model.uploadFile.FileName); //check if the file uploaded is a valid extension if (System.IO.File.Exists(path)) { TempData["Message"] = "Uploaded file already exists"; TempData["classStyle"] = "danger"; model.uploadFile = null; ViewBag.Category_ID = new SelectList(db.Document_Category, "Category_ID", "Category_Name"); ViewBag.Document_Type_ID = new SelectList(db.Document_Type, "Document_Type_ID", "Document_Type_Name"); return(View(model)); } else { System.IO.File.Delete(updatedfile.Directory_Path); model.uploadFile.SaveAs(path); updatedfile.Directory_Path = path; } } db.Entry(updatedfile).State = EntityState.Modified; db.SaveChanges(); var sessionLog = db.Person_Session_Log.Where(p => p.Person_ID == User.Identity.Name).OrderByDescending(p => p.Login_DateTime).FirstOrDefault(); Document_Access_Log ac = new Document_Access_Log(); ac.Access_DateTime = DateTime.Now; ac.Document_Seq = updatedfile.Document_Seq; ac.Session_ID = sessionLog.Session_ID; db.Document_Access_Log.Add(ac); db.SaveChanges(); //record action global.addAudit("Repository", "Repository: Update File", "Update", User.Identity.Name); TempData["Message"] = "File successfuly updated"; TempData["classStyle"] = "success"; return(RedirectToAction("ViewFile")); } else { ViewBag.Category_ID = new SelectList(db.Document_Category, "Category_ID", "Category_Name"); ViewBag.Document_Type_ID = new SelectList(db.Document_Type, "Document_Type_ID", "Document_Type_Name"); return(View(model)); } }