Beispiel #1
0
        private void _requestBtn_Click(object sender, EventArgs e)
        {
            string msg = _requestMessage.Text;

            if (string.IsNullOrEmpty(msg))
            {
                this.InformUser("Please add a request message.  Just type in whatever you like.");
                return;
            }

            ExampleRequest request     = new ExampleRequest(msg);
            TimeSpan       fiveSeconds = new TimeSpan(0, 0, 5);

            try
            {
                ExampleResponse response = this.EventBus.GetResponseTo <ExampleResponse>(request, fiveSeconds);

                if (null == response)
                {
                    this.Log("Did not get a response to the request within 5 seconds.  Ensure there is another .NET Consumer & Producer running");
                }
                else
                {
                    this.Log(string.Format("Got a response to '{0}': '{1}'", response.OriginalMessage, response.ResponseMessage));
                }
            }
            catch (Exception ex)
            {
                this.Log("Could not send the request: " + ex.ToString());
            }
        }
Beispiel #2
0
        public ExampleResponse CreateExample(string workspaceId, string intent, CreateExample request)
        {
            ExampleResponse result = null;

            if (string.IsNullOrEmpty(workspaceId))
            {
                throw new ArgumentNullException("parameter: workspaceId");
            }
            if (string.IsNullOrEmpty(intent))
            {
                throw new ArgumentNullException("parameter: intent");
            }
            if (request == null)
            {
                throw new ArgumentNullException("parameter: request");
            }

            try
            {
                result =
                    this.Client.WithAuthentication(this.UserName, this.Password)
                    .PostAsync($"{this.Endpoint}{PATH_CONVERSATION}/{workspaceId}/intents/{intent}/examples")
                    .WithArgument("version", VERSION_DATE_2017_05_26)
                    .WithHeader("accept", HttpMediaType.TEXT_HTML)
                    .WithBody <CreateExample>(request, MediaTypeHeaderValue.Parse(HttpMediaType.APPLICATION_JSON))
                    .As <ExampleResponse>()
                    .Result;
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }

            return(result);
        }
Beispiel #3
0
        public ExampleResponse GetExample(string workspaceId, string intent, string text)
        {
            ExampleResponse result = null;

            if (string.IsNullOrEmpty(workspaceId))
            {
                throw new ArgumentNullException("parameter: workspaceId");
            }
            if (string.IsNullOrEmpty(intent))
            {
                throw new ArgumentNullException("parameter: intent");
            }
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentNullException("parameter: text");
            }

            try
            {
                result =
                    this.Client.WithAuthentication(this.UserName, this.Password)
                    .GetAsync($"{this.Endpoint}{PATH_CONVERSATION}/{workspaceId}/intents/{intent}/examples/{text}")
                    .WithArgument("version", VERSION_DATE_2017_05_26)
                    .WithHeader("accept", HttpMediaType.APPLICATION_JSON)
                    .As <ExampleResponse>()
                    .Result;
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }

            return(result);
        }
        public ExampleResponse CreateCounterexample(string workspaceId, CreateExample body)
        {
            if (string.IsNullOrEmpty(workspaceId))
            {
                throw new ArgumentNullException(nameof(workspaceId));
            }
            if (body == null)
            {
                throw new ArgumentNullException(nameof(body));
            }

            if (string.IsNullOrEmpty(VersionDate))
            {
                throw new ArgumentNullException("versionDate cannot be null. Use 'CONVERSATION_VERSION_DATE_2017_05_26'");
            }

            ExampleResponse result = null;

            try
            {
                result = this.Client.WithAuthentication(this.UserName, this.Password)
                         .PostAsync($"{this.Endpoint}/v1/workspaces/{workspaceId}/counterexamples")
                         .WithArgument("version", VersionDate)
                         .WithBody <CreateExample>(body)
                         .As <ExampleResponse>()
                         .Result;
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }

            return(result);
        }
Beispiel #5
0
        public override Task <ExampleResponse> UnaryCall(ExampleRequest request, ServerCallContext context)
        {
            var response = new ExampleResponse {
                TotalCount = request.PageIndex * request.PageSize, Message = $"--From Server-- Current index from service is {request.PageIndex}"
            };

            return(Task.FromResult(response));
        }
        public override Task <ExampleResponse> ChamadaTesteService(ExampleRequest exampleRequest, ServerCallContext serverCallContext)
        {
            var response = new ExampleResponse {
                Id = exampleRequest.Status, Nome = $"{exampleRequest.Mensagem} Testado: {exampleRequest.Testado}"
            };

            return(Task.FromResult(response));
        }
Beispiel #7
0
        //一元方法
        public override Task <ExampleResponse> UnaryCall(ExampleRequest request, ServerCallContext context)
        {
            var response = new ExampleResponse()
            {
                Message = "UnaryCall"
            };

            return(Task.FromResult(response));
        }
Beispiel #8
0
        public override async Task <ExampleResponse> UnaryCall(ExampleRequest request, ServerCallContext context)
        {
            var response = new ExampleResponse
            {
                PageIndex = 1, PageData = $"This is UnaryCall- Request-pageIndex {request.PageIndex}"
            };

            return(await Task.FromResult(response));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override async Task <ExampleResponse> UnaryCall(ExampleRequest request,
                                                               ServerCallContext context)
        {
            var response = new ExampleResponse()
            {
                Result = $"{request.ReqStr} World"
            };

            return(response);
        }
Beispiel #10
0
        public ApiResponse <ExampleResponse> Get()
        {
            var example = new ExampleResponse
            {
                Name = "My example",
                Type = ExampleType.Two
            };

            // Response with Example data
            return(new ApiResponse <ExampleResponse>(example));
        }
Beispiel #11
0
        public override async Task StreamingBothWays(IAsyncStreamReader <ExampleRequest> requestStream, IServerStreamWriter <ExampleResponse> responseStream, ServerCallContext context)
        {
            await foreach (var message in requestStream.ReadAllAsync())
            {
                var response = new ExampleResponse {
                    TotalCount = message.PageIndex, Message = $"--From Server-- Current index from response is {message.PageIndex}"
                };

                await responseStream.WriteAsync(response);

                await Task.Delay(TimeSpan.FromSeconds(1), context.CancellationToken);
            }
        }
Beispiel #12
0
        public ExampleResponse GetDetail(int id)
        {
            ExampleResponse response = new ExampleResponse();

            var value = _exampleRepository.GetDetail(id);

            if (value != null)
            {
                response.id   = value.id;
                response.name = value.Name;
                response.age  = value.Age;
            }

            return(response);
        }
Beispiel #13
0
        public void Handle_ExampleRequest(ExampleRequest request, IDictionary <string, string> headers)
        {
            ExampleResponse response = new ExampleResponse();

            response.OriginalMessage = request.Message;
            response.ResponseMessage = string.Format("{0}, eh?  Fascinating.", request.Message);

            try
            {
                this.Log(string.Format("Responding to {0} with {1}", response.OriginalMessage, response.ResponseMessage));
                this.EventBus.RespondTo(headers, response);
            }
            catch (Exception ex)
            {
                this.Log(ex.ToString());
            }
        }
Beispiel #14
0
            protected override void Given()
            {
                _request  = new RestRequest();
                _response = new RestResponse();

                GetMockFor <IRestSharpFactory>()
                .Setup(x => x.CreateClient(RequestExecutor.SLACK_URL))
                .Returns(GetMockFor <IRestClient>().Object);

                GetMockFor <IRestClient>()
                .Setup(x => x.ExecutePostTaskAsync(_request))
                .ReturnsAsync(_response);

                _expectedResult = new ExampleResponse();
                GetMockFor <IResponseVerifier>()
                .Setup(x => x.VerifyResponse <ExampleResponse>(_response))
                .Returns(_expectedResult);
            }
Beispiel #15
0
        public ActionResult <string> Get()
        {
            var response = new ExampleResponse();

            response.Values.Add("value1");
            response.Values.Add("value2");

            foreach (var requestHeader in HttpContext.Request.Headers.OrderBy(a => a.Key))
            {
                response.Headers.Add(requestHeader.Key, requestHeader.Value);
            }

            return(JsonConvert.SerializeObject(response, Formatting.Indented,
                                               new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            }));
        }
Beispiel #16
0
        public override async Task StreamingFromServer(ExampleRequest request, IServerStreamWriter <ExampleResponse> responseStream, ServerCallContext context)
        {
            int startIndex = 1;

            startIndex = request.PageIndex;
            while (!context.CancellationToken.IsCancellationRequested)
            {
                var response = new ExampleResponse {
                    TotalCount = startIndex, Message = $"--From Server-- Current index is {startIndex}"
                };
                startIndex++;

                await responseStream.WriteAsync(response);

                await Task.Delay(TimeSpan.FromSeconds(1));
            }

            return;
        }
Beispiel #17
0
        public override async Task <ExampleResponse> StreamingFromClient(IAsyncStreamReader <ExampleRequest> requestStream, ServerCallContext context)
        {
            string totalIndex = string.Empty;

            await foreach (var message in requestStream.ReadAllAsync())
            {
                totalIndex += (message.PageIndex.ToString() + "|");

                if (message.PageIndex == 0)
                {
                    totalIndex += "Meet 0 to exiting...";
                    break;
                }
            }


            var response = new ExampleResponse {
                TotalCount = 0, Message = $"--From Server-- Current indexes from server is {totalIndex}"
            };

            return(response);
        }
Beispiel #18
0
        public async Task <ResponseBase <List <ExampleResponse> > > Read(long id)
        {
            IRepository <SqlParameterCollection> repository = new SqlServerRepository(connString);
            var lst      = new List <ExampleResponse>();
            var response = new ResponseBase <List <ExampleResponse> >()
            {
                Message = "Datos consultados"
            };

            repository.Parameters.Add("@id", SqlDbType.BigInt).Value = id;

            var result = repository.Get("usp_toures_read");

            if (repository.Status.Code == Status.Ok)
            {
                var x = 0;
                foreach (var item in result)
                {
                    var example = new ExampleResponse()
                    {
                        Id   = (long)result[x]["Id"],
                        Name = (string)result[x]["Name"],
                        Date = (DateTime)result[x]["Date"]
                    };
                    lst.Add(example);

                    x += 1;
                }
                response.Data = lst;
            }
            else
            {
                response.Message = repository.Status.Message;
            }
            response.Code = repository.Status.Code;

            return(await Task.Run(() => response));
        }
        public ExampleResponse GetExample(string workspaceId, string intent, string text)
        {
            if (string.IsNullOrEmpty(workspaceId))
            {
                throw new ArgumentNullException(nameof(workspaceId));
            }
            if (string.IsNullOrEmpty(intent))
            {
                throw new ArgumentNullException(nameof(intent));
            }
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentNullException(nameof(text));
            }

            if (string.IsNullOrEmpty(VersionDate))
            {
                throw new ArgumentNullException("versionDate cannot be null. Use 'CONVERSATION_VERSION_DATE_2017_05_26'");
            }

            ExampleResponse result = null;

            try
            {
                result = this.Client.WithAuthentication(this.UserName, this.Password)
                         .GetAsync($"{this.Endpoint}/v1/workspaces/{workspaceId}/intents/{intent}/examples/{text}")
                         .WithArgument("version", VersionDate)
                         .As <ExampleResponse>()
                         .Result;
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }

            return(result);
        }
Beispiel #20
0
 protected override void When()
 {
     Result = SUT.Execute <ExampleResponse>(_request).Result;
 }
 private void OnExampleResponseReceived(ExampleResponse response)
 {
     _exampleResponse = response;
     Debug.Log(string.Format("User ID: {0}, Nickname: {1}", response.UserId, response.Response.Nickname));
 }