本文整理汇总了C#中Promise.Reject方法的典型用法代码示例。如果您正苦于以下问题:C# Promise.Reject方法的具体用法?C# Promise.Reject怎么用?C# Promise.Reject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Promise
的用法示例。
在下文中一共展示了Promise.Reject方法的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: exception_is_thrown_for_reject_after_reject
public void exception_is_thrown_for_reject_after_reject() {
var promise = new Promise<int>();
promise.Reject(new ApplicationException());
Assert.Throws<ApplicationException>(() =>
promise.Reject(new ApplicationException())
);
}
示例5: ExceptionIsThrownForRejectAfterReject
public void ExceptionIsThrownForRejectAfterReject()
{
var promise = new Promise<int>();
promise.Reject(new ApplicationException());
Assert.Throws<ApplicationException>(() =>
promise.Reject(new ApplicationException())
);
}
示例6: UpgradeIfCan
public IPromise UpgradeIfCan(UpgradeType type)
{
Promise promise = new Promise();
if (IsUpgradeInProgress())
promise.Reject(new UpgradeInProgressException());
else if (isMaxUpgrade(type))
promise.Reject(new MaxUpgradeException());
else if (!currencyService.CanBePurchased(getNexUpgradeCost(type)))
promise.Reject(new NotEnoughCoinsException());
else
{
startUpgrade(type);
promise.Resolve();
}
return promise;
}
示例7: 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;
}
示例8: _if_onRejected_is_not_a_function_it_must_be_ignored_1
public void _if_onRejected_is_not_a_function_it_must_be_ignored_1()
{
var promise = new Promise<object>();
var resultPromise = promise
.Then(
v => Promise.Resolved(),
null
);
var resolved = 0;
var errors = 0;
var e = new Exception();
resultPromise.Then(() => ++resolved);
resultPromise.Catch(ex =>
{
Assert.Equal(e, ex);
++errors;
});
promise.Reject(e);
Assert.Equal(0, resolved);
Assert.Equal(1, errors);
}
示例9: 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;
}
示例10: 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;
}
示例11: Promise_Reject_UserInfo
public void Promise_Reject_UserInfo()
{
var args = default(object[]);
var are = new AutoResetEvent(false);
var resolve = new MockCallback(_ => { });
var reject = new MockCallback(a =>
{
args = a;
are.Set();
});
var promise = new Promise(resolve, reject);
var code = "42";
var message = "foo";
var e = new Exception();
e.Data.Add("qux", "baz");
promise.Reject(code, message, e);
are.WaitOne();
Assert.IsNotNull(args);
Assert.AreEqual(1, args.Length);
var json = args[0] as JObject;
Assert.IsNotNull(json);
var userInfo = json["userInfo"] as JObject;
Assert.IsNotNull(userInfo);
Assert.AreEqual("baz", userInfo["qux"]);
}
示例12: _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);
}
示例13: LoadBonuses
public IPromise LoadBonuses()
{
Promise promise = new Promise();
wwwService.Send<GetBonuses>(new GetBonuses(), (request) => {
bonuses = request.Bonuses;
replaceOrAddBonuses(bonuses);
promise.Resolve();
}, (error) => {
promise.Reject(new Exception(error));
});
return promise;
}
示例14: When_pending_a_promise_may_transition_to_either_the_fulfilled_or_rejected_state
public void When_pending_a_promise_may_transition_to_either_the_fulfilled_or_rejected_state()
{
var pendingPromise1 = new Promise<object>();
Assert.Equal(PromiseState.Pending, pendingPromise1.CurState);
pendingPromise1.Resolve(new object());
Assert.Equal(PromiseState.Resolved, pendingPromise1.CurState);
var pendingPromise2 = new Promise<object>();
Assert.Equal(PromiseState.Pending, pendingPromise2.CurState);
pendingPromise2.Reject(new Exception());
Assert.Equal(PromiseState.Rejected, pendingPromise2.CurState);
}
示例15: LoadPaths
public IPromise LoadPaths()
{
Promise promise = new Promise();
wwwService.Send<GetPaths>(new GetPaths(), (request) => {
paths = request.Paths;
replaceOrAddPaths(paths);
promise.Resolve();
}, (error) => {
promise.Reject(new Exception(error));
});
return promise;
}