예제 #1
0
 public UploadInfoManager(ListView listView)
 {
     lv = listView;
     parser = new UploadInfoParser();
 }
예제 #2
0
파일: UploadTask.cs 프로젝트: rijuG/ShareX
        private void DoAfterUploadJobs()
        {
            try
            {
                if (Info.Job != TaskJob.ShareURL && (Info.TaskSettings.AfterUploadJob.HasFlag(AfterUploadTasks.UseURLShortener) || Info.Job == TaskJob.ShortenURL ||
                    (Info.TaskSettings.AdvancedSettings.AutoShortenURLLength > 0 && Info.Result.URL.Length > Info.TaskSettings.AdvancedSettings.AutoShortenURLLength)))
                {
                    UploadResult result = ShortenURL(Info.Result.URL);

                    if (result != null)
                    {
                        Info.Result.ShortenedURL = result.ShortenedURL;
                    }
                }

                if (Info.Job != TaskJob.ShortenURL && (Info.TaskSettings.AfterUploadJob.HasFlag(AfterUploadTasks.ShareURL) || Info.Job == TaskJob.ShareURL))
                {
                    ShareURL(Info.Result.ToString());
                    if (Info.Job == TaskJob.ShareURL) Info.Result.IsURLExpected = false;
                }

                if (Info.TaskSettings.AfterUploadJob.HasFlag(AfterUploadTasks.CopyURLToClipboard))
                {
                    string txt;

                    if (!string.IsNullOrEmpty(Info.TaskSettings.AdvancedSettings.ClipboardContentFormat))
                    {
                        txt = new UploadInfoParser().Parse(Info, Info.TaskSettings.AdvancedSettings.ClipboardContentFormat);
                    }
                    else
                    {
                        txt = Info.Result.ToString();
                    }

                    if (!string.IsNullOrEmpty(txt))
                    {
                        ClipboardHelpers.CopyText(txt);
                    }
                }

                if (Info.TaskSettings.AfterUploadJob.HasFlag(AfterUploadTasks.OpenURL))
                {
                    string result;

                    if (!string.IsNullOrEmpty(Info.TaskSettings.AdvancedSettings.OpenURLFormat))
                    {
                        result = new UploadInfoParser().Parse(Info, Info.TaskSettings.AdvancedSettings.OpenURLFormat);
                    }
                    else
                    {
                        result = Info.Result.ToString();
                    }

                    URLHelpers.OpenURL(result);
                }

                if (Info.TaskSettings.AfterUploadJob.HasFlag(AfterUploadTasks.ShowQRCode))
                {
                    threadWorker.InvokeAsync(() => new QRCodeForm(Info.Result.ToString()).Show());
                }
            }
            catch (Exception e)
            {
                DebugHelper.WriteException(e);
                if (Info.Result == null) Info.Result = new UploadResult();
                Info.Result.Errors.Add(e.ToString());
            }
        }
예제 #3
0
        private static void task_UploadCompleted(UploadTask 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 = "Error";
                                lvi.SubItems[8].Text = string.Empty;
                                lvi.ImageIndex = 1;
                            }

                            if (Program.Settings.PlaySoundAfterUpload)
                            {
                                SystemSounds.Asterisk.Play();
                            }
                        }
                        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[8].Text = result;
                                }
                            }

                            if (!task.IsStopped && !string.IsNullOrEmpty(result))
                            {
                                if (Program.Settings.SaveHistory)
                                {
                                    HistoryManager.ConvertHistoryToNewFormat(Program.HistoryFilePath, Program.OldHistoryFilePath);
                                    HistoryManager.AddHistoryItemAsync(Program.HistoryFilePath, info.GetHistoryItem());
                                }

                                if (!info.TaskSettings.AdvancedSettings.DisableNotifications)
                                {
                                    string balloonTipText = result;

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

                                    if (Program.Settings.TrayBalloonTipAfterUpload && Program.MainForm.niTray.Visible)
                                    {
                                        Program.MainForm.niTray.Tag = result;
                                        Program.MainForm.niTray.ShowBalloonTip(5000, "ShareX - Task completed", balloonTipText, ToolTipIcon.Info);
                                    }

                                    if (Program.Settings.PlaySoundAfterUpload)
                                    {
                                        SystemSounds.Exclamation.Play();
                                    }
                                }
                            }
                        }

                        if (lvi != null)
                        {
                            lvi.EnsureVisible();
                        }
                    }
                }
            }
            finally
            {
                StartTasks();
                UpdateProgressUI();
            }
        }
예제 #4
0
        private void DoAfterUploadJobs()
        {
            try
            {
                if (Info.TaskSettings.AfterUploadJob.HasFlag(AfterUploadTasks.UseURLShortener) || Info.Job == TaskJob.ShortenURL ||
                    (Info.TaskSettings.AdvancedSettings.AutoShortenURLLength > 0 && Info.Result.URL.Length > Info.TaskSettings.AdvancedSettings.AutoShortenURLLength))
                {
                    UploadResult result = ShortenURL(Info.Result.URL);

                    if (result != null)
                    {
                        Info.Result.ShortenedURL = result.ShortenedURL;
                    }
                }

                if (Info.TaskSettings.AfterUploadJob.HasFlag(AfterUploadTasks.ShareURLToSocialNetworkingService))
                {
                    OAuthInfo twitterOAuth = Program.UploadersConfig.TwitterOAuthInfoList.ReturnIfValidIndex(Program.UploadersConfig.TwitterSelectedAccount);

                    if (twitterOAuth != null)
                    {
                        using (TwitterMsg twitter = new TwitterMsg(twitterOAuth))
                        {
                            twitter.Message = Info.Result.ToString();
                            twitter.Config = Program.UploadersConfig.TwitterClientConfig;
                            twitter.ShowDialog();
                        }
                    }
                }

                if (Info.TaskSettings.AfterUploadJob.HasFlag(AfterUploadTasks.SendURLWithEmail))
                {
                    using (EmailForm emailForm = new EmailForm(Program.UploadersConfig.EmailRememberLastTo ? Program.UploadersConfig.EmailLastTo : string.Empty,
                        Program.UploadersConfig.EmailDefaultSubject, Info.Result.ToString()))
                    {
                        emailForm.Icon = ShareXResources.Icon;

                        if (emailForm.ShowDialog() == DialogResult.OK)
                        {
                            if (Program.UploadersConfig.EmailRememberLastTo)
                            {
                                Program.UploadersConfig.EmailLastTo = emailForm.ToEmail;
                            }

                            Email email = new Email
                            {
                                SmtpServer = Program.UploadersConfig.EmailSmtpServer,
                                SmtpPort = Program.UploadersConfig.EmailSmtpPort,
                                FromEmail = Program.UploadersConfig.EmailFrom,
                                Password = Program.UploadersConfig.EmailPassword
                            };

                            email.Send(emailForm.ToEmail, emailForm.Subject, emailForm.Body);
                        }
                    }
                }

                if (Info.TaskSettings.AfterUploadJob.HasFlag(AfterUploadTasks.CopyURLToClipboard))
                {
                    string txt;

                    if (!string.IsNullOrEmpty(Info.TaskSettings.AdvancedSettings.ClipboardContentFormat))
                    {
                        txt = new UploadInfoParser().Parse(Info, Info.TaskSettings.AdvancedSettings.ClipboardContentFormat);
                    }
                    else
                    {
                        txt = Info.Result.ToString();
                    }

                    if (!string.IsNullOrEmpty(txt))
                    {
                        ClipboardHelpers.CopyText(txt);
                    }
                }

                if (Info.TaskSettings.AfterUploadJob.HasFlag(AfterUploadTasks.ShowQRCode))
                {
                    threadWorker.InvokeAsync(() => new QRCodeForm(Info.Result.ToString()).Show());
                }
            }
            catch (Exception e)
            {
                DebugHelper.WriteException(e);
                if (Info.Result == null) Info.Result = new UploadResult();
                Info.Result.Errors.Add(e.ToString());
            }
        }
예제 #5
0
        private static void task_UploadCompleted(UploadTask 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 = "Error";
                                lvi.SubItems[6].Text = string.Empty;
                                lvi.ImageIndex = 1;
                            }

                            if (task.Info.TaskSettings.GeneralSettings.PlaySoundAfterUpload)
                            {
                                SystemSounds.Asterisk.Play();
                            }
                        }
                        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 (task.Info.TaskSettings.GeneralSettings.SaveHistory)
                                {
                                    HistoryManager.AddHistoryItemAsync(Program.HistoryFilePath, info.GetHistoryItem());
                                }

                                if (!info.TaskSettings.AdvancedSettings.DisableNotifications)
                                {
                                    if (task.Info.TaskSettings.GeneralSettings.PlaySoundAfterUpload)
                                    {
                                        SystemSounds.Exclamation.Play();
                                    }

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

                                    TaskHelpers.ShowResultNotifications(result, info.TaskSettings, info.FilePath);

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

                        if (lvi != null)
                        {
                            lvi.EnsureVisible();
                        }
                    }
                }
            }
            finally
            {
                StartTasks();
                UpdateProgressUI();
            }
        }
예제 #6
0
파일: TaskManager.cs 프로젝트: barsv/ShareX
        private static void task_UploadCompleted(UploadTask 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 = "Error";
                                lvi.SubItems[6].Text = string.Empty;
                                lvi.ImageIndex = 1;
                            }

                            if (task.Info.TaskSettings.GeneralSettings.PlaySoundAfterUpload)
                            {
                                Helpers.PlaySoundAsync(Resources.ErrorSound);
                            }
                        }
                        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 (task.Info.TaskSettings.GeneralSettings.SaveHistory)
                                {
                                    HistoryManager.AddHistoryItemAsync(Program.HistoryFilePath, info.GetHistoryItem());
                                }

                                if (!info.TaskSettings.AdvancedSettings.DisableNotifications && info.Job != TaskJob.ShareURL)
                                {
                                    if (task.Info.TaskSettings.GeneralSettings.PlaySoundAfterUpload)
                                    {
                                        Helpers.PlaySoundAsync(Resources.TaskCompletedSound);
                                    }

                                    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, "ShareX - Task completed", result, ToolTipIcon.Info);
                                                }
                                                break;
                                            case PopUpNotificationType.ToastNotification:
                                                NotificationFormConfig toastConfig = new NotificationFormConfig()
                                                {
                                                    Action = info.TaskSettings.AdvancedSettings.ToastWindowClickAction,
                                                    FilePath = info.FilePath,
                                                    Text = "ShareX - 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
            {
                StartTasks();
                UpdateProgressUI();
            }
        }