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


C# Result.Throw方法代码示例

本文整理汇总了C#中System.Result.Throw方法的典型用法代码示例。如果您正苦于以下问题:C# Result.Throw方法的具体用法?C# Result.Throw怎么用?C# Result.Throw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Result的用法示例。


在下文中一共展示了Result.Throw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateHelper

		private Yield UpdateHelper(string id, string rev, IPlay aDoc, Result<IPlay> aResult)
		{
			//Check if a play with this id exists.
			Result<IPlay> validPlayResult = new Result<IPlay>();
			yield return thePlayDataMapper.Retrieve(aDoc.Id, validPlayResult);
			if (validPlayResult.Value == null)
			{
				aResult.Throw(new ArgumentException());
				yield break;
			}

			//Check if the current user has the update rights.
			if (!HasAuthorization(validPlayResult.Value))
			{
				aResult.Throw(new UnauthorizedAccessException());
				yield break;
			}

			//Check if the source in the play exist and are not null.
			Coroutine.Invoke(CheckSource, aDoc, new Result());

			//Update and return the updated play.
			Result<IPlay> playResult = new Result<IPlay>();
			yield return thePlayDataMapper.Update(id, rev, aDoc, playResult);
			aResult.Return(playResult.Value);
		}
开发者ID:willemda,项目名称:FoireMuses,代码行数:26,代码来源:PlayController.cs

示例2: DeleteConfigValue

        /// <summary>
        /// <para>Deletes a single configuration value from a given section in the
        /// CouchDB server configuration.</para>
        /// <para>(This method is asynchronous.)</para>
        /// </summary>
        /// <param name="section">The configuration section.</param>
        /// <param name="keyName">The name of the configuration key.</param>
        /// <param name="result"></param>
        /// <returns></returns>
        public Result DeleteConfigValue(
      string section, 
      string keyName, 
      Result result)
        {
            if (String.IsNullOrEmpty(section))
            throw new ArgumentException("section cannot be null nor empty");
              if (String.IsNullOrEmpty(keyName))
            throw new ArgumentException("keyName cannot be null nor empty");
              if (result == null)
            throw new ArgumentNullException("result");

              BasePlug
            .At(Constants._CONFIG, XUri.EncodeFragment(section),
            XUri.EncodeFragment(keyName))
            .Delete(DreamMessage.Ok(), new Result<DreamMessage>())
            .WhenDone(
              a =>
              {
            if (a.Status == DreamStatus.Ok)
              result.Return(); // remove " and "\n
            else
              result.Throw(new CouchException(a));
              },
              result.Throw
            );
              return result;
        }
开发者ID:jvdgeest,项目名称:chesterfield,代码行数:37,代码来源:CouchClient.Config.cs

示例3: CheckSource

		private Yield CheckSource(IPlay aPlay, Result aResult)
		{
			//can't be null, it must have a source
			if (aPlay.SourceId == null)
			{
				aResult.Throw(new ArgumentException());
				yield break;
			}

			// if this source exists
			Result<bool> validSourceResult = new Result<bool>();
			yield return Context.Current.Instance.SourceController.Exists(aPlay.SourceId, validSourceResult);
			if (!validSourceResult.Value)
			{
				aResult.Throw(new ArgumentException());
				yield break;
			}
			aResult.Return();
		}
开发者ID:willemda,项目名称:FoireMuses,代码行数:19,代码来源:PlayController.cs

示例4: Logoff

        public Result<bool> Logoff(Result<bool> aResult)
        {
            if (aResult == null)
                throw new ArgumentNullException("aResult");

            BasePlug.At("_session").Delete(new Result<DreamMessage>()).WhenDone(
                a => {
                    if (a.Status == DreamStatus.Ok)
                        aResult.Return(true);
                    else
                        aResult.Throw(new CouchException(a));
                },
                aResult.Throw
            );
            return aResult;
        }
开发者ID:willemda,项目名称:DreamSeat,代码行数:16,代码来源:CouchBase.cs

示例5: CreateHelper

		private Yield CreateHelper(IPlay aDoc, Result<IPlay> aResult)
		{
			//Check if user is set as we need to know the creator.
			if (Context.Current.User == null)
			{
				aResult.Throw(new UnauthorizedAccessException());
				yield break;
			}

			//Check that the sources aren't null and does exists
			yield return Coroutine.Invoke(CheckSource, aDoc, new Result());

			//Insert a the score and return
			Result<IPlay> resultCreate = new Result<IPlay>();
			yield return thePlayDataMapper.Create(aDoc, resultCreate);
			aResult.Return(resultCreate.Value);
		}
开发者ID:willemda,项目名称:FoireMuses,代码行数:17,代码来源:PlayController.cs

示例6: AddAttachment

        /* =========================================================================
         * Asynchronous methods
         * =======================================================================*/
        /// <summary>
        /// <para>Adds an attachment to a document. The document revision must be 
        /// specified when using this method.</para>
        /// <para>(This method is asynchronous.)</para>
        /// </summary>
        /// <param name="id">ID of the CouchDB document.</param>
        /// <param name="rev">Revision of the CouchDB document.</param>
        /// <param name="attachment">Stream of the attachment. Will be closed once
        /// the request is sent.</param>
        /// <param name="attachmentLength">Length of the attachment stream.</param>
        /// <param name="fileName">Filename of the attachment.</param>
        /// <param name="contentType">Content type of the document.</param>
        /// <param name="result"></param>
        /// <returns></returns>
        public Result<JObject> AddAttachment(
      string id, 
      string rev, 
      Stream attachment, 
      long attachmentLength, 
      string fileName, 
      MimeType contentType, 
      Result<JObject> result)
        {
            if (String.IsNullOrEmpty(id))
            throw new ArgumentNullException("id");
              if (String.IsNullOrEmpty(rev))
            throw new ArgumentNullException("rev");
              if (attachment == null)
            throw new ArgumentNullException("attachment");
              if (attachmentLength < 0)
            throw new ArgumentOutOfRangeException("attachmentLength");
              if (String.IsNullOrEmpty(fileName))
            throw new ArgumentNullException("fileName");
              if (contentType == null)
            throw new ArgumentNullException("contentType");
              if (result == null)
            throw new ArgumentNullException("result");

              BasePlug
            .AtPath(XUri.EncodeFragment(id))
            .At(XUri.EncodeFragment(fileName))
            .With(Constants.REV, rev)
            .Put(DreamMessage.Ok(contentType, attachmentLength, attachment),
             new Result<DreamMessage>())
            .WhenDone(
              a =>
              {
            if (a.Status == DreamStatus.Created)
              result.Return(JObject.Parse(a.ToText()));
            else
              result.Throw(new CouchException(a));
              },
              result.Throw
            );

              return result;
        }
开发者ID:jvdgeest,项目名称:chesterfield,代码行数:60,代码来源:CouchDatabase.Attachments.cs

示例7: GetUser

		public Result<User> GetUser(string username, Result<User> aResult)
		{
			theServiceUri.At("users", username)
				.Get(new Result<DreamMessage>())
				.WhenDone(delegate(Result<DreamMessage> answer)
				{
					if (!answer.Value.IsSuccessful)
					{
						if (answer.Value.Status == DreamStatus.NotFound)
							aResult.Return((User)null);
						aResult.Throw(answer.Exception);
					}
					else
					{
						aResult.Return(new User(JObject.Parse(answer.Value.ToText())));
					}
				}
				);
			return aResult;
		}
开发者ID:willemda,项目名称:FoireMuses.WebInterface,代码行数:20,代码来源:FoireMusesConnection.cs

示例8: RestartServer

        /* =========================================================================
         * Asynchronous methods
         * =======================================================================*/
        /// <summary>
        /// <para>Restarts the CouchDB instance. You must be authenticated as a user
        /// with administration privileges for this to work.</para>
        /// <para>(This method is asynchronous.)</para>
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public Result RestartServer(Result result)
        {
            if (result == null)
            throw new ArgumentNullException("result");

              BasePlug
            .At(Constants._RESTART)
            .Post(DreamMessage.Ok(MimeType.JSON, String.Empty),
              new Result<DreamMessage>())
            .WhenDone(
              a =>
              {
            if (a.Status == DreamStatus.Ok)
              result.Return();
            else
              result.Throw(new CouchException(a));
              },
              result.Throw
            );
              return result;
        }
开发者ID:jvdgeest,项目名称:chesterfield,代码行数:31,代码来源:CouchClient.cs

示例9: BulkFascimile

		public Result<bool> BulkFascimile(string sourceId, Stream file, Result<bool> aResult)
		{
			theServiceUri
				.At("sources",sourceId,"fascimiles")
				.Post(DreamMessage.Ok(new MimeType("application/zip"), file.Length, file),new Result<DreamMessage>())
				.WhenDone(delegate(Result<DreamMessage> answer)
				{
					if (!answer.Value.IsSuccessful)
					{
						if (answer.Value.Status == DreamStatus.BadRequest)
							aResult.Return(false);
						else
							aResult.Throw(answer.Exception);
					}
					else
					{
						aResult.Return(true);
					}
				}
				);
			return aResult;
		}
开发者ID:willemda,项目名称:FoireMuses.WebInterface,代码行数:22,代码来源:FoireMusesConnection.cs

示例10: IsLogged

        public Result<bool> IsLogged(Result<bool> aResult)
        {
            if (aResult == null)
                throw new ArgumentNullException("aResult");

            BasePlug.At("_session").Get(new Result<DreamMessage>()).WhenDone(
                a =>
                {
                    if (a.Status == DreamStatus.Ok)
                    {
                        JObject user = JObject.Parse(a.ToText());
                        aResult.Return(user["info"]["authenticated"] != null);
                    }
                    else
                    {
                        aResult.Throw(new CouchException(a));
                    }
                },
                aResult.Throw
            );
            return aResult;
        }
开发者ID:willemda,项目名称:DreamSeat,代码行数:22,代码来源:CouchBase.cs

示例11: CreateDatabase

        /// <summary>
        /// Creates a database
        /// </summary>
        /// <param name="aDatabaseName">Name of new database</param>
        /// <param name="aResult"></param>
        /// <returns></returns>
        public Result<JObject> CreateDatabase(string aDatabaseName, Result<JObject> aResult)
        {
            if (String.IsNullOrEmpty(aDatabaseName))
                throw new ArgumentException("DatabaseName cannot be null nor empty");
            if (aResult == null)
                throw new ArgumentNullException("aResult");

            BasePlug.At(XUri.EncodeFragment(aDatabaseName)).Put(DreamMessage.Ok(), new Result<DreamMessage>()).WhenDone(
                a =>
                {
                    if (a.Status == DreamStatus.Created)
                    {
                        aResult.Return(JObject.Parse(a.ToText()));
                    }
                    else
                    {
                        aResult.Throw(new CouchException(a));
                    }
                },
                aResult.Throw
            );
            return aResult;
        }
开发者ID:willemda,项目名称:DreamSeat,代码行数:29,代码来源:CouchClient.cs

示例12: DeleteDatabase

        /// <summary>
        /// <para>Deletes the specified database.</para>
        /// <para>(This method is asynchronous.)</para>
        /// </summary>
        /// <param name="databaseName">Name of the database to delete.</param>
        /// <param name="result"></param>
        /// <returns></returns>
        public Result<JObject> DeleteDatabase(
      string databaseName, 
      Result<JObject> result)
        {
            if (String.IsNullOrEmpty(databaseName))
            throw new ArgumentException("databaseName cannot be null nor empty");
              if (result == null)
            throw new ArgumentNullException("result");

              BasePlug
            .At(XUri.EncodeFragment(databaseName))
            .Delete(new Result<DreamMessage>())
            .WhenDone(
              a =>
              {
            if (a.Status == DreamStatus.Ok)
              result.Return(JObject.Parse(a.ToText()));
            else
              result.Throw(new CouchException(a));
              },
              result.Throw
            );
              return result;
        }
开发者ID:jvdgeest,项目名称:chesterfield,代码行数:31,代码来源:CouchClient.Databases.cs

示例13: LoadContactsHelper

        private Yield LoadContactsHelper(Result<ViewResult<string,string, Contact>> aResult)
        {
            Result<bool> exists = new Result<bool>();
            yield return theDatabase.DocumentExists("_design/contactview", exists);

            if(exists.HasException){
                aResult.Throw(exists.Exception);
                yield break;
            }

            if (!exists.Value)
            {
                CouchDesignDocument view = new CouchDesignDocument("contactview");
                view.Views.Add("all",
                               new CouchView(
                                  @"function(doc){
                                       if(doc.type && doc.type == 'contact'){
                                          emit(doc.lastName, doc.firstName)
                                       }
                                    }"));

                Result<CouchDesignDocument> creationResult = new Result<CouchDesignDocument>();
                yield return theDatabase.CreateDocument(view, creationResult);

                if(creationResult.HasException)
                {
                    aResult.Throw(creationResult.Exception);
                    yield break;
                }
            }

            var viewRes = new Result<ViewResult<string, string, Contact>>();
            yield return theDatabase.GetView("contactview", "all",viewRes);

            if(viewRes.HasException)
            {
                aResult.Throw(viewRes.Exception);
                yield break;
            }
            aResult.Return(viewRes.Value);
        }
开发者ID:jaimerosales,项目名称:DreamSeat,代码行数:41,代码来源:ContactsListBox.cs

示例14: DeleteHelper

		private Yield DeleteHelper(string id, string rev, Result<bool> aResult)
		{
			//Check if a source with this id exists.
			Result<ISource> validSourceResult = new Result<ISource>();
			yield return theSourceDataMapper.Retrieve(id, validSourceResult);
			if (validSourceResult.Value == null)
			{
				aResult.Throw(new ArgumentException(String.Format("Source not found for id '{0}'", id)));
				yield break;
			}

			yield return theSourceDataMapper.Delete(id, rev ?? validSourceResult.Value.Rev, aResult);
		}
开发者ID:willemda,项目名称:FoireMuses,代码行数:13,代码来源:SourceController.cs

示例15: ProcessIssueBatch

        private Result<IssueData[]> ProcessIssueBatch(ElasticThreadPool pool,  string projectId, string filterId, int pageNumber, int issuesInBatch, Tuplet<bool> canceled, Result<IssueData[]> result) {
            pool.QueueWorkItem(HandlerUtil.WithEnv(delegate {

                // TODO (steveb): use result.IsCanceled instead of shared tuple once cancellation is supported on the result object

                // check if request has been canceled
                if(!canceled.Item1) {
                    IssueData[] issuesForBatch;
                    if(!string.IsNullOrEmpty(filterId)) {
                        issuesForBatch = _service.mc_filter_get_issues(_username, _password, projectId, filterId, pageNumber.ToString(), issuesInBatch.ToString());
                    } else {
                        issuesForBatch = _service.mc_project_get_issues(_username, _password, projectId, pageNumber.ToString(), issuesInBatch.ToString());
                    }
                    result.Return(issuesForBatch);
                } else {
                	
                	// TODO (steveb): throw a more specific exception
                    result.Throw(new Exception("unspecified error"));
                }
            },TaskEnv.Clone()));
            return result;
        } 
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:22,代码来源:MantisService.cs


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