public StateService(ServerService serverService, InstallationService installationService, DownloadService downloadService) { var groupedServerEvents = serverService.Servers .Select(servers => servers .GroupBy(s => s.ForkAndVersion)); var downloadEvents = downloadService.Downloads.GetWeakCollectionChangedObservable() .Select(d => downloadService.Downloads) .Merge(Observable.Return(downloadService.Downloads)); var installationEvents = installationService.Installations; State = groupedServerEvents .CombineLatest(installationEvents, (servers, installations) => (servers, installations)) .Select(d => d.servers.FullJoin(d.installations, s => s.Key, i => i.ForkAndVersion, servers => new ForkInstall(null, null, servers.ToArray()), installation => new ForkInstall(null, installation, new List <Server>()), (servers, installation) => new ForkInstall(null, installation, servers.ToArray()))) .CombineLatest(downloadEvents, (join, downloads) => (join, downloads)) .Select(x => x.join.LeftJoin(x.downloads, s => s.ForkAndVersion, d => d.ForkAndVersion, s => s, (s, download) => new ForkInstall(download, s.Installation, s.Servers))) .Select(x => x.ToDictionary(d => d.ForkAndVersion, d => d)) .Do(x => Log.Information("State changed")) .Replay(1) .RefCount(); }
public ServerService(HttpClient http, InstallationService installService) { _http = http; _installService = installService; Servers = Observable.Timer(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(10)) .SelectMany(_ => GetServerListAsync()) .Replay(1) .RefCount(); }