static async Task <int> Main(string[] args)
        {
            var tw = new TextWriterTraceListener(Console.Out);

            tw.TraceOutputOptions |= TraceOptions.None;
            Trace.Listeners.Add(tw);
            Trace.AutoFlush = true;
            Trace.Indent();

            var app = new CommandLineApplication
            {
                Name        = "TW ING Coding Challenge",
                Description = "The TeamWildenberg console app for the different assignments in the ING Coding Challenge"
            };

            app.HelpOption("-?|-h|--help");
            var versionOption = app.Option("-v|--version", "Check which version we are running", CommandOptionType.NoValue);

            app.OnExecute(() =>
            {
                return(0);
            });
            app.Execute(args);

            if (versionOption.HasValue())
            {
                var assemblyVersion = Assembly.GetEntryAssembly().GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion;
                TraceExtensions.DoMessage($"Version: {assemblyVersion}");
                return(0);
            }
            else
            {
                // instantiate services
                ICurrencyConverterService converterService = new CurrencyConverterService();
                ICsvService csvService = new CsvService(new HttpClient());

                // execute command
                try
                {
                    ICommandAsync cmd = new ChallengeCommand(csvService, converterService);
                    await cmd.Execute().ConfigureAwait(false);

                    return(0);
                }
                catch (CsvServiceException x)
                {
                    TraceExtensions.DoError(x.Message);
                    return(-1);
                }
                catch (Exception)
                {
                    TraceExtensions.DoError($"Something fishy happened, exiting.");
                    throw;
                }
            }
        }
        async void HandleChallenges(ChallengeCommand challengeCommand, IConnection connection)
        {

            await @lock.ReaderLockAsync();

            try
            {

                if (this.connection != connection)
                    return;

                string productID = "PROD0120PW!CCV9@";
                string productKey = "C1BX{V4W}Q3*10SM";

                Debug.WriteLine("[Challenge Received]");

                string data = HandshakeUtility.GenerateChallengeRespose(challengeCommand.ChallengeString, productID, productKey);

                AcceptChallengeCommand cmd = new AcceptChallengeCommand(productID, data);

                try
                {

                    Command response = await responseTracker.GetResponseAsync<AcceptChallengeCommand>(cmd, defaultTimeout);

                    Debug.WriteLine("[Challenge Success]");

                }
                catch (TimeoutException)
                {
                    //there is nothing we can do here
                    return;
                }
                catch (ConnectionErrorException)
                {
                    //there is nothing we can do here
                    return;
                }

            }
            finally
            {
                @lock.ReaderRelease();
            }

        }
Exemple #3
0
 public ChallengeController(ChallengeCommand challengeCommand)
 {
     _challengeCommand = challengeCommand;
 }