GetAsync() public method

public GetAsync ( CancellationToken cancellationToken = default(CancellationToken) ) : Task
cancellationToken CancellationToken
return Task
示例#1
0
        public override async Task <GreetingEvent> HandleAsync(GreetingEvent @event, CancellationToken cancellationToken = default(CancellationToken))
        {
            // Simulated exceptions
            if (@event.Name.ToLower().Equals("roger"))
            {
                throw new ArgumentException("Roger's greeting will not be handled by Want-to-be-greeted.");
            }
            if (@event.Name.ToLower().Equals("devil"))
            {
                throw new ArgumentException("Devil's greeting will not be handled by Want-to-be-greeted.");
            }

            var api    = new IpFyApi(new Uri("https://api.ipify.org"));
            var result = await api.GetAsync(cancellationToken).ConfigureAwait(ContinueOnCapturedContext);

            Console.BackgroundColor = ConsoleColor.Blue;
            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine($"Want-to-be-greeted received hello from {@event.Name}");
            Console.WriteLine(result.Success ? $"Want-to-be-greeted has public IP address is {result.Message}" : $"Call to IpFy API failed : {result.Message}");

            Console.ResetColor();

            return(await base.HandleAsync(@event, cancellationToken).ConfigureAwait(ContinueOnCapturedContext));
        }
        public override async Task <GreetingEvent> HandleAsync(GreetingEvent @event, CancellationToken cancellationToken = default(CancellationToken))
        {
            var api    = new IpFyApi(new Uri("https://api.ipify.org"));
            var result = await api.GetAsync(cancellationToken).ConfigureAwait(ContinueOnCapturedContext);

            // Simulated exceptions
            if (@event.Name.ToLower().Equals("devil"))
            {
                throw new ArgumentException("Devil's greeting will not be handled by Want-to-be-greeted-too.");
            }

            Console.WriteLine("Want-to-be-greeted-too received hello from {0}", @event.Name);
            Console.WriteLine(result.Success ? "Want-to-be-greeted-too has public IP addres is {0}" : "Call to IpFy API failed : {0}",
                              result.Message);

            return(await base.HandleAsync(@event, cancellationToken).ConfigureAwait(ContinueOnCapturedContext));
        }