public async Task LoadUserPlaylists(string kind, RdioUserKeyStore targetUserStore) { int offset = 0; while (true) { var result = await CallAsync("getUserPlaylists", new Dictionary <string, string> { ["user"] = targetUserStore.User.Key, ["kind"] = kind, ["start"] = offset.ToString(), ["extras"] = "-*,key" }) as JArray; if (result?.Count == 0) { break; } offset += result.Count; if (result != null) { targetUserStore.AddPlaylists(kind, result.Select(p => p ["key"].Value <string> ())); } } }
public async Task LoadFavoritesAndSyncedKeysAsync(RdioUserKeyStore targetUserStore) { var result = (JObject) await CallAsync("getKeysInFavoritesAndSynced", new Dictionary <string, string> { ["user"] = targetUserStore.User.Key } ); var synced = result ["syncedKeys"] as JArray; if (synced != null) { targetUserStore.AddSyncedKeys(synced.Values <string> ()); } var favorites = result ["favoritesKeys"] as JArray; if (favorites != null) { targetUserStore.AddFavoritesKeys(favorites.Values <string> ()); } }
public async Task<SyncState> SyncStepAsync (Action syncProgressChanged) { switch (SyncState) { case SyncState.Start: SyncState = SyncState.FindingUser; break; case SyncState.FindingUser: UserKeyStore = new RdioUserKeyStore (await FindUserAsync ()); SyncState = SyncState.FoundUser; break; case SyncState.FoundUser: SyncState = SyncState.SyncingUserKeys; break; case SyncState.SyncingUserKeys: foreach (var kind in new [] { "owned", "favorites", "subscribed", "collab" }) await api.LoadUserPlaylists (kind, UserKeyStore); await api.LoadFavoritesAndSyncedKeysAsync (UserKeyStore); SyncState = SyncState.SyncedUserKeys; break; case SyncState.SyncedUserKeys: SyncState = SyncState.SyncingObjects; break; case SyncState.SyncingObjects: keysProcessor = new ItemsProcessor<string> ( UserKeyStore.AllKeys.Where (k => !ObjectStore.ContainsKey (k)), KeyProcessorAsync, chunkCount => { TotalObjects = keysProcessor.TotalEnqueued; SyncedObjects = keysProcessor.TotalProcessed; syncProgressChanged?.Invoke (); } ); TotalObjects = keysProcessor.TotalEnqueued; SyncedObjects = 0; await keysProcessor.ProcessAsync (CancellationToken); SyncState = SyncState.SyncedObjects; break; case SyncState.SyncedObjects: SyncState = SyncState.Finished; break; } return SyncState; }