/// <summary> /// 添加对象. /// </summary> /// <param name="iTarget">I target.</param> private void AddTarget(UploadItem iTarget) { if (iTarget == null) { return; } this.Targets.Add(iTarget); }
/// <summary> /// 添加对象. /// </summary> /// <param name="iTarget">对象.</param> /// <param name="iFileType">上传文件类型.</param> /// <param name="iHashCode">HashCode(Unity3d打包生成).</param> public void AddTarget( BundleMap iTarget, TUploadFileType iFileType, string iHashCode = null) { if (iTarget == null) { return; } UploadItem _item = null; string filePath = GetLocalBundleFilePath( iTarget.ID, iFileType, (TBundleType.Scene == iTarget.Type)); string checkCode = null; string dataSize = null; if ((false == string.IsNullOrEmpty(filePath)) && (true == File.Exists(filePath))) { if (TCheckMode.Unity3d_Hash128 == this.CheckMode) { checkCode = iHashCode; } else { checkCode = GetFileMD5(filePath); } FileInfo fileInfo = new FileInfo(filePath); dataSize = fileInfo.Length.ToString(); } else { this.Warning("AddTarget()::Target File is not exist!!!(target:{0})", filePath); } bool _exist = this.isTargetExist(iTarget.ID, iFileType, out _item); if (false == _exist) { _item = this.CreateUploadItem(iTarget.ID, iTarget.Type, iFileType); _item.CheckCode = checkCode; _item.DataSize = dataSize; } else { if ((false == string.IsNullOrEmpty(checkCode)) && (false == checkCode.Equals(_item.CheckCode))) { _item.CheckCode = checkCode; _item.DataSize = dataSize; _item.Uploaded = false; } } UtilsAsset.SetAssetDirty(this); }
/// <summary> /// 创建上传者. /// </summary> /// <param name="iTarget">上传目标.</param> /// <param name="iOnStart">开始上传委托.</param> /// <param name="iOnFailed">上传失败委托.</param> /// <param name="iOnSuccessed">上传成功委托.</param> /// <param name="iUploadWay">上传方式.</param> public static Uploader Create( UploadItem iTarget, OnStart iOnStart, OnFailed iOnFailed, OnSuccessed iOnSuccessed, TUploadWay iUploadWay = TUploadWay.Ftp) { Uploader objRet = new Uploader(); objRet.Init(iTarget, iOnStart, iOnFailed, iOnSuccessed, iUploadWay); return(objRet); }
/// <summary> /// 上传失败委托. /// </summary> /// <param name="iUploader">上传器.</param> /// <param name="iTargetInfo">上传目标信息.</param> /// <param name="iRetries">剩余重试次数.</param> /// <param name="iError">错误信息.</param> public void OnUploadFailed(Uploader iUploader, UploadItem iTargetInfo, int iRetries, List <ErrorDetail> iErrors) { lock (_errorLock) { UtilsLog.Error("OnUploadFailed", "{0} State:{1} Retries:{2} Detail:{3}", iTargetInfo.toString(), this._State, iRetries, iErrors.ToString()); this._errors.AddRange(iErrors); this._State = TRunState.Error; if (iUploader != null) { iUploader.Dispose(); GC.Collect(); } } }
/// <summary> /// 创建UploadItem. /// </summary> /// <returns>UploadItem.</returns> /// <param name="iTargetId">目标ID.</param> /// <param name="iBundleType">Bundle类型.</param> /// <param name="iFileType">文件类型.</param> private UploadItem CreateUploadItem( string iTargetId, TBundleType iBundleType, TUploadFileType iFileType) { UploadItem objRet = new UploadItem(); if (objRet != null) { objRet.No = this.GetBundleNo(); objRet.ID = iTargetId; objRet.BundleType = iBundleType; objRet.FileType = iFileType; objRet.Uploaded = false; this.Targets.Add(objRet); } return(objRet); }
/// <summary> /// 上传成功委托. /// </summary> /// <param name="iUploader">上传器.</param> /// <param name="iTargetInfo">下载目标信息.</param> /// <param name="iIsManifest">manifest标志位.</param> /// <param name="iRetries">剩余重试次数.</param> public void OnUploadSuccessed(Uploader iUploader, UploadItem iTargetInfo, int iRetries) { UtilsLog.Info("OnUploadSuccessed", "No:{0} State:{1} Retries:{2}", iTargetInfo.toString(), this._State, iRetries); UploadList.GetInstance().UploadCompleted(iTargetInfo.ID, iTargetInfo.FileType); if (null != iUploader) { iUploader.Dispose(); GC.Collect(); } lock (_uploaderCountLock) { --this.UploaderCount; } }
/// <summary> /// 初始化. /// </summary> /// <param name="iTarget">上传目标.</param> /// <param name="iOnStart">开始上传委托.</param> /// <param name="iOnFailed">上传失败委托.</param> /// <param name="iOnSuccessed">上传成功委托.</param> /// <param name="iUploadWay">上传方式.</param> private void Init( UploadItem iTarget, OnStart iOnStart, OnFailed iOnFailed, OnSuccessed iOnSuccessed, TUploadWay iUploadWay = TUploadWay.Ftp) { this._target = iTarget; this._onStart = iOnStart; this._onFailed = iOnFailed; this._onSuccessed = iOnSuccessed; this._uploadWay = iUploadWay; this.Retries = ServersConf.GetInstance().NetRetries; if (this._server == null) { this._server = ServersConf.GetInstance().UploadServer; } this.UploadBaseUrl = ServersConf.GetBundleUploadBaseURL(this._server, this._target); this.FileName = UploadList.GetLocalBundleFileName(this._target.ID, this._target.FileType); }
/// <summary> /// 上传完成. /// </summary> /// <param name="iTargetID">目标ID.</param> /// <param name="iFileType">文件类型.</param> public void UploadCompleted(string iTargetID, TUploadFileType iFileType) { lock (_targetsThreadLock) { UploadItem uploadItem = null; if (true == this.isTargetExist(iTargetID, iFileType, out uploadItem)) { if (uploadItem == null) { return; } uploadItem.Uploaded = true; if (this._progressCounter != null) { this._progressCounter.UpdateCompletedCount(); long dataSize = (string.IsNullOrEmpty(uploadItem.DataSize) == true) ? 0 : Convert.ToInt64(uploadItem.DataSize); this._progressCounter.UpdateCompletedDataSize(dataSize); } } } }
/// <summary> /// 判断目标是否存在. /// </summary> /// <returns><c>true</c>,存在, <c>false</c> 不存在.</returns> /// <param name="iTargetID">目标ID.</param> /// <param name="iFileType">文件类型.</param> /// <param name="iTarget">目标信息.</param> private bool isTargetExist(string iTargetID, TUploadFileType iFileType, out UploadItem iTarget) { iTarget = null; UploadItem[] targets = this.Targets .Where(o => ( (true == iTargetID.Equals(o.ID)) && (iFileType == o.FileType))) .OrderBy(o => o.No) .ToArray(); if ((targets == null) || (targets.Length <= 0)) { return(false); } if (1 != targets.Length) { this.Warning("isTargetExist()::There is duplicate id exist in upload list!!!(Bundle ID:{0})", iTargetID); } iTarget = targets [0]; return(true); }