public async Task Send(Notification notification,
                               CancellationToken cancellationToken = default)
        {
            await _store.Add(notification, cancellationToken);

            await _sender.Send(notification, cancellationToken);
        }
        public async Task <ResponseMessage> PushMessage(RequestCommand requestCommand)
        {
            var formattedValue = _formatter.Format(new InValue()
            {
                ProfileId        = requestCommand.ProfileId,
                Message          = requestCommand.Message,
                Hyperlink        = requestCommand.Hyperlink,
                Read             = requestCommand.Read,
                NotificationType = requestCommand.NotificationType,
                Parameters       = requestCommand.Parameters,
                User             = requestCommand.UserName,
            });

            if (requestCommand.NotificationType.ToLower().Contains("pub"))
            {
                await _notificationSender.Send("PublicNotificationPush", formattedValue.FormattedValue);
            }
            else
            {
                await _notificationSender.Send("PrivateNotificationPush", formattedValue.FormattedValue, requestCommand.UserName);
            }

            var recordBuilt = BuildRecord(requestCommand);

            await _repository.Insert(recordBuilt);

            return(BuildResponseMessage(recordBuilt));
        }
示例#3
0
        private void NotifyUserOfDelinquencyWithoutReconnection()
        {
            _notificationSender.Send(
                Translation.Get("Notifications_Delinquency_Title"),
                Translation.Get("Notifications_Delinquency_Description"));

            _delinquencyPopupViewModel.SetNoReconnectionData();
            _popups.Show <DelinquencyPopupViewModel>();
        }
示例#4
0
        private VpnReconnectionSteps CalculateSimilarOnAutoProtocolReconnectionStep()
        {
            if (_appSettings.DoNotShowEnableSmartProtocolDialog || _appSettings.GetProtocol() == VpnProtocol.Smart)
            {
                _logger.Info(_appSettings.GetProtocol() == VpnProtocol.Smart
                    ? "Smart protocol is already enabled. Reconnection will fast forward to quick connect."
                    : "Not asking again if the user wants to enable Smart Protocol. Reconnection will fast forward to quick connect.");
                return(VpnReconnectionSteps.QuickConnect);
            }

            if (_appSettings.IsSmartReconnectNotificationsEnabled())
            {
                _notificationSender.Send(
                    Translation.Get("Notifications_EnableSmartProtocol_ttl"),
                    Translation.Get("Notifications_EnableSmartProtocol_msg"));
            }

            bool?isToChangeProtocolToAuto = _modals.Show <EnableSmartProtocolModalViewModel>();

            if (isToChangeProtocolToAuto.HasValue && isToChangeProtocolToAuto.Value)
            {
                _appSettings.OvpnProtocol = "auto";
                return(VpnReconnectionSteps.SimilarOnSmartProtocol);
            }

            _logger.Info("User refused to enable Smart Protocol. Reconnection will fast forward to quick connect.");
            return(VpnReconnectionSteps.QuickConnect);
        }
        public void ShouldCreateAndSendMailOverSender()
        {
            var recipients = new[]
            {
                "mail1",
                "mail2"
            };

            const string title = "mail title";

            const string message = "mail message";

            _target.Send(new Notification
            {
                Targets = recipients,
                Message = message,
                Title   = title
            });

            _mailProvider.Verify(_ => _.BeginSend(), Times.Once);

            _mailSender.Verify(_ => _.Send(It.Is <Email>(m =>
                                                         m.Body.Equals(message) &&
                                                         m.Subject.Equals(title) &&
                                                         MathArrays(m.To, recipients))));
        }
示例#6
0
        public async Task <IActionResult> Register(RegisterModel registerModel)
        {
            if (ModelState.IsValid)
            {
                var users = await _context.GetCollection();

                User user = users.FirstOrDefault(u => u.Email == registerModel.Email);
                if (user == null)
                {
                    var randomWord = GenerateRandomWord();
                    var secretWord = Configuration.GetSection("PasswordStrings").GetSection("EndWord").Value;
                    var password   = _scryptEncoder.Encode(registerModel.Password + randomWord + secretWord);
                    user = new User()
                    {
                        Name       = registerModel.Name,
                        Password   = password,
                        Email      = registerModel.Email,
                        RandomWord = randomWord
                    };
                    _notificationSender.Send("Welcome to our system!", user.Email);
                    await _context.Create(user);
                    await Authenticate(user.Email);

                    return(RedirectToAction("Index", "Main"));
                }
                else
                {
                    ModelState.AddModelError("", "Данная почта занята");
                }
                // await _context.Remove(user.Id);
            }
            return(View("Authorization"));
        }
示例#7
0
        private async Task SendDeliveriesOfOneType(List <NotificationDelivery> deliveries)
        {
            if (deliveries.Count == 0)
            {
                return;
            }

            if (deliveries.Count == 1)
            {
                var delivery = deliveries[0];
                var course   = await courseManager.FindCourseAsync(delivery.Notification.CourseId);

                if (course == null)
                {
                    log.Warn($"Can't find course {delivery.Notification.CourseId}");
                    await notificationsRepo.MarkDeliveryAsFailed(delivery);

                    return;
                }

                try
                {
                    await notificationSender.Send(delivery);

                    await notificationsRepo.MarkDeliveryAsSent(delivery.Id);
                }
                catch (Exception e)
                {
                    log.Warn(e, $"Can\'t send notification {delivery.NotificationId} to {delivery.NotificationTransport}. Will try later");
                    await notificationsRepo.MarkDeliveryAsFailed(delivery);
                }
            }
            else
            {
                try
                {
                    await notificationSender.Send(deliveries);

                    await notificationsRepo.MarkDeliveriesAsSent(deliveries.Select(d => d.Id).ToList());
                }
                catch (Exception e)
                {
                    log.Warn(e, $"Can\'t send multiple notifications [{string.Join(", ", deliveries.Select(d => d.NotificationId))}] to {deliveries[0].NotificationTransport}. Will try later");
                    await notificationsRepo.MarkDeliveriesAsFailed(deliveries);
                }
            }
        }
 protected virtual void OnUserAdded(User user)
 {
     notificationSender.Send(new NotificationContainer()
     {
         Notifications = new[]
         {
             new Notification.Notification()
             {
                 Type   = NotificationType.AddUser,
                 Action = new AddUserActionNotification()
                 {
                     User = user
                 }
             }
         }
     });
 }
示例#9
0
        private void ShowMaximumDeviceLimitModalViewModel()
        {
            bool hasMaxTierPlan = HasMaxTierPlan();

            string notificationDescription = hasMaxTierPlan
                ? Translation.Get("Notifications_MaximumDeviceLimit_Disconnect_Description")
                : Translation.Get("Notifications_MaximumDeviceLimit_Upgrade_Description");

            _notificationSender.Send(Translation.Get("Notifications_MaximumDeviceLimit_Title"),
                                     notificationDescription);

            _maximumDeviceLimitModalViewModel.SetPlan(hasMaxTierPlan);
            _modals.Show <MaximumDeviceLimitModalViewModel>();
        }
示例#10
0
        public void AddCustomer(ICustomer customer)
        {
            bool isCustomerValid = _customerValidator.ValidateCustomer(customer);

            customer.Valid = isCustomerValid;
            if (customer.Valid)
            {
                _notificationSender.Send(customer);
            }

            else
            {
                Console.WriteLine("you are not a valid customer");
            }
        }
示例#11
0
 private void Sender(INotificationSender objSender, List <Reminder> toSendData)
 {
     foreach (var item in toSendData)
     {
         try
         {
             objSender.Send(item);
             MarkAsSent(item);
         }
         catch (Exception ex)
         {
             Log.Error(ex);
         }
     }
 }
示例#12
0
        private void ChangeTrackedHandler(ChangeTrackingArgs args)
        {
            string notificationMessage;

            if (Convert.ToInt32(args.NotificationSettings.NecessaryPrice) >= args.ProductChanges.Price && args.NotificationSettings.Sign == Sign.LessOrEqual ||
                Convert.ToInt32(args.NotificationSettings.NecessaryPrice) <= args.ProductChanges.Price && args.NotificationSettings.Sign == Sign.BiggerOrEqual)
            {
                notificationMessage = EmailNotificationSender.GenerateNotificationMessage(args.NotificationSettings.Availability,
                                                                                          args.NotificationSettings.PriceChanging, args.ProductChanges.Available, args.ProductChanges.Price, args.ProductName);
            }
            else
            {
                notificationMessage = EmailNotificationSender.GenerateNotificationMessage(args.NotificationSettings.Availability,
                                                                                          args.NotificationSettings.PriceChanging, args.ProductChanges.Available, null, args.ProductName);
            }

            _notificationSender.Send(notificationMessage, args.UserEmail);
        }
示例#13
0
        public async Task SendNotification(EmailTemplate template)
        {
            if (template.ViewModel != null)
            {
                template.ViewModel.BlogHost = "todo";
            }

            var body = await _viewRender.RenderToString(template.ViewName, template.ViewModel);

            var notification = new Notification
            {
                Body       = body,
                Recipients = template.Recipients,
                Subject    = template.Subject
            };

            await _sender.Send(notification);
        }
示例#14
0
        private async System.Threading.Tasks.Task SendEmailNotification(SubmissionTemplateType notificationType, string email, string name, IEnumerable <KeyValuePair <string, string> > tokens)
        {
            var template = (EmailTemplate)await templateProviderResolver.Resolve(NotificationChannelType.Email).Get(notificationType);

            var emailContent = (await transformator.Transform(new TransformationData
            {
                Template = template.Content,
                Tokens = new Dictionary <string, string>(tokens)
            })).Content;

            await notificationSender.Send(new EmailNotification
            {
                Subject = template.Subject,
                Content = emailContent,
                To      = new[] { new EmailAddress {
                                      Name = name, Address = email
                                  } }
            });
        }
示例#15
0
        public virtual void DoWork(CancellationToken cancellationToken)
        {
            try
            {
                object lockObject = new object();

                lock (lockObject)
                {
                    List <App> apps = _appService.GetAll();

                    foreach (var app in apps)
                    {
                        AppCallerResponse response = _appCallerService.CallApp(app.Url);

                        if (response.HasNotification)
                        {
                            Notification notification = _notificationService.GetNotification();

                            if (notification == null)
                            {
                                continue;
                            }

                            app.StatusId = (int)response.status;

                            _appService.Update(app);

                            _notificationSender.Send(notification.NotificationValue, "notificaiton subject", "status is " + response.status.ToString() + " responseCode is " + response.ResponseMessage);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logService.InsertLog(new Data.Entities.Log()
                {
                    Exception = ex.Message
                });
            }
        }