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


C# HttpResult类代码示例

本文整理汇总了C#中HttpResult的典型用法代码示例。如果您正苦于以下问题:C# HttpResult类的具体用法?C# HttpResult怎么用?C# HttpResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: SaveUser

        public JsonResult SaveUser(EsbUsers esbUser)
        {
            HttpResult hr = new HttpResult();
            hr.Result = true;

            if( esbUser.UserID == Guid.Empty ) {
                var parameter = new { UserName = esbUser.UserName};
                object obj = CPQuery.From("SELECT 1 FROM esb_Users WHERE UserName = @UserName", parameter).ExecuteScalar<object>();

                if( obj != null ) {
                    hr.Result = false;
                    hr.ErrorMessage = "指定用户名已经存在!";
                    return new JsonResult(hr);
                }

                esbUser.UserID = Guid.NewGuid();
                esbUser.Insert();
            }
            else {
                esbUser.Update();
            }

            hr.KeyValue = esbUser.UserID.ToString();

            return new JsonResult(hr);
        }
开发者ID:udbeeq5566,项目名称:ESB,代码行数:26,代码来源:ESBUserService.cs

示例2: CreateInitializesNewPageInstanceTest

        public void CreateInitializesNewPageInstanceTest()
        {
            var data = Guid.NewGuid().ToString();
            var response = new HttpResponseMessage
            {
                Content = new StringContent(data)
            };
            var outcomes = new List<HttpOutcome>
            {
                new HttpOutcome(
                    new Uri("http://www.google.com"),
                    HttpMethod.Get,
                    HttpStatusCode.OK,
                    Guid.NewGuid().ToString(),
                    TimeSpan.FromMilliseconds(2))
            };
            var result = new HttpResult(new ReadOnlyCollection<HttpOutcome>(outcomes));

            var browser = Substitute.For<IBrowser>();

            var target = new DefaultPageFactory();

            var actual = target.Create<TextPageWrapper>(browser, response, result);

            actual.Should().NotBeNull();
            actual.Browser.Should().Be(browser);
            actual.Result.Should().Be(result);
            actual.StatusCode.Should().Be(response.StatusCode);
            actual.StatusDescription.Should().Be(response.ReasonPhrase);
            actual.Content.Should().Be(data);
        }
开发者ID:roryprimrose,项目名称:Headless,代码行数:31,代码来源:DefaultPageFactoryTests.cs

示例3: HttpGet

        private static IEnumerable<HttpResult> HttpGet(Uri address, int count)
        {
            var stopwatch = new Stopwatch();
            var results = new HttpResult[count];

            for (var i = 0; i < count; i++)
            {
                var client = new HttpClient();
                var isError = false;
                var elapsed = 0L;
                stopwatch.Reset();

                try
                {
                    stopwatch.Start();
                    client.DownloadString(address);
                    elapsed = stopwatch.ElapsedMilliseconds;
                }
                catch (Exception)
                {
                    elapsed = stopwatch.ElapsedMilliseconds;
                    isError = true;
                }
                finally
                {
                    results[i] = new HttpResult
                    {
                        TimeTakenMs = (int)elapsed,
                        IsError = isError
                    };
                }
            }

            return results;
        }
开发者ID:donatasm,项目名称:WCF-Performance-Tuning,代码行数:35,代码来源:Program.cs

示例4: CheckDBConnection

        public JsonResult CheckDBConnection(string dbServer, string dbName, string dbPort, string dbUserName, string dbPassword)
        {
            if( string.IsNullOrEmpty(dbServer) )
                throw new ArgumentException("服务器地址不能为空.");
            if( string.IsNullOrEmpty(dbName) )
                throw new ArgumentException("数据库名称不能为空.");
            if( string.IsNullOrEmpty(dbUserName) )
                throw new ArgumentException("数据库账号不能为空.");
            if( string.IsNullOrEmpty(dbPassword) )
                throw new ArgumentException("数据库密码不能为空.");

            string sqlConnection = string.Empty;
            if( dbPort != "1433" && !string.IsNullOrEmpty(dbPort) )
                sqlConnection = string.Format("server={0},{1};uid={2};pwd={3};database={4}", dbServer, dbPort, dbUserName, dbPassword, dbName);
            else
                sqlConnection = string.Format("server={0};uid={1};pwd={2};database={3}", dbServer, dbUserName, dbPassword, dbName);

            HttpResult hr = new HttpResult() { Result = true };
            SqlConnection dbConnection = null;
            try {
                dbConnection = new SqlConnection(sqlConnection);
                dbConnection.Open();
            }
            catch( Exception ex ) {
                hr.Result = false;
                hr.ErrorMessage = ex.Message;
            }
            finally {
                if( dbConnection != null )
                    dbConnection.Close();
            }
            return new JsonResult(hr);
        }
开发者ID:udbeeq5566,项目名称:ESB,代码行数:33,代码来源:ESBProviderService.cs

示例5: SavePipe

        public JsonResult SavePipe(EsbReceiverInterface pipe)
        {
            HttpResult hr = new HttpResult() { Result = true };

            using (ConnectionScope scope = new ConnectionScope(TransactionMode.Required)){
                if (pipe.ReceiverInterfaceID == Guid.Empty){
                    if (EntityCommon.IsExistData("Esb_ReceiverInterface", "ServiceName", pipe.ServiceName)){
                        hr.Result = false;
                        hr.ErrorMessage = "英文名称不允许重复,请重新录入英文名称!";
                        return new JsonResult(hr);
                    }
                    pipe.ReceiverInterfaceID = Guid.NewGuid();
                    pipe.Status = 1;
                    pipe.CreatedOn = DateTime.Now;
                    pipe.Insert();

                    //自动生成策略
                    EsbDistributeStrategy esbDistributeStrategyEntity = new EsbDistributeStrategy();
                    esbDistributeStrategyEntity.DistributeStrategyID = Guid.NewGuid();
                    esbDistributeStrategyEntity.ReceiverInterfaceID = pipe.ReceiverInterfaceID;
                    esbDistributeStrategyEntity.CreatedOn = DateTime.Now;
                    esbDistributeStrategyEntity.Status = 1;
                    esbDistributeStrategyEntity.Insert();
                }
                else{
                    pipe.ModifiedOn = DateTime.Now;
                    pipe.Update();
                }

                hr.KeyValue = pipe.ReceiverInterfaceID.ToString();
                scope.Commit();
            }
            return new JsonResult(hr);
        }
开发者ID:udbeeq5566,项目名称:ESB,代码行数:34,代码来源:ESBPipeService.cs

示例6: GetWSDL

        public JsonResult GetWSDL(string providerID, string relativePath)
        {
            HttpResult hr = new HttpResult() { Result = true };

            EsbProvider provider = null;
            try
            {
                provider = CPQuery.From("select * from esb_Provider where ProviderID = @ProviderID", new { ProviderID = providerID }).ToSingle<EsbProvider>();
            }
            catch(Exception ex)
            {
                hr.Result = false;
                hr.ErrorMessage = "运行时异常,请与管理员联系!";
                new MyLogger().WriteLog(LogLevel.Error, ex.Message, ex.ToString());
            }

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(string.Format(@"{0}://{1}:{2}{3}?wsdl", provider.Protocol, provider.Domain, provider.Port, relativePath));
            request.Method = "GET";

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                using(StreamReader sr = new StreamReader(response.GetResponseStream()))
                {
                    hr.KeyValue = sr.ReadToEnd();
                }
            }

            return new JsonResult(hr);
        }
开发者ID:udbeeq5566,项目名称:ESB,代码行数:29,代码来源:ESBCommonService.cs

示例7: BeginReceive

        public IAsyncResult BeginReceive(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            if (receiveResult != null)
                throw new InvalidOperationException("Cannot call BeginReceive twice");

            receiveResult = new HttpResult(callback, state, buffer, offset, count);
            try
            {
                // BeginReceive has been called *before* we have sent a piece request.
                // Wait for a piece request to be sent before allowing this to complete.
                if (dataStream == null)
                    return receiveResult;

                DoReceive();
                return receiveResult;
            }
            catch (Exception ex)
            {
                if (sendResult != null)
                    sendResult.Complete(ex);

                if (receiveResult != null)
                    receiveResult.Complete(ex);
            }
            return receiveResult;
        }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:26,代码来源:HTTPConnection.cs

示例8: Can_send_ResponseStream_test_with_Custom_Header

        public void Can_send_ResponseStream_test_with_Custom_Header()
        {
            var mockResponse = new MockHttpResponse();

            var customText = "<h1>Custom Stream</h1>";
            var customTextBytes = customText.ToUtf8Bytes();
            var ms = new MemoryStream();
            ms.Write(customTextBytes, 0, customTextBytes.Length);

            var httpResult = new HttpResult(ms, MimeTypes.Html)
            {
                Headers =
                {
                    {"X-Custom","Header"}
                }
            };

            var reponseWasAutoHandled = mockResponse.WriteToResponse(httpResult, MimeTypes.Html);

            Assert.That(reponseWasAutoHandled.Result, Is.True);

            var writtenString = mockResponse.ReadAsString();
            Assert.That(writtenString, Is.EqualTo(customText));
            Assert.That(mockResponse.Headers["X-Custom"], Is.EqualTo("Header"));
        }
开发者ID:GDBSD,项目名称:ServiceStack,代码行数:25,代码来源:HttpResultTests.cs

示例9: SetMainSite

 public JsonResult SetMainSite(Guid providerGUID)
 {
     HttpResult hr = new HttpResult() { Result = true };
     var param = new { ProviderID = providerGUID };
     CPQuery.From(@"UPDATE dbo.esb_Provider SET IsMainSite=0
                    UPDATE dbo.esb_Provider SET IsMainSite=1 WHERE [email protected]", param).ExecuteNonQuery();
     return new JsonResult(hr);
 }
开发者ID:udbeeq5566,项目名称:ESB,代码行数:8,代码来源:EsbProviderService.cs

示例10: DestroyOnCompletion

    private void DestroyOnCompletion(HttpResult result)
    {
        if (!request.CanBeDestroyed())
            return;

        if (gameObject.GetComponents<Component>().Length <= 2)
            Destroy(gameObject);
        else
            Destroy(this);
    }
开发者ID:Naphier,项目名称:NGTools,代码行数:10,代码来源:WWWController.cs

示例11: Get

        public object Get(PartialFromMemory request)
        {
            var customText = "123456789012345678901234567890";
            var customTextBytes = customText.ToUtf8Bytes();
            var ms = new MemoryStream();
            ms.Write(customTextBytes, 0, customTextBytes.Length);

            var httpResult = new HttpResult(ms, "audio/mpeg");
            return httpResult;
        }
开发者ID:AVee,项目名称:ServiceStack,代码行数:10,代码来源:PartialContentResultTests.cs

示例12: Can_handle_null_HttpResult_StatusDescription

        public void Can_handle_null_HttpResult_StatusDescription()
        {
            var mockResponse = new MockHttpResponse();

            var httpResult = new HttpResult { StatusDescription = null };

            var reponseWasAutoHandled = mockResponse.WriteToResponse(httpResult, MimeTypes.Html);
            Assert.That(reponseWasAutoHandled.Result, Is.True);

            Assert.IsNotNull(mockResponse.StatusDescription);
        }
开发者ID:GDBSD,项目名称:ServiceStack,代码行数:11,代码来源:HttpResultTests.cs

示例13: DeleteValidateDistribute

        public JsonResult DeleteValidateDistribute(string[] GUIDList)
        {
            if( GUIDList == null || GUIDList.Length == 0 )
                throw new ArgumentException("接口列表不能为空.");

            HttpResult hr = new HttpResult() { Result = true };
            string keyList = string.Join("','", GUIDList);
            CPQuery.From(string.Format("delete from esb_VerifyDistribute where VerifyDistributeID in ('{0}')", keyList)).ExecuteNonQuery();

            return new JsonResult(hr);
        }
开发者ID:udbeeq5566,项目名称:ESB,代码行数:11,代码来源:PipeStrategyService.cs

示例14: DeleteInvoker

 public JsonResult DeleteInvoker(string[] invokerGUIDList)
 {
     HttpResult hr = new HttpResult() { Result = true };
     string keyList = string.Join("','", invokerGUIDList);
     using( ConnectionScope scope = new ConnectionScope(TransactionMode.Required) ) {
         CPQuery.From(String.Format("delete from esb_Invoker where InvokerID in ('{0}')",
                                     keyList)).ExecuteNonQuery();
         scope.Commit();
     }
     return new JsonResult(hr);
 }
开发者ID:udbeeq5566,项目名称:ESB,代码行数:11,代码来源:ESBParamService.cs

示例15: HandleImage

    void HandleImage(HttpResult result)
    {
        Texture2D tex = result.texture2d;
        if (tex == null)
        {
            Debug.LogError("Something went wrong!");
            return;
        }

        Vector3 scale = new Vector3(result.texture2d.width / 100f, result.texture2d.height / 100, 1f);
        textureHolder.transform.localScale = scale;
        Material mat = textureHolder.GetComponent<Renderer>().material;
        mat.mainTexture = tex;
        mat.shader = Shader.Find("Unlit/Texture");
    }
开发者ID:Naphier,项目名称:NGTools,代码行数:15,代码来源:TestHttpRequest.cs


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