Exemple #1
0
        static async Task Main(string[] args)
        {
            var            switchMapping = GetSwitchMapping();
            IConfiguration Configuration = new ConfigurationBuilder()
                                           .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                                           .AddJsonFile("secret.appsettings.json", optional: true, reloadOnChange: true)
                                           .AddEnvironmentVariables()
                                           .AddCommandLine(args, switchMapping)
                                           .Build();

            Console.WriteLine($"{FolderKey} = {Configuration[FolderKey]}");
            Console.WriteLine($"{BlobConnectionStringKey} = {Configuration[BlobConnectionStringKey]}");
            Console.WriteLine($"{ServiceBusConnectionStringKey} = {Configuration[ServiceBusConnectionStringKey]}");
            Console.WriteLine($"{InputContainerNameKey} = {Configuration[InputContainerNameKey]}");
            Console.WriteLine($"{OutcomeQueueNameKey} = {Configuration[OutcomeQueueNameKey]}");

            var serviceBusListener = new ServiceBusListener(Configuration[ServiceBusConnectionStringKey], Configuration[OutcomeQueueNameKey]);

            serviceBusListener.StartListening("file-id");

            var files = GetFolderContents(Configuration[FolderKey]);

            var receivedOutcomeInformation = new List <OutcomeInformation>();

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            foreach (var file in files)
            {
                var messageListener = new TransactionOutcomeListener(Path.GetFileName(file));
                messageListener.RegisterNotificationAction(m =>
                {
                    var receivedOutcome = new OutcomeInformation
                    {
                        FileId     = m.GetMessageProperty("file-id"),
                        Outcome    = m.GetMessageProperty("file-outcome"),
                        RebuildSas = m.GetMessageProperty("file-rebuild-sas")
                    };
                    receivedOutcomeInformation.Add(receivedOutcome);
                    return(true);
                });
                serviceBusListener.RegisterListener(messageListener);
            }

            var writer          = new ContainerWriter(Configuration[BlobConnectionStringKey], Configuration[InputContainerNameKey]);
            var submissionTasks = SubmitFiles(writer, files);

            Task.WaitAll(submissionTasks);

            while (files.Count() > receivedOutcomeInformation.Count())
            {
                Console.WriteLine($"{receivedOutcomeInformation.Count()} outcomes received, out of {files.Count()}");
                await Task.Delay(TimeSpan.FromSeconds(1));
            }
            stopWatch.Stop();
            OutputResults(receivedOutcomeInformation, stopWatch.Elapsed);

            Console.WriteLine("Press any key to finish");
            Console.ReadKey();
        }
Exemple #2
0
        private static Task[] SubmitFiles(ContainerWriter writer, IEnumerable <string> files)
        {
            var pendingTasks = new List <Task>();

            foreach (var file in files)
            {
                pendingTasks.Add(writer.Write(file));
            }

            return(pendingTasks.ToArray());
        }