本文整理汇总了C#中System.Threading.Tasks.TaskCompletionSource.TrySetResult方法的典型用法代码示例。如果您正苦于以下问题:C# System.Threading.Tasks.TaskCompletionSource.TrySetResult方法的具体用法?C# System.Threading.Tasks.TaskCompletionSource.TrySetResult怎么用?C# System.Threading.Tasks.TaskCompletionSource.TrySetResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Tasks.TaskCompletionSource
的用法示例。
在下文中一共展示了System.Threading.Tasks.TaskCompletionSource.TrySetResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SupportedFiltersAsync
/// <summary>
/// Returns a list of supported filters that can be applied to this picture. Example filters are: Hue Shift, Crop, etc.
/// </summary>
/// <returns>A Task<IDictionary<String,String> >that can be used to monitor progress on this call.</returns>
public System.Threading.Tasks.Task<IDictionary<String, String>> SupportedFiltersAsync()
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<IDictionary<String, String>>();
SupportedFiltersInternal((bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例2: BatchSumAsync
/// <summary>
/// This method returns the sum of a set of metadata items that correspond to a certain key wildcard. Note that the values of these items
/// need to be numbers or floats, otherwise this method will fail.
/// Unlike the 'Sum' method this method can take a list of keys separated by semicolons and will return a list of sums for all of those keys.
/// </summary>
/// <param name="forKeys">The key to use to filter the items that need to be summed. Is always treated as a wildcard.</param>
/// <param name="withinDistance">Optionally sum only items within a certain number of meters from lat/long.</param>
/// <param name="latitude">Optionally provide a latitude where the search can be started from.</param>
/// <param name="longitude">Optionally provide a longitude where the search can be started from.</param>
/// <param name="updatedMinutesAgo">Optionally sum only on items that have been update a number of minutes ago.</param>
/// <param name="withAppTag">Optionally sum only items that have a certain application tag.</param>
/// <returns>A Task<IEnumerable<MetadataSum> >that can be used to monitor progress on this call.</returns>
public System.Threading.Tasks.Task<IEnumerable<MetadataSum>> BatchSumAsync( string forKeys, string withinDistance = "-1", double latitude = -1, double longitude = -1, int updatedMinutesAgo = -1, string withAppTag = "")
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<IEnumerable<MetadataSum>>();
this.BatchSumInternal(forKeys, withinDistance, latitude, longitude, updatedMinutesAgo, withAppTag, (bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例3: AddPictureWithWatermarkAsync
/// <summary>
/// Add a new picture to this 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="photoStream">A stream containing the photo's contents..</param>
/// <param name="comment">An optional comment for this picture.</param>
/// <param name="latitude">An optional latitude for the picture.</param>
/// <param name="longitude">An optional longitude for the picture.</param>
/// <param name="appTag">An optional application tag.</param>
/// <param name="watermarkmessage">An optional message to watermark the image with.</param>
/// <returns>A Task<Picture>that can be used to monitor progress on this call.</returns>
public System.Threading.Tasks.Task<Picture> AddPictureWithWatermarkAsync(Stream photoStream, string comment = "", double latitude = 0, double longitude = 0, string appTag = "", string watermarkmessage = "")
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<Picture>();
AddPictureWithWatermarkInternal(photoStream, comment, latitude, longitude, appTag, watermarkmessage, (bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例4: GetAllAsync
/// <summary>
/// Get all the metadata items for this user. Note that this can be a very expensive method, try to retrieve specific items if possible
/// or do a search.
/// </summary>
/// <returns>A Task<IDictionary<String,MetadataItem> >that can be used to monitor progress on this call.</returns>
public System.Threading.Tasks.Task<IDictionary<String, MetadataItem>> GetAllAsync()
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<IDictionary<String, MetadataItem>>();
this.GetAllInternal((bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例5: BatchSetAsync
/// <summary>
/// Set metadata item values for keys. You can additionally add a latitude and longitude coordinate to record the location
/// from where these items were set, or tag all items with a custom tag.
/// The item doesn't have to exist to be set, this method acts as an Add method in cases where the item doesn't exist.
/// </summary>
/// <param name="keys">The keys of the metadata items, can't be null or empty.</param>
/// <param name="values">The values of the metadata items, can't be null or empty.</param>
/// <param name="latitude">The optional latitude of the metadata items.</param>
/// <param name="longitude">The optional longitude of the metadata items.</param>
/// <param name="appTag">The optional application tag for these items.</param><exception cref="T:System.ArgumentException">When any key is null or empty.</exception><exception cref="T:System.ArgumentNullException">When any value is or empty.</exception>
/// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns>
public System.Threading.Tasks.Task<Boolean> BatchSetAsync( string keys, string values, double latitude = 0, double longitude = 0, string appTag = "")
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>();
this.BatchSetInternal(keys, values, latitude, longitude, appTag, (bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例6: SendTileAsync
/// <summary>
/// Send a image tile to a windows phone device. The tile is represented by a image URL, you can take a look at the Windows phone docs for image dimensions and formats.
/// </summary>
/// <param name="imageUri">The URL of the tile image.</param>
/// <param name="senderUserId">The ID of the user that sent the notification.</param>
/// <param name="messageCount">The message count for this tile.</param>
/// <param name="messageTitle">The message title for the tile.</param>
/// <param name="deliverAfter">Schedule the message to be delivered after a certain date.</param>
/// <param name="groupName">Send messages to an entire group of users, not just a one.</param>
/// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns>
public System.Threading.Tasks.Task<Boolean> SendTileAsync(string imageUri, int senderUserId, int messageCount = -1, string messageTitle = "", System.DateTime deliverAfter = default(DateTime), string groupName = "")
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>();
SendTileInternal(imageUri, senderUserId, messageCount, messageTitle, deliverAfter, groupName, (bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例7: ConfigurePushAsync
/// <summary>
/// Configure this Windows Phone device for push notifications
/// </summary>
/// <param name="channelName"></param>
/// <param name="enableTiles"></param>
/// <param name="enableToastMessages"></param>
/// <param name="groupName"></param>
/// <param name="allowedDomains"></param>
/// <param name="rawMessageCallback"></param>
/// <param name="toastMessageCallback"></param>
public System.Threading.Tasks.Task<Boolean> ConfigurePushAsync(bool enableTiles, bool enableToastMessages, string groupName = "",
List<string> allowedDomains = null, Action<string> rawMessageCallback = null, Action<IDictionary<string, string>> toastMessageCallback = null, string channelName = null)
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>();
Action<bool, Exception> finish = (result, ex) =>
{
if (ex != null)
{
tcs.TrySetException(ex);
}
else
{
tcs.TrySetResult(result);
}
};
if (allowedDomains == null) allowedDomains = new List<string>();
allowedDomains.Add("http://buddyplatform.s3.amazonaws.com/");
channelName = this.GetChannelName(channelName);
HttpNotificationChannel channel = null;
bool done = false;
if ((channel = HttpNotificationChannel.Find(channelName)) == null)
{
channel = new HttpNotificationChannel(channelName, "www.buddy.com");
if (channel == null)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
finish(false, new Exception("Couldn't create HttpNotificationChannel."));
});
done = true;
}
else
{
channel.Open();
}
}
if (!done && rawMessageCallback != null) channel.HttpNotificationReceived += (s, ev) =>
{
StreamReader reader = new StreamReader(ev.Notification.Body);
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
rawMessageCallback(reader.ReadToEnd());
});
};
if (!done && toastMessageCallback != null) channel.ShellToastNotificationReceived += (s, ev) =>
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
toastMessageCallback(ev.Collection);
});
};
Action<HttpNotificationChannel> registerUri = (newChannel) =>
{
if (enableTiles)
{
BindTile(newChannel, allowedDomains);
}
if (enableToastMessages)
{
BindToast(newChannel);
}
this.RegisterDeviceInternal(newChannel.ChannelUri.ToString(), enableTiles, rawMessageCallback != null, enableToastMessages, groupName, (bcr) =>
{
finish(bcr.Result, bcr.Error == BuddyError.None ? null : new BuddyServiceException(bcr.Error.ToString()));
});
};
if (!done)
{
channel.ChannelUriUpdated += (s, ev) =>
{
registerUri(channel);
};
//.........这里部分代码省略.........
示例8: UpdateAsync
/// <summary>
/// Update the profile of this user.
/// </summary>
/// <param name="name">Optional new name for the user, can't be null or empty.</param>
/// <param name="password">Optional new password for the user, can't be null.</param>
/// <param name="gender">Optional new gender for the user.</param>
/// <param name="age">Optional new age for the user.</param>
/// <param name="email">Optional new email for the user.</param>
/// <param name="status">Optional new status for the user.</param>
/// <param name="fuzzLocation">Optional change in location fuzzing for this user. If location fuzzing is enable, user location will be
/// randomized in all searches by other users.</param>
/// <param name="celebrityMode">Optional change in celebrity mode for this user. If celebrity mode is enabled the user will be hidden from all searches in the system.</param>
/// <param name="appTag">Optional update to the custom application tag for this user.</param>
/// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns>
public System.Threading.Tasks.Task<Boolean> UpdateAsync(string name = "", string password = "", Buddy.UserGender gender = UserGender.Any, int age = 0, string email = "", Buddy.UserStatus status = UserStatus.Any, bool fuzzLocation = false, bool celebrityMode = false, string appTag = "")
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>();
UpdateInternal(name, password, gender, age, email, status, fuzzLocation, celebrityMode, appTag, (bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例9: GetPictureAsync
/// <summary>
/// Retrieve a picture by its unique ID. Any picture that the user owns or is publicly available can be retrieved.
/// </summary>
/// <param name="pictureId">The id of the picture to retrieve.</param>
/// <returns>A Task<Picture>that can be used to monitor progress on this call.</returns>
public System.Threading.Tasks.Task<Picture> GetPictureAsync(int pictureId)
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<Picture>();
GetPictureInternal(pictureId, (bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例10: GetCheckInsAsync
/// <summary>
/// Get a list of user check-in locations.
/// </summary>
/// <param name="afterDate">Filter the list to return only check-in after a date.</param>
/// <returns>A Task<IEnumerable<CheckInLocation> >that can be used to monitor progress on this call.</returns>
public System.Threading.Tasks.Task<IEnumerable<CheckInLocation>> GetCheckInsAsync(System.DateTime afterDate = default(DateTime))
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<IEnumerable<CheckInLocation>>();
GetCheckInsInternal(afterDate, (bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例11: FindUser
public System.Threading.Tasks.Task<Buddy.User> FindUser(string userNameToFetch)
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<User>();
this.FindUserInternal(userNameToFetch, (bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例12: CheckInAsync
/// <summary>
/// Check-in the user at a location.
/// </summary>
/// <param name="latitude">The latitude of the location.</param>
/// <param name="longitude">The longitude of the location.</param>
/// <param name="comment">An optional comment for the check-in.</param>
/// <param name="appTag">An optional application specific tag for the location.</param>
/// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns>
public System.Threading.Tasks.Task<Boolean> CheckInAsync(double latitude, double longitude, string comment = "", string appTag = "")
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>();
CheckInInternal(latitude, longitude, comment, appTag, (bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例13: AddProfilePhotoAsync
/// <summary>
/// Add a profile photo for this user.
/// </summary>
/// <param name="photoSteam">An array of bytes that represent the image you are adding.</param>
/// <param name="appTag">An optional tag for the photo.</param>
/// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns>
public System.Threading.Tasks.Task<Boolean> AddProfilePhotoAsync(Stream photoSteam, string appTag = "")
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>();
AddProfilePhotoInternal(photoSteam, appTag, (bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例14: FindUserAsync
public System.Threading.Tasks.Task<IEnumerable<User>> FindUserAsync(double latitude = 0, double longitude = 0, uint searchDistance = 2147483647, uint recordLimit = 10, Buddy.UserGender gender = UserGender.Any, uint ageStart = 0, uint ageStop = 200, Buddy.UserStatus status = UserStatus.Any, uint checkinsWithinMinutes = 2147483647, string appTag = "")
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<IEnumerable<User>>();
FindUserInternal(latitude, longitude, searchDistance, recordLimit, gender, ageStart, ageStop, status, checkinsWithinMinutes, appTag, (bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例15: RegisterDeviceAsync
/// <summary>
/// Register a Windows device for notificatons with Buddy. The URL is the notifications channel link that provided by the platform. Most of the time
/// you don't need to call this API directly, you can use ConfigurePushAsync instead which will configure everyting for you. Note that if you call this method,
/// you are responsible to configure the device for push notifications.
/// </summary>
/// <param name="deviceUri">The device notification channel URI.</param>
/// <param name="enableTile">Optionally enable tile notifications</param>
/// <param name="enableRaw">Optionally enable raw notifications.</param>
/// <param name="enableToast">Optionally enable toast notifications.</param>
/// <param name="groupName">Register this device as part of a group, so that you can send the whole group messages.</param>
/// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns>
public System.Threading.Tasks.Task<Boolean> RegisterDeviceAsync(string deviceUri, bool enableTile = true, bool enableRaw = true, bool enableToast = true, string groupName = "")
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>();
RegisterDeviceInternal(deviceUri, enableTile, enableRaw, enableToast, groupName, (bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}