Ejemplo n.º 1
0
        public async Task <SantaResults> WriteLetterToSanta(SantaLetter letter)
        {
            // if we're on the Android emulator, running functions locally, need to swap out the function url
            if (santaUrl.Contains("localhost") && DeviceInfo.DeviceType == DeviceType.Virtual && DeviceInfo.Platform == DevicePlatform.Android)
            {
                santaUrl = "http://10.0.2.2:7071/api/WriteSanta";
            }

            SantaResults results = null;

            try
            {
                var letterJson = JsonConvert.SerializeObject(letter);

                var httpResponse = await httpClient.PostAsync(santaUrl, new StringContent(letterJson));

                results = JsonConvert.DeserializeObject <SantaResults>(await httpResponse.Content.ReadAsStringAsync());

                return(results);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);

                results = new SantaResults {
                    SentimentScore = -1
                };
            }

            return(results);
        }
Ejemplo n.º 2
0
        public async Task <SantaResults> WriteLetterToSanta(SantaLetter letter)
        {
            SantaResults results = null;

            try
            {
                var letterJson = JsonConvert.SerializeObject(letter);

                var httpResponse = await httpClient.PostAsync("WriteSanta", new StringContent(letterJson));

                results = JsonConvert.DeserializeObject <SantaResults>(await httpResponse.Content.ReadAsStringAsync());
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }

            if (results == null)
            {
                results = new SantaResults {
                    SentimentScore = -1
                }
            }
            ;

            return(results);
        }
    }
Ejemplo n.º 3
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] SantaLetter theLetter,
            ILogger log)
        {
            SantaResults result;

            try
            {
                // Get the languages
                var detectedLanguages = await textClient.DetectLanguageAsync(
                    inputText : theLetter.LetterText,
                    countryHint : ""
                    );

                if (!string.IsNullOrEmpty(detectedLanguages.ErrorMessage))
                {
                    return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
                }

                // Grab the top scoring one
                var theLanguage = detectedLanguages.DetectedLanguages.OrderByDescending(i => i.Score).First();

                // Get the sentiment
                var detectedSentiments = await textClient.SentimentAsync(
                    inputText : theLetter.LetterText,
                    language : theLanguage.Iso6391Name
                    );

                if (!string.IsNullOrEmpty(detectedSentiments.ErrorMessage))
                {
                    return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
                }

                result = new SantaResults
                {
                    DetectedLanguage = theLanguage.Name,
                    KidName          = theLetter.KidName,
                    LetterText       = theLetter.LetterText,
                    SentimentScore   = detectedSentiments.Score.Value
                };
            }
            catch (Exception ex)
            {
                log.LogError(ex.ToString());

                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }

            return(new OkObjectResult(result));
        }
Ejemplo n.º 4
0
        public string AddMessage(SantaLetter user)
        {
            var data = _SQLiteConnection.Table <SantaLetter>();
            var d1   = data.Where(x => x.KidName == user.KidName && x.LetterText == user.LetterText).FirstOrDefault();

            if (d1 == null)
            {
                _SQLiteConnection.Insert(user);
                return("Sucessfully Added");
            }
            else
            {
                return("Message is Empty");
            }
        }