public DownloadAgent(IDownloadAgentHelper downloadAgentHelper) { m_Helper = downloadAgentHelper; m_Task = null; m_FileStream = null; m_WaitFlushSize = 0; m_StartLength = 0; m_SavedLength = 0; m_Disposed = false; DownloadAgentStart = null; }
public void Reset() { m_Helper.Reset(); if (m_FileStream != null) { m_FileStream.Close(); m_FileStream = null; } m_Task = null; m_WaitFlushSize = 0; }
public void Start(DownloadTask task) { if (task == null) { throw; } m_Task = task; m_Task.Status = DownloadTaskStatus.Doing; string downloadFile = string.Format(); try { if (File.Exists(downloadFile)) { m_FileStream = File.OpenWrite(downloadFile); m_FileStream.Seek(0, SeekOrigin.End); m_StartLength = m_SavedLength = (int)m_FileStream.Length; m_DownloadedLength = 0; } else { string directory = Path.GetDirectoryName(m_Task.DownloadPath); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } m_FileStream = new FileStream(downloadFile, FileMode.Create, FileAccess.Write); m_StartLength = m_SavedLength = m_DownloadedLength = 0; } if (DownloadAgentStart) { DownloadAgentStart(this); } if (m_StartLength > 0) { m_Helper.Download(m_Task.DownloadUri, m_StartLength, m_Task.UserData); } } catch (Exception e) { OnDownloadAgentHelperError(this, new DownloadAgentHelperErrorEventArgs()); } }