public void InvokeDownloadCommandCompleted(DownloadCommand command, DownloadResult result) { if (monitorCommandList.Contains(command)) { if (!monitorResult.DownloadResultMapping.ContainsKey(command)) { monitorResult.DownloadResultMapping.Add(command, result); } monitorCommandList.Remove(command); if (monitorCommandList.Count == 0) { monitorResult.ResultType = DownloadMonitorResultType.ALL_COMPLETED; onCommandAllCompleted(monitorResult); } } }
/// <summary> /// 依序執行所有等待中的下載命令 /// </summary> private IEnumerator excuteDownloadCommandProcess() { while (waitingCommandList.Count > 0) { DownloadCommand command = waitingCommandList[0]; www = new WWW(waitingCommandList[0].DownloadUrl); yield return(www); DownloadResult result = new DownloadResult(); result.Command = command; result.DownloadedTime = DateTime.Now; result.ErrorMsg = www.error; result.Bytes = www.bytes; if (!string.IsNullOrEmpty(result.ErrorMsg)) { Debug.LogErrorFormat("[DownloadService.excuteDownloadCommandProcess] Download {1} error: {0}", waitingCommandList[0].DownloadUrl, result.ErrorMsg); DebugLogger.Instance.LogError("[DownloadService.excuteDownloadCommandProcess] Download error: " + result.ErrorMsg); } else { if (!string.IsNullOrEmpty(command.SavedFileUrl)) { writeToFile(result.Bytes, command.SavedFileUrl); } } for (int i = monitorList.Count - 1; i >= 0; --i) { monitorList[i].InvokeDownloadCommandCompleted(waitingCommandList[0], result); if (monitorList[i].IsCompleted) { monitorList.RemoveAt(i); } } waitingCommandList.RemoveAt(0); } IsDownloading = false; }