Ejemplo n.º 1
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            PostTextResponse response = new PostTextResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("dialogState", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.DialogState = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("intentName", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.IntentName = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("message", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.Message = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("responseCard", targetDepth))
                {
                    var unmarshaller = ResponseCardUnmarshaller.Instance;
                    response.ResponseCard = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("sessionAttributes", targetDepth))
                {
                    var unmarshaller = new DictionaryUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.Instance, StringUnmarshaller.Instance);
                    response.SessionAttributes = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("slots", targetDepth))
                {
                    var unmarshaller = new DictionaryUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.Instance, StringUnmarshaller.Instance);
                    response.Slots = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("slotToElicit", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.SlotToElicit = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Ejemplo n.º 2
0
        static void ThreadTextPostRequests(TextLoadTest loadTest)
        {
            TextLoadTestData data;

            while (dataInQueue.TryDequeue(out data))
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();

                string content = string.Format("{{ \"Name\": \"{0}\", \"Text\": \"{1}\", \"City\": \"{2}\", \"ParentId\": 0 }}", data.name, data.text, data.city);

                PostTextResponse response = PostRequest <PostTextResponse>(string.Format("{0}/v1/text", loadTest.ApiUri), "application/json", content);

                sw.Stop();

                elapsedMilliseconds.Add(sw.ElapsedMilliseconds);

                string responseSerialized = JsonConvert.SerializeObject(response.Data, Formatting.None);
                Console.WriteLine(responseSerialized);
            }
        }
Ejemplo n.º 3
0
        private async Task <string> GetIntentFromLexAsync(String customerContact)
        {
            try
            {
                AmazonLexClient lexClient   = new AmazonLexClient(primaryRegion);
                PostTextRequest textRequest = new PostTextRequest();
                textRequest.UserId    = "MailBot";
                textRequest.BotAlias  = "DEV";
                textRequest.BotName   = "NBC_Mailbot_Intents";
                textRequest.InputText = customerContact;
                PostTextResponse textRespone = await lexClient.PostTextAsync(textRequest);

                return(textRespone.IntentName);
            }
            catch (Exception error)
            {
                await SendFailureAsync("Getting Intent", error.Message);

                Console.WriteLine("ERROR : GetIntentFromLexAsync : " + error.StackTrace);
                return("GeneralEnquiries");
            }
        }
Ejemplo n.º 4
0
        public virtual HttpResponseMessage PostText(PostTextRequest request)
        {
            PostTextResponse response = new PostTextResponse();

            try
            {
                if (request == null)
                {
                    throw new ArgumentException("Request content is invalid");
                }

                SaveTextRequest saveTextRequest = new SaveTextRequest();
                saveTextRequest.City          = request.City;
                saveTextRequest.Text          = new TextDto();
                saveTextRequest.Text.Name     = request.Name;
                saveTextRequest.Text.Value    = request.Text;
                saveTextRequest.Text.ParentId = Convert.ToInt32(request.ParentId);

                SaveTextResponse saveTextResponse = _textService.SaveText(saveTextRequest);

                response.Data          = new TextResponse();
                response.Data.Text     = saveTextResponse.Text.Value;
                response.Data.Id       = saveTextResponse.Text.Id.ToString();
                response.Data.ParentId = saveTextResponse.Text.ParentId.ToString();
                response.Data.City     = saveTextResponse.City.Name;
                response.Data.Lat      = saveTextResponse.City.Latitude.ToString();
                response.Data.Lon      = saveTextResponse.City.Longitude.ToString();
                response.Data.Temp     = saveTextResponse.City.Temperature.ToString();
            }
            catch (Exception ex)
            {
                response.Error = string.Format("Internal server error: {0}", ex.Message);
            }

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            PostTextResponse response = new PostTextResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("activeContexts", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <ActiveContext, ActiveContextUnmarshaller>(ActiveContextUnmarshaller.Instance);
                    response.ActiveContexts = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("alternativeIntents", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <PredictedIntent, PredictedIntentUnmarshaller>(PredictedIntentUnmarshaller.Instance);
                    response.AlternativeIntents = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("botVersion", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.BotVersion = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("dialogState", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.DialogState = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("intentName", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.IntentName = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("message", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.Message = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("messageFormat", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.MessageFormat = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("nluIntentConfidence", targetDepth))
                {
                    var unmarshaller = IntentConfidenceUnmarshaller.Instance;
                    response.NluIntentConfidence = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("responseCard", targetDepth))
                {
                    var unmarshaller = ResponseCardUnmarshaller.Instance;
                    response.ResponseCard = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("sentimentResponse", targetDepth))
                {
                    var unmarshaller = SentimentResponseUnmarshaller.Instance;
                    response.SentimentResponse = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("sessionAttributes", targetDepth))
                {
                    var unmarshaller = new DictionaryUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.Instance, StringUnmarshaller.Instance);
                    response.SessionAttributes = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("sessionId", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.SessionId = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("slots", targetDepth))
                {
                    var unmarshaller = new DictionaryUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.Instance, StringUnmarshaller.Instance);
                    response.Slots = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("slotToElicit", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.SlotToElicit = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }