private void DownloadRateUpdater(Object obj) { CDownloadFile cdfParent = ((CDownloadFile)obj); if (((CDownloadFile)obj).FileDownloading == true) { a_iKiBytesPerTick[iTickCount] = cdfParent.m_iReadBytes - iPreviousTickReadBytes; iTickCount = (++iTickCount % 50); cdfParent.m_dblKibPerSecond = 0.0; foreach (int iKiBytesTick in a_iKiBytesPerTick) { cdfParent.m_dblKibPerSecond += iKiBytesTick; } cdfParent.m_dblKibPerSecond = cdfParent.m_dblKibPerSecond / 5120; // / 1024 / 5; iPreviousTickReadBytes = cdfParent.m_iReadBytes; if (cdfParent.DownloadProgressUpdate != null && iPreviousTickReadBytes > 0) { //cdfParent.DownloadProgressUpdate(cdfParent); cdfParent.DownloadProgressUpdate(cdfParent); } } else { // Don't run again. this.ProgressTick.Dispose(); } }
private void DownloadRateUpdater(Object obj) { CDownloadFile cdfParent = ((CDownloadFile)obj); int iTickCount = 0; int[] a_iKiBytesPerTick = new int[50]; int iPreviousTickReadBytes = 0; while (((CDownloadFile)obj).FileDownloading == true) { a_iKiBytesPerTick[iTickCount] = cdfParent.m_iReadBytes - iPreviousTickReadBytes; iTickCount = (++iTickCount % 50); cdfParent.m_dblKibPerSecond = 0.0; foreach (int iKiBytesTick in a_iKiBytesPerTick) { cdfParent.m_dblKibPerSecond += iKiBytesTick; } cdfParent.m_dblKibPerSecond = cdfParent.m_dblKibPerSecond / 5120; // / 1024 / 5; iPreviousTickReadBytes = cdfParent.m_iReadBytes; if (cdfParent.DownloadProgressUpdate != null && iPreviousTickReadBytes > 0) { //cdfParent.DownloadProgressUpdate(cdfParent); FrostbiteConnection.RaiseEvent(cdfParent.DownloadProgressUpdate.GetInvocationList(), cdfParent); } Thread.Sleep(100); } }
private void ReadCallBack(IAsyncResult ar) { CDownloadFile cdfParent = (CDownloadFile)ar.AsyncState; if (cdfParent.m_blFileDownloading == true) { try { int iBytesRead = -1; if ((iBytesRead = cdfParent.m_stmResponseStream.EndRead(ar)) > 0) { if (this.CompleteFileData.Length < this.BytesDownloaded + iBytesRead) { byte[] resizedFileData = new byte[this.CompleteFileData.Length + iBytesRead]; this.CompleteFileData.CopyTo(resizedFileData, 0); this.ma_bCompleteFile = resizedFileData; } Array.Copy(this.ma_bBufferStream, 0, this.CompleteFileData, this.BytesDownloaded, iBytesRead); cdfParent.m_iReadBytes += iBytesRead; IAsyncResult arResult = cdfParent.m_stmResponseStream.BeginRead(cdfParent.ma_bBufferStream, 0, CDownloadFile.INT_BUFFER_SIZE, new AsyncCallback(cdfParent.ReadCallBack), cdfParent); ThreadPool.RegisterWaitForSingleObject(arResult.AsyncWaitHandle, new WaitOrTimerCallback(cdfParent.ReadTimeoutCallback), cdfParent, cdfParent.m_iTimeout, true); } else { cdfParent.m_blFileDownloading = false; if (cdfParent.DownloadComplete != null) { cdfParent.DownloadComplete(cdfParent); //cdfParent.DownloadComplete(cdfParent); } cdfParent.m_stmResponseStream.Close(); cdfParent.m_stmResponseStream.Dispose(); cdfParent.m_stmResponseStream = null; } } catch (Exception e) { cdfParent.m_blFileDownloading = false; if (cdfParent.DownloadError != null) { cdfParent.m_strLastError = e.Message; cdfParent.DownloadError(cdfParent); //cdfParent.DownloadError(cdfParent); } } } }
private void RequestTimeoutCallback(object objState, bool blTimedOut) { if (blTimedOut == true) { CDownloadFile cdfParent = (CDownloadFile)objState; if (cdfParent != null) { cdfParent.m_wrRequest.Abort(); } } }
private void ReadCallBack(IAsyncResult ar) { CDownloadFile cdfParent = (CDownloadFile)ar.AsyncState; if (cdfParent.m_blFileDownloading == true) { try { int iBytesRead = -1; if ((iBytesRead = cdfParent.m_stmResponseStream.EndRead(ar)) > 0) { if (cdfParent.m_blUnknownSize == true) { Array.Resize <byte>(ref cdfParent.ma_bCompleteFile, cdfParent.ma_bCompleteFile.Length + iBytesRead); } else if (cdfParent.m_blUnknownSize == false && cdfParent.FileName == "xml") { Array.Resize <byte>(ref cdfParent.ma_bCompleteFile, iBytesRead); } Array.Copy(cdfParent.ma_bBufferStream, 0, cdfParent.ma_bCompleteFile, cdfParent.m_iReadBytes, iBytesRead); cdfParent.m_iReadBytes += iBytesRead; IAsyncResult arResult = cdfParent.m_stmResponseStream.BeginRead(cdfParent.ma_bBufferStream, 0, CDownloadFile.INT_BUFFER_SIZE, new AsyncCallback(cdfParent.ReadCallBack), cdfParent); ThreadPool.RegisterWaitForSingleObject(arResult.AsyncWaitHandle, new WaitOrTimerCallback(cdfParent.ReadTimeoutCallback), cdfParent, cdfParent.m_iTimeout, true); } else { cdfParent.m_blFileDownloading = false; if (cdfParent.DownloadComplete != null) { FrostbiteConnection.RaiseEvent(cdfParent.DownloadComplete.GetInvocationList(), cdfParent); //cdfParent.DownloadComplete(cdfParent); } cdfParent.m_stmResponseStream.Close(); cdfParent.m_stmResponseStream.Dispose(); cdfParent.m_stmResponseStream = null; } } catch (Exception e) { cdfParent.m_blFileDownloading = false; if (cdfParent.DownloadError != null) { cdfParent.m_strLastError = e.Message; FrostbiteConnection.RaiseEvent(cdfParent.DownloadError.GetInvocationList(), cdfParent); //cdfParent.DownloadError(cdfParent); } } } }
private void ResponseCallback(IAsyncResult ar) { CDownloadFile cdfParent = (CDownloadFile)ar.AsyncState; try { cdfParent.m_wrResponse = cdfParent.m_wrRequest.EndGetResponse(ar); string strContentLength = null; if ((strContentLength = cdfParent.m_wrResponse.Headers["Content-Length"]) != null) { cdfParent.m_iCompleteFileSize = Convert.ToInt32(strContentLength); cdfParent.ma_bCompleteFile = new byte[cdfParent.m_iCompleteFileSize]; cdfParent.m_blUnknownSize = false; if (cdfParent.DownloadDiscoveredFileSize != null) { //cdfParent.DownloadDiscoveredFileSize(cdfParent); FrostbiteConnection.RaiseEvent(cdfParent.DownloadDiscoveredFileSize.GetInvocationList(), cdfParent); } } else { cdfParent.ma_bCompleteFile = new byte[0]; } cdfParent.m_stmResponseStream = cdfParent.m_wrResponse.GetResponseStream(); if (cdfParent.m_wrResponse.Headers.Get("Content-Encoding") != null && cdfParent.m_wrResponse.Headers.Get("Content-Encoding").ToLower() == "gzip") { cdfParent.m_stmResponseStream = new GZipStream(cdfParent.m_stmResponseStream, CompressionMode.Decompress); } IAsyncResult arResult = cdfParent.m_stmResponseStream.BeginRead(cdfParent.ma_bBufferStream, 0, CDownloadFile.INT_BUFFER_SIZE, new AsyncCallback(cdfParent.ReadCallBack), cdfParent); ThreadPool.RegisterWaitForSingleObject(arResult.AsyncWaitHandle, new WaitOrTimerCallback(cdfParent.ReadTimeoutCallback), cdfParent, cdfParent.m_iTimeout, true); } catch (Exception e) { cdfParent.m_blFileDownloading = false; if (cdfParent.DownloadError != null) { cdfParent.m_strLastError = e.Message; FrostbiteConnection.RaiseEvent(cdfParent.DownloadError.GetInvocationList(), cdfParent); //cdfParent.DownloadError(cdfParent); } } }
private void ResponseCallback(IAsyncResult ar) { CDownloadFile cdfParent = (CDownloadFile)ar.AsyncState; try { cdfParent.m_wrResponse = cdfParent.m_wrRequest.EndGetResponse(ar); string strContentLength = null; if ((strContentLength = cdfParent.m_wrResponse.Headers["Content-Length"]) != null) { cdfParent.m_iCompleteFileSize = Convert.ToInt32(strContentLength); cdfParent.ma_bCompleteFile = new byte[cdfParent.m_iCompleteFileSize]; cdfParent.m_blUnknownSize = false; if (cdfParent.DownloadDiscoveredFileSize != null) { //cdfParent.DownloadDiscoveredFileSize(cdfParent); cdfParent.DownloadDiscoveredFileSize(cdfParent); } } cdfParent.ma_bCompleteFile = new byte[0]; cdfParent.m_stmResponseStream = cdfParent.m_wrResponse.GetResponseStream(); IAsyncResult arResult = cdfParent.m_stmResponseStream.BeginRead(cdfParent.ma_bBufferStream, 0, CDownloadFile.INT_BUFFER_SIZE, new AsyncCallback(cdfParent.ReadCallBack), cdfParent); ThreadPool.RegisterWaitForSingleObject(arResult.AsyncWaitHandle, new WaitOrTimerCallback(cdfParent.ReadTimeoutCallback), cdfParent, cdfParent.m_iTimeout, true); } catch (Exception e) { cdfParent.m_blFileDownloading = false; if (cdfParent.DownloadError != null) { cdfParent.m_strLastError = e.Message; cdfParent.DownloadError(cdfParent); //cdfParent.DownloadError(cdfParent); } } }
private void ReadTimeoutCallback(object objState, bool blTimedOut) { if (blTimedOut == true) { CDownloadFile cdfParent = (CDownloadFile)objState; if (cdfParent != null && cdfParent.m_stmResponseStream != null) { cdfParent.m_stmResponseStream.Close(); if (cdfParent.DownloadError != null) { cdfParent.m_strLastError = "Read Timeout"; cdfParent.DownloadError(cdfParent); //cdfParent.DownloadError(cdfParent); } } } }
private void ReadTimeoutCallback(object objState, bool blTimedOut) { if (blTimedOut == true) { CDownloadFile cdfParent = (CDownloadFile)objState; if (cdfParent != null && cdfParent.m_stmResponseStream != null) { cdfParent.m_stmResponseStream.Close(); if (cdfParent.DownloadError != null) { cdfParent.m_strLastError = "Read Timeout"; FrostbiteConnection.RaiseEvent(cdfParent.DownloadError.GetInvocationList(), cdfParent); //cdfParent.DownloadError(cdfParent); } } } }
private void downloadPromoFeed_DownloadComplete(CDownloadFile cdfSender) { string xmlDocumentText = Encoding.UTF8.GetString(cdfSender.CompleteFileData); XmlDocument rssDocument = new XmlDocument(); try { rssDocument.LoadXml(xmlDocumentText); if (this.RssUpdateSuccess != null) { this.PromoUpdateSuccess(this, rssDocument); } } catch (Exception) { } }
private void downloadPromoFeed_DownloadError(CDownloadFile cdfSender) { // RSS Error if (this.RssUpdateError != null) { this.PromoUpdateError(this); } }
private void downloadRssFeed_DownloadComplete(CDownloadFile cdfSender) { string xmlDocumentText = Encoding.UTF8.GetString(cdfSender.CompleteFileData); XmlDocument rssDocument = new XmlDocument(); try { rssDocument.LoadXml(xmlDocumentText); /* not used anymore if (this.PackageManager != null) { this.PackageManager.LoadRemotePackages(rssDocument); } */ if (this.RssUpdateSuccess != null) { this.RssUpdateSuccess(this, rssDocument); } } catch (Exception) { } }
public void UpdateRss() { // Begin RSS Update if (this.BeginRssUpdate != null) { this.BeginRssUpdate(this); } CDownloadFile downloadRssFeed = new CDownloadFile("https://forum.myrcon.com/external.php?do=rss&type=newcontent§ionid=1&days=120&count=10"); downloadRssFeed.DownloadComplete += new CDownloadFile.DownloadFileEventDelegate(downloadRssFeed_DownloadComplete); downloadRssFeed.DownloadError += new CDownloadFile.DownloadFileEventDelegate(downloadRssFeed_DownloadError); downloadRssFeed.BeginDownload(); CDownloadFile downloadPromoFeed = new CDownloadFile("https://myrcon.com/procon/streams/banners/format/xml"); downloadPromoFeed.DownloadComplete += new CDownloadFile.DownloadFileEventDelegate(downloadPromoFeed_DownloadComplete); downloadPromoFeed.DownloadError += new CDownloadFile.DownloadFileEventDelegate(downloadPromoFeed_DownloadError); downloadPromoFeed.BeginDownload(); }
private void downloadPromoFeed_DownloadError(CDownloadFile cdfSender) { // RSS Error if (this.RssUpdateError != null) { FrostbiteConnection.RaiseEvent(this.PromoUpdateError.GetInvocationList(), this); } }
private void downloadRssFeed_DownloadComplete(CDownloadFile cdfSender) { string xmlDocumentText = Encoding.UTF8.GetString(cdfSender.CompleteFileData); XmlDocument rssDocument = new XmlDocument(); try { rssDocument.LoadXml(xmlDocumentText); if (this.PackageManager != null) { this.PackageManager.LoadRemotePackages(rssDocument); } if (this.RssUpdateSuccess != null) { FrostbiteConnection.RaiseEvent(this.RssUpdateSuccess.GetInvocationList(), this, rssDocument); } } catch (Exception) { } }
public void UpdateRss() { // Begin RSS Update if (this.BeginRssUpdate != null) { FrostbiteConnection.RaiseEvent(this.BeginRssUpdate.GetInvocationList(), this); } CDownloadFile downloadRssFeed = new CDownloadFile("http://phogue.net/feed/"); downloadRssFeed.DownloadComplete += new CDownloadFile.DownloadFileEventDelegate(downloadRssFeed_DownloadComplete); downloadRssFeed.DownloadError += new CDownloadFile.DownloadFileEventDelegate(downloadRssFeed_DownloadError); downloadRssFeed.BeginDownload(); }