Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Download
- {
- public event EventHandler<DownloadStatusChangedEventArgs> DownloadStatusChanged;
- public event EventHandler<DownloadProgressChangedEventArgs> DownloadProgressChanged;
- public event EventHandler DownloadCompleted;
- public bool stop = true; // by default stop is true
- public void DownloadFile(string DownloadLink, string Path)
- {
- stop = false; // always set this bool to false, everytime this method is called
- long ExistingLength = 0;
- FileStream saveFileStream;
- if (File.Exists(Path))
- {
- FileInfo fileInfo = new FileInfo(Path);
- ExistingLength = fileInfo.Length;
- }
- if (ExistingLength > 0)
- {
- saveFileStream = new FileStream(Path, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
- }
- else
- {
- saveFileStream = new FileStream(Path, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
- }
- var request = (HttpWebRequest)HttpWebRequest.Create(DownloadLink);
- request.Proxy = null;
- request.AddRange(ExistingLength);
- try
- {
- using (var response = (HttpWebResponse)request.GetResponse())
- {
- long FileSize = ExistingLength + response.ContentLength; //response.ContentLength gives me the size that is remaining to be downloaded
- bool downloadResumable; // need it for sending empty progress
- if ((int)response.StatusCode == 206)
- {
- //Console.WriteLine("Resumable");
- var downloadStatusArgs = new DownloadStatusChangedEventArgs();
- downloadResumable = true;
- downloadStatusArgs.ResumeSupported = downloadResumable;
- OnDownloadStatusChanged(downloadStatusArgs);
- }
- else // sometimes a server that supports partial content will lose its ability to send partial content(weird behavior) and thus the download will lose its resumability
- {
- //Console.WriteLine("Resume Not Supported");
- ExistingLength = 0;
- var downloadStatusArgs = new DownloadStatusChangedEventArgs();
- downloadResumable = false;
- downloadStatusArgs.ResumeSupported = downloadResumable;
- OnDownloadStatusChanged(downloadStatusArgs);
- // restart downloading the file from the beginning because it isn't resumable
- // if this isn't done, the method downloads the file from the beginning and starts writing it after the previously half downloaded file, thus increasing the filesize and corrupting the downloaded file
- saveFileStream.Dispose(); // dispose object to free it for the next operation
- File.WriteAllText(Path, string.Empty); // clear the contents of the half downloaded file that can't be resumed
- saveFileStream = new FileStream(Path, FileMode.Append, FileAccess.Write, FileShare.ReadWrite); // reopen it for writing
- }
- using (var stream = response.GetResponseStream())
- {
- byte[] downBuffer = new byte[4096];
- int byteSize = 0;
- long totalReceived = byteSize + ExistingLength;
- var sw = new Stopwatch();
- sw.Start();
- while ((byteSize = stream.Read(downBuffer, 0, downBuffer.Length)) > 0)
- {
- saveFileStream.Write(downBuffer, 0, byteSize);
- totalReceived += byteSize;
- var args = new DownloadProgressChangedEventArgs();
- args.BytesReceived = totalReceived;
- args.TotalBytesToReceive = FileSize;
- float currentSpeed = totalReceived / (float)sw.Elapsed.TotalSeconds;
- args.CurrentSpeed = currentSpeed;
- if (downloadResumable == true)
- {
- args.ProgressPercentage = ((float)totalReceived / (float)FileSize) * 100;
- long bytesRemainingtoBeReceived = FileSize - totalReceived;
- args.TimeLeft = (long)(bytesRemainingtoBeReceived / currentSpeed);
- }
- else
- {
- //args.ProgressPercentage = Unknown;
- //args.TimeLeft = Unknown;
- }
- OnDownloadProgressChanged(args);
- if (stop == true)
- return;
- }
- sw.Stop();
- }
- }
- var completedArgs = new EventArgs();
- OnDownloadCompleted(completedArgs);
- }
- catch (WebException e)
- {
- string filename = System.IO.Path.GetFileName(Path);
- Console.WriteLine(e.Message);
- }
- finally
- {
- saveFileStream.Dispose();
- }
- }
- public void StopDownload()
- {
- stop = true;
- }
- protected virtual void OnDownloadStatusChanged(DownloadStatusChangedEventArgs e)
- {
- EventHandler<DownloadStatusChangedEventArgs> handler = DownloadStatusChanged;
- if (handler != null)
- {
- handler(this, e);
- }
- }
- protected virtual void OnDownloadProgressChanged(DownloadProgressChangedEventArgs e)
- {
- EventHandler<DownloadProgressChangedEventArgs> handler = DownloadProgressChanged;
- if (handler != null)
- {
- handler(this, e);
- }
- }
- protected virtual void OnDownloadCompleted(EventArgs e)
- {
- EventHandler handler = DownloadCompleted;
- if (handler != null)
- {
- handler(this, e);
- }
- }
- }
- public class DownloadStatusChangedEventArgs : EventArgs
- {
- public bool ResumeSupported { get; set; }
- }
- public class DownloadProgressChangedEventArgs : EventArgs
- {
- public long BytesReceived { get; set; }
- public long TotalBytesToReceive { get; set; }
- public float ProgressPercentage { get; set; }
- public float CurrentSpeed { get; set; } // in bytes
- public long TimeLeft { get; set; } // in seconds
- }
- public interface ILogger
- {
- void LogMessage(string message, params Object[] args);
- }
- public class ConsoleLogger : ILogger
- {
- public void LogMessage(string message, params Object[] args)
- {
- Console.WriteLine(string.Format(message, args));
- }
- }
- public class EventLogger : ILogger
- {
- // ...
- }
- private ILogger _Logger;
- public ClassName(ILogger logger)
- {
- _Logger = logger;
- }
- logger.LogMessage(/* ... */);
- if (logger != null) { logger.LogMessage(/* ... */); }
- if (ExistingLength > 0)
- saveFileStream = new FileStream(Path, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
- else
- saveFileStream = new FileStream(Path, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
- File.WriteAllText(Path, string.Empty); // clear the contents of the half downloaded file that can't be resumed
- saveFileStream = new FileStream(Path, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
- if (stop == true)
- return;
- if (stop == true) return;
- if (stop) return;
- else
- {
- //args.ProgressPercentage = Unknown;
- //args.TimeLeft = Unknown;
- }
- public void DownloadFile(string DownloadLink, string Path)
- {
- stop = false;
- long ExistingLength = 0;
- //using (FileStream saveFileStream = new FileStream()
- try
- {
- if (File.Exists(Path))
- {
- FileInfo fileInfo = new FileInfo(Path);
- ExistingLength = fileInfo.Length;
- }
- if (ExistingLength > 0)
- {
- saveFileStream = new FileStream(Path, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
- }
- else
- {
- saveFileStream = new FileStream(Path, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
- }
- var request = (HttpWebRequest)HttpWebRequest.Create(DownloadLink);
- request.Proxy = null;
- request.AddRange(ExistingLength);
- try
- {
- using (var response = (HttpWebResponse)request.GetResponse())
- {
- long FileSize = ExistingLength + response.ContentLength; //response.ContentLength gives me the size that is remaining to be downloaded
- bool downloadResumable; // need it for sending empty progress
- if ((int)response.StatusCode == 206)
- {
- //Console.WriteLine("Resumable");
- var downloadStatusArgs = new DownloadStatusChangedEventArgs();
- downloadResumable = true;
- downloadStatusArgs.ResumeSupported = downloadResumable;
- OnDownloadStatusChanged(downloadStatusArgs);
- }
- else // sometimes a server that supports partial content will lose its ability to send partial content(weird behavior) and thus the download will lose its resumability
- {
- //Console.WriteLine("Resume Not Supported");
- ExistingLength = 0;
- var downloadStatusArgs = new DownloadStatusChangedEventArgs();
- downloadResumable = false;
- downloadStatusArgs.ResumeSupported = downloadResumable;
- OnDownloadStatusChanged(downloadStatusArgs);
- // restart downloading the file from the beginning because it isn't resumable
- // if this isn't done, the method downloads the file from the beginning and starts writing it after the
- // previously half downloaded file, thus increasing the filesize and corrupting the downloaded file
- saveFileStream.Flush();// clear the contents of the half downloaded file that can't be resumed
- }
- using (var stream = response.GetResponseStream())
- {
- byte[] downBuffer = new byte[4096];
- int byteSize = 0;
- long totalReceived = byteSize + ExistingLength;
- var sw = new Stopwatch();
- sw.Start();
- while ((byteSize = stream.Read(downBuffer, 0, downBuffer.Length)) > 0)
- {
- saveFileStream.Write(downBuffer, 0, byteSize);
- totalReceived += byteSize;
- var args = new DownloadProgressChangedEventArgs();
- args.BytesReceived = totalReceived;
- args.TotalBytesToReceive = FileSize;
- float currentSpeed = totalReceived / (float)sw.Elapsed.TotalSeconds;
- args.CurrentSpeed = currentSpeed;
- if (downloadResumable == true)
- {
- args.ProgressPercentage = ((float)totalReceived / (float)FileSize) * 100;
- long bytesRemainingtoBeReceived = FileSize - totalReceived;
- args.TimeLeft = (long)(bytesRemainingtoBeReceived / currentSpeed);
- }
- OnDownloadProgressChanged(args);
- if (stop == true) return;
- }
- sw.Stop();
- }
- }
- var completedArgs = new EventArgs();
- OnDownloadCompleted(completedArgs);
- }
- catch (WebException e)
- {
- string filename = System.IO.Path.GetFileName(Path);
- Console.WriteLine(e.Message);
- }
- }
- finally
- {
- saveFileStream.Close()
- saveFileStream.Dispose()
- }
- }
- public interface ILogger
- {
- void Log(string format, params object[] args);
- void Log(object message);
- }
- public class Downloader
- {
- public Downloader(ILogger logger)
- {
- _logger = logger;
- }
- public event EventHandler<DownloadStatusChangedEventArgs> ResumablityChanged;
- public event EventHandler<DownloadProgressChangedEventArgs> ProgressChanged;
- public event EventHandler Completed;
- public bool stop = true; // by default stop is true
- private ILogger _logger;
- public void DownloadFile(string downloadLink, string path)
- {
- stop = false; // always set this bool to false, everytime this method is called
- var fileInfo = new FileInfo(path);
- long existingLength = 0;
- if (fileInfo.Exists)
- existingLength = fileInfo.Length;
- var request = (HttpWebRequest)HttpWebRequest.Create(downloadLink);
- request.Proxy = null;
- request.AddRange(existingLength);
- try
- {
- using (var response = (HttpWebResponse)request.GetResponse())
- {
- long fileSize = existingLength + response.ContentLength; //response.ContentLength gives me the size that is remaining to be downloaded
- bool downloadResumable; // need it for sending empty progress
- if (response.StatusCode == HttpStatusCode.PartialContent)
- {
- downloadResumable = true;
- }
- else // sometimes a server that supports partial content will lose its ability to send partial content(weird behavior) and thus the download will lose its resumability
- {
- _logger.Log("Resume Not Supported");
- existingLength = 0;
- downloadResumable = false;
- }
- OnResumabilityChanged(new DownloadStatusChangedEventArgs(downloadResumable));
- using (var saveFileStream = fileInfo.Open(downloadResumable ? FileMode.Append : FileMode.Create, FileAccess.Write))
- using (var stream = response.GetResponseStream())
- {
- byte[] downBuffer = new byte[4096];
- int byteSize = 0;
- long totalReceived = byteSize + existingLength;
- var sw = Stopwatch.StartNew();
- while (!stop && (byteSize = stream.Read(downBuffer, 0, downBuffer.Length)) > 0)
- {
- saveFileStream.Write(downBuffer, 0, byteSize);
- totalReceived += byteSize;
- var currentSpeed = totalReceived / sw.Elapsed.TotalSeconds;
- OnProgressChanged(new DownloadProgressChangedEventArgs(totalReceived, fileSize, (long)currentSpeed));
- }
- sw.Stop();
- }
- }
- if (!stop)
- OnCompleted(EventArgs.Empty);
- }
- catch (WebException e)
- {
- _logger.Log(e);
- }
- }
- public void StopDownload()
- {
- stop = true;
- }
- protected virtual void OnResumabilityChanged(DownloadStatusChangedEventArgs e)
- {
- var handler = ResumablityChanged;
- if (handler != null)
- {
- handler(this, e);
- }
- }
- protected virtual void OnProgressChanged(DownloadProgressChangedEventArgs e)
- {
- var handler = ProgressChanged;
- if (handler != null)
- {
- handler(this, e);
- }
- }
- protected virtual void OnCompleted(EventArgs e)
- {
- var handler = Completed;
- if (handler != null)
- {
- handler(this, e);
- }
- }
- }
- public class DownloadStatusChangedEventArgs : EventArgs
- {
- public DownloadStatusChangedEventArgs(bool canResume)
- {
- ResumeSupported = canResume;
- }
- public bool ResumeSupported { get; private set; }
- }
- public class DownloadProgressChangedEventArgs : EventArgs
- {
- public DownloadProgressChangedEventArgs(long totalReceived, long fileSize, long currentSpeed)
- {
- BytesReceived = totalReceived;
- TotalBytesToReceive = fileSize;
- CurrentSpeed = currentSpeed;
- }
- public long BytesReceived { get; private set; }
- public long TotalBytesToReceive { get; private set; }
- public float ProgressPercentage { get { return ((float)BytesReceived / (float)TotalBytesToReceive) * 100; } }
- /// <summary>in Bytes</summary>
- public long CurrentSpeed { get; private set; }
- public TimeSpan TimeLeft
- {
- get
- {
- var bytesRemainingtoBeReceived = TotalBytesToReceive - BytesReceived;
- return TimeSpan.FromSeconds(bytesRemainingtoBeReceived / CurrentSpeed);
- }
- }
- }
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.Net;
- using System.Threading;
- namespace Downloader
- {
- public interface ILogger
- {
- void LogMessage(string message, params Object[] args);
- }
- public class ConsoleLogger : ILogger
- {
- public void LogMessage(string message, params Object[] args)
- {
- Console.WriteLine(string.Format(message, args));
- }
- }
- public class Download
- {
- private ILogger _Logger;
- public CallingClass(ILogger logger)
- {
- _Logger = logger;
- }
- public event EventHandler<DownloadStatusChangedEventArgs> ResumablityChanged;
- public event EventHandler<DownloadProgressChangedEventArgs> ProgressChanged;
- public event EventHandler Completed;
- public bool stop = true; // by default stop is true
- public bool paused = false;
- SemaphoreSlim pauseLock = new SemaphoreSlim(1);
- string filename;
- public void DownloadFile(string DownloadLink, string Path)
- {
- filename = System.IO.Path.GetFileName(Path);
- stop = false; // always set this bool to false, everytime this method is called
- var fileInfo = new FileInfo(Path);
- long existingLength = 0;
- if (fileInfo.Exists)
- existingLength = fileInfo.Length;
- var request = (HttpWebRequest)HttpWebRequest.Create(DownloadLink);
- request.Proxy = null;
- request.AddRange(existingLength);
- try
- {
- using (var response = (HttpWebResponse)request.GetResponse())
- {
- long fileSize = existingLength + response.ContentLength; //response.ContentLength gives me the size that is remaining to be downloaded
- bool downloadResumable; // need it for not sending any progress
- if ((int)response.StatusCode == 206) //same as: response.StatusCode == HttpStatusCode.PartialContent
- {
- logger.LogMessage("Resumable");
- downloadResumable = true;
- }
- else // sometimes a server that supports partial content will lose its ability to send partial content(weird behavior) and thus the download will lose its resumability
- {
- logger.LogMessage("Not Resumable");
- existingLength = 0;
- downloadResumable = false;
- }
- OnResumabilityChanged(new DownloadStatusChangedEventArgs(downloadResumable));
- using (var saveFileStream = fileInfo.Open(downloadResumable ? FileMode.Append : FileMode.Create, FileAccess.Write))
- using (var stream = response.GetResponseStream())
- {
- byte[] downBuffer = new byte[4096];
- int byteSize = 0;
- long totalReceived = byteSize + existingLength;
- var sw = Stopwatch.StartNew();
- while (!stop && (byteSize = stream.Read(downBuffer, 0, downBuffer.Length)) > 0)
- {
- saveFileStream.Write(downBuffer, 0, byteSize);
- totalReceived += byteSize;
- float currentSpeed = totalReceived / (float)sw.Elapsed.TotalSeconds;
- OnProgressChanged(new DownloadProgressChangedEventArgs(totalReceived, fileSize, (long)currentSpeed));
- pauseLock.Wait();
- pauseLock.Release();
- }
- sw.Stop();
- }
- }
- if (!stop) OnCompleted(EventArgs.Empty);
- }
- catch (WebException e)
- {
- logger.LogMessage(e);
- }
- }
- public void pause()
- {
- if (!paused)
- {
- paused = true;
- // Note this cannot block for more than a moment
- // since the download thread doesn't keep the lock held
- pauseLock.Wait();
- }
- }
- public void unpause()
- {
- if (paused)
- {
- paused = false;
- pauseLock.Release();
- }
- }
- public void StopDownload()
- {
- stop = true;
- this.unpause(); // stop waiting on lock if needed
- }
- protected virtual void OnResumabilityChanged(DownloadStatusChangedEventArgs e)
- {
- var handler = ResumablityChanged;
- if (handler != null)
- {
- handler(this, e);
- }
- }
- protected virtual void OnProgressChanged(DownloadProgressChangedEventArgs e)
- {
- var handler = ProgressChanged;
- if (handler != null)
- {
- handler(this, e);
- }
- }
- protected virtual void OnCompleted(EventArgs e)
- {
- var handler = Completed;
- if (handler != null)
- {
- handler(this, e);
- }
- }
- }
- public class DownloadStatusChangedEventArgs : EventArgs
- {
- public DownloadStatusChangedEventArgs(bool canResume)
- {
- ResumeSupported = canResume;
- }
- public bool ResumeSupported { get; private set; }
- }
- public class DownloadProgressChangedEventArgs : EventArgs
- {
- public DownloadProgressChangedEventArgs(long totalReceived, long fileSize, long currentSpeed)
- {
- BytesReceived = totalReceived;
- TotalBytesToReceive = fileSize;
- CurrentSpeed = currentSpeed;
- }
- public long BytesReceived { get; private set; }
- public long TotalBytesToReceive { get; private set; }
- public float ProgressPercentage
- {
- get
- {
- return ((float)BytesReceived / (float)TotalBytesToReceive) * 100;
- }
- }
- public float CurrentSpeed { get; private set; } // in bytes
- public TimeSpan TimeLeft
- {
- get
- {
- var bytesRemainingtoBeReceived = TotalBytesToReceive - BytesReceived;
- return TimeSpan.FromSeconds(bytesRemainingtoBeReceived / CurrentSpeed);
- }
- }
- }
- }
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.Net;
- using System.Threading;
- namespace Downloader
- {
- public interface ILogger
- {
- void LogMessage(string message, params Object[] args);
- }
- public class ConsoleLogger : ILogger
- {
- public void LogMessage(string message, params Object[] args)
- {
- Console.WriteLine(string.Format(message, args));
- }
- }
- public class Download
- {
- private ILogger _Logger;
- public CallingClass(ILogger logger)
- {
- _Logger = logger;
- }
- public event EventHandler<DownloadStatusChangedEventArgs> ResumablityChanged;
- public event EventHandler<DownloadProgressChangedEventArgs> ProgressChanged;
- public event EventHandler Completed;
- public bool stop = true; // by default stop is true
- public bool paused = false;
- SemaphoreSlim pauseLock = new SemaphoreSlim(1);
- string filename;
- public void DownloadFile(string DownloadLink, string Path)
- {
- filename = System.IO.Path.GetFileName(Path);
- stop = false; // always set this bool to false, everytime this method is called
- var fileInfo = new FileInfo(Path);
- long existingLength = 0;
- if (fileInfo.Exists)
- existingLength = fileInfo.Length;
- var request = (HttpWebRequest)HttpWebRequest.Create(DownloadLink);
- request.Proxy = null;
- request.AddRange(existingLength);
- try
- {
- using (var response = (HttpWebResponse)request.GetResponse())
- {
- long fileSize = existingLength + response.ContentLength; //response.ContentLength gives me the size that is remaining to be downloaded
- bool downloadResumable; // need it for not sending any progress
- if ((int)response.StatusCode == 206) //same as: response.StatusCode == HttpStatusCode.PartialContent
- {
- logger.LogMessage("Resumable");
- downloadResumable = true;
- }
- else // sometimes a server that supports partial content will lose its ability to send partial content(weird behavior) and thus the download will lose its resumability
- {
- logger.LogMessage("Not Resumable");
- if (existingLength > 0)
- {
- if (ResumeUnsupportedWarning() == false) // warn and ask for confirmation to continue if the half downloaded file is unresumable
- {
- return;
- }
- }
- existingLength = 0;
- downloadResumable = false;
- }
- OnResumabilityChanged(new DownloadStatusChangedEventArgs(downloadResumable));
- using (var saveFileStream = fileInfo.Open(downloadResumable ? FileMode.Append : FileMode.Create, FileAccess.Write))
- using (var stream = response.GetResponseStream())
- {
- byte[] downBuffer = new byte[4096];
- int byteSize = 0;
- long totalReceived = byteSize + existingLength;
- var sw = Stopwatch.StartNew();
- while (!stop && (byteSize = stream.Read(downBuffer, 0, downBuffer.Length)) > 0)
- {
- saveFileStream.Write(downBuffer, 0, byteSize);
- totalReceived += byteSize;
- float currentSpeed = totalReceived / (float)sw.Elapsed.TotalSeconds;
- OnProgressChanged(new DownloadProgressChangedEventArgs(totalReceived, fileSize, (long)currentSpeed));
- pauseLock.Wait();
- pauseLock.Release();
- }
- sw.Stop();
- }
- }
- if (!stop) OnCompleted(EventArgs.Empty);
- }
- catch (WebException e)
- {
- System.Windows.MessageBox.Show(e.Message, filename);
- }
- }
- public void pause()
- {
- if (!paused)
- {
- paused = true;
- // Note this cannot block for more than a moment
- // since the download thread doesn't keep the lock held
- pauseLock.Wait();
- }
- }
- public void unpause()
- {
- if (paused)
- {
- paused = false;
- pauseLock.Release();
- }
- }
- public void StopDownload()
- {
- stop = true;
- this.unpause(); // stop waiting on lock if needed
- }
- public bool ResumeUnsupportedWarning()
- {
- var messageBoxResult = System.Windows.MessageBox.Show("When trying to resume the download , Mackerel got a response from the server that it doesn't support resuming the download. It's possible that it's a temporary error of the server, and you will be able to resume the file at a later time, but at this time Mackerel can download this file from the beginning.nnDo you want to download this file from the beginning?", filename, System.Windows.MessageBoxButton.YesNo);
- if (messageBoxResult == System.Windows.MessageBoxResult.Yes)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- protected virtual void OnResumabilityChanged(DownloadStatusChangedEventArgs e)
- {
- var handler = ResumablityChanged;
- if (handler != null)
- {
- handler(this, e);
- }
- }
- protected virtual void OnProgressChanged(DownloadProgressChangedEventArgs e)
- {
- var handler = ProgressChanged;
- if (handler != null)
- {
- handler(this, e);
- }
- }
- protected virtual void OnCompleted(EventArgs e)
- {
- var handler = Completed;
- if (handler != null)
- {
- handler(this, e);
- }
- }
- }
- public class DownloadStatusChangedEventArgs : EventArgs
- {
- public DownloadStatusChangedEventArgs(bool canResume)
- {
- ResumeSupported = canResume;
- }
- public bool ResumeSupported { get; private set; }
- }
- public class DownloadProgressChangedEventArgs : EventArgs
- {
- public DownloadProgressChangedEventArgs(long totalReceived, long fileSize, long currentSpeed)
- {
- BytesReceived = totalReceived;
- TotalBytesToReceive = fileSize;
- CurrentSpeed = currentSpeed;
- }
- public long BytesReceived { get; private set; }
- public long TotalBytesToReceive { get; private set; }
- public float ProgressPercentage
- {
- get
- {
- return ((float)BytesReceived / (float)TotalBytesToReceive) * 100;
- }
- }
- public float CurrentSpeed { get; private set; } // in bytes
- public TimeSpan TimeLeft
- {
- get
- {
- var bytesRemainingtoBeReceived = TotalBytesToReceive - BytesReceived;
- return TimeSpan.FromSeconds(bytesRemainingtoBeReceived / CurrentSpeed);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement