private async void RetrieveDatabases() { if (String.IsNullOrWhiteSpace(SqlInstance)) { return; } IsBusy = true; BusyMessage = "Retrieving Databases for " + SqlInstance; Databases.IsNotifying = false; try { Databases.Clear(); IEnumerable <string> dbs = await RetrieveDatabasesAsync(); Databases.AddRange(dbs); } finally { IsBusy = false; Databases.IsNotifying = true; Databases.Refresh(); } }
private async Task <bool> GetDatabasesAsync() { DacpRequest request = new DacpRequest("/databases"); try { var databases = await GetListAsync(request, n => DacpDatabase.GetDatabase(this, n)).ConfigureAwait(false); if (databases == null || databases.Count == 0) { return(false); } List <DacpDatabase> newSharedDatabases = new List <DacpDatabase>(); for (int i = 0; i < databases.Count; i++) { var db = databases[i]; // The main database will be first in the list if (i == 0) { if (MainDatabase != null && MainDatabase.ID == db.ID) { continue; } bool success = await db.RequestContainersAsync().ConfigureAwait(false); if (!success) { return(false); } MainDatabase = db; continue; } // Shared database if (db.Type == DatabaseType.Shared) { newSharedDatabases.Add(db); continue; } // Internet Radio if (db.Type == DatabaseType.InternetRadio) { if (InternetRadioDatabase != null && InternetRadioDatabase.ID == db.ID) { continue; } InternetRadioDatabase = db; continue; } // iTunes Radio if (db.Type == DatabaseType.iTunesRadio) { if (iTunesRadioDatabase != null && iTunesRadioDatabase.ID == db.ID) { continue; } iTunesRadioDatabase = (iTunesRadioDatabase)db; // Attempt to load the stations asynchronously to determine whether iTunes Radio is enabled. var task = iTunesRadioDatabase.RequestStationsAsync(); continue; } } // Update shared databases Dictionary <int, DacpDatabase> removedSharedDBs = SharedDatabases.ToDictionary(db => db.ID); foreach (var sharedDB in newSharedDatabases) { removedSharedDBs.Remove(sharedDB.ID); if (SharedDatabases.Any(db => db.ID == sharedDB.ID)) { continue; } SharedDatabases.Add(sharedDB); } foreach (DacpDatabase db in removedSharedDBs.Values) { SharedDatabases.Remove(db); } Databases.Clear(); Databases.AddRange(databases); } catch { return(false); } return(true); }
public async Task<Databases> GetDatabasesAsync() { ThrowIfDisposed(); var result = new Databases(); var json = await GetDatabasesJsonAsync().ForAwait(); var data = Requester.JsonSerializer.Deserialize<InfluxDbResponse>(json); if (data?.Results == null || !data.Results.Any()) return result; foreach (var serie in data.Results.SelectMany(r => r.Series)) result.AddRange(serie.Values.Select(value => value.First.ToObject<string>()).ToArray()); return result; }