private async Task ProcessMrzAsync( IReadOnlyList <string> files, Options options, object state) { Console.WriteLine($"Starting MRZ processing of {files.Count} files"); foreach (var file in files) { Console.WriteLine($"Starting processing of file: {file}"); TaskInfo task; options.SourcePath = file; var parameters = ProcessingParamsBuilder.GetMrzProcessingParams(); using (_scope.Start("Uploading")) using (var fileStream = File.OpenRead(file)) { task = await _ocrClient.ProcessMrzAsync(parameters, fileStream, options.FileName).ConfigureAwait(false); } UploadFileCompleted?.Invoke(this, new UploadCompletedEventArgs(task, state)); task = await WaitTaskAsync(task.TaskId, state).ConfigureAwait(false); await DownloadResultFilesAsync(task, options, state).ConfigureAwait(false); } Console.WriteLine("Processing has completed"); }
private async Task ProcessFieldAsync( IReadOnlyList <string> files, Options options, object state) { Console.WriteLine($"Starting {options.Mode} processing of {files.Count} files"); foreach (var file in files) { Console.WriteLine($"Starting processing of file: {file}"); TaskInfo task; options.SourcePath = file; using (_scope.Start("Uploading")) using (var fileStream = File.OpenRead(file)) { task = await StartFieldProcessingAsync(fileStream, options).ConfigureAwait(false); } UploadFileCompleted?.Invoke(this, new UploadCompletedEventArgs(task, state)); task = await WaitTaskAsync(task.TaskId, state).ConfigureAwait(false); await DownloadResultFilesAsync(task, options, state).ConfigureAwait(false); } Console.WriteLine("Processing has completed"); }
public async Task <ResultSuccess> UploadFile(string UploadURL, string File, string FileType, UploadFileCompleted OnUploadFileCompleted, UploadProgressChanged OnUploadProgressChanged) { try { UploadFileCompleted_EventHandler = OnUploadFileCompleted; UploadProgressChanged_EventHandler = OnUploadProgressChanged; System.Net.WebClient client = new WebClient(); client.UploadProgressChanged += Client_UploadProgressChanged; client.UploadFileCompleted += Client_UploadFileCompleted; client.Headers["Authorization"] = "Basic "; //client.Headers.Add("Content-Type", FileType); await client.UploadFileTaskAsync(UploadURL, "POST", File); client.UploadProgressChanged -= Client_UploadProgressChanged; client.UploadFileCompleted -= Client_UploadFileCompleted; return(new ResultSuccess()); } catch (Exception err) { return(new ResultSuccess(false, err.ProperMessage())); } }
private async Task <TaskInfo> SubmitImagesAsync(IReadOnlyList <string> files, object state) { var task = default(TaskInfo); for (var i = 0; i < files.Count; i++) { using (_scope.Start($"Uploading {i + 1}/{files.Count} file: {files[i]}")) using (var fileStream = File.OpenRead(files[i])) { task = await _ocrClient.SubmitImageAsync( new ImageSubmittingParams { TaskId = task?.TaskId }, fileStream, Path.GetFileNameWithoutExtension(files[i])) .ConfigureAwait(false); } } UploadFileCompleted?.Invoke(this, new UploadCompletedEventArgs(task, state)); return(task); }
private async Task ProcessFileAsync(string filePath, Options options, object state) { Console.WriteLine($"Start single file processing: {filePath}"); TaskInfo task; var parameters = ProcessingParamsBuilder.GetImageProcessingParams(options); using (_scope.Start("Uploading")) using (var fileStream = File.OpenRead(filePath)) { task = await _ocrClient.ProcessImageAsync(parameters, fileStream, options.FileName).ConfigureAwait(false); } UploadFileCompleted?.Invoke(this, new UploadCompletedEventArgs(task, state)); task = await WaitTaskAsync(task.TaskId, state).ConfigureAwait(false); await DownloadResultFilesAsync(task, options, state).ConfigureAwait(false); Console.WriteLine("Processing has completed"); }
private void RegisterUploadDelegates() { // We do all this magic because other threads should NOT change the UI. // We want the changes made to the reusable `TransferFileProgressArgs` instance // to raise change events on the context of the Main thread. Implementation.UploadStarted += (TransferFileProgressArgs args, Action action) => { EventDispatcher.Invoke(() => { if (action != null) { action.Invoke(); } if (UploadFileStarted != null) { UploadFileStarted.Invoke(this, args); } }); }; Implementation.UploadProgressed += (TransferFileProgressArgs args, Action action) => { EventDispatcher.Invoke(() => { if (action != null) { action.Invoke(); } if (UploadFileProgress != null) { UploadFileProgress.Invoke(this, args); } }); }; Implementation.UploadCanceled += (TransferFileProgressArgs args, Action action) => { EventDispatcher.Invoke(() => { if (action != null) { action.Invoke(); } if (UploadFileCanceled != null) { UploadFileCanceled.Invoke(this, args); } }); }; Implementation.UploadFailed += (TransferFileProgressArgs args, Action action) => { EventDispatcher.Invoke(() => { if (action != null) { action.Invoke(); } if (UploadFileFailed != null) { UploadFileFailed.Invoke(this, args); } }); }; Implementation.UploadCompleted += (TransferFileProgressArgs args, Action action) => { EventDispatcher.Invoke(() => { if (action != null) { action.Invoke(); } if (UploadFileCompleted != null) { UploadFileCompleted.Invoke(this, args); } }); }; }
private void Upload_ResponseReceived(File file) { UploadFileCompleted?.Invoke(file.Id); }