private void DeleteFile(int id) { Logger.Info("Delete File Id == {0}", id); string deletePath = null; // var f = new TCommonFile(); using (var db = new db_coreContext()) { TCommonFile file = db.TCommonFile.First(f => f.Id == id); deletePath = file.FilePath; Logger.Info("Delete File Server Path == {0}", deletePath); // 删除服务器文件 // bool isSuccess = StartDelete(deletePath); // 假删除,仅改数据库 file.IsDelete = true; db.SaveChanges(); Logger.Info("id = {0} 的文件删除成功", id); MessageBox.Show("删除成功"); // 更新界面文件列表 foreach (var f in Files) { if (f.Id == id) { Files.Remove(f); break; } } } // foreach (TCommonFile file in Files) // { // if (file.Id == id) // { // deletePath = file.FilePath; // Logger.Info("Delete File Server Path == {0}", deletePath); // // // 删除文件 // bool isSuccess = StartDelete(deletePath); // // if (isSuccess == true) // 删除成功 // { // // 删除数据库记录 // using (var db = new db_coreContext()) // { // // db.TCommonFile.Remove(f); // // f.IsDelete = true; // file.IsDelete = true; // // } // } // else // { // MessageBox.Show("删除失败!"); // } // // f = file; // break; // } // } }
private async Task <string> StartUploadAsync(string path) { var stopwatch = new Stopwatch(); stopwatch.Start(); string serverFileName = await Task.Run(() => fastdfs_client_net.Facade.Upload(path)); if (string.IsNullOrEmpty(serverFileName)) { Logger.Error("文件({0})上传失败", path); MessageBox.Show("上传失败"); return(null); } // 文件信息 System.IO.FileInfo fileInfo = new System.IO.FileInfo(path); // 存数据库 string filename = fileInfo.Name; double fileSize = System.Math.Ceiling(fileInfo.Length / 1024.0); string fileType = System.IO.Path.GetExtension(path).Split('.').Last(); string ip = ConfigurationManager.AppSettings["fastdfs_Nodes"]; Logger.Info("上传文件名:" + filename); Logger.Info("上传文件大小:{0} KB", fileSize); Logger.Info("上传文件类型:" + fileType); using (var db = new db_coreContext()) { var file = new TCommonFile(); file.FileName = filename; file.FileSize = fileSize; file.FileType = fileType; file.Ip = ip; file.UploadTime = DateTime.Now; file.Uploader = "system"; file.FilePath = serverFileName; db.TCommonFile.Add(file); db.SaveChanges(); Files.Add(file); // Files.Add(file); } stopwatch.Stop(); var time = stopwatch.ElapsedMilliseconds; Logger.Info("文件({0})上传成功, 耗时:{1}s", filename, time / 1000); string info = "上传成功!耗时: "; if (time > 60000) { info += time / 60000.0; info += "Min"; } else if (time > 1000) { info += time / 1000.0; info += "S"; } else { info += time; info += "ms"; } MessageBox.Show(Application.Current.MainWindow, info, "上传状态", MessageBoxButton.OK, MessageBoxImage.Information); return("OK"); }