本文整理汇总了C#中Promise.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# Promise.Resolve方法的具体用法?C# Promise.Resolve怎么用?C# Promise.Resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Promise
的用法示例。
在下文中一共展示了Promise.Resolve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SignIn
public Promise SignIn(string domain, string username, string password)
{
Promise promise = new Promise();
try
{
Uri serverUri = new Uri(appSettings.ServerURI, UriKind.RelativeOrAbsolute);
Uri restUri = new Uri(serverUri, "rest/");
StudentRepository repo = new StudentRepository(restUri);
if (repo == null)
{
throw new Exception("StudentRepository is not initialized.");
}
repo.SignIn(domain, username, password, (StudentRepository.Response response) =>
{
if (response.Success)
{
Token = Guid.NewGuid().ToString();
promise.Resolve(response.Item);
}
else
{
promise.Reject(new Exception(response.Error));
}
});
}
catch (Exception e)
{
promise.Reject(e);
}
return promise;
}
示例2: LoadSettings
public Promise LoadSettings(string studentId)
{
Promise promise = new Promise();
try
{
Uri serverUri = new Uri(appSettings.ServerURI, UriKind.RelativeOrAbsolute);
Uri restUri = new Uri(serverUri, "rest/");
CourseSettingsRepository repo = new CourseSettingsRepository(restUri);
if (repo == null)
{
throw new Exception("CourseSettingsRepository is not initialized.");
}
repo.GetByKey("studentid/", studentId, (CourseSettingsRepository.Response response) =>
{
if (response.Success)
{
promise.Resolve(response.Item);
}
else
{
promise.Reject(new Exception(response.Error));
}
});
}
catch (Exception e)
{
promise.Reject(e);
}
return promise;
}
示例3: LoadActivities
public Promise LoadActivities(string courseId)
{
Promise promise = new Promise();
try
{
Uri serverUri = new Uri(appSettings.ServerURI, UriKind.RelativeOrAbsolute);
Uri restUri = new Uri(serverUri, "rest/");
ActivityRepository repo = new ActivityRepository(restUri);
if (repo == null)
{
throw new Exception("ActivityRepository is not initialized.");
}
repo.GetActivities(courseId, (response) =>
{
if (response.Success)
{
promise.Resolve(response.Items);
}
else
{
promise.Reject(new Exception(response.Error));
}
});
}
catch (Exception e)
{
promise.Reject(e);
}
return promise;
}
示例4: ShouldAddFriend
public void ShouldAddFriend(Cloud cloud)
{
// Use two test accounts
Login2NewUsers(cloud, (gamer1, gamer2) => {
// Expects friend status change event
Promise restOfTheTestCompleted = new Promise();
gamer1.StartEventLoop();
gamer1.Community.OnFriendStatusChange += (FriendStatusChangeEvent e) => {
Assert(e.FriendId == gamer2.GamerId, "Should come from P2");
Assert(e.NewStatus == FriendRelationshipStatus.Add, "Should have added me");
restOfTheTestCompleted.Done(CompleteTest);
};
// Add gamer1 as a friend of gamer2
gamer2.Community.AddFriend(gamer1.GamerId)
.ExpectSuccess(addResult => {
// Then list the friends of gamer1, gamer2 should be in it
return gamer1.Community.ListFriends();
})
.ExpectSuccess(friends => {
Assert(friends.Count == 1, "Expects one friend");
Assert(friends[0].GamerId == gamer2.GamerId, "Wrong friend ID");
restOfTheTestCompleted.Resolve();
});
});
}
示例5: ShouldAssociateGodfather
public void ShouldAssociateGodfather(Cloud cloud)
{
Login2NewUsers(cloud, (gamer1, gamer2) => {
// Expects godchild event
Promise restOfTheTestCompleted = new Promise();
gamer1.StartEventLoop();
gamer1.Godfather.OnGotGodchild += (GotGodchildEvent e) => {
Assert(e.Gamer.GamerId == gamer2.GamerId, "Should come from player2");
Assert((object)e.Reward == (object)Bundle.Empty, "No reward should be associated");
restOfTheTestCompleted.Done(CompleteTest);
};
// P1 generates a code and associates P2 with it
gamer1.Godfather.GenerateCode()
// Use code
.ExpectSuccess(genCode => gamer2.Godfather.UseCode(genCode))
.ExpectSuccess(dummy => gamer2.Godfather.GetGodfather())
.ExpectSuccess(result => {
Assert(result.GamerId == gamer1.GamerId, "P1 should be godfather");
Assert(result.AsBundle().Root.Has("godfather"), "Underlying structure should be accessible");
return gamer1.Godfather.GetGodchildren();
})
.ExpectSuccess(result => {
Assert(result.Count == 1, "Should have only one godchildren");
Assert(result[0].GamerId == gamer2.GamerId, "P2 should be godchildren");
restOfTheTestCompleted.Resolve();
});
});
}
示例6: GetJsonString
public IPromise<string> GetJsonString()
{
var promise = new Promise<string> ();
using (var client = new WebClient())
{
if (this.headers != null) {
foreach(KeyValuePair<string, string> h in this.headers){
client.Headers.Add(h.Key, h.Value);
}
}
client.DownloadStringCompleted +=
(s, ev) =>
{
if (ev.Error != null){
promise.Reject(ev.Error);
} else {
promise.Resolve(ev.Result);
}
};
client.DownloadStringAsync(new Uri(this.url), null);
}
return promise;
}
示例7: GET
public IPromise<string> GET(Dictionary<string, string> parameters)
{
if (parameters == null) {
throw new ArgumentNullException ();
}
var promise = new Promise<string> ();
using(var client = new WebClient()){
if (this.headers != null) {
foreach(KeyValuePair<string, string> h in this.headers){
client.Headers.Add(h.Key, h.Value);
}
}
client.DownloadStringCompleted +=
(s, ev) =>
{
if (ev.Error != null){
promise.Reject(ev.Error);
} else {
promise.Resolve(ev.Result);
}
};
client.DownloadStringAsync(new Uri(this.url + "?" + PromisedRequest.Helpers.GenerateQueryString(parameters)), null);
}
return promise;
}
示例8: Download
/// <summary>
/// Download text from a URL.
/// A promise is returned that is resolved when the download has completed.
/// The promise is rejected if an error occurs during download.
/// </summary>
static IPromise<string> Download(string url)
{
Console.WriteLine("Downloading " + url + " ...");
var promise = new Promise<string>();
using (var client = new WebClient())
{
client.DownloadStringCompleted +=
(s, ev) =>
{
if (ev.Error != null)
{
Console.WriteLine("An error occurred... rejecting the promise.");
// Error during download, reject the promise.
promise.Reject(ev.Error);
}
else
{
Console.WriteLine("... Download completed.");
// Downloaded completed successfully, resolve the promise.
promise.Resolve(ev.Result);
}
};
client.DownloadStringAsync(new Uri(url), null);
}
return promise;
}
示例9: _must_not_transition_to_any_other_state
public void _must_not_transition_to_any_other_state()
{
var rejectedPromise = new Promise<object>();
rejectedPromise.Reject(new Exception());
Assert.Throws<ApplicationException>(() => rejectedPromise.Resolve(new object()));
Assert.Equal(PromiseState.Rejected, rejectedPromise.CurState);
}
示例10: _must_have_a_value_which_must_not_change
public void _must_have_a_value_which_must_not_change()
{
var promisedValue = new object();
var fulfilledPromise = new Promise<object>();
var handled = 0;
fulfilledPromise.Then(v =>
{
Assert.Equal(promisedValue, v);
++handled;
});
fulfilledPromise.Resolve(promisedValue);
Assert.Throws<ApplicationException>(() => fulfilledPromise.Resolve(new object()));
Assert.Equal(1, handled);
}
示例11: exception_is_thrown_for_resolve_after_reject
public void exception_is_thrown_for_resolve_after_reject() {
var promise = new Promise<int>();
promise.Reject(new ApplicationException());
Assert.Throws<ApplicationException>(() =>
promise.Resolve(5)
);
}
示例12: ExceptionIsThrownForResolveAfterReject
public void ExceptionIsThrownForResolveAfterReject()
{
var promise = new Promise<int>();
promise.Reject(new ApplicationException());
Assert.Throws<ApplicationException>(() =>
promise.Resolve(5)
);
}
示例13: CanResolvePromiseAndTriggerThenHandler
public void CanResolvePromiseAndTriggerThenHandler()
{
var promise = new Promise();
var completed = 0;
promise.Then(() => ++completed);
promise.Resolve();
Assert.AreEqual(1, completed);
}
示例14: can_handle_Done_onResolved
public void can_handle_Done_onResolved()
{
var promise = new Promise();
var callback = 0;
promise.Done(() => ++callback);
promise.Resolve();
Assert.Equal(1, callback);
}
示例15: LoadDifficulties
public IPromise LoadDifficulties()
{
Promise promise = new Promise();
wwwService.Send<GetDifficulties>(new GetDifficulties(), (request) => {
difficulties = request.Difficulties;
replaceOrAddDifficulties(difficulties);
promise.Resolve();
}, (error) => {
promise.Reject(new Exception(error));
});
return promise;
}