Exemplo n.º 1
0
        public static void Register(HttpConfiguration config)
        {
            IntentHandlers = new IntentList()
            {
                { "ReservationIntent", (cm) => Handlers.ReservationIntent.Process(cm) },
                { "DefaultWelcomeIntent", (cm) => Handlers.WelcomeIntent.Process(cm) }
            };
            // Json settings
            config.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver  = new CamelCasePropertyNamesContractResolver();
            config.Formatters.JsonFormatter.SerializerSettings.Formatting        = Formatting.Indented;
            JsonConvert.DefaultSettings = () => new JsonSerializerSettings()
            {
                ContractResolver  = new CamelCasePropertyNamesContractResolver(),
                Formatting        = Newtonsoft.Json.Formatting.Indented,
                NullValueHandling = NullValueHandling.Ignore,
            };

            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetAsync()
        {
            IntentList intentList = new IntentList();

            try
            {
                var lines = await System.IO.File.ReadAllLinesAsync("intents.txt");

                intentList.Intents = lines.ToList();
                return(Ok(intentList));
            }
            catch
            {
                if (!System.IO.File.Exists("intents.txt"))
                {
                    await System.IO.File.WriteAllLinesAsync("intents.txt", new List <string> {
                        "value-1", "value-2"
                    });
                }
                return(Ok(intentList));
            }
        }