public static async Task Main(string[] args) { var options = new DocoptNet.Docopt().Apply(Usage, args, version: "File system sorter sample app 1.0", exit: true); var inbox = options["<directory>"].ToString(); var outbox = options["--output"].ToString(); var errorBox = options["--failures"]?.ToString() ?? Path.Combine(options["<directory>"].ToString(), "failures"); EnsureDirectoryExists(inbox); EnsureDirectoryExists(outbox); EnsureDirectoryExists(errorBox); var cancellation = new CancellationTokenSource(); Console.CancelKeyPress += (s, e) => { Console.WriteLine("Cancelling processing..."); cancellation.Cancel(); }; var fileSorter = new FileSorter(outbox, errorBox); // Creates an EventingDocumentSource wrapping a FileSystemWatcher emitting // a new document into the pipeline whenever a document is created in the // inbox path. var filesystem = FileSystem.WatchForChanges(inbox, cancellation.Token); var pipeline = await WaivesApi.CreatePipelineAsync(new WaivesOptions { ClientId = "clientId", ClientSecret = "clientSecret" }, cancellation.Token); pipeline.WithDocumentsFrom(filesystem) .ClassifyWith(options["<classifier>"].ToString()) .Then(d => fileSorter.MoveDocument(d)) .OnDocumentError(e => fileSorter.HandleFailure(e)) .OnPipelineCompleted(() => Console.WriteLine("Processing completed, press any key to exit.")); try { await pipeline.RunAsync(cancellation.Token); } catch (PipelineException ex) { Console.WriteLine(ex); } }
public static async Task Main(string[] args) { // Point at a blob storage account var options = new Docopt().Apply(Usage, args, version: "Blob Storage processor sample app 1.0", exit: true); var connectionString = options["--connection-string"]?.ToString() ?? string.Empty; var containerSas = options["--container-sas"]?.ToString() ?? string.Empty; var containers = EnumerateContainers(connectionString, containerSas, options["<container>"].AsEnumerable(i => i.ToString())); // Identify all blobs in the specified containers var blobs = (await Task.WhenAll(containers.Select(c => c.GetBlobs()))).SelectMany(c => c); // Create an Enumerable of Waives documents from the blobs var blobStorageDocuments = blobs.Select(b => new BlobStorageDocument(b)); // Create a document source emitting each document in turn var blobStorage = new EnumerableDocumentSource(blobStorageDocuments); var writer = CreateResultWriter(options["--output"].ToString()); var pipeline = await WaivesApi.CreatePipelineAsync(new WaivesOptions { ClientId = "clientId", ClientSecret = "clientSecret" }); pipeline.WithDocumentsFrom(blobStorage) .ClassifyWith(options["--classifier"].ToString()) .Then(d => writer.Write(d)) .OnDocumentError(e => Console.WriteLine($"Processing {e.Document} failed: {e.Exception.Message}")) .OnPipelineCompleted(() => { Console.WriteLine(("Processing completed.")); }); try { await pipeline.RunAsync(); } catch (PipelineException ex) { Console.WriteLine(ex); } }