/// <summary> /// /// </summary> /// <param name="data"></param> /// <param name="stopwatch"></param> private void ContentImgUploadToOSS(List <Web_ItemLibrary> data, Stopwatch stopwatch) { InfoStatus infoStatus = new InfoStatus(); int i = 0; string[] xtAdmin = { "系统用户01", "系统用户02", "系统用户03", "系统用户04", "系统用户05", "系统用户06", "管理员" }; string filePath = string.Empty; foreach (var item in data) { if (!string.IsNullOrEmpty(item.ItemContentBefore)) { string[] imgDatas = ContentHelper.GetImgsByContentBefore(item.ItemContentBefore); string proContent = item.ItemContentBefore.ToLower(); if (imgDatas.Length > 0 && imgDatas != null) { yxxm++; this.tsslgyxm.Text = $"共计项目:{gjxm},有效项目{yxxm}"; this.tsslgj.Text = (int.Parse(this.tsslgj.Text) + imgDatas.Length).ToString(); string userName = "******" + (xtAdmin.Contains(item.CreateUserName) ? "部落建筑" : item.CreateUserName); var bytes = Encoding.UTF8.GetBytes(userName); char[] padding = { '=' }; string userNameURLBase64 = Convert.ToBase64String(bytes, Base64FormattingOptions.None).TrimEnd(padding).Replace('+', '-').Replace('/', '_'); List <CallbackUploadInfo> callbacks = new List <CallbackUploadInfo>(); for (int j = 0; j < imgDatas.Length; j++) { filePath = imgDatas[j].ToLower() .Replace(_domain, _D) .Replace(_itemfiles.ToLower(), ItemImages.ToLower()) .Replace('/', '\\').ToLower(); //处理文件(将原图上传到oss) if (filePath.Contains(_samll)) { filePath = filePath.Replace(_samll, ""); } else if (filePath.Contains(_nS)) { filePath = filePath.Replace(_nS, "\\"); //判断/s/里面的图片是否带 Ori_ string tempFilePath = filePath.Replace(filePath.Split('\\').LastOrDefault(), "Ori_" + filePath.Split('\\').LastOrDefault()); if (File.Exists(tempFilePath)) { filePath = tempFilePath; } } //判断文件是否存在 if (File.Exists(filePath)) { var fileInfo = new System.IO.FileInfo(filePath); if (fileInfo.Length >= ImgLeng) { CompressImg.PicCompress(filePath); } // 移动操作 string ossImgPath = filePath .Replace(ItemImages.ToLower(), _itemfiles.ToLower()) .Remove(0, 3) .Replace('\\', '/').ToLower(); //处理带Ori的数据 if (ossImgPath.Contains("Ori_".ToLower())) { ossImgPath = ossImgPath.Replace("Ori_".ToLower(), ""); } //暂时注释 this.OssUpload(ossImgPath, filePath, item.ItemId, ref infoStatus); //内容数据修改 //https://www.pic1.jzbl.com/itemfiles/0d54bf62-e42b-460b-aab4-7e6bd1990221/001cc6d4-bd91-4d22-8ad8-e6fa5be7f294/6367192853011954234817412.jpg?x-oss-process=image/quality,q_90/watermark,image_V2F0ZXJtYXJrL3dhdGVybWFyay5wbmc=,size_30,type_d3F5LXplbmhlaQ,text_QOS4iua1t-azm-WiqOaVsOeggeenkeaKgOaciemZkOWFrOWPuA,color_E94743,shadow_50,order_0,align_2,interval_10,t_90,g_sw,x_20,y_20 CallbackUploadInfo callback = new CallbackUploadInfo(); string ossPro = string.Empty; if (fileInfo.Length >= 500000) { ossPro = string.Format(ossProcess, 20, userNameURLBase64); } else if (fileInfo.Length >= 400000) { ossPro = string.Format(ossProcess, 30, userNameURLBase64); } else if (fileInfo.Length >= 300000) { ossPro = string.Format(ossProcess, 40, userNameURLBase64); } else if (fileInfo.Length >= 200000) { ossPro = string.Format(ossProcess, 50, userNameURLBase64); } else if (fileInfo.Length >= 100000) { ossPro = string.Format(ossProcess, 90, userNameURLBase64); } else { ossPro = string.Format(ossProcess, 100, userNameURLBase64); } string ossUrl = _domainOne + ossImgPath + ossPro; proContent = proContent.Replace(imgDatas[j].ToLower(), ossUrl); callback.smallImgUrl = _domainOne + ossImgPath + "?x-oss-process=image/quality,q_90/resize,w_400"; callback.bigImgUrl = ossUrl; callbacks.Add(callback); } else { infoStatus.iStatus = (int)EnumStatus.OldFileUnExists; infoStatus.Summary = "本地文件不存在"; } } // 修改数据 this.DataUpdata(item.ItemId, proContent, callbacks); infoStatus.Summary = infoStatus.Summary + ",【" + imgDatas.Length + "】数据修改成功"; infoStatus.iStatus = (int)EnumStatus.Ok; } } else { infoStatus.iStatus = (int)EnumStatus.Unknown; infoStatus.Summary = "项目内容不存在"; } if (this.InvokeRequired) { this.Invoke(new DelegateWriteMessage(_comm.WriteMessage), new object[] { 2, item.ItemId, filePath, infoStatus.OldPath, infoStatus.iStatus, infoStatus.Summary }); this.Invoke(new DelegateCurrent(_comm.Current), new object[] { i, item.ItemId }); this.Invoke(new DelegateTimeCost(_comm.TimeCost), new object[] { stopwatch.Elapsed.ToString() }); } else { _comm.WriteMessage(2, item.ItemId, filePath, infoStatus.OldPath, infoStatus.iStatus, infoStatus.Summary); _comm.Current(i, item.ItemId); _comm.TimeCost(stopwatch.Elapsed.ToString()); } } }
private void imgTextPro(List <Web_UserBuildingCircle> data) { Stopwatch watch = new Stopwatch(); watch.Start(); //过来只有在服务器上的数据 var domainData = data.Where(o => !string.IsNullOrEmpty(o.FirstTitleImg) && o.FirstTitleImg.Contains(_domain)).ToList(); string domainOSSFirstTitlet = string.Empty; foreach (var item in domainData) { infoStatus.Summary = "处理再" + _domain + "域名数据"; //处理封面图片数据 string filePath = item.FirstTitleImg.ToLower() .Replace(_domain, _D) .Replace(_itemfiles.ToLower(), ItemImages.ToLower()) .Replace('/', '\\').ToLower(); if (filePath.Contains(_nS)) { filePath = filePath.Replace(_nS, "\\"); //判断/s/里面的图片是否带 Ori_ string tempFilePath = filePath.Replace(filePath.Split('\\').LastOrDefault(), "Ori_" + filePath.Split('\\').LastOrDefault()); if (File.Exists(tempFilePath)) { filePath = tempFilePath; } } //判断文件是否存在 if (File.Exists(filePath)) { var fileInfo = new System.IO.FileInfo(filePath); if (fileInfo.Length >= ImgLeng) { CompressImg.PicCompress(filePath); } // 移动操作 string ossImgPath = filePath .Replace(ItemImages.ToLower(), _itemfiles.ToLower()) .Remove(0, 3) .Replace('\\', '/').ToLower(); //处理带Ori的数据 if (ossImgPath.Contains("Ori_".ToLower())) { ossImgPath = ossImgPath.Replace("Ori_".ToLower(), ""); } this.OssUpload(ossImgPath, filePath, ref infoStatus); domainOSSFirstTitlet = _domainOne + ossImgPath + firstTitletImg; } //处理 对象数据 var obj = item.ResourceObj.ToList <CallbackUploadInfo>(); List <CallbackUploadInfo> callbackUploadInfos = new List <CallbackUploadInfo>(); if (obj != null) { foreach (var itemRes in obj) { string filePathRes = itemRes.smallImgUrl .Replace(_domain, _D) .Replace(_itemfiles.ToLower(), ItemImages.ToLower()) .Replace('/', '\\').ToLower(); if (filePathRes.Contains(_nS)) { filePathRes = filePathRes.Replace(_nS, "\\"); //判断/s/里面的图片是否带 Ori_ string tempFilePath = filePathRes.Replace(filePathRes.Split('\\').LastOrDefault(), "Ori_" + filePathRes.Split('\\').LastOrDefault()); if (File.Exists(tempFilePath)) { filePathRes = tempFilePath; } //判断文件是否存在 if (File.Exists(filePathRes)) { var fileInfo = new System.IO.FileInfo(filePathRes); if (fileInfo.Length >= ImgLeng) { CompressImg.PicCompress(filePathRes); } // 移动操作 string ossImgPath = filePathRes .Replace(ItemImages.ToLower(), _itemfiles.ToLower()) .Remove(0, 3) .Replace('\\', '/').ToLower(); //处理带Ori的数据 if (ossImgPath.Contains("Ori_".ToLower())) { ossImgPath = ossImgPath.Replace("Ori_".ToLower(), ""); } this.OssUpload(ossImgPath, filePathRes, ref infoStatus); CallbackUploadInfo callback = new CallbackUploadInfo(); string ossPro = string.Empty; if (fileInfo.Length >= 500000) { ossPro = string.Format(bigImg, 20); } else if (fileInfo.Length >= 400000) { ossPro = string.Format(bigImg, 30); } else if (fileInfo.Length >= 300000) { ossPro = string.Format(bigImg, 40); } else if (fileInfo.Length >= 200000) { ossPro = string.Format(bigImg, 50); } else if (fileInfo.Length >= 100000) { ossPro = string.Format(bigImg, 90); } else { ossPro = string.Format(bigImg, 100); } string ossUrl = _domainOne + ossImgPath + ossPro; callback.smallImgUrl = _domainOne + ossImgPath + "?x-oss-process=image/quality,q_90/resize,w_400"; callback.bigImgUrl = ossUrl; callback.fileName = itemRes.fileName; callbackUploadInfos.Add(callback); } } } } // 保存数据 try { using (var context = new DataModelEntities()) { var itemData = context.Web_UserBuildingCircle.FirstOrDefault(o => o.TalkId.Equals(item.TalkId)); if (itemData != null) { itemData.FirstTitleImg = domainOSSFirstTitlet; itemData.ResourceObj = callbackUploadInfos.Count == 0 ? null : callbackUploadInfos.ToJson(); itemData.TalkContent = string.IsNullOrEmpty(itemData.TalkContent.Trim()) ? itemData.TalkTitle : itemData.TalkContent; itemData.TalkTitle = string.IsNullOrEmpty(itemData.TalkTitle) ? null : "NULL"; context.SaveChanges(); } } } catch (Exception ex) { Console.WriteLine("Failed with error info: {0}", ex.Message); MessageBox.Show(string.Format("保存数据出错!{0}", ex.Message)); } if (this.InvokeRequired) { this.Invoke(new DelegateWriteMessage(_comm.WriteMessage), new object[] { 2, item.TalkId, filePath, infoStatus.OldPath, infoStatus.iStatus, infoStatus.Summary }); this.Invoke(new DelegateCurrent(_comm.Current), new object[] { 1, item.TalkId }); this.Invoke(new DelegateTimeCost(_comm.TimeCost), new object[] { watch.Elapsed.ToString() }); } else { _comm.WriteMessage(2, item.TalkId, filePath, infoStatus.OldPath, infoStatus.iStatus, infoStatus.Summary); _comm.Current(1, item.TalkId); _comm.TimeCost(watch.Elapsed.ToString()); } } // 修改https://www.pic1.jzbl.com 的后缀 var domainOneData = data.Where(o => !string.IsNullOrEmpty(o.FirstTitleImg) && o.FirstTitleImg.Contains(_domainOne)).ToList(); // var domainOneData = data.Where(o =>o.TalkId.Equals("615a6f97-4fda-439a-b5c4-3b0e708bce13")).ToList(); foreach (var itemOne in domainOneData) { infoStatus.Summary = "处理再" + _domainOne + "域名数据"; List <CallbackUploadInfo> callbackUploadInfos = new List <CallbackUploadInfo>(); //处理oss图片有后缀的,只压缩图片就行 if (itemOne.FirstTitleImg.Split('.').LastOrDefault().ToLower().Equals("jpg")) { domainOSSFirstTitlet = itemOne.FirstTitleImg + firstTitletImg; //处理 对象数据 var obj = itemOne.ResourceObj.ToList <CallbackUploadInfo>(); if (obj != null) { foreach (var itemRes in obj) { CallbackUploadInfo callback = new CallbackUploadInfo(); string ossPro = string.Empty; ossPro = string.Format(bigImg, 90); string ossUrl = itemRes.smallImgUrl + ossPro; callback.smallImgUrl = itemRes.smallImgUrl + "?x-oss-process=image/quality,q_90/resize,w_400"; callback.bigImgUrl = ossUrl; callback.fileName = itemRes.fileName; callbackUploadInfos.Add(callback); } } infoStatus.Summary = "处理oss图片有后缀的,只压缩图片就行"; } else { string sourcekey = itemOne.FirstTitleImg.Replace(_domainOne, ""); string targetkey = sourcekey + ".jpg"; CopyObject(bucketName, sourcekey, bucketName, targetkey); domainOSSFirstTitlet = _domainOne + targetkey; //处理 对象数据 var obj = itemOne.ResourceObj.ToList <CallbackUploadInfo>(); if (obj != null) { foreach (var itemRes in obj) { CallbackUploadInfo callback = new CallbackUploadInfo(); string sourcekeylist = itemRes.smallImgUrl.Replace(_domainOne, ""); string targetkeylist = sourcekeylist + ".jpg"; CopyObject(bucketName, sourcekeylist, bucketName, targetkeylist); string ossPro = string.Empty; ossPro = string.Format(bigImg, 90); string ossUrl = itemRes.smallImgUrl + ossPro; callback.smallImgUrl = itemRes.smallImgUrl + "?x-oss-process=image/quality,q_90/resize,w_400"; callback.bigImgUrl = ossUrl; callback.fileName = itemRes.fileName; callbackUploadInfos.Add(callback); } } infoStatus.Summary = "处理oss图片没有后缀,先拷贝,再删除原图"; } // 保存数据 try { using (var context = new DataModelEntities()) { var itemData = context.Web_UserBuildingCircle.FirstOrDefault(o => o.TalkId.Equals(itemOne.TalkId)); if (itemData != null) { itemData.FirstTitleImg = domainOSSFirstTitlet; itemData.ResourceObj = callbackUploadInfos.Count == 0 ? null : callbackUploadInfos.ToJson(); itemData.TalkContent = string.IsNullOrEmpty(itemData.TalkContent.Trim()) ? itemData.TalkTitle : itemData.TalkContent; itemData.TalkTitle = string.IsNullOrEmpty(itemData.TalkTitle) ? null : "NULL"; context.SaveChanges(); } } } catch (Exception ex) { Console.WriteLine("Failed with error info: {0}", ex.Message); MessageBox.Show(string.Format("保存数据出错!{0}", ex.Message)); } if (this.InvokeRequired) { this.Invoke(new DelegateWriteMessage(_comm.WriteMessage), new object[] { 2, itemOne.TalkId, "---------", infoStatus.OldPath, infoStatus.iStatus, infoStatus.Summary }); this.Invoke(new DelegateCurrent(_comm.Current), new object[] { 1, itemOne.TalkId }); this.Invoke(new DelegateTimeCost(_comm.TimeCost), new object[] { watch.Elapsed.ToString() }); } else { _comm.WriteMessage(2, itemOne.TalkId, "---------", infoStatus.OldPath, infoStatus.iStatus, infoStatus.Summary); _comm.Current(1, itemOne.TalkId); _comm.TimeCost(watch.Elapsed.ToString()); } } }
private void videoPro(List <Web_UserBuildingCircle> data) { Stopwatch watch = new Stopwatch(); watch.Start(); //过来只有在服务器上的数据https://www.pic.jzbl.com var domainData = data.Where(o => o.FirstTitleImg.Contains(_domain)).ToList(); string domainOSSFirstTitlet = string.Empty; foreach (var item in domainData) { //处理封面图片数据 string filePath = item.FirstTitleImg.ToLower() .Replace(_domain, _D) .Replace(_itemfiles.ToLower(), ItemImages.ToLower()) .Replace('/', '\\').ToLower(); if (filePath.Contains(_nS)) { filePath = filePath.Replace(_nS, "\\"); //判断/s/里面的图片是否带 Ori_ string tempFilePath = filePath.Replace(filePath.Split('\\').LastOrDefault(), "Ori_" + filePath.Split('\\').LastOrDefault()); if (File.Exists(tempFilePath)) { filePath = tempFilePath; } } //判断文件是否存在 if (File.Exists(filePath)) { var fileInfo = new System.IO.FileInfo(filePath); if (fileInfo.Length >= ImgLeng) { CompressImg.PicCompress(filePath); } // 移动操作 string ossImgPath = filePath .Replace(ItemImages.ToLower(), _itemfiles.ToLower()) .Remove(0, 3) .Replace('\\', '/').ToLower(); //处理带Ori的数据 if (ossImgPath.Contains("Ori_".ToLower())) { ossImgPath = ossImgPath.Replace("Ori_".ToLower(), ""); } this.OssUpload(ossImgPath, filePath, ref infoStatus); domainOSSFirstTitlet = _domainOne + ossImgPath + firstTitletImg; } //处理 对象数据 var obj = item.ResourceObj.ToList <CallbackUploadInfo>(); List <CallbackUploadInfo> callbackUploadInfos = new List <CallbackUploadInfo>(); if (obj != null) { foreach (var itemRes in obj) { string filePathRes = itemRes.smallImgUrl .Replace(_domain, _D) .Replace(_itemfiles.ToLower(), ItemImages.ToLower()) .Replace('/', '\\').ToLower(); if (filePathRes.Contains(_nS)) { filePathRes = filePathRes.Replace(_nS, "\\"); //判断/s/里面的图片是否带 Ori_ string tempFilePath = filePathRes.Replace(filePathRes.Split('\\').LastOrDefault(), "Ori_" + filePathRes.Split('\\').LastOrDefault()); if (File.Exists(tempFilePath)) { filePathRes = tempFilePath; } //判断文件是否存在 if (File.Exists(filePathRes)) { var fileInfo = new System.IO.FileInfo(filePathRes); if (fileInfo.Length >= ImgLeng) { CompressImg.PicCompress(filePathRes); } // 移动操作 string ossImgPath = filePathRes .Replace(ItemImages.ToLower(), _itemfiles.ToLower()) .Remove(0, 3) .Replace('\\', '/').ToLower(); //处理带Ori的数据 if (ossImgPath.Contains("Ori_".ToLower())) { ossImgPath = ossImgPath.Replace("Ori_".ToLower(), ""); } this.OssUpload(ossImgPath, filePathRes, ref infoStatus); CallbackUploadInfo callback = new CallbackUploadInfo(); string ossPro = string.Empty; if (fileInfo.Length >= 500000) { ossPro = string.Format(bigImg, 20); } else if (fileInfo.Length >= 400000) { ossPro = string.Format(bigImg, 30); } else if (fileInfo.Length >= 300000) { ossPro = string.Format(bigImg, 40); } else if (fileInfo.Length >= 200000) { ossPro = string.Format(bigImg, 50); } else if (fileInfo.Length >= 100000) { ossPro = string.Format(bigImg, 90); } else { ossPro = string.Format(bigImg, 100); } string ossUrl = _domainOne + ossImgPath + ossPro; callback.smallImgUrl = _domainOne + ossImgPath + smallImg; callback.bigImgUrl = ossUrl; callback.fileName = itemRes.fileName; callbackUploadInfos.Add(callback); } } } } // 保存数据 try { using (var context = new DataModelEntities()) { var itemData = context.Web_UserBuildingCircle.FirstOrDefault(o => o.TalkId.Equals(item.TalkId)); if (itemData != null) { itemData.FirstTitleImg = domainOSSFirstTitlet; itemData.ResourceObj = callbackUploadInfos.Count == 0 ? null : callbackUploadInfos.ToJson(); itemData.TalkContent = string.IsNullOrEmpty(itemData.TalkContent.Trim()) ? itemData.TalkTitle : itemData.TalkContent; itemData.TalkTitle = string.IsNullOrEmpty(itemData.TalkTitle) ? null : "NULL"; context.SaveChanges(); } } } catch (Exception ex) { Console.WriteLine("Failed with error info: {0}", ex.Message); MessageBox.Show(string.Format("保存数据出错!{0}", ex.Message)); } if (this.InvokeRequired) { this.Invoke(new DelegateWriteMessage(_comm.WriteMessage), new object[] { 2, item.TalkId, filePath, infoStatus.OldPath, infoStatus.iStatus, infoStatus.Summary }); this.Invoke(new DelegateCurrent(_comm.Current), new object[] { 1, item.TalkId }); this.Invoke(new DelegateTimeCost(_comm.TimeCost), new object[] { watch.Elapsed.ToString() }); } else { _comm.WriteMessage(2, item.TalkId, filePath, infoStatus.OldPath, infoStatus.iStatus, infoStatus.Summary); _comm.Current(1, item.TalkId); _comm.TimeCost(watch.Elapsed.ToString()); } } }
private void ContentImgDataCopy(List <Web_ItemLibrary> data, Stopwatch watch) { _G = txtTarget.Text.TrimEnd('\\'); string summary = string.Empty; string oldPath = string.Empty; int operate = (int)EnumOperate.Content; string itemId = string.Empty; string newPath = string.Empty; int status = 0; // int iExists = 1, iUnExists = 1; try { for (int i = 0; i < data.Count; i++) { itemId = data[i].ItemId; string content = data[i].ItemContentBefore; if (!string.IsNullOrEmpty(content)) { string[] imgDatas = ContentHelper.GetImgsByContentBefore(content); if (imgDatas.Length > 0 && imgDatas != null) { yxxm++; this.tsslgyxm.Text = $"共计项目:{gjxm},有效项目{yxxm}"; this.tsslgj.Text = (int.Parse(this.tsslgj.Text) + imgDatas.Length).ToString(); for (int j = 0; j < imgDatas.Length; j++) { string filePath = imgDatas[j].Replace(_domain, _G).Replace('/', '\\').ToLower(); string filePathCopy = filePath.Replace(_itemfiles.ToLower(), _itemfilescopy.ToLower()); //判断文件是否存在 if (!File.Exists(filePath)) { oldPath = filePath; summary = $"路径:{filePath} 状态:< > 源文件不存在"; status = (int)EnumStatus.OldFileUnExists; } else { //判断文件是否存在 if (File.Exists(filePathCopy)) { status = (int)EnumStatus.NewFileExists; oldPath = filePath; newPath = filePathCopy; summary = $"拷贝(src 压缩图片)文件:{filePath} 到 {filePathCopy} 状态:》文件已存在《"; } else { string tfileName = filePathCopy.Split('\\').LastOrDefault(); string tbasePath = filePathCopy.Replace(tfileName, ""); if (!Directory.Exists(tbasePath)) { Directory.CreateDirectory(tbasePath); } //处理掉SRC上的图片 File.Copy(filePath, filePathCopy); status = (int)EnumStatus.Ok; oldPath = filePath; newPath = filePathCopy; summary = $"拷贝src 上的图片:{filePath} 到 {filePathCopy} 状态:》成功《"; //再针对SRC上的图片进行拷贝 if (filePath.Contains(_samll)) //判断图片是否带_smaill (最开始那一批) { //计算原图 string nSPath = filePath.Replace(_samll, "").Replace(_nS, "\\"); string nSfilePath = filePathCopy.Replace(_samll, "").Replace(_nS, "\\"); if (File.Exists(nSfilePath)) { status = (int)EnumStatus.NewFileExists; oldPath = nSPath; newPath = nSfilePath; summary = $"拷贝(新路径原图)文件:{nSPath} 到 {nSfilePath} 状态:》文件已存在1《"; } else { string fileName = nSfilePath.Split('\\').LastOrDefault(); string basePath = nSfilePath.Replace(fileName, ""); if (!Directory.Exists(basePath)) { Directory.CreateDirectory(basePath); } File.Copy(nSPath, nSfilePath); status = (int)EnumStatus.Ok; oldPath = nSPath; newPath = nSfilePath; summary = $"拷贝(新路径原图)文件:{nSPath} 到 {nSfilePath} 状态:》成功《"; } } else if (filePath.Contains(_nS)) //判断图片是否带 /s/ (第二批) { //计算原图 string nSPath = filePath.Replace(_nS, "\\"); string nSfilePath = filePathCopy.Replace(_nS, "\\"); if (File.Exists(nSfilePath)) { status = (int)EnumStatus.NewFileExists; oldPath = nSPath; newPath = nSfilePath; summary = $"拷贝(新路径原图)文件:{nSPath} 到 {nSfilePath} 状态:》文件已存在2《"; } else { string fileName = nSfilePath.Split('\\').LastOrDefault(); string basePath = nSfilePath.Replace(fileName, ""); if (!Directory.Exists(basePath)) { Directory.CreateDirectory(basePath); } File.Copy(nSPath, nSfilePath); status = (int)EnumStatus.Ok; oldPath = nSPath; newPath = nSfilePath; summary = $"拷贝(新路径原图)文件:{nSPath} 到 {nSfilePath} 状态:》成功《"; } // itemFiles/8e5dc0f7-ed86-4d3c-89db-3a8593f6a2d7/2019-12-19/7ccc9e54-69e9-487d-a8fb-fd3ca2610cc9/i/Ori_4e9ef95d1576763073.jpg nSPath = nSPath.Replace(nSPath.Split('\\').LastOrDefault(), "Ori_" + nSPath.Split('\\').LastOrDefault()); nSfilePath = nSfilePath.Replace(nSfilePath.Split('\\').LastOrDefault(), "Ori_" + nSfilePath.Split('\\').LastOrDefault()); if (File.Exists(nSPath) && !File.Exists(nSfilePath)) { string fileName = nSfilePath.Split('\\').LastOrDefault(); string basePath = nSfilePath.Replace(fileName, ""); if (!Directory.Exists(basePath)) { Directory.CreateDirectory(basePath); } File.Copy(nSPath, nSfilePath); status = (int)EnumStatus.Ok; oldPath = nSPath; newPath = nSfilePath; summary = $"拷贝(新路径原图)文件:{nSPath} 到 {nSfilePath} 状态:》成功《"; } else if (File.Exists(nSfilePath)) { status = (int)EnumStatus.NewFileExists; oldPath = nSPath; newPath = nSfilePath; summary = $"拷贝(新路径原图)文件:{nSPath} 到 {nSfilePath} 状态:》文件已存在3《"; } } //对 filePathCopy 的图片进行处理 //1.等比例压缩 xx_dblys.jpg xx_等比例压缩.jpg if (cb01.Checked) { } //2.压缩一把 if (cb02.Checked) { CompressImg.PicCompress(filePathCopy); } //3.打水印 生成新图 xx_yssy.jpg xx_压缩水印.jpg if (cb03.Checked) { } } } //数据写入 if (this.InvokeRequired) { this.Invoke(new DelegateWriteMessage(_comm.WriteMessage), new object[] { operate, itemId, oldPath, newPath, status, summary }); this.Invoke(new DelegateCurrent(_comm.Current), new object[] { i, itemId.ToString() }); this.Invoke(new DelegateTimeCost(_comm.TimeCost), new object[] { watch.Elapsed.ToString() }); } else { _comm.WriteMessage(operate, itemId, oldPath, newPath, status, summary); _comm.Current(i, ""); _comm.TimeCost(watch.Elapsed.ToString()); } } } } else { status = 4; summary = "内容为空"; } } //summary = $"共计{data.Count}条,本地存在{iExists}条,不存在{iUnExists}条"; //if (this.InvokeRequired) //{ // this.Invoke(new DelegateWriteMessage(_comm.WriteMessage), new object[] { 0, "", "", "", 0, summary }); //} //else //{ // _comm.WriteMessage(operate, itemId, oldPath, newPath, status, summary); //} if (!watch.IsRunning) { watch.Stop(); } } catch (Exception ex) { MessageBox.Show(" 错误:" + ex); } }