本文整理汇总了C#中Promise.PostResult方法的典型用法代码示例。如果您正苦于以下问题:C# Promise.PostResult方法的具体用法?C# Promise.PostResult怎么用?C# Promise.PostResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Promise
的用法示例。
在下文中一共展示了Promise.PostResult方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChangePassword
/// <summary>Changes the password of the current user. Works for e-mail type accounts.</summary>
/// <returns>Promise resolved when the operation has completed.</returns>
/// <param name="newPassword">The new password to be used for signing in.</param>
public Promise<Done> ChangePassword(string newPassword)
{
var task = new Promise<Done>();
if (Gamer.Network != LoginNetwork.Email) {
task.PostResult(ErrorCode.BadParameters, "Unavailable for " + Gamer.Network.Describe() + " accounts");
return task;
}
HttpRequest req = Gamer.MakeHttpRequest("/v1/gamer/password");
req.BodyJson = Bundle.CreateObject("password", newPassword);
return Common.RunRequest(req, task, (HttpResponse response) => {
task.PostResult(new Done(response.BodyJson));
});
}
示例2: ChangeEmailAddress
/// <summary>Changes the e-mail address of the current user. Works for e-mail type accounts.</summary>
/// <returns>Promise resolved when the operation has completed.</returns>
/// <param name="newEmailAddress">The new e-mail address to be used for signing in.</param>
public Promise<Done> ChangeEmailAddress(string newEmailAddress)
{
var task = new Promise<Done>();
if (Gamer.Network != LoginNetwork.Email) {
return task.PostResult(ErrorCode.BadParameters, "Unavailable for " + Gamer.Network.Describe() + " accounts");
}
Bundle config = Bundle.CreateObject();
config["email"] = newEmailAddress;
HttpRequest req = Gamer.MakeHttpRequest("/v1/gamer/email");
req.BodyJson = config;
return Common.RunRequest(req, task, (HttpResponse response) => {
task.PostResult(new Done(response.BodyJson));
});
}
示例3: LoginToFacebook
/// <summary>
/// Logs in to Facebook and returns an access token (FB API) that can be used to log in with CotC.
/// </summary>
/// <returns>task returning a facebook access token in case of success.</returns>
/// <param name="permissions">List of permissions to request for.</param>
public Promise<AccessToken> LoginToFacebook(List<string> permissions) {
var task = new Promise<AccessToken>();
DoOnGUI.Add(() => {
FB.LogInWithReadPermissions(permissions, (ILoginResult result) => {
if (result.Error != null) {
task.PostResult(ErrorCode.SocialNetworkError, "Facebook/ " + result.Error);
}
else if (!FB.IsLoggedIn) {
task.PostResult(ErrorCode.LoginCanceled, "Login canceled");
}
else {
task.PostResult(AccessToken.CurrentAccessToken);
}
});
});
return task;
}
示例4: Create
/// <summary>
/// Creates a match, available for join by other players. If you would like to make your match private, please read
/// the general documentation about matches.
/// </summary>
/// <returns>Promise resolved when the operation has completed. The attached Match object allows to operate with the
/// match.</returns>
/// <param name="maxPlayers">The maximum number of players who may be in the game at a time.</param>
/// <param name="description">String describing the match (available for other who want to join).</param>
/// <param name="customProperties">Freeform object containing the properties of the match, which may be used by other players
/// to search for a suited match.</param>
/// <param name="shoe">Freeform object containing a list of objects which will be shuffled upon match creation. This offers
/// an easy way to make a random generator that is safe, unbiased (since made on the server) and can be verified
/// by all players once the game is finished. This bundle needs to be an array (use Bundle.CreateArray).</param>
public Promise<Match> Create(int maxPlayers, string description = null, Bundle customProperties = null, Bundle shoe = null)
{
var task = new Promise<Match>();
if (shoe != null && shoe.Type != Bundle.DataType.Array) {
task.PostResult(ErrorCode.BadParameters, "The shoe must be an array");
return task;
}
UrlBuilder url = new UrlBuilder("/v1/gamer/matches").QueryParam("domain", domain);
HttpRequest req = Gamer.MakeHttpRequest(url);
Bundle config = Bundle.CreateObject();
config["maxPlayers"] = maxPlayers;
config["description"] = description;
config["customProperties"] = customProperties;
config["shoe"] = shoe;
req.BodyJson = config;
return Common.RunRequest(req, task, (HttpResponse response) => {
task.PostResult(new Match(Gamer, response.BodyJson["match"]));
});
}
示例5: FetchFriends
/// <summary>
/// Fetches the list of friends on facebook and sends them to CotC so that they automatically become friend with you.
/// Note that this can only fetch the friends who are actually playing the game, so the list may be empty especially
/// when in development.
/// </summary>
/// <returns>Promise resolved when the request has finished. The value is as returned by
/// #CotcSdk.GamerCommunity.ListNetworkFriends.</returns>
/// <param name="gamer">Gamer object used to link the data to the account.</param>
/// <param name="automatching">If true, synchronizes the CotC friends with your facebook friends. They will be
/// reported by ListFriends and such).</param>
public Promise<SocialNetworkFriendResponse> FetchFriends(Gamer gamer, bool automatching = true) {
var task = new Promise<SocialNetworkFriendResponse>();
EnsureFacebookLoaded(() => {
DoFacebookRequestWithPagination("/me/friends", HttpMethod.GET)
.Then(result => {
gamer.Community.ListNetworkFriends(LoginNetwork.Facebook, result, automatching)
.ForwardTo(task);
})
.Catch(ex => {
task.PostResult(ErrorCode.SocialNetworkError, "Facebook request failed");
});
});
return task;
}
示例6: DoFacebookRequestWithPagination
// Recursive
private void DoFacebookRequestWithPagination(Promise<List<SocialNetworkFriend>> task, IGraphResult result, List<SocialNetworkFriend> addDataTo) {
if (result.Error != null) {
Common.LogWarning("Error in facebook request: " + result.Error.ToString());
task.PostResult(ErrorCode.SocialNetworkError, "Facebook/ Network #1");
return;
}
// Gather the result from the last request
try {
Common.Log("FB response: " + result.RawResult);
Bundle fbResult = Bundle.FromJson(result.RawResult);
List<Bundle> data = fbResult["data"].AsArray();
foreach (Bundle element in data) {
addDataTo.Add(new SocialNetworkFriend(element["id"], element["first_name"], element["last_name"], element["name"]));
}
string nextUrl = fbResult["paging"]["next"];
// Finished
if (data.Count == 0 || nextUrl == null) {
task.PostResult(addDataTo);
return;
}
FB.API(nextUrl, HttpMethod.GET, (IGraphResult res) => {
DoFacebookRequestWithPagination(task, res, addDataTo);
});
}
catch (Exception e) {
Common.LogError("Error decoding FB data: " + e.ToString());
task.PostResult(ErrorCode.SocialNetworkError, "Decoding facebook data: " + e.Message);
return;
}
}
示例7: ShareLink
/// <summary>Shares a short story consisting of a link and some information on facebook.</summary>
/// <returns>A promise with a bundle optionally containing {postId: "<the post ID on facebook>"}.</returns>
/// <param name="url">The URL to which this post should link.</param>
/// <param name="title">The desired title of the content in the link.</param>
/// <param name="description">A short description, rendered below title in the story.</param>
/// <param name="photoUrl">A URL for the thumbnail image that appears on the post.</param>
public Promise<Bundle> ShareLink(string url = null, string title = "", string description = "", string photoUrl = null) {
var task = new Promise<Bundle>();
DoOnGUI.Add(() => {
Uri uri = url != null ? new Uri(url) : null;
Uri photoUri = photoUrl != null ? new Uri(photoUrl) : null;
FB.ShareLink(uri, title, description, photoUri, shareResult => {
if (shareResult.Cancelled || !String.IsNullOrEmpty(shareResult.Error)) {
task.PostResult(ErrorCode.Canceled, "Facebook share canceled");
}
else if (!String.IsNullOrEmpty(shareResult.PostId)) {
// Print post identifier of the shared content
task.PostResult(Bundle.CreateObject("postId", shareResult.PostId));
}
else {
// Share succeeded without postID
task.PostResult(Bundle.Empty);
}
});
});
return task;
}
示例8: ListNetworkFriends
/// <summary>
/// When you have data about friends from another social network, you can post them to CotC servers using
/// these function.
/// This will automatically add them as a friend on CotC as they get recognized on our servers.
/// The friends get associated to the domain of this object.
/// Note: this function was once called PostSocialNetworkFriends but renamed due to it being misleading.
/// </summary>
/// <returns>Promise resolved when the operation has completed. The attached value is the same list as passed,
/// enriched with potential information about the gamer (member #CotcSdk.SocialNetworkFriend.ClanInfo) for
/// gamers who are already registered on CotC servers.</returns>
/// <param name="network">The network with which these friends are associated.</param>
/// <param name="friends">A list of data about the friends fetched on the social network.</param>
/// <param name="automatching">If true, synchronizes the CotC friends with the list. That is, the provided
/// social network friends become your friends on CotC as well (reported on ListFriends and such).</param>
public Promise<SocialNetworkFriendResponse> ListNetworkFriends(LoginNetwork network, List<SocialNetworkFriend> friends, bool automatching = false)
{
var task = new Promise<SocialNetworkFriendResponse>();
UrlBuilder url = new UrlBuilder("/v2.12/gamer/friends").Path(domain).QueryParam("network", network.Describe());
HttpRequest req = Gamer.MakeHttpRequest(url);
Bundle body = Bundle.CreateObject();
Bundle friendData = (body["friends"] = Bundle.CreateObject());
foreach (SocialNetworkFriend f in friends) {
friendData[f.Id] = f.ToBundle();
}
body["automatching"] = automatching;
req.BodyJson = body;
return Common.RunRequest(req, task, (HttpResponse response) => {
task.PostResult(new SocialNetworkFriendResponse(response.BodyJson));
});
}
示例9: Setup
/// <summary>Call this at the very beginning to start using the library.</summary>
/// <returns>Promise resolved when the process has finished, with the Cloud to be used for your operations (most
/// likely synchronously).</returns>
/// <param name="apiKey">The community key.</param>
/// <param name="apiSecret">The community secret (credentials when registering to CotC).</param>
/// <param name="environment">The URL of the server. Should use one of the predefined constants.</param>
/// <param name="httpVerbose">Set to true to output detailed information about the requests performed to CotC servers. Can be used
/// for debugging, though it does pollute the logs.</param>
/// <param name="httpTimeout">Sets a custom timeout for all requests in seconds. Defaults to 1 minute.</param>
/// <param name="httpType">HTTP layer to be used. Currently 0 is the default (mono-based) one. Works pretty well, but is severely
/// aged has a few issues on some platforms (which are all overcomable). Type 1 uses the new
/// UnityEngine.Experimental.Networking.UnityWebRequest class and is also supported on all platforms.</param>
public static Promise<Cloud> Setup(string apiKey, string apiSecret, string environment, int loadBalancerCount, bool httpVerbose, int httpTimeout, int httpType)
{
var task = new Promise<Cloud>();
lock (SpinLock) {
Cloud cloud = new Cloud(apiKey, apiSecret, environment, loadBalancerCount, httpVerbose, httpTimeout, httpType);
return task.PostResult(cloud);
}
}