Пример #1
0
 public DownloadProgress(Guid downloadId, DownloadProgressState state, Uri requestUri, long totalRead, long?contentLength)
 {
     DownloadId    = downloadId;
     State         = state;
     RequestUri    = requestUri;
     TotalRead     = totalRead;
     ContentLength = contentLength;
 }
Пример #2
0
 void pd17Task_DownloadProgressChanged(DownloadProgressState processState, int done, int total)
 {
     if (processState == DownloadProgressState.Started)
     {
         this.BeginInvoke((MethodInvoker) delegate()
         {
             label1.Text = "할인쿠폰 다운로드 진행합니다.";
         });
     }
     else if (processState == DownloadProgressState.Processing)
     {
         this.BeginInvoke((MethodInvoker) delegate()
         {
             label1.Text = string.Format("할인쿠폰 권종 다운로드 {0}/{1}건 진행중", done, total);
         });
     }
     else
     {
         this.BeginInvoke((MethodInvoker) delegate()
         {
             MessageBox.Show("할인쿠폰 권종 다운로드 완료.");
         });
     }
 }
Пример #3
0
		/// <summary>
		/// Handles the <see cref="INotifyPropertyChanged.PropertyChanged"/> event of the file downloader tasks.
		/// </summary>
		/// <param name="sender">The object that raised the event.</param>
		/// <param name="e">A <see cref="PropertyChangedEventArgs"/> describing the event arguments.</param>
		private void Downloader_PropertyChanged(object sender, PropertyChangedEventArgs e)
		{
			if (m_booFinishedDownloads)
				return;
			FileDownloadTask fdtDownloader = (FileDownloadTask)sender;
			if (e.PropertyName.Equals(ObjectHelper.GetPropertyName<IBackgroundTask>(x => x.OverallProgress)) ||
				e.PropertyName.Equals(ObjectHelper.GetPropertyName<IBackgroundTask>(x => x.OverallProgressMaximum)))
			{
				Int64 intLastProgress = 0;
				if (m_dicDownloaderProgress.ContainsKey(fdtDownloader))
					intLastProgress = m_dicDownloaderProgress[fdtDownloader].OverallProgress;
				else if (m_dicDownloaderProgress.Count == 0)
				{
					//this means this is the first update, or the first update after
					// the task was resumed, so the current item progress can be assumed
					// to be the last progress
					intLastProgress = ItemProgress;
				}
				if (intLastProgress <= fdtDownloader.OverallProgress)
					if (!m_dicDownloaderProgress.ContainsKey(fdtDownloader))
						m_dicDownloaderProgress[fdtDownloader] = new DownloadProgressState(fdtDownloader);
					else
						m_dicDownloaderProgress[fdtDownloader].Update(fdtDownloader);
				Int64 intProgress = 0;
				Int64 intProgressMaximum = 0;
				Int32 intSpeed = 0;
				TimeSpan tspTimeRemaining = TimeSpan.Zero;
				foreach (DownloadProgressState dpsState in m_dicDownloaderProgress.Values)
				{
					if (dpsState != null)
					{
						intProgress += dpsState.AdjustedProgress;
						intProgressMaximum += dpsState.AdjustedProgressMaximum;
						intSpeed += dpsState.DownloadSpeed;
						if (tspTimeRemaining < dpsState.TimeRemaining)
							tspTimeRemaining = dpsState.TimeRemaining;
					}
				}
				ItemProgress = intProgress;
				ItemProgressMaximum = intProgressMaximum;

				if (swtSpeed.IsRunning)
				{
					if (swtSpeed.ElapsedMilliseconds >= 1000)
					{
						if (m_intPreviousProgress == 0)
							m_intPreviousProgress = (Int64)(fdtDownloader.ResumedByteCount > 0 ? fdtDownloader.ResumedByteCount : 0);
						if (m_dicDownloaderProgress.ContainsKey(fdtDownloader))
							TaskSpeed = (int)((double)(m_dicDownloaderProgress[fdtDownloader].AdjustedProgress - m_intPreviousProgress) / (swtSpeed.ElapsedMilliseconds / 1000));
						if (TaskSpeed >= 0)
						{
							if (m_lstPreviousSpeed.Count == 10)
								m_lstPreviousSpeed.Pop();
							m_lstPreviousSpeed.Push(TaskSpeed);
						}
						if (m_lstPreviousSpeed.Count > 1)
							TaskSpeed = (int)m_lstPreviousSpeed.Average();
						if (m_dicDownloaderProgress.ContainsKey(fdtDownloader))
							m_intPreviousProgress = m_dicDownloaderProgress[fdtDownloader].AdjustedProgress;
						swtSpeed.Reset();
						swtSpeed.Start();
					}
					else
						TaskSpeed = (m_lstPreviousSpeed.Count > 0) && (m_lstPreviousSpeed.Average() > 0) ? (int)m_lstPreviousSpeed.Average() : intSpeed;
				}
				else
				{
					swtSpeed.Start();
				}

				double dblMinutes = (intSpeed == 0) ? 99 : tspTimeRemaining.TotalMinutes;
				Int32 intSeconds = (intSpeed == 0) ? 99 : tspTimeRemaining.Seconds;
				if ((ItemProgress == 0) && (intSpeed == 0))
					ItemMessage = "Starting the download...";
				else if ((ItemProgress == intLastProgress) && (intSpeed == 0))
					ItemMessage = "Resuming the download...";
				else
				{
					ETA_Minutes = dblMinutes;
					ETA_Seconds = intSeconds;

					if (m_dicDownloaderProgress.ContainsKey(fdtDownloader))
					{
						DownloadProgress = m_dicDownloaderProgress[fdtDownloader].AdjustedProgress;
						DownloadMaximum = m_dicDownloaderProgress[fdtDownloader].AdjustedProgressMaximum;
					}
				}

				ActiveThreads = fdtDownloader.ActiveThreads;
			}
			else if (e.PropertyName.Equals(ObjectHelper.GetPropertyName<IBackgroundTask>(x => x.OverallMessage)) ||
				e.PropertyName.Equals(ObjectHelper.GetPropertyName<IBackgroundTask>(x => x.Status)))
			{
				if (fdtDownloader.Status == TaskStatus.Retrying)
				{
					OverallMessage = fdtDownloader.OverallMessage;
				}
				else if (fdtDownloader.Status == TaskStatus.Running)
				{
					OverallMessage = String.Format("{0}{1}", m_strRepositoryMessage, GetModDisplayName());
					FileServer = m_strFileserverCaptions[(Int32)fdtDownloader.ItemProgress];
				}
				else if (fdtDownloader.Status == TaskStatus.Paused)
				{
					OverallMessage = String.Format("{0}{1}", "Paused: ", GetModDisplayName());
					FileServer = String.Empty;
				}
				InnerTaskStatus = fdtDownloader.Status;
			}
		}
Пример #4
0
 private static void Report(IProgress <DownloadProgress> progress, Guid downloadId, DownloadProgressState state, Uri requestUri, long totalRead, HttpResponseMessage response)
 {
     progress?.Report(new DownloadProgress(downloadId, state, requestUri, totalRead, response.Content?.Headers.ContentLength));
 }