Exemplo n.º 1
0
        /// <summary>
        /// 增加下载任务。
        /// </summary>
        /// <param name="downloadPath">下载后存放路径。</param>
        /// <param name="downloadUri">原始下载地址。</param>
        /// <param name="priority">下载任务的优先级。</param>
        /// <param name="userData">用户自定义数据。</param>
        /// <returns>新增下载任务的序列编号。</returns>
        public int AddDownload(string downloadPath, string downloadUri, int priority, object userData)
        {
            if (File.Exists(downloadPath))
            {
                Debug.LogError("the file has exit,do not need to load again!");
                return(-1);
            }
            if (string.IsNullOrEmpty(downloadPath))
            {
                Debug.LogError("Download path is invalid.");
            }

            if (string.IsNullOrEmpty(downloadUri))
            {
                Debug.LogError("Download uri is invalid.");
            }

            if (TotalAgentCount <= 0)
            {
                Debug.LogError("You must add download agent first.");
            }

            DownloadTask downloadTask = DownloadTask.Create(downloadPath, downloadUri, priority, m_FlushSize, m_Timeout, userData);

            m_TaskPool.AddTask(downloadTask);
            return(downloadTask.SerialId);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 增加 Web 请求任务。
        /// </summary>
        /// <param name="webRequestUri">Web 请求地址。</param>
        /// <param name="postData">要发送的数据流。</param>
        /// <param name="priority">Web 请求任务的优先级。</param>
        /// <param name="userData">用户自定义数据。</param>
        /// <returns>新增 Web 请求任务的序列编号。</returns>
        public int AddWebRequest(string webRequestUri, byte[] postData, int priority, object userData)
        {
            if (string.IsNullOrEmpty(webRequestUri))
            {
                Debug.Log("Web request uri is invalid.");
            }

            if (TotalAgentCount <= 0)
            {
                Debug.Log("You must add web request agent first.");
            }

            WebRequestTask webRequestTask = WebRequestTask.Create(webRequestUri, postData, priority, m_Timeout, userData);

            m_TaskPool.AddTask(webRequestTask);
            return(webRequestTask.SerialId);
        }