當前位置: 首頁>>代碼示例>>C#>>正文


C# Promise.Reject方法代碼示例

本文整理匯總了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;
		}
開發者ID:rtaylornc,項目名稱:IntelliMediaCore,代碼行數:35,代碼來源:AuthenticationService.cs

示例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;
		}
開發者ID:rtaylornc,項目名稱:IntelliMediaCore,代碼行數:34,代碼來源:CourseSettingsService.cs

示例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;
		}
開發者ID:rtaylornc,項目名稱:IntelliMediaCore,代碼行數:34,代碼來源:ActivityService.cs

示例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())
			);
		}
開發者ID:zon,項目名稱:cardinal,代碼行數:9,代碼來源:PromiseTests.cs

示例5: ExceptionIsThrownForRejectAfterReject

        public void ExceptionIsThrownForRejectAfterReject()
        {
            var promise = new Promise<int>();

            promise.Reject(new ApplicationException());

            Assert.Throws<ApplicationException>(() =>
                promise.Reject(new ApplicationException())
            );
        }
開發者ID:rob-blackbourn,項目名稱:JetBlack.Promises,代碼行數:10,代碼來源:PromiseFixture.cs

示例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;
 }
開發者ID:kicholen,項目名稱:SpaceShooter,代碼行數:16,代碼來源:ShipService.cs

示例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;
        }
開發者ID:avenema,項目名稱:C-Sharp-Promise,代碼行數:35,代碼來源:Program.cs

示例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);
            }
開發者ID:avenema,項目名稱:C-Sharp-Promise,代碼行數:25,代碼來源:2.2.cs

示例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;
        }
開發者ID:cadrogui,項目名稱:Promised-C-Sharp-HTTP-Requests,代碼行數:27,代碼來源:PomisedRequest.cs

示例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;
        }
開發者ID:cadrogui,項目名稱:Promised-C-Sharp-HTTP-Requests,代碼行數:31,代碼來源:PomisedRequest.cs

示例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"]);
        }
開發者ID:chukcha-wtf,項目名稱:react-native-windows,代碼行數:27,代碼來源:PromiseTests.cs

示例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);
            }
開發者ID:avenema,項目名稱:C-Sharp-Promise,代碼行數:9,代碼來源:2.1.cs

示例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;
 }
開發者ID:kicholen,項目名稱:SpaceShooter,代碼行數:12,代碼來源:BonusService.cs

示例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);
        }
開發者ID:avenema,項目名稱:C-Sharp-Promise,代碼行數:12,代碼來源:2.1.cs

示例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;
 }
開發者ID:kicholen,項目名稱:SpaceShooter,代碼行數:12,代碼來源:PathService.cs


注:本文中的Promise.Reject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。