public override WorkerTask CreateTask(WorkerTask.JobLevel2 job, TaskInfo tiCreateTask = null)
        {
            if (tiCreateTask == null) tiCreateTask = new TaskInfo();

            tiCreateTask.Job = job;

            WorkerTask createTask = new WorkerTask(CreateWorker(), tiCreateTask);

            return createTask;
        }
 public virtual WorkerTask CreateTask(WorkerTask.JobLevel2 job, TaskInfo tiCreateTask = null)
 {
     return new WorkerTask(Engine.ConfigWorkflow);
 }
        public bool UploadUsingFileSystem(params string[] fileList)
        {
            List<string> strListFilePath = new List<string>();
            bool succ = true;
            foreach (string fp in fileList)
            {
                try
                {
                    if (!string.IsNullOrEmpty(fp) && File.Exists(fp))
                    {
                        if (HelpersLib.GraphicsHelper.Core.IsValidImage(fp))
                        {
                            string dirfp = Path.GetDirectoryName(fp);
                            string fsfp = FileSystem.GetUniqueFilePath(Engine.ConfigWorkflow, Engine.ImagesDir, Path.GetFileName(fp));
                            if (fp != fsfp && dirfp != Engine.ImagesDir)
                            {
                                string dir = Path.GetDirectoryName(fsfp);
                                if (!Directory.Exists(dir))
                                {
                                    Directory.CreateDirectory(dir);
                                }
                                try
                                {
                                    File.Copy(fp, fsfp, true);
                                    if (Path.GetDirectoryName(fp) == Engine.ConfigUI.FolderMonitorPath)
                                    {
                                        File.Delete(fp);
                                    }
                                }
                                catch (Exception e)
                                {
                                    fsfp = fp;
                                    DebugHelper.WriteException(e);
                                }
                                strListFilePath.Add(fsfp);
                            }
                            else
                            {
                                strListFilePath.Add(fp);
                            }
                        }
                        else
                        {
                            strListFilePath.Add(fp); // yes we use the orignal file path
                        }
                    }
                }
                catch (Exception ex)
                {
                    DebugHelper.WriteException(ex, "Error while uploading using file system");
                    succ = false;
                }
            }

            strListFilePath.Sort();
            List<Image> tempImages = new List<Image>();
            bool bCreateAni = strListFilePath.Count > 1 && strListFilePath.Count < Engine.ConfigWorkflow.ImageAnimatedFramesMax && HelpersLib.GraphicsHelper.Core.HasIdenticalImages(strListFilePath, out tempImages);

            if (bCreateAni)
            {
                WorkerTask agifTask = CreateTask(WorkerTask.JobLevel2.UploadFromExplorer);
                agifTask.SetImages(tempImages);
                agifTask.RunWorker();
            }
            else
            {
                foreach (string fp in strListFilePath)
                {
                    var tifs = new TaskInfo() { ExistingFilePath = fp };
                    var fpdataTask = CreateTask(WorkerTask.JobLevel2.UploadFromExplorer, tifs);
                    fpdataTask.UpdateLocalFilePath(fp);
                    fpdataTask.RunWorker();
                }
            }
            return succ;
        }
        public override WorkerTask CreateTask(WorkerTask.JobLevel2 job, TaskInfo tiCreateTask = null)
        {
            DebugHelper.WriteLine(string.Format("Creating job: {0}", job));
            if (tiCreateTask == null) tiCreateTask = new TaskInfo();

            tiCreateTask.Job = job;
            tiCreateTask.DestConfig = GetDestConfig(ucDestOptions);
            if (job == WorkerTask.JobLevel2.CaptureRectRegionClipboard)
            {
                tiCreateTask.DestConfig.TaskClipboardContent.Clear();
                tiCreateTask.DestConfig.ImageUploaders.Clear();
                tiCreateTask.DestConfig.TaskClipboardContent.Add(ClipboardContentEnum.Data);
            }
            tiCreateTask.TrayIcon = this.niTray;

            WorkerTask createTask = new WorkerTask(CreateWorker(), tiCreateTask);

            switch (job)
            {
                case WorkerTask.JobLevel2.Translate:
                    Loader.MyGTGUI.btnTranslate.Enabled = false;
                    createTask.SetTranslationInfo(new GoogleTranslateInfo()
                    {
                        Text = Loader.MyGTGUI.txtTranslateText.Text,
                        SourceLanguage = Engine.ConfigGT.GoogleSourceLanguage,
                        TargetLanguage = Engine.ConfigGT.GoogleTargetLanguage
                    });

                    break;
            }

            return createTask;
        }
 public void CaptureSelectedWindowFromList(IntPtr handle)
 {
     TaskInfo tiCaptureWindowFromList = new TaskInfo() { Handle = handle };
     WorkerTask hkswTask = CreateTask(WorkerTask.JobLevel2.CaptureSelectedWindowFromList, tiCaptureWindowFromList);
     RunWorkerAsync(hkswTask);
 }
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bw = (BackgroundWorker)sender;
            UploaderInfo[] uploaders = (UploaderInfo[])e.Argument;

            foreach (UploaderInfo uploader in uploaders)
            {
                if (this.IsDisposed || !isTesting || uploader == null)
                {
                    break;
                }

                DestConfig dcTester = new DestConfig();
                dcTester.Outputs.Add(OutputEnum.RemoteHost);

                TaskInfo tiTester = new TaskInfo()
                {
                    Job = WorkerTask.JobLevel2.UploadFromClipboard,
                    DestConfig = dcTester
                };
                WorkerTask task = new WorkerTask(new BackgroundWorker() { WorkerReportsProgress = true }, tiTester);

                uploader.Timer = new Stopwatch();
                uploader.Timer.Start();
                uploader.Task = task;
                bw.ReportProgress((int)UploadStatus.Uploading, uploader);

                try
                {
                    switch (uploader.UploaderType)
                    {
                        case UploaderType.ImageUploader:
                            task.WorkflowConfig.DestConfig.ImageUploaders.Add(uploader.ImageUploader);
                            task.UpdateLocalFilePath(TestImageFilePath);
                            task.PublishData();
                            break;
                        case UploaderType.FileUploader:
                            task.WorkflowConfig.DestConfig.ImageUploaders.Add(ImageDestination.FileUploader);
                            task.WorkflowConfig.DestConfig.FileUploaders.Add(uploader.FileUploader);
                            task.UpdateLocalFilePath(TestFilePath);
                            task.PublishData();
                            break;
                        case UploaderType.TextUploader:
                            task.WorkflowConfig.DestConfig.TextUploaders.Add(uploader.TextUploader);
                            task.SetText(TestText);
                            task.PublishData();
                            break;
                        case UploaderType.UrlShortener:
                            task.WorkflowConfig.DestConfig.LinkUploaders.Add(uploader.UrlShortener);
                            task.ShortenURL(TestURL);
                            if (task.UploadResults.Count > 0)
                            {
                                task.UploadResults[0].URL = task.UploadResults[0].ShortenedURL;
                            }
                            break;
                        default:
                            throw new Exception("Unknown uploader.");
                    }
                }
                catch (Exception ex)
                {
                    ConsoleWriteLine(ex.ToString());
                }
                finally
                {
                    uploader.Timer.Stop();
                    uploader.Task = task;
                    bw.ReportProgress((int)UploadStatus.Uploaded, uploader);
                }
            }
        }
        public WorkerTask(Workflow wf, bool cloneWorkflow = true)
        {
            Info = new TaskInfo();
            UploadResults = new List<UploadResult>();
            Errors = new List<string>();
            States.Add(TaskState.Created);
            MyWorker = new BackgroundWorker { WorkerReportsProgress = true };

            if (cloneWorkflow)
            {
                IClone cm = new CloneManager();
                WorkflowConfig = cm.Clone(wf);
            }
            else
            {
                WorkflowConfig = wf;
            }
        }
        public WorkerTask(BackgroundWorker worker, TaskInfo info)
            : this(Engine.ConfigWorkflow)
        {
            Info = info;

            if (!string.IsNullOrEmpty(info.ExistingFilePath))
            {
                UpdateLocalFilePath(info.ExistingFilePath);
            }

            MyWorker = worker;
            PrepareOutputs(info.DestConfig); // step 1

            DialogResult result = StartWork(info.Job) ? DialogResult.OK : DialogResult.Cancel; // step 2

            if (result == DialogResult.OK && Engine.ConfigUI.PromptForOutputs) // step 3
            {
                var wfw = new WorkflowWizard(this) { Icon = Resources.zss_tray };
                result = wfw.ShowDialog();
            }

            if (Job1 == EDataType.Image && result == DialogResult.OK)
            {
                if (!States.Contains(TaskState.ImageProcessed))
                {
                    ProcessImage(TempImage);
                }
            }

            if (result == DialogResult.Cancel)
            {
                States.Add(TaskState.CancellationPending);
            }

            if (States.Contains(TaskState.CancellationPending))
            {
                SetNotifyIconStatus(Info.TrayIcon, ready: true);
            }
        }