/// <summary>
        /// 文件上传的参数类
        /// </summary>
        /// <param name="fileUploads">上传文件描述对象列表</param>
        /// <param name="saveToDir">上传文件保存的磁盘目录(如:X:\\xxx\\xxx)</param>
        /// <param name="fileTotalSize">上传文件总结大小</param>
        public UploadParameter(UploadItem[] fileUploads, string saveToDir, long fileTotalSize)
        {

            this.SaveToDir = saveToDir;
            this.FileUploads = fileUploads;
            this.FileTotalSize = fileTotalSize;

            this.AutoMKDir = FileUploadDefault.AutoMKDir;
            this.BufferSize = FileUploadDefault.BufferSize;
                       

            this.AllowFileSize = FileUploadDefault.AllowFileSize;            
            this.AllowFileCount = FileUploadDefault.AllowFileCount;
            this.AllowSingleFileSize = FileUploadDefault.AllowSingleFileSize;

            this.FileTypes = new List<string>();
            this.FileTypes.AddRange(FileUploadDefault.UnOrAllowTypes);

            this.IsUseTranstion = FileUploadDefault.IsUseTranstion;
            this.FileUploadMode = FileUploadDefault.FileUploadModeD;

            this.TypeValidMode = FileUploadDefault.FileUploadTypeValidModeD;
            this.FileExistDoOption = FileUploadDefault.FileUploadExistDoOptionD;
        }
 private static void upload_OnUploadItemProgressChange(UploadItem upload, long progress)
 {
 }
        private static void UploadParam_OnUploadItemStart(UploadItem upload)
        {

        }
 private static bool UploadParam_OnUploadItemValidFailed(UploadItem upload, FileUploadTypeValidOption validOption)
 {
     return false;
 }
        /// <summary>
        /// 验证文件类型是否无效(当文件类型与参数fileSuffix一样时,表示有效)
        /// 如果当文件类型与参数fileSuffix不一样时,通过调用 uploadParam.ExcuteOnUploadItemValidFailed来确定文件是否有效
        /// </summary>
        /// <returns></returns>
        private static bool IsinValidFileTypeWhenNotEqual(UploadParameter uploadParam, UploadItem uploadItem, string fileSuffix)
        {
            if (fileSuffix.Equals(
                uploadItem.FileSuffix, StringComparison.OrdinalIgnoreCase))
            {
                return !(uploadItem.IsValid = true);
            }

            uploadItem.IsValid = false;
            uploadItem.InValidMessages.Add(" 文件 [" + uploadItem.FileName + "] 上传类型验证无效 ");

            // 调用ExcuteOnUploadItemValidFailed进行(如果返回false,表示不允许忽略错误,禁止继续上传文件)
            return !(uploadItem.IsValid = uploadParam.ExcuteOnUploadItemValidFailed(uploadItem, FileUploadTypeValidOption.FileType));
        }
        /// <summary>
        /// 辅助函数(对 FileUploadExistDoOption 进行分解处理,switch FileUploadExistDoOption -> SFUEDoPtion)
        /// </summary>
        /// <param name="doOption">FileUploadExistDoOption对象</param>
        /// <param name="fileDir">文件保存的目录(不是文件保存路径,是保存目录。比如 X:\\www\\root\\)</param>
        /// <param name="upload">当前上传文件信息描述对象</param>
        private static void SFUEDoOption(FileUploadExistDoOption doOption, string fileDir, ref UploadItem upload)
        {
            string _str = string.Empty;
            switch (doOption)
            {
                case FileUploadExistDoOption.ThrowEx:
                    throw new APIFW_InvalidOperationException("上传文件[" + upload.FileName + "]已经存在服务器上");

                case FileUploadExistDoOption.AutoNewName:
                    upload.FileName = "RN_" + MD5Utility.Encrypt(Guid.NewGuid().ToString(), MD5Mode.Default) + "_" + upload.FileName;
                    break;

                case FileUploadExistDoOption.BakAndUpload:
                    _str = "BAK_" + DateTime.Now.ToString("yyyyMMdd") +
                        MD5Utility.Encrypt(Guid.NewGuid().ToString(), MD5Mode.Default) + "_";

                    File.Move(Path.Combine(fileDir, upload.FileName), Path.Combine(fileDir, _str + upload.FileName));
                    break;

                default:
                    break;
            }
        }
        /// <summary>
        /// 尝试对长传文件进行保存路径与文件名称调整(该方法可能会递归调用自己,但不会出现死循环
        /// 有最大次数限制,如果达到最大调整次数还没有成功,会抛出 APIFW_InvalidOperationException 异常)
        /// </summary>
        /// <param name="param">上传配置参数</param>
        /// <param name="item">当前执行上传文件对象</param>
        /// <param name="callCount">对路径进行调整的次数</param>
        /// <param name="fileNewPath">文件的上传保存路径</param>
        private static void AdjustUploadItemFileName(UploadParameter param, ref UploadItem item, ref int callCount, ref string fileNewPath)
        {
            fileNewPath = Path.Combine(param.SaveToDir, item.FileName);
            if (File.Exists(fileNewPath))
            {
                SFUEDoOption(param.FileExistDoOption, param.SaveToDir, ref item);

                if (callCount++ > FileUploadDefault.ReUploadItemNameMaxCount)
                    throw new APIFW_InvalidOperationException("上传文件名称冲突,程序尝试了[" + FileUploadDefault.ReUploadItemNameMaxCount + "]次重命名任然失败,请重新尝试");

                FileUploadUtility.AdjustUploadItemFileName(param, ref item, ref callCount, ref fileNewPath);
            }
        }
 /// <summary>
 /// 执行 OnUploadItemCompleted 事件绑定的委托方法
 /// </summary>
 /// <param name="uploadItem">当前上传完成对象UploadItem</param>
 public void ExcuteOnUploadItemCompleted(UploadItem uploadItem)
 {
     if (this.Events["OnUploadItemCompleted"] != null)
     {
         foreach (Delegate delgate in this.Events["OnUploadItemCompleted"].GetInvocationList())
         {
             delgate.Method.Invoke(delgate.Target, new object[] { uploadItem });
         }
     }
 }
 void Arg_OnUploadItemFailedHandler(UploadItem upload, Exception fail)
 {
     base.Html("调用 -> OnUploadItemFailedHandler {0} <br/> Exception{1}", upload.FileName, fail.ToString());
 }
 void Arg_OnUploadItemCompleted(UploadItem upload)
 {
     base.Html("调用 -> OnUploadItemCompleted {0} <br/>", upload.FileName);
     // throw new NotImplementedException();
 }
 private void Arg_OnUploadItemStart(UploadItem upload)
 {
     base.Html("调用 -> OnUploadItemStart {0} <br/>", upload.FileName);
     // throw new NotImplementedException();
 }
 private bool Arg_OnUploadItemValidFailed(UploadItem upload, FileUploadTypeValidOption validOption)
 {
     base.Html("调用 -> OnUploadItemValidFailed {0} ,Suffix is {1}<br/>", upload.FileName, upload.FileSuffix);
     return false;
     // throw new NotImplementedException();
 }
 /// <summary>
 /// 执行 OnUploadItemProgressChange 事件绑定的委托方法
 /// </summary>
 /// <param name="uploadItem">当前上传对象UploadItem</param>
 /// <param name="completed">已经写入磁盘的数据大小(单位:字节)</param>
 public void ExcuteOnUploadItemProgressChange(UploadItem uploadItem, long completed)
 {
     if (this.Events["OnUploadItemProgressChange"] != null)
     {
         foreach (Delegate delgate in this.Events["OnUploadItemProgressChange"].GetInvocationList())
         {
             delgate.Method.Invoke(delgate.Target, new object[] { uploadItem, completed });
         }
     }
 }
 /// <summary>
 /// 执行 OnUploadItemValidFailed 事件绑定的委托方法(返回是否继续上传文件标识)
 /// </summary>
 /// <param name="uploadItem">当前开始上传对象UploadItem</param>
 /// <param name="validOption">FileUploadTypeValidOption选项</param>
 public bool ExcuteOnUploadItemValidFailed(UploadItem uploadItem, FileUploadTypeValidOption validOption)
 {
     bool isContinue = false;
     if (this.Events["OnUploadItemValidFailed"] != null)
     {
         foreach (Delegate delgate in this.Events["OnUploadItemValidFailed"].GetInvocationList())
         {
             isContinue = (bool)delgate.Method.Invoke(delgate.Target, new object[] { uploadItem, validOption });
         }
     }
     return isContinue;
 }
 /// <summary>
 /// 执行 OnUploadItemFailedHandler 事件绑定的委托方法
 /// </summary>
 /// <param name="uploadItem">当前上传对象UploadItem</param>
 /// <param name="exception">引发的异常信息Exception对象</param>
 /// <returns></returns>
 public bool ExcuteOnUploadItemFailedHandler(UploadItem uploadItem, Exception exception)
 {
     if (this.Events["OnUploadItemFailedHandler"] != null)
     {
         foreach (Delegate delgate in this.Events["OnUploadItemFailedHandler"].GetInvocationList())
         {
             delgate.Method.Invoke(delgate.Target, new object[] { uploadItem, exception });
         }
         return true;
     }
     return false;
 }
 private static void upload_OnUploadItemCompleted(UploadItem upload)
 {
 }
 private static void upload_OnUploadItemFailedHandler(UploadItem upload, Exception fail)
 {
     throw fail;
 }
 void Arg_OnUploadItemProgressChange(UploadItem upload, long compelted)
 {
     base.Html("调用 -> OnUploadItemProgressChange {0},progress is {1} <br/>", upload.FileName, compelted);
 }