Inheritance: IRdioObjectKeyVisitor
Exemple #1
0
		public async Task SyncUser (string userId, bool syncFollowing)
		{
			var startTime = DateTime.UtcNow;
			var syncController = new UserSyncController (api, userId,
				sharedObjectStore ?? new RdioObjectStore ());

			do {
				try {
					await syncController.SyncStepAsync (() => DisplayStatusBar (
						syncController.SyncedObjects, syncController.TotalObjects));
				} catch (Exception e) {
					var webException = e as WebException;
					var httpRequestException = e as HttpRequestException;
					if (webException != null || httpRequestException != null) {
						Console.WriteLine ("  ! Connection Error");
						if (verbose)
							Console.Error.WriteLine (e);	
					} else if (e is UserNotFoundException)
						Console.WriteLine ("  ! Could not find Rdio user {0}",
							syncController.UserIdentifier);
					else if (e is OperationCanceledException)
						Console.WriteLine ("  ! Canceled");
					else
						Console.WriteLine (e);

					syncController = null;
					return;
				}

				switch (syncController.SyncState) {
				case SyncState.Start:
					break;
				case SyncState.FindingUser:
					Console.WriteLine ("Starting work for '{0}'...",
						syncController.UserIdentifier);
					break;
				case SyncState.FoundUser:
					Console.WriteLine ("  * Resolved user {0} ({1})...",
						syncController.UserKeyStore.User.DisplayName,
						syncController.UserKeyStore.User.Key);
					break;
				case SyncState.SyncingUserKeys:
					Console.WriteLine ("  * Fetching keys...");
					break;
				case SyncState.SyncedUserKeys:
					Console.WriteLine ("    {0} toplevel keys of interest",
						syncController.UserKeyStore.TotalKeys);
					break;
				case SyncState.SyncingObjects:
					Console.WriteLine ("  * Fetching objects...");
					break;
				case SyncState.SyncedObjects:
					Console.WriteLine ();
					Console.WriteLine ("    {0} objects fetched",
						syncController.TotalObjects);
					break;
				case SyncState.Finished:
					Console.WriteLine ("  * Fetched in {0}",
						(DateTime.UtcNow - startTime).ToFriendlyString ());

					if (sharedObjectStore == null) {
						var path = Path.Combine (outputDir, syncController.FileName);
						Console.WriteLine ("  * Exporting to {0}...", path);
						syncController.CreateExporter ().Export (path);
					} else
						userKeyStores.Add (syncController.UserKeyStore);

					Console.WriteLine ("  * Done!");
					break;
				}
			} while (syncController.SyncState != SyncState.Finished);

			if (syncFollowing) {
				var user = syncController.UserKeyStore.User;
				foreach (var followingKey in api.GetUserFollowingAsync (user).Result)
					SyncUser (followingKey, false).Wait ();
			}
		}
Exemple #2
0
        public async Task SyncUser(string userId, bool syncFollowing)
        {
            var startTime      = DateTime.UtcNow;
            var syncController = new UserSyncController(api, userId,
                                                        sharedObjectStore ?? new RdioObjectStore());

            do
            {
                try {
                    await syncController.SyncStepAsync(() => DisplayStatusBar (
                                                           syncController.SyncedObjects, syncController.TotalObjects));
                } catch (Exception e) {
                    var webException         = e as WebException;
                    var httpRequestException = e as HttpRequestException;
                    if (webException != null || httpRequestException != null)
                    {
                        Console.WriteLine("  ! Connection Error");
                        if (verbose)
                        {
                            Console.Error.WriteLine(e);
                        }
                    }
                    else if (e is UserNotFoundException)
                    {
                        Console.WriteLine("  ! Could not find Rdio user {0}",
                                          syncController.UserIdentifier);
                    }
                    else if (e is OperationCanceledException)
                    {
                        Console.WriteLine("  ! Canceled");
                    }
                    else
                    {
                        Console.WriteLine(e);
                    }

                    syncController = null;
                    return;
                }

                switch (syncController.SyncState)
                {
                case SyncState.Start:
                    break;

                case SyncState.FindingUser:
                    Console.WriteLine("Starting work for '{0}'...",
                                      syncController.UserIdentifier);
                    break;

                case SyncState.FoundUser:
                    Console.WriteLine("  * Resolved user {0} ({1})...",
                                      syncController.UserKeyStore.User.DisplayName,
                                      syncController.UserKeyStore.User.Key);
                    break;

                case SyncState.SyncingUserKeys:
                    Console.WriteLine("  * Fetching keys...");
                    break;

                case SyncState.SyncedUserKeys:
                    Console.WriteLine("    {0} toplevel keys of interest",
                                      syncController.UserKeyStore.TotalKeys);
                    break;

                case SyncState.SyncingObjects:
                    Console.WriteLine("  * Fetching objects...");
                    break;

                case SyncState.SyncedObjects:
                    Console.WriteLine();
                    Console.WriteLine("    {0} objects fetched",
                                      syncController.TotalObjects);
                    break;

                case SyncState.Finished:
                    Console.WriteLine("  * Fetched in {0}",
                                      (DateTime.UtcNow - startTime).ToFriendlyString());

                    if (sharedObjectStore == null)
                    {
                        var path = Path.Combine(outputDir, syncController.FileName);
                        Console.WriteLine("  * Exporting to {0}...", path);
                        syncController.CreateExporter().Export(path);
                    }
                    else
                    {
                        userKeyStores.Add(syncController.UserKeyStore);
                    }

                    Console.WriteLine("  * Done!");
                    break;
                }
            } while (syncController.SyncState != SyncState.Finished);

            if (syncFollowing)
            {
                var user = syncController.UserKeyStore.User;
                foreach (var followingKey in api.GetUserFollowingAsync(user).Result)
                {
                    SyncUser(followingKey, false).Wait();
                }
            }
        }