Exemplo n.º 1
0
        /// <summary>
        /// Ensures the connection is successful by sending a test request.
        /// </summary>
        /// <param name="api">The league client api.</param>
        /// <returns>The league client api.</returns>
        private static async Task <LeagueClientApi> EnsureConnectionAsync(LeagueClientApi api)
        {
            while (true)
            {
                try
                {
                    await api.RequestHandler
                    .GetResponseAsync <string>(HttpMethod.Get, "/riotclient/app-name")
                    .ConfigureAwait(false);

                    var delay   = Task.Delay(200);
                    var connect = api.EventHandler.ConnectAsync();

                    var finished = await Task.WhenAny(delay, connect).ConfigureAwait(false);

                    if (finished == delay)
                    {
                        continue;
                    }

                    return(api);
                }
                catch (Exception)
                {
                    await Task.Delay(200).ConfigureAwait(false);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Connects to the league client api.
        /// </summary>
        /// <returns>A new instance of <see cref="LeagueClientApi" /> that's connected to the client api.</returns>
        public static async Task <LeagueClientApi> ConnectAsync()
        {
            var(port, token) = await GetAuthCredentialsAsync().ConfigureAwait(false);

            var eventHandler = new LeagueEventHandler(port, token);
            var api          = new LeagueClientApi(port, token, eventHandler);

            return(await EnsureConnectionAsync(api).ConfigureAwait(false));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Ensures the connection is successful by sending a test request.
        /// </summary>
        /// <param name="api">The league client api.</param>
        /// <returns>The league client api.</returns>
        private static async Task <LeagueClientApi> EnsureConnectionAsync(LeagueClientApi api)
        {
            while (true)
            {
                try
                {
                    await api.RequestHandler.GetResponseAsync <string>(HttpMethod.Get, "/riotclient/app-name").ConfigureAwait(false);

                    await Task.Run(() => api.EventHandler.Connect()).ConfigureAwait(false);

                    return(api);
                }
                catch (Exception)
                {
                    await Task.Delay(100).ConfigureAwait(false);
                }
            }
        }