private Task(EDataType dataType, TaskJob job) { Status = TaskStatus.InQueue; Info = new UploadInfo(); Info.Job = job; Info.DataType = dataType; Info.UploadDestination = dataType; }
private static void ChangeListViewItemStatus(UploadInfo info) { if (ListViewControl != null) { ListViewItem lvi = ListViewControl.Items[info.ID]; lvi.SubItems[1].Text = info.Status; } }
private static void task_UploadProgressChanged(UploadInfo info) { if (ListViewControl != null) { ListViewItem lvi = ListViewControl.Items[info.ID]; lvi.SubItems[2].Text = string.Format("{0:N0}% {1:N0} KiB / {2:N0} KiB", info.Progress.Percentage, info.Progress.Position / 1024, info.Progress.Length / 1024); lvi.SubItems[3].Text = string.Format("{0:N0} kB/s", info.Progress.Speed); lvi.SubItems[4].Text = ProperTimeSpan(info.Progress.Elapsed); lvi.SubItems[5].Text = ProperTimeSpan(info.Progress.Remaining); } }
private static void task_UploadStarted(UploadInfo info) { string status = string.Format("Upload started. ID: {0}, Filename: {1}", info.ID, info.FileName); if (!string.IsNullOrEmpty(info.FilePath)) { status += ", Filepath: " + info.FilePath; } Program.MyLogger.WriteLine(status); ListViewItem lvi = ListViewControl.Items[info.ID]; lvi.Text = info.FileName; lvi.SubItems[1].Text = info.Status; lvi.ImageIndex = 0; }
private static void CreateListViewItem(UploadInfo info) { if (ListViewControl != null) { Program.MyLogger.WriteLine("Upload in queue. ID: {0}, Job: {1}, Type: {2}, Host: {3}", info.ID, info.Job, info.UploadDestination, info.UploaderHost); ListViewItem lvi = new ListViewItem(); lvi.Text = info.FileName; lvi.SubItems.Add("In queue"); lvi.SubItems.Add(string.Empty); lvi.SubItems.Add(string.Empty); lvi.SubItems.Add(string.Empty); lvi.SubItems.Add(string.Empty); lvi.SubItems.Add(info.DataType.ToString()); lvi.SubItems.Add(info.UploaderHost); lvi.SubItems.Add(string.Empty); lvi.BackColor = info.ID % 2 == 0 ? Color.White : Color.WhiteSmoke; lvi.ImageIndex = 3; ListViewControl.Items.Add(lvi); lvi.EnsureVisible(); ListViewControl.FillLastColumn(); } }
private static void task_UploadStarted(UploadInfo info) { string status = string.Format("Upload started. ID: {0}, Filename: {1}", info.ID, info.FileName); if (!string.IsNullOrEmpty(info.FilePath)) status += ", Filepath: " + info.FilePath; Program.MyLogger.WriteLine(status); ListViewItem lvi = ListViewControl.Items[info.ID]; lvi.Text = info.FileName; lvi.SubItems[1].Text = info.Status; lvi.ImageIndex = 0; }
private static void task_UploadPreparing(UploadInfo info) { UpdateTrayIcon(); Program.MyLogger.WriteLine("Upload preparing. ID: {0}", info.ID); ChangeListViewItemStatus(info); }
private static void task_UploadCompleted(UploadInfo info) { try { if (ListViewControl != null && info != null && info.Result != null) { ListViewItem lvi = ListViewControl.Items[info.ID]; lvi.Tag = info.Result; if (info.Result.IsError) { string errors = string.Join("\r\n\r\n", info.Result.Errors.ToArray()); Program.MyLogger.WriteLine("Upload failed. ID: {0}, Filename: {1}, Errors:\r\n{2}", info.ID, info.FileName, errors); lvi.SubItems[1].Text = "Error"; lvi.SubItems[8].Text = string.Empty; lvi.ImageIndex = 1; if (Program.Settings.AutoPlaySound) { SystemSounds.Asterisk.Play(); } } else { Program.MyLogger.WriteLine("Upload completed. ID: {0}, Filename: {1}, URL: {2}, Duration: {3}ms", info.ID, info.FileName, info.Result.URL, (int)info.UploadDuration.TotalMilliseconds); lvi.SubItems[1].Text = info.Status; lvi.ImageIndex = 2; if (!string.IsNullOrEmpty(info.Result.URL)) { string url = string.IsNullOrEmpty(info.Result.ShortenedURL) ? info.Result.URL : info.Result.ShortenedURL; lvi.SubItems[8].Text = url; if (Program.Settings.ClipboardAutoCopy) { ZAppHelper.CopyTextSafely(url); } if (Program.Settings.SaveHistory) { HistoryManager.AddHistoryItemAsync(Program.HistoryFilePath, info.GetHistoryItem()); } if (Program.mainForm.niTray.Visible) { Program.mainForm.niTray.Tag = url; Program.mainForm.niTray.ShowBalloonTip(5000, "ZUploader - Upload completed", url, ToolTipIcon.Info); } } if (Program.Settings.AutoPlaySound) { SystemSounds.Exclamation.Play(); } } lvi.EnsureVisible(); } } finally { StartTasks(); UpdateTrayIcon(); } }