private void TaskListObtained(object sender, ListTaskEventArgs e) { if (e.Error == null) { Task[] serverTasks = e.Result; // move to ServerTasks collection ServerTasks.Clear(); foreach (Task task in serverTasks.OrderByDescending(t => t.RegistrationTime)) { UserTask userTask = new UserTask(task); ServerTasks.Add(userTask); } } else { MessageBox.Show("Cannot obtain list of server tasks:\n" + e.Error.Message, "error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void DownloadCompleted(object sender, TaskEventArgs e) { UserTask task = e.UserState as UserTask; if (e.Error != null) { task.TaskStatus = "Downloading error"; task.OutputFilePath = "<error>"; task.ErrorMessage = e.Error.Message; moveTaskToCompleted(task); return; } if (task.IsFieldLevel) { task.RecognizedText = FieldLevelXml.ReadText(task.OutputFilePath); } task.TaskStatus = "Ready"; moveTaskToCompleted(task); }
private void ProcessingCompleted(object sender, TaskEventArgs e) { UserTask task = e.UserState as UserTask; if (task.SourceIsTempFile) { File.Delete(task.SourceFilePath); } if (e.Error != null) { task.TaskStatus = "Processing error"; task.OutputFilePath = "<error>"; task.ErrorMessage = e.Error.Message; moveTaskToCompleted(task); return; } if (e.Result.Status == TaskStatus.NotEnoughCredits) { task.TaskStatus = "Not enough credits"; task.OutputFilePath = "<not enough credits>"; MessageBox.Show("Not enough credits to process the file.\nPlease add more pages to your application's account.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); moveTaskToCompleted(task); return; } if (e.Result.Status != TaskStatus.Completed) { task.TaskStatus = "Internal server error"; moveTaskToCompleted(task); return; } task.TaskStatus = "Downloading"; // Start downloading restClientAsync.DownloadFileAsync(e.Result, task.OutputFilePath, task); }
private void ProcessingCompleted(object sender, TaskEventArgs e) { UserTask task = e.UserState as UserTask; if (task.SourceIsTempFile) { File.Delete(task.SourceFilePath); } if (e.Error != null) { task.TaskStatus = "Processing error"; task.OutputFilePath = "<error>"; task.ErrorMessage = e.Error.Message; moveTaskToCompleted(task); return; } if (e.Result.Status == TaskStatus.NotEnoughCredits) { task.TaskStatus = "Not enough credits"; moveTaskToCompleted(task); return; } if (e.Result.Status != TaskStatus.Completed) { task.TaskStatus = "Internal server error"; moveTaskToCompleted(task); return; } task.TaskStatus = "Downloading"; // Start downloading restClientAsync.DownloadFileAsync(e.Result, task.OutputFilePath, task); }
private void fieldSelected(object sender, RegionSelectedEventArgs e) { string tempFilePath = System.IO.Path.GetTempFileName(); e.CroppedImage.Save(tempFilePath, System.Drawing.Imaging.ImageFormat.Tiff); string outputDir = getOutputDir(); UserTask task = new UserTask(tempFilePath); task.TaskStatus = "Uploading"; task.SourceIsTempFile = true; task.IsFieldLevel = true; // TODO: correct output name task.OutputFilePath = System.IO.Path.Combine( outputDir, "field-level" + System.IO.Path.GetRandomFileName() + ".xml"); task.SourceImage = e.CroppedImage; _userTasks.Add(task); _fieldLevelTasks.Add(task); // Select mode: text, barcode, checkmark if (flModeText.IsChecked == true) { TextFieldProcessingSettings settings = new TextFieldProcessingSettings(); restClientAsync.ProcessTextFieldAsync(tempFilePath, settings, task); } else if (flModeBarcode.IsChecked == true) { BarcodeFieldProcessingSettings settings = new BarcodeFieldProcessingSettings(); restClientAsync.ProcessBarcodeFieldAsync(tempFilePath, settings, task); } else { CheckmarkFieldProcessingSettings settings = new CheckmarkFieldProcessingSettings(); string userSettings = Properties.Settings.Default.CheckmarkOptions; if (!String.IsNullOrEmpty(userSettings)) settings.Params = userSettings; restClientAsync.ProcessCheckmarkFieldAsync(tempFilePath, settings, task); } // temp file will be deleted in ProcessingCompleted callback }
// Move task from _userTasks to _completedTasks void moveTaskToCompleted(UserTask task) { _userTasks.Remove(task); _completedTasks.Insert(0, task); }
void addFileTask(string filePath) { // Initialize output directory string outputDir = getOutputDir(); // Different behavior for full-text recognition and business card recognition if (modeGeneral.IsChecked == true) { ProcessingSettings settings = GetProcessingSettings(); UserTask task = new UserTask(filePath); task.TaskStatus = "Uploading"; task.OutputFilePath = System.IO.Path.Combine( outputDir, System.IO.Path.GetFileNameWithoutExtension(filePath) + settings.GetOutputFileExt(settings.OutputFormats[0])); _userTasks.Add(task); settings.Description = String.Format("{0} -> {1}", Path.GetFileName(filePath), settings.GetOutputFileExt(settings.OutputFormats[0])); restClientAsync.ProcessImageAsync(filePath, settings, task); } else if (modeBcr.IsChecked == true) { // Business-card recognition BusCardProcessingSettings settings = GetBusCardProcessingSettings(); string ext; if (formatVCard.IsChecked == true) { settings.OutputFormat = BusCardProcessingSettings.OutputFormatEnum.vCard; ext = ".vcf"; } else { settings.OutputFormat = BusCardProcessingSettings.OutputFormatEnum.xml; ext = ".xml"; } UserTask task = new UserTask(filePath); task.TaskStatus = "Uploading"; task.OutputFilePath = System.IO.Path.Combine( outputDir, System.IO.Path.GetFileNameWithoutExtension(filePath) + ext); _userTasks.Add(task); restClientAsync.ProcessBusinessCardAsync(filePath, settings, task); } else { // Machine-readable zone recognition UserTask task = new UserTask(filePath); task.TaskStatus = "Uploading"; task.OutputFilePath = System.IO.Path.Combine( outputDir, System.IO.Path.GetFileNameWithoutExtension(filePath) + ".xml"); _userTasks.Add(task); restClientAsync.ProcessMrzAsync(filePath, task); } }
void addFileTask(string filePath) { // Initialize output directory string outputDir = getOutputDir(); // Different behavior for full-text recognition and business card recognition if (formatVCard.IsChecked == false) { ProcessingSettings settings = GetProcessingSettings(); UserTask task = new UserTask(filePath); task.TaskStatus = "Uploading"; task.OutputFilePath = System.IO.Path.Combine( outputDir, System.IO.Path.GetFileNameWithoutExtension(filePath) + settings.OutputFileExt); _userTasks.Add(task); settings.Description = String.Format("{0} -> {1}", Path.GetFileName(filePath), settings.OutputFileExt); restClientAsync.ProcessImageAsync(filePath, settings, task); } else { // Business-card recognition BusCardProcessingSettings settings = GetBusCardProcessingSettings(); UserTask task = new UserTask(filePath); task.TaskStatus = "Uploading"; task.OutputFilePath = System.IO.Path.Combine( outputDir, System.IO.Path.GetFileNameWithoutExtension(filePath) + ".vcf"); _userTasks.Add(task); restClientAsync.ProcessBusinessCardAsync(filePath, settings, task); } }