Ejemplo n.º 1
0
        private static void HandleSyncMessage(CommandLineApplication command)
        {
            var profileArgument = command.Argument("[profile]", "The name of the json profile file to use (excluded file extension)");
            var noProtection    = command.Option("--noprotection", "Don't sign or encrypt message", CommandOptionType.NoValue);

            command.HelpOption("-?|-h|--help");
            command.OnExecute(() =>
            {
                if (string.IsNullOrEmpty(profileArgument.Value))
                {
                    command.ShowHelp();
                    return(2);
                }
                Configure(profileArgument.Value, noProtection.HasValue());

                if (Directory.Exists(_clientSettings.SourceDirectory) == false)
                {
                    _logger.LogError("Directory does not exist");
                    command.ShowHelp();
                    return(2);
                }
                _files = new Stack <string>(Directory.GetFiles(_clientSettings.SourceDirectory));

                if (noProtection.HasValue())
                {
                    _messagingClient.DefaultMessageProtection = new NoMessageProtection();
                }
                // since we are synchronous, we don't fire off multiple tasks, we do them sequentially
                for (var s = GetNextPath(); !string.IsNullOrEmpty(s); s = GetNextPath())
                {
                    _logger.LogInformation($"Processing file {s}");
                    var result = _messagingClient.SendAndWaitAsync(_logger, new OutgoingMessage()
                    {
                        MessageFunction      = _clientSettings.MessageFunction,
                        ToHerId              = _clientSettings.ToHerId,
                        MessageId            = Guid.NewGuid().ToString("D"),
                        ScheduledSendTimeUtc = DateTime.UtcNow,
                        PersonalId           = "99999999999",
                        Payload              = XDocument.Load(File.OpenRead(s))
                    }).Result;
                    _logger.LogInformation(result.ToString());
                }
                return(0);
            });
        }