protected override void OnBindingContextChanged() { base.OnBindingContextChanged(); var textModel = BindingContext as TextMoodModel; var emoji = EmojiServices.GetEmoji(textModel.SentimentScore); _titleLabel.Text = textModel.Text; _descriptionLabel.Text = $"{emoji} {textModel.CreatedAt.ToLocalTime().ToString("g")}"; }
static Grid CreateDataTemplate(ITextMoodModel textModel) { var emoji = EmojiServices.GetEmoji(textModel.SentimentScore); var titleLabel = new Label { FontAttributes = FontAttributes.Bold, Text = textModel.Text }; var descriptionLabel = new Label { Text = $"{emoji} {textModel.CreatedAt.ToLocalTime().ToString("g")}" }; var gridLayout = new Grid { Padding = new Thickness(20, 5), RowSpacing = 2, ColumnSpacing = 10, RowDefinitions = { new RowDefinition { Height = new GridLength(0, GridUnitType.Auto) }, new RowDefinition { Height = new GridLength(0, GridUnitType.Auto) } }, ColumnDefinitions = { new ColumnDefinition { Width = new GridLength(0, GridUnitType.Auto) } } }; gridLayout.Children.Add(titleLabel, 0, 0); gridLayout.Children.Add(descriptionLabel, 0, 1); return(gridLayout); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequest req, [Queue(QueueNameConstants.TextModelForDatabase)] ICollector <TextMoodModel> textModelForDatabaseCollection, [Queue(QueueNameConstants.SendUpdate)] ICollector <TextMoodModel> sendUpdateCollection, ILogger log) { try { log.LogInformation("Text Message Received"); log.LogInformation("Parsing Request Body"); var httpRequestBody = await HttpRequestServices.GetContentAsString(req).ConfigureAwait(false); log.LogInformation("Creating New Text Model"); var textMessageBody = TwilioServices.GetTextMessageBody(httpRequestBody, log) ?? throw new NullReferenceException("Text Message Body Null"); var textMoodModel = new TextMoodModel(textMessageBody); log.LogInformation("Retrieving Sentiment Score"); textMoodModel.SentimentScore = await TextAnalysisServices.GetSentiment(textMoodModel.Text).ConfigureAwait(false) ?? -1; log.LogInformation("Adding TextMoodModel to Storage Queue"); textModelForDatabaseCollection.Add(textMoodModel); sendUpdateCollection.Add(textMoodModel); var response = $"Text Sentiment: {EmojiServices.GetEmoji(textMoodModel.SentimentScore)}"; log.LogInformation($"Sending OK Response: {response}"); return(new ContentResult { StatusCode = (int)HttpStatusCode.OK, Content = TwilioServices.CreateTwilioResponse(response), ContentType = "application/xml" }); } catch (Exception e) { log.LogError(e, e.Message); throw; } }
public static HttpResponseMessage Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage httpRequest, [Queue(QueueNameConstants.TextModelForDatabase)] out TextMoodModel textModelForDatabase, TraceWriter log) { log.Info("Text Message Received"); log.Info("Parsing Request Message"); var httpRequestBody = httpRequest.Content.ReadAsStringAsync().GetAwaiter().GetResult(); log.Info("Creating New Text Model"); textModelForDatabase = new TextMoodModel(TwilioServices.GetTextMessageBody(httpRequestBody, log)); log.Info("Retrieving Sentiment Score"); textModelForDatabase.SentimentScore = TextAnalysisServices.GetSentiment(textModelForDatabase.Text).GetAwaiter().GetResult() ?? -1; var response = $"Text Sentiment: {EmojiServices.GetEmoji(textModelForDatabase.SentimentScore)}"; log.Info($"Sending OK Response: {response}"); return(new HttpResponseMessage { Content = new StringContent(TwilioServices.CreateTwilioResponse(response), Encoding.UTF8, "application/xml") }); }