当前位置: 首页>>代码示例>>C#>>正文


C# Promise.Resolve方法代码示例

本文整理汇总了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;
		}
开发者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: 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();
            });
        });
    }
开发者ID:StudioJD,项目名称:unity-sdk,代码行数:26,代码来源:CommunityTests.cs

示例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();
            });
        });
    }
开发者ID:StudioJD,项目名称:unity-sdk,代码行数:29,代码来源:GodfatherTests.cs

示例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;
        }
开发者ID:cadrogui,项目名称:Promised-C-Sharp-HTTP-Requests,代码行数:27,代码来源:PomisedRequest.cs

示例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;
        }
开发者ID:cadrogui,项目名称:Promised-C-Sharp-HTTP-Requests,代码行数:31,代码来源:PomisedRequest.cs

示例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;
        }
开发者ID:avenema,项目名称:C-Sharp-Promise,代码行数:35,代码来源:Program.cs

示例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);
            }
开发者ID:avenema,项目名称:C-Sharp-Promise,代码行数:9,代码来源:2.1.cs

示例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);
            }
开发者ID:avenema,项目名称:C-Sharp-Promise,代码行数:18,代码来源:2.1.cs

示例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)
			);
		}
开发者ID:zon,项目名称:cardinal,代码行数:9,代码来源:PromiseTests.cs

示例12: ExceptionIsThrownForResolveAfterReject

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

            promise.Reject(new ApplicationException());

            Assert.Throws<ApplicationException>(() =>
                promise.Resolve(5)
            );
        }
开发者ID:rob-blackbourn,项目名称:JetBlack.Promises,代码行数:10,代码来源:PromiseFixture.cs

示例13: CanResolvePromiseAndTriggerThenHandler

        public void CanResolvePromiseAndTriggerThenHandler()
        {
            var promise = new Promise();
            var completed = 0;

            promise.Then(() => ++completed);
            promise.Resolve();

            Assert.AreEqual(1, completed);
        }
开发者ID:rob-blackbourn,项目名称:JetBlack.Promises,代码行数:10,代码来源:PromiseNonGenericFixture.cs

示例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);
        }
开发者ID:Renanse,项目名称:C-Sharp-Promise,代码行数:11,代码来源:Promise_NonGeneric_Tests.cs

示例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;
 }
开发者ID:kicholen,项目名称:SpaceShooter,代码行数:12,代码来源:DifficultyService.cs


注:本文中的Promise.Resolve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。