Ejemplo n.º 1
0
        public static void Remove(WorkerTask task)
        {
            if (task != null)
            {
                task.Stop();
                Tasks.Remove(task);
                UpdateMainFormTip();

                ListViewItem lvi = FindListViewItem(task);

                if (lvi != null)
                {
                    ListViewControl.Items.Remove(lvi);
                }

                task.Dispose();
            }
        }
Ejemplo n.º 2
0
 public static WorkerTask CreateURLShortenerTask(string url, TaskSettings taskSettings)
 {
     WorkerTask task = new WorkerTask(taskSettings);
     task.Info.Job = TaskJob.ShortenURL;
     task.Info.DataType = EDataType.URL;
     task.Info.FileName = string.Format(Resources.UploadTask_CreateURLShortenerTask_Shorten_URL___0__, taskSettings.URLShortenerDestination.GetLocalizedDescription());
     task.Info.Result.URL = url;
     return task;
 }
Ejemplo n.º 3
0
 public static WorkerTask CreateTextUploaderTask(string text, TaskSettings taskSettings)
 {
     WorkerTask task = new WorkerTask(taskSettings);
     task.Info.Job = TaskJob.TextUpload;
     task.Info.DataType = EDataType.Text;
     task.Info.FileName = TaskHelpers.GetFilename(taskSettings, taskSettings.AdvancedSettings.TextFileExtension);
     task.tempText = text;
     return task;
 }
Ejemplo n.º 4
0
 public static WorkerTask CreateImageUploaderTask(Image image, TaskSettings taskSettings)
 {
     WorkerTask task = new WorkerTask(taskSettings);
     task.Info.Job = TaskJob.Job;
     task.Info.DataType = EDataType.Image;
     task.Info.FileName = TaskHelpers.GetImageFilename(taskSettings, image);
     task.tempImage = image;
     return task;
 }
Ejemplo n.º 5
0
        public static WorkerTask CreateFileUploaderTask(string filePath, TaskSettings taskSettings)
        {
            WorkerTask task = new WorkerTask(taskSettings);
            task.Info.FilePath = filePath;
            task.Info.DataType = TaskHelpers.FindDataType(task.Info.FilePath, taskSettings);

            if (task.Info.TaskSettings.UploadSettings.FileUploadUseNamePattern)
            {
                string ext = Path.GetExtension(task.Info.FilePath);
                task.Info.FileName = TaskHelpers.GetFilename(task.Info.TaskSettings, ext);
            }

            if (task.Info.TaskSettings.AdvancedSettings.ProcessImagesDuringFileUpload && task.Info.DataType == EDataType.Image)
            {
                task.Info.Job = TaskJob.Job;
                task.tempImage = ImageHelpers.LoadImage(task.Info.FilePath);
            }
            else
            {
                task.Info.Job = TaskJob.FileUpload;

                if (!task.LoadFileStream())
                {
                    return null;
                }
            }

            return task;
        }
Ejemplo n.º 6
0
        public static WorkerTask CreateFileJobTask(string filePath, TaskSettings taskSettings)
        {
            WorkerTask task = new WorkerTask(taskSettings);
            task.Info.FilePath = filePath;
            task.Info.DataType = TaskHelpers.FindDataType(task.Info.FilePath, taskSettings);

            if (task.Info.TaskSettings.UploadSettings.FileUploadUseNamePattern)
            {
                string ext = Path.GetExtension(task.Info.FilePath);
                task.Info.FileName = TaskHelpers.GetFilename(task.Info.TaskSettings, ext);
            }

            task.Info.Job = TaskJob.Job;

            if (task.Info.IsUploadJob && !task.LoadFileStream())
            {
                return null;
            }

            return task;
        }
Ejemplo n.º 7
0
        public static WorkerTask CreateDownloadUploadTask(string url, TaskSettings taskSettings)
        {
            WorkerTask task = new WorkerTask(taskSettings);
            task.Info.Job = TaskJob.DownloadUpload;
            task.Info.DataType = TaskHelpers.FindDataType(url, taskSettings);

            string filename = URLHelpers.URLDecode(url, 10);
            filename = URLHelpers.GetFileName(filename);
            filename = Helpers.GetValidFileName(filename);

            if (string.IsNullOrEmpty(filename))
            {
                return null;
            }

            task.Info.FileName = filename;
            task.Info.Result.URL = url;
            return task;
        }
Ejemplo n.º 8
0
 public static WorkerTask CreateDataUploaderTask(EDataType dataType, Stream stream, string fileName, TaskSettings taskSettings)
 {
     WorkerTask task = new WorkerTask(taskSettings);
     task.Info.Job = TaskJob.DataUpload;
     task.Info.DataType = dataType;
     task.Info.FileName = fileName;
     task.Data = stream;
     return task;
 }
Ejemplo n.º 9
0
 public static void Start(WorkerTask task)
 {
     if (task != null)
     {
         Tasks.Add(task);
         UpdateMainFormTip();
         task.StatusChanged += task_StatusChanged;
         task.UploadStarted += task_UploadStarted;
         task.UploadProgressChanged += task_UploadProgressChanged;
         task.UploadCompleted += task_UploadCompleted;
         CreateListViewItem(task);
         StartTasks();
     }
 }
Ejemplo n.º 10
0
        private static void task_UploadProgressChanged(WorkerTask task)
        {
            if (task.Status == TaskStatus.Working && ListViewControl != null)
            {
                TaskInfo info = task.Info;

                ListViewItem lvi = FindListViewItem(task);

                if (lvi != null)
                {
                    lvi.SubItems[1].Text = string.Format("{0:0.0}%", info.Progress.Percentage);
                    lvi.SubItems[2].Text = string.Format("{0} / {1}", info.Progress.Position.ToSizeString(Program.Settings.BinaryUnits), info.Progress.Length.ToSizeString(Program.Settings.BinaryUnits));

                    if (info.Progress.Speed > 0)
                    {
                        lvi.SubItems[3].Text = ((long)info.Progress.Speed).ToSizeString(Program.Settings.BinaryUnits) + "/s";
                    }

                    lvi.SubItems[4].Text = Helpers.ProperTimeSpan(info.Progress.Elapsed);
                    lvi.SubItems[5].Text = Helpers.ProperTimeSpan(info.Progress.Remaining);
                }

                UpdateProgressUI();
            }
        }
Ejemplo n.º 11
0
        private static void task_UploadStarted(WorkerTask task)
        {
            TaskInfo info = task.Info;

            string status = string.Format("Upload started. Filename: {0}", info.FileName);
            if (!string.IsNullOrEmpty(info.FilePath)) status += ", Filepath: " + info.FilePath;
            DebugHelper.WriteLine(status);

            ListViewItem lvi = FindListViewItem(task);

            if (lvi != null)
            {
                lvi.Text = info.FileName;
                lvi.SubItems[1].Text = info.Status;
                lvi.ImageIndex = 0;
            }
        }
Ejemplo n.º 12
0
        private static void task_UploadCompleted(WorkerTask task)
        {
            try
            {
                if (ListViewControl != null && task != null)
                {
                    if (task.RequestSettingUpdate)
                    {
                        Program.MainForm.UpdateMainFormSettings();
                    }

                    TaskInfo info = task.Info;

                    if (info != null && info.Result != null)
                    {
                        ListViewItem lvi = FindListViewItem(task);

                        if (info.Result.IsError)
                        {
                            string errors = string.Join("\r\n\r\n", info.Result.Errors.ToArray());

                            DebugHelper.WriteLine("Task failed. Filename: {0}, Errors:\r\n{1}", info.FileName, errors);

                            if (lvi != null)
                            {
                                lvi.SubItems[1].Text = Resources.TaskManager_task_UploadCompleted_Error;
                                lvi.SubItems[6].Text = string.Empty;
                                lvi.ImageIndex = 1;
                            }

                            if (!info.TaskSettings.AdvancedSettings.DisableNotifications)
                            {
                                if (info.TaskSettings.GeneralSettings.PlaySoundAfterUpload)
                                {
                                    TaskHelpers.PlayErrorSound(info.TaskSettings);
                                }

                                if (info.TaskSettings.GeneralSettings.PopUpNotification != PopUpNotificationType.None && Program.MainForm.niTray.Visible && !string.IsNullOrEmpty(errors))
                                {
                                    Program.MainForm.niTray.Tag = null;
                                    Program.MainForm.niTray.ShowBalloonTip(5000, "ShareXYZ - " + Resources.TaskManager_task_UploadCompleted_Error, errors, ToolTipIcon.Error);
                                }
                            }
                        }
                        else
                        {
                            DebugHelper.WriteLine("Task completed. Filename: {0}, URL: {1}, Duration: {2} ms", info.FileName, info.Result.ToString(), (int)info.UploadDuration.TotalMilliseconds);

                            string result = info.Result.ToString();

                            if (string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(info.FilePath))
                            {
                                result = info.FilePath;
                            }

                            if (lvi != null)
                            {
                                lvi.Text = info.FileName;
                                lvi.SubItems[1].Text = info.Status;
                                lvi.ImageIndex = 2;

                                if (!string.IsNullOrEmpty(result))
                                {
                                    lvi.SubItems[6].Text = result;
                                }
                            }

                            if (!task.StopRequested && !string.IsNullOrEmpty(result))
                            {
                                if (info.TaskSettings.GeneralSettings.SaveHistory && (!info.TaskSettings.AdvancedSettings.HistorySaveOnlyURL ||
                                   (!string.IsNullOrEmpty(info.Result.URL) || !string.IsNullOrEmpty(info.Result.ShortenedURL))))
                                {
                                    HistoryManager.AddHistoryItemAsync(Program.HistoryFilePath, info.GetHistoryItem());
                                }

                                RecentManager.Add(result);

                                if (Program.Settings.RecentLinksRemember)
                                {
                                    Program.Settings.RecentLinks = RecentManager.Items.ToArray();
                                }
                                else
                                {
                                    Program.Settings.RecentLinks = null;
                                }

                                if (!info.TaskSettings.AdvancedSettings.DisableNotifications && info.Job != TaskJob.ShareURL)
                                {
                                    if (info.TaskSettings.GeneralSettings.PlaySoundAfterUpload)
                                    {
                                        TaskHelpers.PlayTaskCompleteSound(info.TaskSettings);
                                    }

                                    if (!string.IsNullOrEmpty(info.TaskSettings.AdvancedSettings.BalloonTipContentFormat))
                                    {
                                        result = new UploadInfoParser().Parse(info, info.TaskSettings.AdvancedSettings.BalloonTipContentFormat);
                                    }

                                    if (!string.IsNullOrEmpty(result))
                                    {
                                        switch (info.TaskSettings.GeneralSettings.PopUpNotification)
                                        {
                                            case PopUpNotificationType.BalloonTip:
                                                if (Program.MainForm.niTray.Visible)
                                                {
                                                    Program.MainForm.niTray.Tag = result;
                                                    Program.MainForm.niTray.ShowBalloonTip(5000, "ShareXYZ - " + Resources.TaskManager_task_UploadCompleted_ShareXYZ___Task_completed,
                                                        result, ToolTipIcon.Info);
                                                }
                                                break;
                                            case PopUpNotificationType.ToastNotification:
                                                NotificationFormConfig toastConfig = new NotificationFormConfig()
                                                {
                                                    Action = info.TaskSettings.AdvancedSettings.ToastWindowClickAction,
                                                    FilePath = info.FilePath,
                                                    Text = "ShareXYZ - " + Resources.TaskManager_task_UploadCompleted_ShareXYZ___Task_completed + "\r\n" + result,
                                                    URL = result
                                                };
                                                NotificationForm.Show((int)(info.TaskSettings.AdvancedSettings.ToastWindowDuration * 1000),
                                                    info.TaskSettings.AdvancedSettings.ToastWindowPlacement,
                                                    info.TaskSettings.AdvancedSettings.ToastWindowSize, toastConfig);
                                                break;
                                        }
                                    }

                                    if (info.TaskSettings.GeneralSettings.ShowAfterUploadForm)
                                    {
                                        AfterUploadForm dlg = new AfterUploadForm(info);
                                        NativeMethods.ShowWindow(dlg.Handle, (int)WindowShowStyle.ShowNoActivate);
                                    }
                                }
                            }
                        }

                        if (lvi != null)
                        {
                            lvi.EnsureVisible();
                        }
                    }
                }
            }
            finally
            {
                if (!IsBusy && Program.CLI.IsCommandExist("AutoClose"))
                {
                    Application.Exit();
                }
                else
                {
                    StartTasks();
                    UpdateProgressUI();
                }
            }
        }
Ejemplo n.º 13
0
 private static void task_StatusChanged(WorkerTask task)
 {
     DebugHelper.WriteLine("Task status: " + task.Status);
     ChangeListViewItemStatus(task);
     UpdateProgressUI();
 }
Ejemplo n.º 14
0
        private static ListViewItem FindListViewItem(WorkerTask task)
        {
            if (ListViewControl != null)
            {
                foreach (ListViewItem lvi in ListViewControl.Items)
                {
                    WorkerTask tag = lvi.Tag as WorkerTask;

                    if (tag != null && tag == task)
                    {
                        return lvi;
                    }
                }
            }

            return null;
        }
Ejemplo n.º 15
0
        private static void CreateListViewItem(WorkerTask task)
        {
            if (ListViewControl != null)
            {
                TaskInfo info = task.Info;

                DebugHelper.WriteLine("Task in queue. Job: {0}, Type: {1}, Host: {2}", info.Job, info.UploadDestination, info.UploaderHost);

                ListViewItem lvi = new ListViewItem();
                lvi.Tag = task;
                lvi.Text = info.FileName;
                lvi.SubItems.Add(Resources.TaskManager_CreateListViewItem_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(string.Empty);
                lvi.ImageIndex = 3;
                if (Program.Settings.ShowMostRecentTaskFirst)
                {
                    ListViewControl.Items.Insert(0, lvi);
                }
                else
                {
                    ListViewControl.Items.Add(lvi);
                }
                lvi.EnsureVisible();
                ListViewControl.FillLastColumn();
            }
        }
Ejemplo n.º 16
0
        private static void ChangeListViewItemStatus(WorkerTask task)
        {
            if (ListViewControl != null)
            {
                ListViewItem lvi = FindListViewItem(task);

                if (lvi != null)
                {
                    lvi.SubItems[1].Text = task.Info.Status;
                }
            }
        }