/// <summary> /// Upload file and start recognition asynchronously /// Performs callbacks: /// UploadFileCompleted /// TaskProcessingCompleted /// </summary> private void processFileAsync(string filePath, IProcessingSettings settings, object taskId) { // Create an AsyncOperation for taskId. AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(taskId); // Multiple threads will access the task dictionary, // so it must be locked to serialize access. lock (processJobs.SyncRoot) { if (processJobs.Contains(taskId)) { throw new ArgumentException( "Task ID parameter must be unique", "taskId"); } processJobs[taskId] = asyncOp; } // Start the asynchronous operation. processFileWorkerEventHandler workerDelegate = new processFileWorkerEventHandler(processFileWorker); workerDelegate.BeginInvoke( filePath, settings, asyncOp, null, null); }
public StorageQueueMessagePump(IStorageQueueClient storageQueueClient, IProcessingSettings settings, ILog log) { _storageQueueClient = storageQueueClient; _settings = settings; _log = log; _maxConcurrent = new SemaphoreSlim(_settings.MaxConcurrentCalls); }
public PipelineInformation(Type processorInterfaceType, IEventSubscription subscription, IProcessingSettings processingSettings, IHostConfiguration hostConfiguration) { ProcessorInterfaceType = processorInterfaceType; Subscription = subscription; ProcessingSettings = processingSettings; HostConfiguration = hostConfiguration; }
private void processFieldWorker(string filePath, IProcessingSettings settings, AsyncOperation asyncOp) { Exception e = null; Task task = new Task(); try { if (settings is TextFieldProcessingSettings) { task.Id = _syncClient.ProcessTextField(filePath, settings as TextFieldProcessingSettings); } else if (settings is BarcodeFieldProcessingSettings) { task.Id = _syncClient.ProcessBarcodeField(filePath, settings as BarcodeFieldProcessingSettings); } else if (settings is CheckmarkFieldProcessingSettings) { task.Id = _syncClient.ProcessCheckmarkField(filePath, settings as CheckmarkFieldProcessingSettings); } else { throw new ArgumentException("Invalid type of processing settings"); } // Notify that upload was completed Task uploadedTask = new Task(task.Id, TaskStatus.Submitted); UploadCompletedEventArgs uploadCompletedEventArgs = new UploadCompletedEventArgs(uploadedTask, asyncOp.UserSuppliedState); asyncOp.Post(onUploadCompletedDelegate, uploadCompletedEventArgs); // Wait until task finishes startTaskMonitorIfNecessary(); _taskList.AddTask(task); task = waitUntilTaskFinishes(task); } catch (Exception ex) { e = ex; } lock (processJobs.SyncRoot) { processJobs.Remove(asyncOp.UserSuppliedState); } bool canceled = false; // Package the results of the operation in EventArgs TaskEventArgs ev = new TaskEventArgs(task, e, canceled, asyncOp.UserSuppliedState); // End the task. The asyncOp object is responsible // for marshaling the call. asyncOp.PostOperationCompleted(onProcessingCompleteDelegate, ev); }
public ServiceBusQueueChannelReceiver(IProcessingSettings settings, ServiceBusConfiguration configuration, IHostConfiguration hostConfiguration, IMessageProcessor processor) { _configuration = configuration; _processor = processor; Settings = settings; _log = hostConfiguration.Log; //new client factory per ServiceBusQueueChannelReceiver means a separate communication channel per reader instead of a shared _clientFactory = new ClientFactory(configuration.ConnectionString); _managementClient = new ManagementClient(configuration.ConnectionString); }
protected RedisChannelReceiver(IConnectionMultiplexer connectionMultiplexer, string queueName, IProcessingSettings settings, RedisConfiguration redisConfiguration, IHostConfiguration hostConfiguration, IMessageProcessor processor) { ConnectionMultiplexer = connectionMultiplexer; _settings = settings; _redisConfiguration = redisConfiguration; _hostConfiguration = hostConfiguration; _processor = processor; _queueName = queueName; _maxConcurrent = new SemaphoreQueue(settings.MaxConcurrentCalls); }
public StorageQueueChannelReceiver(IProcessingSettings settings, IMessageProcessor processor, IHostConfiguration hostConfiguration, IStorageBusConfiguration storageOptions) { if (settings.PrefetchCount > 32) { throw new ArgumentOutOfRangeException(nameof(settings), "PrefetchCount is set too high. The maximum number of messages that may be retrieved at a time is 32."); } Settings = settings; _storageOptions = storageOptions; _processor = processor; _hostConfiguration = hostConfiguration; }
public ServiceBusTopicChannelReceiver(IProcessingSettings settings, IMessageSerializer serializer, IEventSubscription <TTopic> subscription, IServiceBusConfiguration configuration, IHostConfiguration hostConfiguration, IMessageProcessor processor) { Settings = settings; _managementClient = new ServiceBusAdministrationClient(configuration.ConnectionString); _serializer = serializer; _subscription = subscription; _log = hostConfiguration.Log; _configuration = configuration; _hostConfiguration = hostConfiguration; _processor = processor; //new client factory per ServiceBusTopicChannelReceiver means a separate communication channel per reader instead of a shared _clientFactory = new ClientFactory(configuration.ConnectionString); }
// This method performs the actual prime number computation. // It is executed on the worker thread. private void processFileWorker(string filePath, IProcessingSettings settings, AsyncOperation asyncOp) { Exception e = null; // Check that the task is still active. // The operation may have been canceled before // the thread was scheduled. Task task = null; try { if (settings is ProcessingSettings) { task = _syncClient.ProcessImage(filePath, settings as ProcessingSettings); } else if (settings is BusCardProcessingSettings) { task = _syncClient.ProcessBusinessCard(filePath, settings as BusCardProcessingSettings); } else if (settings is CaptureDataSettings) { string templateName = (settings as CaptureDataSettings).TemplateName; task = _syncClient.CaptureData(filePath, templateName); } // Notify subscriber that upload completed Task uploadedTask = new Task(task.Id, TaskStatus.Submitted); UploadCompletedEventArgs uploadCompletedEventArgs = new UploadCompletedEventArgs(uploadedTask, asyncOp.UserSuppliedState); asyncOp.Post(onUploadCompletedDelegate, uploadCompletedEventArgs); startTaskMonitorIfNecessary(); _taskList.AddTask(task); task = waitUntilTaskFinishes(task); // task is modified on server } catch (Exception ex) { e = ex; } processCompletionMethod(task, e, false, asyncOp); }
/// <summary> /// Start one of 3 possible field-processing tasks /// </summary> private void processFieldAsync(string filePath, IProcessingSettings settings, object taskId) { AsyncOperation asynOp = AsyncOperationManager.CreateOperation(taskId); lock (processJobs.SyncRoot) { if (processJobs.Contains(taskId)) { throw new ArgumentException("Task ID parameter must be unique", "taskId"); } processJobs[taskId] = asynOp; } processFieldWorkerEventHandler workerDelegate = new processFieldWorkerEventHandler(processFieldWorker); workerDelegate.BeginInvoke( filePath, settings, asynOp, null, null); }
/// <summary> /// Start one of 3 possible field-processing tasks /// </summary> private void processFieldAsync(string filePath, IProcessingSettings settings, object taskId) { AsyncOperation asynOp = AsyncOperationManager.CreateOperation(taskId); lock (processJobs) { if (processJobs.ContainsKey(taskId)) { throw new ArgumentException("Task ID parameter must be unique", "taskId"); } processJobs[taskId] = asynOp; } processFieldWorkerEventHandler workerDelegate = new processFieldWorkerEventHandler(processFieldWorker); workerDelegate.BeginInvoke( filePath, settings, asynOp, null, null); }
/// <summary> /// Upload file and start recognition asynchronously /// Performs callbacks: /// UploadFileCompleted /// TaskProcessingCompleted /// </summary> private void processFileAsync(string filePath, IProcessingSettings settings, object taskId) { // Create an AsyncOperation for taskId. AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(taskId); // Multiple threads will access the task dictionary, // so it must be locked to serialize access. lock (processJobs) { if (processJobs.ContainsKey(taskId)) { throw new ArgumentException( "Task ID parameter must be unique", "taskId"); } processJobs[taskId] = asyncOp; } // Start the asynchronous operation. processFileWorkerEventHandler workerDelegate = new processFileWorkerEventHandler(processFileWorker); workerDelegate.BeginInvoke( filePath, settings, asyncOp, null, null); }
private void processFieldWorker(string filePath, IProcessingSettings settings, AsyncOperation asyncOp) { Exception e = null; Task task = new Task(); try { if (settings is TextFieldProcessingSettings) { task = _syncClient.ProcessTextField(filePath, settings as TextFieldProcessingSettings); } else if (settings is BarcodeFieldProcessingSettings) { task = _syncClient.ProcessBarcodeField(filePath, settings as BarcodeFieldProcessingSettings); } else if (settings is CheckmarkFieldProcessingSettings) { task = _syncClient.ProcessCheckmarkField(filePath, settings as CheckmarkFieldProcessingSettings); } else { throw new ArgumentException("Invalid type of processing settings"); } // Notify that upload was completed Task uploadedTask = new Task(task.Id, TaskStatus.Submitted); UploadCompletedEventArgs uploadCompletedEventArgs = new UploadCompletedEventArgs(uploadedTask, asyncOp.UserSuppliedState); asyncOp.Post(onUploadCompletedDelegate, uploadCompletedEventArgs); // Wait until task finishes startTaskMonitorIfNecessary(); _taskList.AddTask(task); task = waitUntilTaskFinishes(task); } catch (Exception ex) { e = ex; } lock (processJobs) { processJobs.Remove(asyncOp.UserSuppliedState); } bool canceled = false; // Package the results of the operation in EventArgs TaskEventArgs ev = new TaskEventArgs(task, e, canceled, asyncOp.UserSuppliedState); // End the task. The asyncOp object is responsible // for marshaling the call. asyncOp.PostOperationCompleted(onProcessingCompleteDelegate, ev); }
// This method performs the actual file processing. // It is executed on the worker thread. private void processFileWorker(string filePath, IProcessingSettings settings, AsyncOperation asyncOp) { Exception e = null; // Check that the task is still active. // The operation may have been canceled before // the thread was scheduled. Task task = null; try { if (settings is ProcessingSettings) { task = _syncClient.ProcessImage(filePath, settings as ProcessingSettings); } else if (settings is BusCardProcessingSettings) { task = _syncClient.ProcessBusinessCard(filePath, settings as BusCardProcessingSettings); } else if (settings is CaptureDataSettings) { string templateName = (settings as CaptureDataSettings).TemplateName; task = _syncClient.CaptureData(filePath, templateName); } // Notify subscriber that upload completed Task uploadedTask = new Task(task.Id, TaskStatus.Submitted); UploadCompletedEventArgs uploadCompletedEventArgs = new UploadCompletedEventArgs(uploadedTask, asyncOp.UserSuppliedState); asyncOp.Post(onUploadCompletedDelegate, uploadCompletedEventArgs); startTaskMonitorIfNecessary(); _taskList.AddTask(task); task = waitUntilTaskFinishes(task); // task is modified on server } catch (Exception ex) { e = ex; } processCompletionMethod(task, e, false, asyncOp); }
/// <summary> /// Process directory or file with given path /// </summary> /// <param name="sourcePath">File or directory to be processed</param> /// <param name="outputPath">Path to directory to store results /// Will be created if it doesn't exist /// </param> /// <param name="processAsDocument">If true, all images are processed as a single document</param> public void ProcessPath(string sourcePath, string outputPath, IProcessingSettings settings, ProcessingModeEnum processingMode) { List<string> sourceFiles = new List<string>(); if (Directory.Exists(sourcePath)) { sourceFiles.AddRange(Directory.GetFiles(sourcePath)); sourceFiles.Sort(); } else if (File.Exists(sourcePath)) { sourceFiles.Add(sourcePath); } else { Console.WriteLine("Invalid source path"); return; } if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } if (processingMode == ProcessingModeEnum.SinglePage || (processingMode == ProcessingModeEnum.MultiPage && sourceFiles.Count == 1) ) { ProcessingSettings fullTextSettings = settings as ProcessingSettings; foreach (string filePath in sourceFiles) { string outputFileName = Path.GetFileNameWithoutExtension(filePath); string outputFilePath = Path.Combine(outputPath, outputFileName); Console.WriteLine("Processing " + Path.GetFileName(filePath)); ProcessFile(filePath, outputFilePath, fullTextSettings); } } else if(processingMode == ProcessingModeEnum.MultiPage) { ProcessingSettings fullTextSettings = settings as ProcessingSettings; string outputFileName = "document"; string outputFilePath = Path.Combine(outputPath, outputFileName); ProcessDocument(sourceFiles, outputFilePath, fullTextSettings); } else if (processingMode == ProcessingModeEnum.ProcessTextField) { TextFieldProcessingSettings fieldSettings = settings as TextFieldProcessingSettings; foreach (string filePath in sourceFiles) { string outputFileName = Path.GetFileNameWithoutExtension(filePath); string ext = ".xml"; string outputFilePath = Path.Combine(outputPath, outputFileName + ext); Console.WriteLine("Processing " + Path.GetFileName(filePath)); ProcessTextField(filePath, outputFilePath, fieldSettings); } } else if (processingMode == ProcessingModeEnum.ProcessMrz) { foreach (string filePath in sourceFiles) { string outputFileName = Path.GetFileNameWithoutExtension(filePath); string ext = ".xml"; string outputFilePath = Path.Combine(outputPath, outputFileName + ext); Console.WriteLine("Processing " + Path.GetFileName(filePath)); ProcessMrz(filePath, outputFilePath); } } }
public IChannelReceiver Create(Type messageType, IEventSubscription subscription, IProcessingSettings processingSettings, IHostConfiguration configuration, IMessageProcessor processor) { var queueReaderType = typeof(ServiceBusTopicChannelReceiver <>).MakeGenericType(messageType); var queueReader = (IChannelReceiver)Activator.CreateInstance(queueReaderType, processingSettings, subscription, Configuration, configuration, processor); return(queueReader); }
public RedisCommandChannelReceiver(IConnectionMultiplexer connectionMultiplexer, IProcessingSettings settings, IMessageSerializer serializer, RedisConfiguration configuration, IHostConfiguration hostConfiguration, IMessageProcessor processor) : base(connectionMultiplexer, AutoMessageMapper.GetQueueName <T>(), settings, serializer, configuration, hostConfiguration, processor) { }
public RedisEventChannelReceiver(IConnectionMultiplexer connectionMultiplexer, IProcessingSettings settings, IMessageSerializer serializer, IEventSubscription <T> subscription, RedisConfiguration configuration, IHostConfiguration hostConfiguration, IMessageProcessor processor) : base(connectionMultiplexer, RedisQueueConventions.GetSubscriptionQueueName(AutoMessageMapper.GetQueueName <T>(), subscription.Name), settings, serializer, configuration, hostConfiguration, processor) { _subscription = subscription; _redisConfiguration = configuration; }
/// <summary> /// Process directory or file with given path /// </summary> /// <param name="sourcePath">File or directory to be processed</param> /// <param name="outputPath">Path to directory to store results /// Will be created if it doesn't exist /// </param> /// <param name="processAsDocument">If true, all images are processed as a single document</param> public void ProcessPath(string sourcePath, string outputPath, IProcessingSettings settings, ProcessingModeEnum processingMode) { List <string> sourceFiles = new List <string>(); if (Directory.Exists(sourcePath)) { sourceFiles.AddRange(Directory.GetFiles(sourcePath)); sourceFiles.Sort(); } else if (File.Exists(sourcePath)) { sourceFiles.Add(sourcePath); } else { Console.WriteLine("Invalid source path"); return; } if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } if (processingMode == ProcessingModeEnum.SinglePage || (processingMode == ProcessingModeEnum.MultiPage && sourceFiles.Count == 1)) { ProcessingSettings fullTextSettings = settings as ProcessingSettings; foreach (string filePath in sourceFiles) { string outputFileName = Path.GetFileNameWithoutExtension(filePath); string outputFilePath = Path.Combine(outputPath, outputFileName); Console.WriteLine("Processing " + Path.GetFileName(filePath)); ProcessFile(filePath, outputFilePath, fullTextSettings); } } else if (processingMode == ProcessingModeEnum.MultiPage) { ProcessingSettings fullTextSettings = settings as ProcessingSettings; string outputFileName = "document"; string outputFilePath = Path.Combine(outputPath, outputFileName); ProcessDocument(sourceFiles, outputFilePath, fullTextSettings); } else if (processingMode == ProcessingModeEnum.ProcessTextField) { TextFieldProcessingSettings fieldSettings = settings as TextFieldProcessingSettings; foreach (string filePath in sourceFiles) { string outputFileName = Path.GetFileNameWithoutExtension(filePath); string ext = ".xml"; string outputFilePath = Path.Combine(outputPath, outputFileName + ext); Console.WriteLine("Processing " + Path.GetFileName(filePath)); ProcessTextField(filePath, outputFilePath, fieldSettings); } } else if (processingMode == ProcessingModeEnum.ProcessMrz) { foreach (string filePath in sourceFiles) { string outputFileName = Path.GetFileNameWithoutExtension(filePath); string ext = ".xml"; string outputFilePath = Path.Combine(outputPath, outputFileName + ext); Console.WriteLine("Processing " + Path.GetFileName(filePath)); ProcessMrz(filePath, outputFilePath); } } }
public IChannelReceiver Create(Type messageType, IEventSubscription subscription, IProcessingSettings processingSettings, IHostConfiguration configuration, IMessageProcessor processor) { var queueReaderType = typeof(RedisCommandChannelReceiver <>).MakeGenericType(messageType); var queueReader = (IChannelReceiver)Activator.CreateInstance(queueReaderType, _connectionMultiplexer, processingSettings, Configuration, configuration, processor); return(queueReader); }