public async Task <bool> RequestCommunication(int?groupID, int?recipientID, int?jobID, CommunicationJob communicationJob)
        {
            var communicationRequest = new RequestCommunicationRequest()
            {
                GroupID              = groupID,
                JobID                = jobID,
                RecipientUserID      = recipientID,
                CommunicationJob     = communicationJob,
                AdditionalParameters = null
            };

            string json = JsonConvert.SerializeObject(communicationRequest);

            var content = new StringContent(json, Encoding.UTF8, "application/json");


            using (HttpResponseMessage response = await Client.PostAsync("/api/RequestCommunication", content))
            {
                string jsonResponse = await response.Content.ReadAsStringAsync();

                var requestCommunicationResponse = JsonConvert.DeserializeObject <ResponseWrapper <RequestCommunicationResponse, CommunicationServiceErrorCode> >(jsonResponse);
                if (requestCommunicationResponse.HasContent && requestCommunicationResponse.IsSuccessful)
                {
                    return(requestCommunicationResponse.Content.Success);
                }
            }

            return(false);
        }
Beispiel #2
0
        public async Task Run([ServiceBusTrigger("job", Connection = "ServiceBus")] Message mySbMsg, ILogger log)
        {
            LogDetails logDetails = new LogDetails()
            {
                Queue = "Job"
            };

            logDetails.Started       = DateTime.Now;
            logDetails.MessageId     = mySbMsg.MessageId;
            logDetails.DeliveryCount = mySbMsg.SystemProperties.DeliveryCount;

            try
            {
                string converted = Encoding.UTF8.GetString(mySbMsg.Body, 0, mySbMsg.Body.Length);
                RequestCommunicationRequest requestCommunicationRequest = JsonConvert.DeserializeObject <RequestCommunicationRequest>(converted);

                logDetails.Job = Enum.GetName(typeof(CommunicationJobTypes), requestCommunicationRequest.CommunicationJob.CommunicationJobType);

                IMessage message = _messageFactory.Create(requestCommunicationRequest);
                List <SendMessageRequest> messageDetails = await message.IdentifyRecipients(requestCommunicationRequest.RecipientUserID, requestCommunicationRequest.JobID, requestCommunicationRequest.GroupID, requestCommunicationRequest.RequestID, requestCommunicationRequest.AdditionalParameters);

                if (messageDetails.Count == 0)
                {
                    log.LogInformation("No recipients identified");
                    logDetails.PotentialRecipientCount = 0;
                }
                else
                {
                    logDetails.PotentialRecipientCount = messageDetails.Count;
                    var rec = JsonConvert.SerializeObject(messageDetails);
                    log.LogInformation($"Recipients { rec}");  // Can we see this anywhere?  could be useful for testing one of our theories.
                }

                Guid batchId = Guid.NewGuid();

                foreach (var m in messageDetails)
                {
                    await _messageFactory.AddToMessageQueueAsync(new SendMessageRequest()
                    {
                        BatchID = batchId,
                        CommunicationJobType = requestCommunicationRequest.CommunicationJob.CommunicationJobType,
                        TemplateName         = m.TemplateName,
                        RecipientUserID      = m.RecipientUserID,
                        JobID                = m.JobID,
                        GroupID              = m.GroupID,
                        MessageType          = MessageTypes.Email,
                        RequestID            = m.RequestID,
                        AdditionalParameters = m.AdditionalParameters
                    });
                }
            }
            catch (Exception exc)
            {
                await LogAndAddToCosmos(log, logDetails, "error", exc);

                throw exc;
            }

            await LogAndAddToCosmos(log, logDetails);
        }
Beispiel #3
0
        public async Task Run([TimerTrigger("%RegistrationChasersCronExpression%")] TimerInfo myTimer, ILogger log)
        {
            RequestCommunicationRequest req = new RequestCommunicationRequest()
            {
                CommunicationJob = new CommunicationJob()
                {
                    CommunicationJobType = CommunicationJobTypes.SendRegistrationChasers
                }
            };

            await _communicationService.RequestCommunicationAsync(req, CancellationToken.None);

            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
        }
        public async Task <bool> RequestCommunicationAsync(RequestCommunicationRequest requestCommunicationRequest, CancellationToken cancellationToken)
        {
            string path        = $"api/RequestCommunication";
            var    jsonContent = new StringContent(JsonConvert.SerializeObject(requestCommunicationRequest), Encoding.UTF8, "application/json");

            using (HttpResponseMessage response = await _httpClientWrapper.PostAsync(HttpClientConfigName.CommunicationService, path, jsonContent, cancellationToken).ConfigureAwait(false))
            {
                string jsonResponse = await response.Content.ReadAsStringAsync();

                var emailSentResponse = JsonConvert.DeserializeObject <ResponseWrapper <RequestCommunicationResponse, CommunicationServiceErrorCode> >(jsonResponse);
                if (emailSentResponse.HasContent && emailSentResponse.IsSuccessful)
                {
                    return(emailSentResponse.Content.Success);
                }
                return(false);
            }
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]
            [RequestBodyType(typeof(RequestCommunicationRequest), "Request Communication")] RequestCommunicationRequest req,
            ILogger log)
        {
            try
            {
                var request = JsonConvert.SerializeObject(req);
                log.LogInformation($"RequestCommunicationRequest {request}");

                RequestCommunicationResponse response = await _mediator.Send(req);

                return(new OkObjectResult(ResponseWrapper <RequestCommunicationResponse, CommunicationServiceErrorCode> .CreateSuccessfulResponse(response)));
            }
            catch (Exception exc)
            {
                log.LogError("Exception occured in Request Communication", exc);
                return(new ObjectResult(ResponseWrapper <RequestCommunicationResponse, CommunicationServiceErrorCode> .CreateUnsuccessfulResponse(CommunicationServiceErrorCode.InternalServerError, "Internal Error"))
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }
Beispiel #6
0
 public IMessage Create(RequestCommunicationRequest sendCommunicationRequest)
 {
     return(GetMessage(sendCommunicationRequest.CommunicationJob.CommunicationJobType));
 }
Beispiel #7
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]
            RequestCommunicationRequest req,
            ILogger log)
        {
            try
            {
                var request = JsonConvert.SerializeObject(req);
                log.LogInformation($"RequestCommunicationRequest {request}");

                //TaskNotificationMessage message = new TaskNotificationMessage(
                //    _connectUserService,
                //    _connectRequestService,
                //    _connectGroupService);

                //TaskDetailMessage message = new TaskDetailMessage(
                //    _connectGroupService,
                //    _connectUserService,
                //    _connectRequestService,
                //    _emailConfig,
                //    _cosmosDbService
                //    );

                //TaskUpdateSimplifiedMessage message = new TaskUpdateSimplifiedMessage(
                //    _connectRequestService,
                //    _connectUserService,
                //    _connectGroupService,
                //    _linkRepository,
                //    _linkConfig,
                //    _sendGridConfig,
                //    _connectAddressService);

                //NewCredentialsMessage message = new NewCredentialsMessage(
                //    _connectUserService,
                //    _connectGroupService);

                //TaskUpdateNewMessage message = new TaskUpdateNewMessage(
                //        _connectRequestService,
                //        _connectUserService,
                //        _connectGroupService,
                //        _linkRepository,
                //        _linkConfig,
                //        _sendGridConfig
                //    );

                //RegistrationChaserMessage message = new RegistrationChaserMessage(
                //    _connectUserService, _cosmosDbService, _emailConfig);


                //TestLinkSubstitutionMessage message = new TestLinkSubstitutionMessage(
                //    _connectRequestService,
                //    _linkRepository,
                //    _emailConfig,
                //    _sendGridConfig
                //    );

                //RequestorTaskConfirmation message = new RequestorTaskConfirmation(
                //    _connectRequestService,
                //    _connectGroupService,
                //    _connectAddressService,
                //    _linkRepository,
                //    _linkConfig,
                //    _sendGridConfig);

                //NewRequestNotificationMessage message = new NewRequestNotificationMessage(
                //    _connectRequestService,
                //    _connectAddressService,
                //    _connectUserService,
                //    _cosmosDbService,
                //    _emailConfig,
                //    _connectGroupService
                //    );

                //ShiftReminderMessage message = new ShiftReminderMessage(_connectRequestService, _connectUserService, _connectAddressService, _linkRepository, _linkConfig);

                //DailyDigestMessage message = new DailyDigestMessage(
                //    _connectGroupService,
                //    _connectUserService,
                //    _connectRequestService,
                //    _emailConfig,
                //    _connectAddressService,
                //    _cosmosDbService
                //    );

                //NewTaskPendingApprovalNotification message = new NewTaskPendingApprovalNotification(
                //    _connectRequestService,
                //    _connectGroupService,
                //    _connectUserService,
                //    _linkRepository,
                //    _linkConfig);

                //TaskReminderMessage message = new TaskReminderMessage(
                //    _connectRequestService,
                //    _connectUserService,
                //    _cosmosDbService
                //    );

                GroupWelcomeMessage message = new GroupWelcomeMessage(_connectGroupService, _connectUserService, _sendGridConfig);

                var recipients = await message.IdentifyRecipients(req.RecipientUserID, req.JobID, req.GroupID, req.RequestID, req.AdditionalParameters);

                recipients = recipients.Take(1).ToList();

                //recipients = recipients.Where(x => x.RecipientUserID == 20232).ToList();


                //SendMessageRequest smr = recipients.ElementAt(0);
                foreach (SendMessageRequest smr in recipients)
                {
                    var emailBuildData = await message.PrepareTemplateData(Guid.NewGuid(), smr.RecipientUserID, smr.JobID, smr.GroupID, smr.RequestID, smr.AdditionalParameters, smr.TemplateName);

                    if (emailBuildData != null)
                    {
                        //emailBuildData.EmailToAddress = "*****@*****.**";
                        //emailBuildData.EmailToName = "Jawwad";
                        var json2 = JsonConvert.SerializeObject(emailBuildData.BaseDynamicData);
                        _connectSendGridService.SendDynamicEmail(string.Empty, smr.TemplateName, UnsubscribeGroupName.TaskNotification, emailBuildData);
                    }
                }

                int i = 1;

                return(new OkResult());
            }
            catch (Exception exc)
            {
                log.LogError("Exception occured in Request Communication", exc);
                return(new ObjectResult(ResponseWrapper <RequestCommunicationResponse, CommunicationServiceErrorCode> .CreateUnsuccessfulResponse(CommunicationServiceErrorCode.InternalServerError, "Internal Error"))
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }