private async Task SynchronizeServer(List <PlexMediaSource> allExisting, PlexMediaSource server) { Option <PlexMediaSource> maybeExisting = allExisting.Find(s => s.ClientIdentifier == server.ClientIdentifier); await maybeExisting.Match( existing => { existing.ProductVersion = server.ProductVersion; existing.ServerName = server.ServerName; var toAdd = server.Connections .Filter(connection => existing.Connections.All(c => c.Uri != connection.Uri)).ToList(); var toRemove = existing.Connections .Filter(connection => server.Connections.All(c => c.Uri != connection.Uri)).ToList(); return(_mediaSourceRepository.Update(existing, toAdd, toRemove)); }, async() => { if (server.Connections.Any()) { server.Connections.Head().IsActive = true; } await _mediaSourceRepository.Add(server); }); }
private async Task SynchronizeServer(List <PlexMediaSource> allExisting, PlexMediaSource server) { if (server.Connections.All(c => c.Uri != LocalhostUri)) { var localhost = new PlexConnection { PlexMediaSource = server, PlexMediaSourceId = server.Id, Uri = LocalhostUri }; server.Connections.Add(localhost); } Option <PlexMediaSource> maybeExisting = allExisting.Find(s => s.ClientIdentifier == server.ClientIdentifier); foreach (PlexMediaSource existing in maybeExisting) { existing.Platform = server.Platform; existing.PlatformVersion = server.PlatformVersion; existing.ProductVersion = server.ProductVersion; existing.ServerName = server.ServerName; var toAdd = server.Connections .Filter(connection => existing.Connections.All(c => c.Uri != connection.Uri)).ToList(); var toRemove = existing.Connections .Filter(connection => server.Connections.All(c => c.Uri != connection.Uri)).ToList(); await _mediaSourceRepository.Update(existing, toAdd, toRemove); await FindConnectionToActivate(existing); } if (maybeExisting.IsNone) { await _mediaSourceRepository.Add(server); await FindConnectionToActivate(server); } }