Exemplo n.º 1
0
        private void GenericSubscriptionQueue_MessageReceived
            (RabbitMQ.Client.IBasicConsumer sender, RabbitMQ.Client.Events.BasicDeliverEventArgs args)
        {
            RabbitMQ.Client.Events.EventingBasicConsumer consumer = (RabbitMQ.Client.Events.EventingBasicConsumer)sender;

            try {
                // don't reprocess items that have been processed
                if (genericSubscriptionQueue.GetLastProcessedUndelivered() != args.DeliveryTag)
                {
                    BaseNotification notification = NotificationExtension.Deserialize(Encoding.ASCII.GetString(args.Body));

                    eventLogRepository.WriteInformationLog("Processing notification type: {NotificationType}. Data: {QueueMessage}".Inject(new { QueueMessage = notification.ToJson(), NotificationType = notification.NotificationType.ToString() }));

                    var handler = notificationHandlerFactory(notification.NotificationType); // autofac will get the right handler
                    handler.ProcessNotification(notification);

                    // Always clear the context at the end of a transaction
                    _uow.ClearContext();
                }

                genericSubscriptionQueue.Ack(consumer, args.DeliveryTag);
            } catch (QueueDataError <string> serializationEx)  {
                eventLogRepository.WriteErrorLog("Serializing problem with notification.", serializationEx);
            } catch (QueueDataError <BaseNotification> notificationEx) {
                eventLogRepository.WriteErrorLog("Error processing notification.", notificationEx);

                PublishToQueue(notificationEx.ProcessingObject, Configuration.RabbitMQNotificationErrorQueue);
            } catch (Exception ex) {
                eventLogRepository.WriteErrorLog("Unhandled error processing notification.", ex);
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult> AddPsychologist([FromBody] CreatePsychologistResource model)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                var emailExists = await _userManager.FindByEmailAsync(model.EmailAddress);

                if (emailExists != null)
                {
                    message = "Account with provided email address  already exist.";
                    return(BadRequest(new { message }));
                }

                var psychologistWithContactNumberExists = _dbContext.Psychologists.Any(item => item.WorkContactNumber.Equals(model.WorkContactNumber));

                if (psychologistWithContactNumberExists)
                {
                    message = "An account with  the provided work contact number number already exist.";
                    return(BadRequest(new { message }));
                }


                var newUser = new ApplicationUser()
                {
                    UserName    = model.EmailAddress,
                    Email       = model.EmailAddress,
                    PhoneNumber = model.WorkContactNumber,
                };

                var assignedPassword = GenerateRandomPassword();
                var result           = await _userManager.CreateAsync(newUser, assignedPassword);

                if (result.Succeeded)
                {
                    var role = await _roleManager.FindByNameAsync("psychologist".ToLower());

                    await _userManager.AddToRoleAsync(newUser, role.Name);

                    var created = _userService.AddPsychologist(model, assignedPassword);


                    var emailToken = await _userManager.GenerateEmailConfirmationTokenAsync(newUser);

                    var code = HttpUtility.UrlEncode(emailToken);

                    //TODO: Once Deployed, Require Confirmed Email Address and Send Confirmation Link Via Email
                    //var confirmLink = "https://api_hosting_domain/api/account/confirmemail?userId=" + newUser.Id + "&token=" + code;

                    NotificationExtension.AddPsychologistNotification(created.PsychologistId);
                    return(Ok());
                }
                message = "Something went wrong. Please try again.";
                return(BadRequest(new { message }));
            }
            message = "Something went wrong. Please try again.";
            return(BadRequest(new { message }));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> RegisterPatient([FromBody] RegisterPatientResource model)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                var emailExists = await _userManager.FindByEmailAsync(model.Email);

                if (emailExists != null)
                {
                    message = "Account with provided email address  already exist.";
                    return(BadRequest(new { message }));
                }

                var patientWithContactNumberExists = _dbContext.Patients.Any(item => item.ContactNumber.Equals(model.ContactNumber));

                if (patientWithContactNumberExists)
                {
                    message = "An account with  the provided cell phone number already exist.";
                    return(BadRequest(new { message }));
                }

                var newUser = new ApplicationUser()
                {
                    UserName    = model.Email,
                    Email       = model.Email,
                    PhoneNumber = model.ContactNumber,
                };

                var result = await _userManager.CreateAsync(newUser, model.Password);

                if (result.Succeeded)
                {
                    var role = await _roleManager.FindByNameAsync("Patient".ToLower());

                    await _userManager.AddToRoleAsync(newUser, role.Name);

                    //var emailToken = await _userManager.GenerateEmailConfirmationTokenAsync(newUser);
                    //var code = HttpUtility.UrlEncode(emailToken);
                    //var confirmLink = "https://hotsting_domain/api/account/confirmemail?userId=" + newUser.Id + "&token=" + code;
                    //Email.SendAccountConfirmationEmail(newUser.Email, newUser.UserName, confirmLink);

                    NotificationExtension.NewPatientAlert(newUser);

                    var token = GenerateJwtToken(newUser, role.Name);
                    return(Ok(new { token }));
                }
                message = "Something went wrong. Please try again.";
                return(BadRequest(new { message }));
            }
            message = "Something went wrong. Please try again.";
            return(BadRequest(new { message }));
        }
Exemplo n.º 4
0
        public void GetByID_Flow_Notification()
        {
            var id            = 1;
            var notifications = new List <Notification> {
                new Notification {
                    Id = id
                }
            }.AsQueryable();

            var mockSet = MockHelper.MockDbSet(notifications);

            var result = NotificationExtension.GetById(mockSet.Object, id);

            Assert.AreEqual(id, result.Id);
        }
Exemplo n.º 5
0
        private void ConsumeMessages()
        {
            while (consumingMessages && doListenForMessagesInTask)
            {
                string msg = ConsumeMessageFromQueue();

                if (msg != null)
                {
                    BaseNotification notification = NotificationExtension.Deserialize(msg);

                    eventLogRepository.WriteInformationLog("Processing notification from queue. Notification: {QueueMessage}".InjectSingleValue("QueueMessage", msg));

                    var handler = notificationHandlerFactory(notification.NotificationType); // autofac will get the right handler
                    handler.ProcessNotification(notification);

                    // Always clear the context at the end of a transaction
                    _uow.ClearContext();
                }
                else
                {
                    consumingMessages = false;
                }
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            using (NotificationContext dbContext = new NotificationContext()) {
                dbContext.Configuration.AutoDetectChangesEnabled = false;

                GenericQueueRepositoryImpl rmq = new GenericQueueRepositoryImpl();

                string rmqMessage = rmq.ConsumeFromQueue(Configuration.RabbitMQNotificationServer,
                                                         Configuration.RabbitMQNotificationUserNameConsumer,
                                                         Configuration.RabbitMQNotificationUserPasswordConsumer,
                                                         Configuration.RabbitMQVHostNotification,
                                                         Configuration.RabbitMQQueueNotification);

                while (rmqMessage != null)
                {
                    BaseNotification rmqNotification = NotificationExtension.Deserialize(rmqMessage);

                    if (rmqNotification.NotificationType == NotificationType.Eta)
                    {
                        KeithLink.Svc.Core.Models.Messaging.Queue.EtaNotification eta = (KeithLink.Svc.Core.Models.Messaging.Queue.EtaNotification)rmqNotification;
                        Console.WriteLine(string.Format("Processing {0} orders", eta.Orders.Count));

                        foreach (OrderEta order in eta.Orders)
                        {
                            Models.EtaNotification notice = new Models.EtaNotification();

                            if (order.ActualTime != null && order.ActualTime.Length > 0)
                            {
                                notice.ActualTime = DateTime.Parse(order.ActualTime);
                            }
                            notice.Branch = order.BranchId;
                            if (order.EstimatedTime != null && order.EstimatedTime.Length > 0)
                            {
                                notice.EstimatedTime = DateTime.Parse(order.EstimatedTime);
                            }
                            notice.OrderId = order.OrderId;
                            if (order.OutOfSequence.HasValue)
                            {
                                notice.OutOfSequence = order.OutOfSequence.Value;
                            }
                            notice.RouteId = order.RouteId;
                            if (order.ScheduledTime != null && order.ScheduledTime.Length > 0)
                            {
                                notice.ScheduledTime = DateTime.Parse(order.ScheduledTime);
                            }
                            notice.StopNumber = order.StopNumber;

                            dbContext.Notifications.Add(notice);
                            dbContext.SaveChanges();
                        } // end foreach
                    }     // end if

                    rmqMessage = rmq.ConsumeFromQueue(Configuration.RabbitMQNotificationServer,
                                                      Configuration.RabbitMQNotificationUserNameConsumer,
                                                      Configuration.RabbitMQNotificationUserPasswordConsumer,
                                                      Configuration.RabbitMQVHostNotification,
                                                      Configuration.RabbitMQQueueNotification);
                } // wend

                if (dbContext.Database.Connection.State == System.Data.ConnectionState.Open)
                {
                    dbContext.Database.Connection.Close();
                }
            } //end using
        }
Exemplo n.º 7
0
 public IActionResult ResendAccountCreatedEmailToPsychologist(int psychologistId)
 {
     NotificationExtension.ResentAddPsychologistNotification(psychologistId);
     return(Ok());
 }