static async Task<TwitchChannel[]> ConnectAsync(params string[] channelNames) { TwitchConnection twitch = new TwitchConnection(); string[] loginData = File.ReadLines("login.txt").Take(2).ToArray(); var connectResult = await twitch.ConnectAsync(loginData[0], loginData[1]); if (connectResult != ConnectResult.Connected) { Console.WriteLine("Failed to login."); return null; } //TwitchChannel result = Create(channel); //await result.JoinAsync(); //return result; TwitchChannel[] channels = (from channelName in channelNames select twitch.Create(channelName)).ToArray(); Task[] channelTasks = (from channel in channels select channel.JoinAsync()).ToArray(); var result = new TwitchChannel[channelTasks.Length]; for (int i = 0; i < result.Length; ++i) await channelTasks[i]; return channels; }
async Task<TwitchChannel> Connect(string channelName) { Debug.Assert(m_channel == null); var twitch = new TwitchConnection(ClientType.Full); var connection = twitch.ConnectAsync(m_options.User, m_options.Pass); var channel = JoinChannel(twitch, channelName); var result = await connection; if (result == ConnectResult.LoginFailed) { WriteStatus("Failed to login, please change options.ini and restart the application."); return null; } while (result != ConnectResult.Connected) { if (result == ConnectResult.LoginFailed) { WriteStatus("Failed to login, please change options.ini and restart the application."); return null; } else if (result == ConnectResult.NetworkError) { if (!NativeMethods.IsConnectedToInternet()) { WriteStatus("Not connected to the internet."); do { await Task.Delay(5000); } while (!NativeMethods.IsConnectedToInternet()); WriteStatus("Re-connected to the internet."); } else { WriteStatus("Failed to connect: network error"); } } await Task.Delay(5000); result = await twitch.ConnectAsync(m_options.User, m_options.Pass); } await channel.JoinAsync(); WriteStatus("Connected to channel {0}.", channel.Name); return channel; }