private async Task <bool> CreatePlexServerConnection(string ipAddress) { var connection = new PlexServerConnection(_restConnection, ipAddress, _myPlexConnection.User); await connection.ConnectAsync(); var needRebuild = false; lock (_syncObject) { if (!_serverConnections.ContainsKey(connection.MachineIdentifier)) { _serverConnections.Add(connection.MachineIdentifier, connection); _plexServerConnections.Add(connection); needRebuild = true; } } if (needRebuild) { await RebuildNowPlaying(); UpdateConnections(); } return(connection.ConnectionStatus == ConnectionStatus.Connected); }
public async Task <IEnumerable <IPlexServerConnection> > CreateServerConnectionsAsync() { var serverConnections = new List <IPlexServerConnection>(); List <Device> servers; lock (_deviceSyncObj) servers = Servers.ToList(); foreach (var device in servers) { PlexServerConnection connection; lock (_deviceSyncObj) { if (!_serverConnections.TryGetValue(device.Key, out connection)) { connection = new PlexServerConnection(_restConnection, device, User); _serverConnections.Add(device.Key, connection); } } serverConnections.Add(connection); if (connection.User == null && User != null) { connection.User = User; } if (connection.ConnectionStatus != Connection.ConnectionStatus.Connected) { await connection.ConnectAsync(); } } return(serverConnections); }