public async Task <ActionResult <NotificationSendResult> > SendNotification([FromBody] Notification notificationRequest)
        {
            var notification = await _notificationSearchService.GetNotificationAsync(notificationRequest.Type, notificationRequest.TenantIdentity);

            var result = await _notificationSender.SendNotificationAsync(notification.PopulateFromOther(notificationRequest));

            return(Ok(result));
        }
        protected virtual async Task TryToSendNotificationsAsync(GenericChangedEntry <Subscription> changedEntry)
        {
            //Collection of order notifications
            var notifications = new List <SubscriptionEmailNotificationBase>();

            if (IsSubscriptionCanceled(changedEntry))
            {
                //Resolve SubscriptionCanceledEmailNotification with template defined on store level
                var notification = await _notificationSearchService.GetNotificationAsync <SubscriptionCanceledEmailNotification>(new TenantIdentity(changedEntry.NewEntry.StoreId, nameof(Store)));

                if (notification != null)
                {
                    notifications.Add(notification);
                }
            }

            if (changedEntry.EntryState == EntryState.Added)
            {
                //Resolve NewSubscriptionEmailNotification with template defined on store level
                var notification = await _notificationSearchService.GetNotificationAsync <NewSubscriptionEmailNotification>(new TenantIdentity(changedEntry.NewEntry.StoreId, nameof(Store)));

                if (notification != null)
                {
                    notifications.Add(notification);
                }
            }

            foreach (var notification in notifications)
            {
                await SetNotificationParametersAsync(notification, changedEntry.NewEntry);

                await _notificationSender.SendNotificationAsync(notification, changedEntry.NewEntry.CustomerOrderPrototype.LanguageCode);
            }
        }
        public async Task Do()
        {
            var notification = await _notificationSearchService.GetNotificationAsync <ExtendedSampleEmailNotification>();

            if (notification != null)
            {
                notification.LanguageCode = "en-US";
                notification.SetFromToMembers("*****@*****.**", "*****@*****.**");
                await _notificationSender.SendNotificationAsync(notification);
            }
        }
예제 #4
0
        private async Task SendAsync(Check check, CheckNotification notification, CancellationToken token)
        {
            string text;

            if (notification.IsHealthy)
            {
                text = $"The check '{check.Name}' has been HEALTHY since {notification.CheckResult.Time.ToLocalTime()}.";
            }
            else
            {
                text = $"The check '{check.Name}' has been FAILING since {notification.CheckResult.Time.ToLocalTime()}.";
            }

            await _sender.SendNotificationAsync(text, token);
        }
예제 #5
0
        public async Task <IActionResult> GetInvoicePdf(string orderNumber)
        {
            var searchCriteria = AbstractTypeFactory <CustomerOrderSearchCriteria> .TryCreateInstance();

            searchCriteria.Number = orderNumber;
            searchCriteria.Take   = 1;

            var orders = await _searchService.SearchCustomerOrdersAsync(searchCriteria);

            var order = orders.Results.FirstOrDefault();

            if (order == null)
            {
                throw new InvalidOperationException($"Cannot find order with number {orderNumber}");
            }

            var notification = new InvoiceEmailNotification {
                CustomerOrder = order
            };
            await _notificationSender.SendNotificationAsync(notification, order.LanguageCode);

            var message = AbstractTypeFactory <NotificationMessage> .TryCreateInstance($"{notification.Kind}Message");

            message.LanguageCode = order.LanguageCode;
            var emailNotificationMessage = (EmailNotificationMessage)notification.ToMessage(message, _notificationTemplateRenderer);

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = { ColorMode = ColorMode.Color, Orientation = Orientation.Landscape, PaperSize = PaperKind.A4Plus },
                Objects        = { new ObjectSettings {
                                       PagesCount = true, HtmlContent = emailNotificationMessage.Body
                                   } }
            };
            var    converter = new SynchronizedConverter(new PdfTools());
            var    byteArray = converter.Convert(pdf);
            Stream stream    = new MemoryStream(byteArray);

            return(new FileStreamResult(stream, "application/pdf"));
        }
        public void RecordReward(RecordRewardRequest request)
        {
            logger.Info(
                MyOperation.RecordReward,
                OperationStatus.Started,
                new LogInfo(MyLogInfoKey.User, request.Username),
                new LogInfo(MyLogInfoKey.GiveawaysProvider, request.GiveawaysProvider),
                new LogInfo(MyLogInfoKey.GiveawayId, request.GiveawayId));

            ValidateRequest(request);

            Reward reward = GetRewardObjectFromRequest(request);

            reward.SteamApp = storefrontDataRetriever.GetAppData(reward.SteamApp.Id).ToServiceModel();

            if (WasRewardAlreadyRecorded(reward))
            {
                logger.Warn(
                    MyOperation.RecordReward,
                    OperationStatus.Failure,
                    "Reward already recorded",
                    new LogInfo(MyLogInfoKey.User, request.Username),
                    new LogInfo(MyLogInfoKey.GiveawaysProvider, request.GiveawaysProvider),
                    new LogInfo(MyLogInfoKey.GiveawayId, request.GiveawayId));

                return;
            }

            StoreReward(reward);
            notificationSender.SendNotificationAsync(reward);

            logger.Info(
                MyOperation.RecordReward,
                OperationStatus.Success,
                new LogInfo(MyLogInfoKey.User, request.Username),
                new LogInfo(MyLogInfoKey.GiveawaysProvider, request.GiveawaysProvider),
                new LogInfo(MyLogInfoKey.GiveawayId, request.GiveawayId));
        }
        public async Task <IActionResult> SendDynamicNotificationAnStoreEmail(SendDynamicNotificationRequest request)
        {
            var store = await _storeService.GetByIdAsync(request.StoreId);

            if (store == null)
            {
                throw new InvalidOperationException(string.Concat("Store not found. StoreId: ", request.StoreId));
            }

            if (string.IsNullOrEmpty(store.Email) && string.IsNullOrEmpty(store.AdminEmail))
            {
                throw new InvalidOperationException(string.Concat("Both store email and admin email are empty. StoreId: ", request.StoreId));
            }

            var notification = new StoreDynamicEmailNotification()
            {
                FormType = request.Type,
                Fields   = request.Fields
            };
            await _notificationSender.SendNotificationAsync(notification, request.Language);

            return(Ok());
        }
예제 #8
0
        public async Task <ActionResult <NotificationSendResult> > SendNotification([FromBody] Notification notification, string language)
        {
            var result = await _notificationSender.SendNotificationAsync(notification, language);

            return(Ok(result));
        }
        protected virtual async Task TryToSendOrderNotificationsAsync(GenericChangedEntry <CustomerOrder> changedEntry)
        {
            // Collection of order notifications
            var notifications = new List <OrderEmailNotificationBase>();

            if (IsOrderCanceled(changedEntry))
            {
                var notification = await _notificationSearchService.GetNotificationAsync <CancelOrderEmailNotification>(new TenantIdentity(changedEntry.NewEntry.StoreId, nameof(Store)));

                if (notification != null)
                {
                    notification.CustomerOrder = changedEntry.NewEntry;
                    notifications.Add(notification);
                }
            }

            if (changedEntry.EntryState == EntryState.Added && !changedEntry.NewEntry.IsPrototype)
            {
                var notification = await _notificationSearchService.GetNotificationAsync <OrderCreateEmailNotification>(new TenantIdentity(changedEntry.NewEntry.StoreId, nameof(Store)));

                if (notification != null)
                {
                    notification.CustomerOrder = changedEntry.NewEntry;
                    notifications.Add(notification);
                }
            }

            if (HasNewStatus(changedEntry))
            {
                var notification = await _notificationSearchService.GetNotificationAsync <NewOrderStatusEmailNotification>(new TenantIdentity(changedEntry.NewEntry.StoreId, nameof(Store)));

                if (notification != null)
                {
                    notification.CustomerOrder = changedEntry.NewEntry;
                    notification.NewStatus     = changedEntry.NewEntry.Status;
                    notification.OldStatus     = changedEntry.OldEntry.Status;
                    notifications.Add(notification);
                }
            }

            if (IsOrderPaid(changedEntry))
            {
                var notification = await _notificationSearchService.GetNotificationAsync <OrderPaidEmailNotification>(new TenantIdentity(changedEntry.NewEntry.StoreId, nameof(Store)));

                if (notification != null)
                {
                    notification.CustomerOrder = changedEntry.NewEntry;
                    notifications.Add(notification);
                }
            }

            if (IsOrderSent(changedEntry))
            {
                var notification = await _notificationSearchService.GetNotificationAsync <OrderSentEmailNotification>(new TenantIdentity(changedEntry.NewEntry.StoreId, nameof(Store)));

                if (notification != null)
                {
                    notification.CustomerOrder = changedEntry.NewEntry;
                    notifications.Add(notification);
                }
            }

            foreach (var notification in notifications)
            {
                notification.CustomerOrder = changedEntry.NewEntry;
                await SetNotificationParametersAsync(notification, changedEntry);

                await _notificationSender.SendNotificationAsync(notification, changedEntry.NewEntry.LanguageCode);
            }
        }