public void UploadDirectoryCheck(ref FolderInfo folderInfo) { try { if (Directory.GetFiles(folderInfo.LocalPath).Count() == 0) { folderInfo.CheckResult = "待上传目录为空"; return; } string checkFile = string.Empty; if (folderInfo.CategoryType == CategoryType.Gallery) { checkFile = Path.Combine(folderInfo.LocalPath, "cover.jpg"); if (!File.Exists(checkFile)) { folderInfo.CheckResult = "缺少封面文件cover.jpg"; return; } checkFile = Path.Combine(folderInfo.LocalPath, "info.txt"); if (!File.Exists(checkFile)) { folderInfo.CheckResult = "缺少描述文件info.txt"; return; } if (folderInfo.IsExistVideo) { checkFile = Path.Combine(folderInfo.LocalPath, "video.rar"); if (!File.Exists(checkFile)) { folderInfo.CheckResult = "缺少视频文件video.rar"; return; } } string infoContent = File.ReadAllText(Path.Combine(folderInfo.LocalPath, "info.txt"), Encoding.GetEncoding("gb2312")).Trim().Replace("\r", "").Replace("\n", ""); StringSplitOptions infoFileSplitOptions = ClientConfig.InfoFileSplitIncludeEmpty ? StringSplitOptions.None : StringSplitOptions.RemoveEmptyEntries; string[] columns = infoContent.Split(new char[] { '|' }, infoFileSplitOptions); switch (folderInfo.StoreTableName) { case "Album_Brand": //品牌画册 case "Album_Magazine": //服装杂志 case "Album_Book": //款式书籍 { if (columns.Count() != 3) { folderInfo.CheckResult = "信息文件info.txt格式不正确"; return; } folderInfo.GalleryName = columns[0]; folderInfo.PageCount = int.Parse(columns[1]); folderInfo.Introudce = columns[2]; folderInfo.Designer = string.Empty; folderInfo.Address = string.Empty; break; } case "Album_Confer": //发布会 { if (columns.Count() != 4) { folderInfo.CheckResult = "信息文件info.txt格式不正确"; return; } folderInfo.GalleryName = columns[0]; folderInfo.Designer = columns[1]; folderInfo.Address = columns[2]; folderInfo.Introudce = columns[3]; folderInfo.PageCount = 0; break; } default: { folderInfo.CheckResult = string.Format("无法识别该表:{0}", folderInfo.StoreTableName); return; } } } // end if(folderInfo.CategoryType == CategoryType.Gallery) folderInfo.WaitUploadFilesCount = 0; foreach (string file in Directory.GetFiles(folderInfo.LocalPath)) { string fileName = Path.GetFileName(file).ToLower(); string fileExtenName = Path.GetExtension(file).ToLower(); if (ClientConfig.VectorPictureExtenName.Contains(fileExtenName)) { string directoryName = Path.GetDirectoryName(file); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file).ToLower(); string thumbFile = Path.Combine(directoryName, "sm_" + fileNameWithoutExtension + ".jpg"); string bigThumbFile = Path.Combine(directoryName, "big_" + fileNameWithoutExtension + ".jpg"); if (!File.Exists(thumbFile)) { folderInfo.CheckResult = string.Format("失量图缺少缩略图文件{0}", thumbFile); return; } if (!File.Exists(bigThumbFile)) { folderInfo.CheckResult = string.Format("失量图缺少预览图文件{0}", bigThumbFile); return; } if (folderInfo.dicVectorFile.ContainsKey(fileNameWithoutExtension)) { string value = folderInfo.dicVectorFile[fileNameWithoutExtension]; value = string.Format("{0}|{1}", value, fileName); folderInfo.dicVectorFile[fileNameWithoutExtension] = value; } else { folderInfo.dicVectorFile.Add(fileNameWithoutExtension, fileName); } } if (folderInfo.CategoryType == CategoryType.Gallery) { if (fileName != "info.txt" && fileName != "video.rar" && !ClientConfig.PictureExtenName.Contains(fileExtenName)) { folderInfo.CheckResult = string.Format("{0}不是图片文件", file); return; } } else if (folderInfo.CategoryType == CategoryType.Picture) { if (!ClientConfig.PictureExtenName.Contains(fileExtenName) && !ClientConfig.VectorPictureExtenName.Contains(fileExtenName)) { folderInfo.CheckResult = string.Format("{0}不是图片文件或失量图文件", file); return; } } if ((File.GetAttributes(file) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { continue; } if (fileName == "info.txt") { continue; } folderInfo.WaitUploadFilesCount++; }// end foreach (string file in Directory.GetFiles(folderInfo.LocalPath)) if (folderInfo.WaitUploadFilesCount == 0) { folderInfo.CheckResult = "该目录无文件符合上传要求!"; return; } } catch (Exception ex) { folderInfo.CheckResult = "异常:" + ex.Message; } }
private void UploadDirectoryTurnToSucessful(FolderInfo uploadFolderInfo, int itemIndex) { if (_listBoxUploadDirectory.InvokeRequired) { _listBoxUploadDirectory.Invoke(_delegateTurnToSucessful, uploadFolderInfo, itemIndex); } else { _listBoxSucessfulDirectory.Items.Add(uploadFolderInfo); _listBoxUploadDirectory.Items.RemoveAt(itemIndex); } }
private void UpLoadProcess() { try { while (_isRun && (DateTime.Now.Hour < ClientConfig.RestHourStart || DateTime.Now.Hour > ClientConfig.RestHourEnd)) { FolderInfo uploadFolderInfo = new FolderInfo(); int uploadDirectoryCount = 0; lock (_listBoxUploadDirectory) { uploadDirectoryCount = _listBoxUploadDirectory.Items.Count - 1; } for (int index = uploadDirectoryCount; index >= 0; index--) { try { uploadFolderInfo = _listBoxUploadDirectory.Items[index] as FolderInfo; uploadFolderInfo.IsRunning = true; uploadFolderInfo.SucessfulUploadFilesCount = 0; uploadFolderInfo.UploadResult.Clear(); //目录、相册创建 if (!RemoteDirectoryCreateProcess(ref uploadFolderInfo, index)) { continue; } //文件上传 FileUploadProcess(uploadFolderInfo, index); //全部文件上传完成才打包,所以这里阻塞 while (uploadFolderInfo.WaitUploadFilesCount > 0) { if ((DateTime.Now.Subtract(_fileUploadStartTime).Minutes) > (ClientConfig.SendTimeout + 1)) { break; } Thread.Sleep(5000); } //相册文件打包 if (uploadFolderInfo.CategoryType == CategoryType.Gallery) { if (!FileBundlingProcess(uploadFolderInfo, index)) { continue; } } UploadDirectoryTurnProcess(uploadFolderInfo, index); } catch (ThreadInterruptedException) { } catch (Exception ex) { //转移到失败目录 string errorInfo = string.Format("目录:{0}\r\nUpLoadProcess()异常:{1}", uploadFolderInfo.LocalPath, ex.ToString()); Tools.LogWrite(errorInfo); uploadFolderInfo.UploadResult.AppendLine(ex.Message); UploadDirectoryTurnToFail(uploadFolderInfo, index); } finally { uploadFolderInfo.IsRunning = false; } } // end for Thread.Sleep(10000); } // while (_isRun) } catch (ThreadAbortException) { } catch (Exception ex) { MessageBox.Show(ex.Message); Tools.LogWrite(ex.ToString()); } }
private bool RemoteDirectoryCreateProcess(ref FolderInfo uploadFolderInfo,int itemIndex) { CommonResponse response; if (uploadFolderInfo.CategoryType == CategoryType.Picture) { response = DirectoryCreate(uploadFolderInfo); } else { response = GalleryCreate(uploadFolderInfo); if (response.IsSuccessful) { uploadFolderInfo.GalleryId = int.Parse(response.ResultMessage); } } if (!response.IsSuccessful) { string errorInfo = string.Format("目录:{0}\r\n服务器目录创建失败:{1}", uploadFolderInfo.LocalPath, response.ResultMessage); Tools.LogWrite(errorInfo); uploadFolderInfo.UploadResult.AppendLine(response.ResultMessage); UploadDirectoryTurnToFail(uploadFolderInfo, itemIndex); } return response.IsSuccessful; }
private void UploadDirectoryTurnProcess(FolderInfo uploadFolderInfo, int itemIndex) { if (string.IsNullOrEmpty(uploadFolderInfo.UploadResult.ToString())) { DirectoryInfo directoryInfo = new DirectoryInfo(uploadFolderInfo.LocalPath); directoryInfo.Attributes = FileAttributes.ReadOnly; UploadDirectoryTurnToSucessful(uploadFolderInfo, itemIndex); } else { UploadDirectoryTurnToFail(uploadFolderInfo, itemIndex); } }
private CommonResponse GalleryCreate(FolderInfo uploadFolderInfo) { string[] paths = uploadFolderInfo.LocalPath.Split(new char[] { '\\' }); string localDirectory = paths[paths.Length - 1]; GalleryCreateRequest request = new GalleryCreateRequest(); request.Token = ClientConfig.Token; request.Account = ClientConfig.Account; request.PassWord = ClientConfig.PassWord; request.CategoryId = uploadFolderInfo.CategoryId; request.FileServerId = _fileServerInfo.Id; request.GalleryName = uploadFolderInfo.GalleryName; request.ConverRelativeFilePath = "/Small" + uploadFolderInfo.LevelPath.Replace("|", "/") + "/" + localDirectory + "/Cover.jpg"; request.BundlingRelativeFilePath = "/Big" + uploadFolderInfo.LevelPath.Replace("|", "/") + "/" + localDirectory + "/Package.zip"; request.PageCount = uploadFolderInfo.PageCount; request.Introudce = uploadFolderInfo.Introudce; request.VideoRelativeFilePath = "/Big" + uploadFolderInfo.LevelPath.Replace("|", "/") + "/" + localDirectory + "/Video.rar"; request.Designer = uploadFolderInfo.Designer; request.Address = uploadFolderInfo.Address; request.OriginalAbsoluteFileDirectory = _fileServerInfo.OriginalFileServerRootDirectory + uploadFolderInfo.LevelPath.Replace("|", "\\\\") + "\\\\" + localDirectory; request.ThumbAbsoluteFileDirectory = _fileServerInfo.ThumbFileServerRootDirectory + uploadFolderInfo.LevelPath.Replace("|", "\\\\") + "\\\\" + localDirectory; request.StoreTableName = uploadFolderInfo.StoreTableName; string checkFile = Path.Combine(uploadFolderInfo.LocalPath, "video.rar"); request.IsExistVideo = File.Exists(checkFile); CommonResponse response = _proxy.GalleryCreate(request); return response; }
private void FileUploadProcess(FolderInfo uploadFolderInfo, int itemIndex) { foreach (string file in Directory.GetFiles(uploadFolderInfo.LocalPath)) { try { if ((File.GetAttributes(file) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { continue; } if (Path.GetFileName(file).ToLower() == "info.txt") { File.SetAttributes(file, FileAttributes.ReadOnly); continue; } UploadInfo uploadInfo = new UploadInfo(); uploadInfo.FolderInfo = uploadFolderInfo; uploadInfo.FilePath = file; Task task = new Task(FileUpload, uploadInfo); task.Start(); } catch (Exception ex) { string uploadResult = string.Format("{0},{1}", Path.GetFileName(file), ex.ToString()); string errorInfo = string.Format("目录:{0}\r\n异常:{1}", uploadFolderInfo.LocalPath, uploadResult); Tools.LogWrite(errorInfo); uploadFolderInfo.UploadResult.AppendLine(uploadResult); } } }
private bool FileBundlingProcess(FolderInfo uploadFolderInfo, int itemIndex) { string[] paths = uploadFolderInfo.LocalPath.Split(new char[] { '\\' }); string localDirectory = paths[paths.Length - 1]; GalleryBundlingRequest request = new GalleryBundlingRequest(); request.FileServerId = _fileServerInfo.Id; request.Token = ClientConfig.Token; request.Account = ClientConfig.Account; request.PassWord = ClientConfig.PassWord; request.OriginalAbsoluteFileDirectory = _fileServerInfo.OriginalFileServerRootDirectory + uploadFolderInfo.LevelPath.Replace("|", "\\\\") + "\\\\" + localDirectory; CommonResponse response = _proxy.FileBundling(request); if (!response.IsSuccessful) { string errorInfo = string.Format("目录:{0}\r\n服务端目录打包异常:{1}", uploadFolderInfo.LocalPath, response.ResultMessage); Tools.LogWrite(errorInfo); uploadFolderInfo.UploadResult.AppendLine(response.ResultMessage); UploadDirectoryTurnToFail(uploadFolderInfo, itemIndex); } return response.IsSuccessful; }
private CommonResponse DirectoryCreate(FolderInfo uploadFolderInfo) { string[] paths = uploadFolderInfo.LocalPath.Split(new char[] { '\\' }); string localDirectory = paths[paths.Length - 1]; DirectoryCreateRequest request = new DirectoryCreateRequest(); request.FileServerId = _fileServerInfo.Id; request.Token = ClientConfig.Token; request.Account = ClientConfig.Account; request.PassWord = ClientConfig.PassWord; request.OriginalAbsoluteFileDirectory = _fileServerInfo.OriginalFileServerRootDirectory + uploadFolderInfo.LevelPath.Replace("|", "\\\\") + "\\\\" + localDirectory; request.ThumbAbsoluteFileDirectory = _fileServerInfo.ThumbFileServerRootDirectory + uploadFolderInfo.LevelPath.Replace("|", "\\\\") + "\\\\" + localDirectory; CommonResponse response = _proxy.DirectoryCreate(request); return response; }
private void treeCategory_AfterSelect(object sender, TreeViewEventArgs e) { try { TreeNode selectedNode = treeCategory.SelectedNode; Category category = selectedNode.Tag as Category; string typeName = "类型:" + (category.Type == CategoryType.Picture ? "图片" : "相册"); string isExistVideo = "视频:" + (category.IsExistVideo ? "需要" : "不需"); string isThumbSquare = "缩略图:" + (category.IsThumbSquare ? "正方形" : "按比例"); string localDirectoryPath = "本地目录:" + category.LocalDirectoryPath; string tipInfo = string.Format("{0} {1} {2} {3}", typeName, isExistVideo, isThumbSquare, localDirectoryPath); statusLabel.Text = tipInfo; toolTip1.SetToolTip(treeCategory,tipInfo); if (category.IsDetail) { if (string.IsNullOrEmpty(category.LocalDirectoryPath) || !Directory.Exists(category.LocalDirectoryPath)) { listBoxLocalDirectory.Items.Clear(); return; } listBoxLocalDirectory.Items.Clear(); foreach (string localFile in Directory.GetDirectories(category.LocalDirectoryPath)) { FolderInfo localFolderInfo = new FolderInfo(); localFolderInfo.CategoryId = category.Id; localFolderInfo.CategoryType = category.Type; localFolderInfo.LevelPath = category.LevelPath; localFolderInfo.LevelCategory = category.LevelCategory.Remove(0, 1); localFolderInfo.StoreTableName = category.StoreTableName; localFolderInfo.IsExistVideo = category.IsExistVideo; localFolderInfo.IsThumbSquare = category.IsThumbSquare; localFolderInfo.LocalPath = localFile; localFolderInfo.IsRunning = false; listBoxLocalDirectory.Items.Add(localFolderInfo); } } else { listBoxLocalDirectory.Items.Clear(); } } catch (Exception ex) { Tools.LogWrite(ex.ToString()); MessageBox.Show(ex.Message); } }