Tunez.Scrobbler.Login C# (CSharp) Method

Login() public method

public Login ( ) : Task
return Task
		public async Task<bool> Login ()
		{
			if (string.IsNullOrEmpty (Username) || string.IsNullOrEmpty (Password))
				return false;

			try {
				if (SessionKey != null)
					return true;

				if (File.Exists (SessionKeyFile)) {
					SessionKey = File.ReadAllText (SessionKeyFile);
					return true;
				}
			} catch (Exception ex) {
				LoggingService.LogError (ex, "Could not read the cached session key");
				Files.Delete (SessionKeyFile);
				LoggingService.LogError (ex, "Deleted the cached session key");
			}

			try {
				var uri = CreateAuthenticationUri ();
				var response = await PostAsync (uri);
				return HandleAuthResponse (response);
			} catch (Exception ex) {
				LoggingService.LogError (ex, "Could not log in to last.fm");
			}

			return false;
		}