public void Finished() { DownloadState = DownloadStates.Finished; ProgressPercentage = 100; //100% DownloadedSize = FileSize; AssociatedDownloadControl.UpdateProgress(); }
public void Resume() { if (DownloadState == DownloadStates.Paused) { DownloadState = DownloadStates.InProgress; Task.Run(() => Downloading()); } }
// Pause download public void Pause() { if (DownloadState == DownloadStates.InProgress) { DownloadState = DownloadStates.Paused; AssociatedDownloadControl.UpdateProgress(); } }
public void Start() { if (DownloadState == DownloadStates.PreStart || DownloadState == DownloadStates.Paused) { DownloadState = DownloadStates.InProgress; StartDownload(); } }
public void Cancel() { if (DownloadState == DownloadStates.InProgress) { DownloadState = DownloadStates.Canceled; ResetProperties(); AssociatedDownloadControl.UpdateProgress(); } }
public TorrentInfo(InfoHash hash, string name, int priority, ActiveStates activestate, DownloadStates downloadstate, IEnumerable<string> labels, ulong size, ulong remaining, ulong uploaded) { Hash = hash; Name = name; Priority = priority; ActiveState = activestate; DownloadState = downloadstate; Labels = new ReadOnlyCollection<string>(new List<string>(labels)); Size = size; Remaining = remaining; Uploaded = uploaded; }
int GetImageIndex(DownloadStates status) { if ((status & DownloadStates.Remove) != 0) { return 1; } else if ((status & DownloadStates.Installed) != 0) { return 2; } else if ((status & DownloadStates.Add) != 0) { return 3; } return 0; }
// Restart download public void Restart() { if (DownloadState == DownloadStates.Canceled || DownloadState == DownloadStates.Finished) { ResetProperties(); if (File.Exists(DownloadTo)) { File.Delete(DownloadTo); } DownloadState = DownloadStates.PreStart; AssociatedDownloadControl.UpdateProgress(); Task.Run(() => AssociatedDownloadControl.AssociatedView.Dispatcher.Invoke(() => { Start(); })); } }
//Preset None, Add, Remove, (Oma, installoitu. //Update Add (Available), Remove (Disable), None (Installed) string GetStatusText(bool preset, DownloadStates status) { //If latest version is installed. if (status == DownloadStates.None) { if (preset) { return "None"; } //If new version is available. return "Available"; } if ((status & DownloadStates.Remove) != 0) { if (preset) { return "Remove"; } return "Disable"; } //Item is marked as downloaded. if ((status & DownloadStates.Add) != 0) { if (preset) { return "Add"; } return "Download"; } /* //If new version is available. if ((status & DownloadStates.Available) != 0) { return "Available"; } * */ if ((status & DownloadStates.Installed) != 0) { return "Installed"; } throw new Exception("Invalid status."); }
DownloadStates ToggleState(bool preset, DownloadStates status) { //If latest version is installed. if (status == DownloadStates.None) { return DownloadStates.Add; } //Remove disabled status. if ((status & DownloadStates.Remove) != 0) { return status & ~DownloadStates.Remove; } //Remove download status. if ((status & DownloadStates.Add) != 0) { return DownloadStates.Remove; } //Do nothing if version is installed. if ((status & DownloadStates.Installed) != 0) { return DownloadStates.Installed; } throw new Exception("Invalid status."); }
void UpdateState(bool preset, object target, DownloadStates state) { TreeNode node = ItemToTreeNode[target] as TreeNode; ListViewItem li = ItemToListItem[target] as ListViewItem; if (target is GXDeviceManufacturer) { GXDeviceManufacturer item = target as GXDeviceManufacturer; item.Status = state; if (li != null) { li.SubItems[1].Text = GetStatusText(preset, item.Status); } if (node != null) { node.ImageIndex = node.SelectedImageIndex = GetImageIndex(item.Status); } foreach (GXDeviceModel it in item.Models) { UpdateState(preset, it, state); } } else if (target is GXDeviceModel) { GXDeviceModel item = target as GXDeviceModel; item.Status = state; if (li != null) { li.SubItems[1].Text = GetStatusText(preset, item.Status); } if (node != null) { node.ImageIndex = node.SelectedImageIndex = GetImageIndex(item.Status); } foreach (GXDeviceVersion it in item.Versions) { UpdateState(preset, it, state); } } else if (target is GXDeviceVersion) { GXDeviceVersion item = target as GXDeviceVersion; item.Status = state; if (li != null) { li.SubItems[1].Text = GetStatusText(preset, item.Status); } if (node != null) { node.ImageIndex = node.SelectedImageIndex = GetImageIndex(item.Status); } foreach (GXPublishedDeviceProfile it in item.Templates) { UpdateState(preset, it, state); } } else if (target is GXPublishedDeviceProfile) { GXPublishedDeviceProfile item = target as GXPublishedDeviceProfile; item.Status = state; if (li != null) { li.SubItems[1].Text = GetStatusText(preset, item.Status); } if (node != null) { node.ImageIndex = node.SelectedImageIndex = GetImageIndex(item.Status); } } else if (target is GXDeviceProfileVersion) { GXDeviceProfileVersion item = target as GXDeviceProfileVersion; if (item.Status == DownloadStates.Installed && state == DownloadStates.Remove) { throw new Exception("Can't disable installed template."); } item.Status = state; if (li != null) { li.SubItems[1].Text = GetStatusText(preset, item.Status); } } else { throw new Exception("Unknown target type."); } }
/// <summary> /// Initializes a new instance of the <see cref="DownloadStateChangedEventArgs"/> class. /// </summary> /// <param name="previousState">The previous state of the download.</param> /// <param name="download">The download which raised the event.</param> internal DownloadStateChangedEventArgs(DownloadStates previousState, Download download) : base(download) { PreviousState = previousState; }
private static void WebClient_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { DownloadState = DownloadStates.Downloaded; }
private static void WebClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { DownloadState = DownloadStates.Downloading; }
internal void DownloadStateChangedEventArgs_Instantiates_With_The_Given_Data(string username, string filename, int token, DownloadStates downloadStates) { var dl = new Download(username, filename, token); var d = new DownloadStateChangedEventArgs(downloadStates, dl); Assert.Equal(downloadStates, d.PreviousState); }