private static void TransferCompletionToTask <T>(System.Threading.Tasks.TaskCompletionSource <T> tcs, System.ComponentModel.AsyncCompletedEventArgs e, Func <T> getResult, Action unregisterHandler) { if (e.UserState != tcs) { return; } try { unregisterHandler(); } finally { if (e.Cancelled) { tcs.TrySetCanceled(); } else if (e.Error != null) { tcs.TrySetException(e.Error); } else { tcs.TrySetResult(getResult()); } } }
/// <summary> /// Finds the receipt list based on the FromDateTime parameter for the currently logged in user. /// </summary> /// <param name="fromDateTime">The starting date and time to get receipts from, leave this blank to get all the receipts.</param> /// <returns>A Task<IEnumerable<Receipt> >that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<IEnumerable<Receipt>> GetReceiptsForUserAsync(this Buddy.Commerce commerce, System.Nullable<System.DateTime> fromDateTime = null) { var tcs = new System.Threading.Tasks.TaskCompletionSource<IEnumerable<Receipt>>(); commerce.GetReceiptsForUserInternal(fromDateTime, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Retrieves a sound from the Buddy sound library, and returns a Stream. Your application should perisist this stream locally in a location such as IsolatedStorage. /// </summary> /// <param name="soundName">The name of the sound file. See the Buddy Developer Portal "Sounds" page to find sounds and get their names.</param> /// <param name="quality">The quality level of the file to retrieve.</param> public Task<Stream> GetSoundAsync(string soundName, Buddy.Sounds.SoundQuality quality) { var tcs = new System.Threading.Tasks.TaskCompletionSource<Stream>(); this.GetSoundInternal(soundName, quality, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Finds the receipt associated with the specified CustomTransactionID for the currently logged in user. /// </summary> /// <param name="customTransactionID">The CustomTransactionID of the transaction. For Facebook payments this is the OrderID of the transaction.</param> /// <returns>A Task<IEnumerable<Receipt> >that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<IEnumerable<Receipt>> GetReceiptForUserAndTransactionIDAsync(this Buddy.Commerce commerce, string customTransactionID) { var tcs = new System.Threading.Tasks.TaskCompletionSource<IEnumerable<Receipt>>(); commerce.GetReceiptForUserAndTransactionIDInternal(customTransactionID, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Retrieves a sound from the Buddy sound library, and returns a Stream. Your application should perisist this stream locally in a location such as IsolatedStorage. /// </summary> /// <param name="soundName">The name of the sound file. See the Buddy Developer Portal "Sounds" page to find sounds and get their names.</param> /// <param name="quality">The quality level of the file to retrieve.</param> public Task <Stream> GetSoundAsync(string soundName, Buddy.Sounds.SoundQuality quality) { var tcs = new System.Threading.Tasks.TaskCompletionSource <Stream>(); this.GetSoundInternal(soundName, quality, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return(tcs.Task); }
/// <summary> /// Remove a GameState key. /// </summary> /// <param name="gameStateKey">The key to remove from the GameState.</param> /// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<Boolean> RemoveAsync(this Buddy.GameStates gameStates, string gameStateKey) { var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>(); gameStates.RemoveInternal(gameStateKey, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Get all sent message by the current user. /// </summary> /// <param name="afterDate">Optionally retreive only messages after a certain DateTime.</param> /// <returns>A Task<IEnumerable<Message> >that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<IEnumerable<Message>> GetSentAsync(this Buddy.Messages messages, System.DateTime afterDate = default(DateTime)) { var tcs = new System.Threading.Tasks.TaskCompletionSource<IEnumerable<Message>>(); messages.GetSentInternal(afterDate, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Get a Place by it's globally unique identifier. This method can also be used to calculate a distance from a lat/long to a place. /// </summary> /// <param name="placeId">The ID of the place to retreive.</param> /// <param name="latitude">The optional latitude to calcualte a distance to.</param> /// <param name="longitude">The optioanl longitude to calculate a distance to.</param> /// <returns>A Task<Place>that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<Place> GetAsync(this Buddy.Places places, int placeId, double latitude = 0, double longitude = 0) { var tcs = new System.Threading.Tasks.TaskCompletionSource<Place>(); places.GetInternal(placeId, latitude, longitude, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Delete this message group. /// </summary> /// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<Boolean> DeleteAsync(this Buddy.MessageGroup messageGroup) { var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>(); messageGroup.DeleteInternal((bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Check for the existance of an identity value in the system. The search is perform for the entire app. /// </summary> /// <param name="values">The value to search for. This can either be a single value or a semi-colon separated list of values.</param> /// <returns>A Task<IEnumerable<IdentityItemSearchResult> >that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<IEnumerable<IdentityItemSearchResult>> CheckForValuesAsync(this Buddy.Identity identity, string values) { var tcs = new System.Threading.Tasks.TaskCompletionSource<IEnumerable<IdentityItemSearchResult>>(); identity.CheckForValuesInternal(values, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Returns all the identity values for this user. /// </summary> /// <returns>A Task<IEnumerable<IdentityItem> >that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<IEnumerable<IdentityItem>> GetAllAsync(this Buddy.Identity identity) { var tcs = new System.Threading.Tasks.TaskCompletionSource<IEnumerable<IdentityItem>>(); identity.GetAllInternal((bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Get a virtual album by its globally unique identifier. All the album photos will be retreived as well. Note that this method internally does two web-service calls, and the IAsyncResult object /// returned is only valid for the first one. /// </summary> /// <param name="albumId">The ID of the virtual album to retrieve.</param> /// <returns>A Task<VirtualAlbum>that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<VirtualAlbum> GetAsync(this Buddy.VirtualAlbums virtualAlbums, int albumId) { var tcs = new System.Threading.Tasks.TaskCompletionSource<VirtualAlbum>(); virtualAlbums.GetInternal(albumId, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Create a new virtual album. Note that this method internally does two web-service calls, and the IAsyncResult object /// returned is only valid for the first one. /// </summary> /// <param name="name">The name of the new virtual album.</param> /// <param name="appTag">An optional application tag for the album.</param> /// <returns>A Task<VirtualAlbum>that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<VirtualAlbum> CreateAsync(this Buddy.VirtualAlbums virtualAlbums, string name, string appTag = "") { var tcs = new System.Threading.Tasks.TaskCompletionSource<VirtualAlbum>(); virtualAlbums.CreateInternal(name, appTag, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Update virtual album picture comment or app.tag. /// </summary> /// <param name="picture">The picture to be updated, either PicturePublic or Picture works.</param> /// <param name="newComment">The new comment to set for the picture.</param> /// <param name="newAppTag">An optional new application tag for the picture.</param> /// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<Boolean> UpdatePictureAsync(this Buddy.VirtualAlbum virtualAlbum, Buddy.PicturePublic picture, string newComment, string newAppTag = "") { var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>(); virtualAlbum.UpdatePictureInternal(picture, newComment, newAppTag, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Add a list of pictures to this virtual album. /// </summary> /// <param name="pictures">The list of pictures to add to this photo album. Either PicturePublic or Picture works.</param> /// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<Boolean> AddPictureBatchAsync(this Buddy.VirtualAlbum virtualAlbum, System.Collections.Generic.List<Buddy.PicturePublic> pictures) { var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>(); virtualAlbum.AddPictureBatchInternal(pictures, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Get a list of startups in the specified metro area. /// </summary> /// <param name="metroName">The name of the metro area within which to search for startups.</param> /// <param name="recordLimit">The number of search results to return.</param> /// <returns>A Task<IEnumerable<Startup> >that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<IEnumerable<Startup>> GetFromMetroAreaAsync(this Buddy.Startups startups, string metroName, int recordLimit) { var tcs = new System.Threading.Tasks.TaskCompletionSource<IEnumerable<Startup>>(); startups.GetFromMetroAreaInternal(metroName, recordLimit, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Searches for statups by name within the distance of the specified location. Note: To search for all startups within the distance from the specified location, leave the SearchName parameter empty. /// </summary> /// <param name="searchDistanceInMeters">The radius of the startup search.</param> /// <param name="latitude">The latitude where the search should start.</param> /// <param name="longitude">The longitude where the search should start.</param> /// <param name="numberOfResults">The number of search results to return.</param> /// <param name="searchForName">Optional search string, for example: "Star*" to search for all startups that begin with the string "Star".</param> /// <returns>A Task<IEnumerable<Startup> >that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<IEnumerable<Startup>> FindAsync(this Buddy.Startups startups, int searchDistanceInMeters, double latitude, double longitude, int numberOfResults=20, string searchForName = "") { var tcs = new System.Threading.Tasks.TaskCompletionSource<IEnumerable<Startup>>(); startups.FindInternal(searchDistanceInMeters, latitude, longitude, numberOfResults, searchForName, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Get all GameState keys and values. /// </summary> /// <returns>A Task<IDictionary<String,GameState> >that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<IDictionary<String, GameState>> GetAllAsync(this Buddy.GameStates gameStates) { var tcs = new System.Threading.Tasks.TaskCompletionSource<IDictionary<String, GameState>>(); gameStates.GetAllInternal((bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Returns information about all items in the store for the current application which are marked as free. /// </summary> /// <returns>A Task<IEnumerable<StoreItem> >that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<IEnumerable<StoreItem>> GetFreeStoreItemsAsync(this Buddy.Commerce commerce) { var tcs = new System.Threading.Tasks.TaskCompletionSource<IEnumerable<StoreItem>>(); commerce.GetFreeStoreItemsInternal((bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Accept a friend request from a user. /// </summary> /// <param name="user">The user to accept as friend. Can't be null and must be on the friend requests list.</param> /// <param name="appTag">Tag this friend accept with a string.</param> /// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<Boolean> AcceptAsync(this Buddy.FriendRequests friendRequests, Buddy.User user, string appTag = "") { var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>(); friendRequests.AcceptInternal(user, appTag, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Remove an identity value for this user. /// </summary> /// <param name="value">The value to remove.</param> /// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<Boolean> RemoveAsync(this Buddy.Identity identity, string value) { var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>(); identity.RemoveInternal(value, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Saves a receipt for the purchase of an item made to the application's store. /// </summary> /// <param name="totalCost">The total cost for the items purchased in the transaction.</param> /// <param name="totalQuantity">The total number of items purchased.</param> /// <param name="storeItemID">The store ID of the item of the item being purchased.</param> /// <param name="storeName">The name of the application's store to be saved with the transaction. This field is used by the commerce analytics to track purchases.</param> /// <param name="receiptData">Optional information to store with the receipt such as notes about the transaction.</param> /// <param name="customTransactionID">An optional app-specific ID to associate with the purchase.</param> /// <param name="appData">Optional metadata to associate with the transaction.</param> /// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<Boolean> SaveReceiptAsync(this Buddy.Commerce commerce, string totalCost, int totalQuantity, int storeItemID, string storeName, string receiptData = "", string customTransactionID = "", string appData = "") { var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>(); commerce.SaveReceiptInternal(totalCost, totalQuantity, storeItemID, storeName, receiptData, customTransactionID, appData, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Send a message to the entire message group. /// </summary> /// <param name="message">The message to send to this group. Must be less then 1000 characters.</param> /// <param name="latitude">The optional latitude from where this message was sent.</param> /// <param name="longitude">The optional longitude from where this message was sent.</param> /// <param name="appTag">An optional application tag for this message.</param> /// <returns>A Task<IDictionary<Int32,Boolean> >that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<IDictionary<Int32, Boolean>> SendMessageAsync(this Buddy.MessageGroup messageGroup, string message, double latitude = 0, double longitude = 0, string appTag = "") { var tcs = new System.Threading.Tasks.TaskCompletionSource<IDictionary<Int32, Boolean>>(); messageGroup.SendMessageInternal(message, latitude, longitude, appTag, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Get all message groups that this user is part of. /// </summary> /// <returns>A Task<IEnumerable<MessageGroup> >that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<IEnumerable<MessageGroup>> GetMyAsync(this Buddy.MessageGroups messageGroups) { var tcs = new System.Threading.Tasks.TaskCompletionSource<IEnumerable<MessageGroup>>(); messageGroups.GetMyInternal((bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Create a new message group. /// </summary> /// <param name="name">The name of the new group, must be unique for the app.</param> /// <param name="openGroup">Optionally whether to make to group open for all user (anyone can join), or closed (only the owner can add users to it).</param> /// <param name="appTag">An optional application tag for this message group.</param> /// <returns>A Task<MessageGroup>that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<MessageGroup> CreateAsync(this Buddy.MessageGroups messageGroups, string name, bool openGroup, string appTag = "") { var tcs = new System.Threading.Tasks.TaskCompletionSource<MessageGroup>(); messageGroups.CreateInternal(name, openGroup, appTag, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Get all geo-location categories in Buddy. /// </summary> /// <returns>A Task<IDictionary<Int32,String> >that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<IDictionary<Int32, String>> GetCategoriesAsync(this Buddy.Places places) { var tcs = new System.Threading.Tasks.TaskCompletionSource<IDictionary<Int32, String>>(); places.GetCategoriesInternal((bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Check if a group with this name already exists. /// </summary> /// <param name="name">The name of the group to check for.</param> /// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<Boolean> CheckIfExistsAsync(this Buddy.MessageGroups messageGroups, string name) { var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>(); messageGroups.CheckIfExistsInternal(name, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Remove a user from the current list of friends. /// </summary> /// <param name="user">The user to remove from the friends list. Must be already on the list and can't be null.</param> /// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<Boolean> RemoveAsync(this Buddy.Friends friends, Buddy.User user) { var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>(); friends.RemoveInternal(user, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Send a message to a user from the current authenticated user. /// </summary> /// <param name="toUser">The user to send a message to.</param> /// <param name="message">The message to send, must be less then 200 characters.</param> /// <param name="appTag">An optional application tag to set for the message.</param> /// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<Boolean> SendAsync(this Buddy.Messages messages, Buddy.User toUser, string message, string appTag = "") { var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>(); messages.SendInternal(toUser, message, appTag, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Add a new score for this user. /// </summary> /// <param name="score">The numeric value of the score.</param> /// <param name="board">The optional name of the game board.</param> /// <param name="rank">The optional rank for this score. This can be used for adding badges, achievements, etc.</param> /// <param name="latitude">The optional latitude for this score.</param> /// <param name="longitude">The optional longitude for this score.</param> /// <param name="oneScorePerPlayer">The optional one-score-per-player paramter. Setting this to true will always update the score for this user, instead of creating a new one.</param> /// <param name="appTag">An optional application tag for this score.</param> /// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<Boolean> AddAsync(this Buddy.GameScores gameScores, double score, string board = null, string rank = null, double latitude = 0, double longitude = 0, bool oneScorePerPlayer = false, string appTag = null) { var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>(); gameScores.AddInternal(score, board, rank, latitude, longitude, oneScorePerPlayer, appTag, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Updates the value of this metadata item. /// </summary> /// <param name="value">The new value for this item, can't be null.</param> /// <param name="latitude">The optional latitude for this item.</param> /// <param name="longitude">The optional longitude for this item.</param> /// <param name="appTag">The optional application tag for this item.</param> /// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<Boolean> SetAsync(this Buddy.MetadataItem metadataItem, string value, double latitude = 0, double longitude = 0, string appTag = "") { var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>(); metadataItem.SetInternal(value, latitude, longitude, appTag, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }
/// <summary> /// Return all score entries for this user. /// </summary> /// <param name="recordLimit">Limit the number of entries returned.</param> /// <returns>A Task<IEnumerable<GameScore> >that can be used to monitor progress on this call.</returns> public static System.Threading.Tasks.Task<IEnumerable<GameScore>> GetAllAsync(this Buddy.GameScores gameScores, int recordLimit = 100) { var tcs = new System.Threading.Tasks.TaskCompletionSource<IEnumerable<GameScore>>(); gameScores.GetAllInternal(recordLimit, (bcr) => { if (bcr.Error != BuddyServiceClient.BuddyError.None) { tcs.TrySetException(new BuddyServiceException(bcr.Error)); } else { tcs.TrySetResult(bcr.Result); } }); return tcs.Task; }