Exemple #1
0
        private void OnDownloadAgentHelperUpdateBytes(object sender, DownloadAgentHelperUpdateBytesEventArgs e)
        {
            m_WaitTime = 0f;
            try
            {
                m_FileStream.Write(e.GetBytes(), e.Offset, e.Length);
                m_WaitFlushSize += e.Length;
                m_SavedLength   += e.Length;

                if (m_WaitFlushSize >= m_Task.FlushSize)
                {
                    m_FileStream.Flush();
                    m_WaitFlushSize = 0;
                }
            }
            catch (Exception exception)
            {
                DownloadAgentHelperErrorEventArgs downloadAgentHelperErrorEventArgs = DownloadAgentHelperErrorEventArgs.Create(false, exception.ToString());
                OnDownloadAgentHelperError(this, downloadAgentHelperErrorEventArgs);
                ReferencePool.Release(downloadAgentHelperErrorEventArgs);
            }
        }
        /// <summary>
        /// 创建下载代理辅助器更新数据流事件。
        /// </summary>
        /// <param name="bytes">下载的数据流。</param>
        /// <param name="offset">数据流的偏移。</param>
        /// <param name="length">数据流的长度。</param>
        /// <returns>创建的下载代理辅助器更新数据流事件。</returns>
        public static DownloadAgentHelperUpdateBytesEventArgs Create(byte[] bytes, int offset, int length)
        {
            if (bytes == null)
            {
                throw new Exception("Bytes is invalid.");
            }

            if (offset < 0 || offset >= bytes.Length)
            {
                throw new Exception("Offset is invalid.");
            }

            if (length <= 0 || offset + length > bytes.Length)
            {
                throw new Exception("Length is invalid.");
            }

            DownloadAgentHelperUpdateBytesEventArgs downloadAgentHelperUpdateBytesEventArgs = ReferencePool.Acquire <DownloadAgentHelperUpdateBytesEventArgs>();

            downloadAgentHelperUpdateBytesEventArgs.m_Bytes = bytes;
            downloadAgentHelperUpdateBytesEventArgs.Offset  = offset;
            downloadAgentHelperUpdateBytesEventArgs.Length  = length;
            return(downloadAgentHelperUpdateBytesEventArgs);
        }