-
-
Notifications
You must be signed in to change notification settings - Fork 261
/
Copy pathCloudCodeServiceExtensions.cs
55 lines (52 loc) · 2.52 KB
/
CloudCodeServiceExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Parse.Abstractions.Infrastructure;
namespace Parse;
/// <summary>
/// The ParseCloud class provides methods for interacting with Parse Cloud Functions.
/// </summary>
/// <example>
/// For example, this sample code calls the
/// "validateGame" Cloud Function and calls processResponse if the call succeeded
/// and handleError if it failed.
///
/// <code>
/// var result =
/// await ParseCloud.CallFunctionAsync<IDictionary<string, object>>("validateGame", parameters);
/// </code>
/// </example>
public static class CloudCodeServiceExtensions
{
/// <summary>
/// Calls a cloud function.
/// </summary>
/// <typeparam name="T">The type of data you will receive from the cloud function. This
/// can be an IDictionary, string, IList, ParseObject, or any other type supported by
/// ParseObject.</typeparam>
/// <param name="name">The cloud function to call.</param>
/// <param name="parameters">The parameters to send to the cloud function. This
/// dictionary can contain anything that could be passed into a ParseObject except for
/// ParseObjects themselves.</param>
/// <returns>The result of the cloud call.</returns>
public static Task<T> CallCloudCodeFunctionAsync<T>(this IServiceHub serviceHub, string name, IDictionary<string, object> parameters)
{
return CallCloudCodeFunctionAsync<T>(serviceHub, name, parameters, CancellationToken.None);
}
/// <summary>
/// Calls a cloud function.
/// </summary>
/// <typeparam name="T">The type of data you will receive from the cloud function. This
/// can be an IDictionary, string, IList, ParseObject, or any other type supported by
/// ParseObject.</typeparam>
/// <param name="name">The cloud function to call.</param>
/// <param name="parameters">The parameters to send to the cloud function. This
/// dictionary can contain anything that could be passed into a ParseObject except for
/// ParseObjects themselves.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The result of the cloud call.</returns>
public static async Task<T> CallCloudCodeFunctionAsync<T>(this IServiceHub serviceHub, string name, IDictionary<string, object> parameters, CancellationToken cancellationToken)
{
return await serviceHub.CloudCodeController.CallFunctionAsync<T>(name, parameters, await serviceHub.GetCurrentSessionToken(), serviceHub, cancellationToken);
}
}