Пример #1
0
        protected void BwTask_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            WorkerTask bwTask = e.Result as WorkerTask;

            UploadManager.ShowUploadResults(bwTask, true);
            bwTask.Dispose();
        }
Пример #2
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();
            }
        }
Пример #3
0
        /// <summary>
        /// Sets Clipboard text and returns the content
        /// </summary>
        /// <returns></returns>
        public static void ShowUploadResults(WorkerTask task, bool showDialog)
        {
            if (!task.WorkflowConfig.ClipboardOverwrite && !Clipboard.ContainsFileDropList() && !Clipboard.ContainsImage() && !Clipboard.ContainsText() || task.WorkflowConfig.ClipboardOverwrite)
            {
                if (task.UploadResults.Count > 0)
                {
                    if (task.WorkflowConfig.DestConfig.TaskClipboardContent.Count > 1 || Engine.ConfigUI.ShowUploadResultsWindow || showDialog)
                    {
                        ClipboardOptions cmp = new ClipboardOptions(task);
                        cmp.Icon = Resources.zss_main;
                        if (showDialog)
                        {
                            cmp.ShowDialog();
                        }
                        else
                        {
                            NativeMethods.ShowWindow(cmp.Handle, (int)WindowShowStyle.ShowNoActivate);
                        }
                        showDialog = true;
                    }
                }

                if (task.WorkflowConfig.DestConfig.Outputs.Contains(OutputEnum.Clipboard))
                {
                    StringBuilder clipboardText = new StringBuilder();

                    if (task.JobIsImageToClipboard())
                    {
                        Adapter.CopyImageToClipboard(task.TempImage, task.WorkflowConfig.ClipboardForceBmp);
                    }
                    else if (task.WorkflowConfig.DestConfig.TaskClipboardContent.Contains(ClipboardContentEnum.Local))
                    {
                        foreach (UploadResult ur in task.UploadResults)
                        {
                            if (Engine.ConfigUI.ConfLinkFormat.Count > 0)
                            {
                                clipboardText.AppendLine(ur.GetUrlByType((LinkFormatEnum)task.WorkflowConfig.DestConfig.LinkFormat[0], ur.LocalFilePath));
                            }

                            if (!Engine.ConfigUI.ClipboardAppendMultipleLinks && clipboardText.Length > 0)
                            {
                                break;
                            }
                        }
                    }
                    else if (task.WorkflowConfig.DestConfig.TaskClipboardContent.Contains(ClipboardContentEnum.OCR))
                    {
                        if (!string.IsNullOrEmpty(task.OCRText))
                        {
                            clipboardText.Append(task.OCRText);
                        }
                    }

                    // If the user requests for the full image URL, preference is given for the Shortened URL is exists
                    else if (task.Job1 == EDataType.Image && task.WorkflowConfig.DestConfig.LinkFormat.Contains((int)LinkFormatEnum.FULL))
                    {
                        if (task.Job3 == WorkerTask.JobLevel3.ShortenURL && !string.IsNullOrEmpty(task.UploadResults[0].ShortenedURL))
                        {
                            foreach (UploadResult ur in task.UploadResults)
                            {
                                if (!string.IsNullOrEmpty(ur.ShortenedURL))
                                {
                                    clipboardText.AppendLine(ur.ShortenedURL);
                                    if (!Engine.ConfigUI.ClipboardAppendMultipleLinks && clipboardText.Length > 0)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        // If no shortened URL exists then default full URL will be used
                        else
                        {
                            foreach (UploadResult ur in task.UploadResults)
                            {
                                if (!string.IsNullOrEmpty(ur.URL))
                                {
                                    clipboardText.AppendLine(FileSystem.GetBrowserFriendlyUrl(ur.URL));
                                    if (!Engine.ConfigUI.ClipboardAppendMultipleLinks && clipboardText.Length > 0)
                                    {
                                        break;
                                    }
                                }
                            }
                            if (clipboardText.Length == 0 && task.WorkflowConfig.DestConfig.TaskClipboardContent.Contains(ClipboardContentEnum.Local))
                            {
                                foreach (UploadResult ur in task.UploadResults)
                                {
                                    if (!string.IsNullOrEmpty(ur.LocalFilePath))
                                    {
                                        clipboardText.AppendLine(ur.LocalFilePath);
                                        if (!Engine.ConfigUI.ClipboardAppendMultipleLinks && clipboardText.Length > 0)
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    else
                    {
                        // From this point onwards app needs to respect all other Clipboard URL modes for Images
                        if (task.UploadResults.Count > 0 && task.Job1 == EDataType.Image)
                        {
                            foreach (UploadResult ur in task.UploadResults)
                            {
                                if (task.WorkflowConfig.DestConfig.LinkFormat.Count > 0)
                                {
                                    clipboardText.AppendLine(ur.GetUrlByType((LinkFormatEnum)task.WorkflowConfig.DestConfig.LinkFormat[0], ur.URL));
                                }

                                if (!Engine.ConfigUI.ClipboardAppendMultipleLinks && clipboardText.Length > 0)
                                {
                                    break;
                                }
                            }
                        }
                        // Text and File catagories are still left to process. Exception for Google Translate
                        else if (task.Job1 == EDataType.Text && task.Job2 == WorkerTask.JobLevel2.Translate)
                        {
                            if (task.TranslationInfo != null)
                            {
                                clipboardText.AppendLine(task.TranslationInfo.Result);
                            }
                        }
                        // Text and File catagories are still left to process. If shortened URL exists, preference is given to that
                        else if (task.UploadResults.Count > 0 && task.Job3 == WorkerTask.JobLevel3.ShortenURL && !string.IsNullOrEmpty(task.UploadResults[0].ShortenedURL))
                        {
                            foreach (UploadResult ur in task.UploadResults)
                            {
                                if (!string.IsNullOrEmpty(ur.ShortenedURL))
                                {
                                    clipboardText.AppendLine(ur.ShortenedURL);
                                    break;
                                }
                            }
                        }
                        // Otherwise full URL for Text or File is used
                        else if (task.UploadResults.Count > 0)
                        {
                            clipboardText.AppendLine(FileSystem.GetBrowserFriendlyUrl(task.UploadResults[0].URL));
                        }
                    }

                    if (clipboardText.Length > 0)
                    {
                        bool bClipboardFormatOnLongUrl = Engine.ConfigUI.EnableClipboardFormatForLongURLs && task.Job1 == EDataType.URL;
                        bool bClipboardFormat          = bClipboardFormatOnLongUrl || task.Job1 != EDataType.URL;
                        var  np = new NameParser(NameParserType.Clipboard)
                        {
                            Link     = clipboardText.ToString().Trim(),
                            FileSize = task.Info.FileSize,
                            FileName = task.Info.FileName
                        };
                        if (bClipboardFormat)
                        {
                            np.WindowText = task.Info.WindowTitleText;
                        }

                        string tempText = bClipboardFormat ? np.Convert(Engine.ConfigUI.ClipboardFormat) : clipboardText.ToString().Trim();

                        if (!string.IsNullOrEmpty(tempText))
                        {
                            DebugHelper.WriteLine("Setting Clipboard with URL: " + tempText);
                            Clipboard.SetText(tempText); // auto
                            Engine.zPreviousSetClipboardText = tempText;
                            Engine.IsClipboardUploading      = false;

                            // optional deletion link
                            if (task.UploadResults != null)
                            {
                                foreach (UploadResult ur in task.UploadResults)
                                {
                                    string linkdel = ur.DeletionURL;
                                    if (!string.IsNullOrEmpty(linkdel))
                                    {
                                        DebugHelper.WriteLine("Deletion Link: " + linkdel);
                                    }
                                }
                            }
                        }
                    }
                }

                if (!showDialog)
                {
                    task.Dispose();
                }
            }
        }