public static async Task Run([QueueTrigger(QueueNameConstants.TextModelForDatabase)] TextMoodModel textModel, ILogger log)
        {
            log.LogInformation("Saving TextModel to Database");

            if (textModel.Text.Length > 128)
            {
                textModel.Text = textModel.Text.Substring(0, 128);
            }

            await TextMoodDatabase.InsertTextModel(textModel).ConfigureAwait(false);
        }
示例#2
0
        public static async Task Run([QueueTrigger(QueueNameConstants.SendUpdate)] TextMoodModel textModel, TraceWriter log)
        {
            try
            {
                var hub = await GetConnection().ConfigureAwait(false);

                await hub.InvokeAsync(SignalRConstants.SendNewTextMoodModelName, textModel).ConfigureAwait(false);
            }
            catch (System.Exception e)
            {
                log.Info(e.Message);
            }
        }
        public static void Run(
            [QueueTrigger(QueueNameConstants.TextModelForDatabase)] TextMoodModel textModel,
            [Queue(QueueNameConstants.SendUpdate)] out TextMoodModel textModelOutput,
            TraceWriter log)
        {
            log.Info("Saving TextModel to Database");

            if (textModel.Text.Length > 128)
            {
                textModel.Text = textModel.Text.Substring(0, 128);
            }

            TextMoodDatabase.InsertTextModel(textModel).GetAwaiter().GetResult();

            textModelOutput = textModel;
        }
        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;
            }
        }
示例#5
0
        public static async Task Run([QueueTrigger(QueueNameConstants.SendUpdate)] TextMoodModel textModel, ILogger log)
        {
            InitializationFailed += HandleInitializationFailed;

            try
            {
                var hub = await GetConnection().ConfigureAwait(false);

                await hub.InvokeAsync(SignalRConstants.SendNewTextMoodModelMethod, textModel).ConfigureAwait(false);
            }
            catch (System.Exception e)
            {
                log.LogError(e, e.Message);
                throw;
            }
            finally
            {
                InitializationFailed -= HandleInitializationFailed;
            }

            void HandleInitializationFailed(object?sender, string message) => log.LogInformation($"Initialization Failed: {message}");
        }
示例#6
0
        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")
            });
        }
示例#7
0
 public void SendNewTextMoodModel(TextMoodModel textMoodModel) => Clients.All.SendAsync(nameof(SendNewTextMoodModel), textMoodModel);
示例#8
0
 public Task SendNewTextMoodModel(TextMoodModel textMoodModel) => Clients.All.SendAsync(SignalRConstants.SendNewTextMoodModelCommand, textMoodModel);
示例#9
0
 public static async Task Run([QueueTrigger(QueueNameConstants.SendUpdate)] TextMoodModel textModel, TraceWriter log) =>
 await Proxy.Invoke(SignalRConstants.SendNewTextMoodModelName, textModel).ConfigureAwait(false);
示例#10
0
 public void SendNewTextMoodModel(TextMoodModel textMoodModel) => Clients.Others.SendNewTextMoodModel(textMoodModel);