Esempio n. 1
0
        /// <summary>
        /// Trigger call to notifify the monitor of a change
        /// </summary>
        /// <param name="value">
        /// The model to be used by the monitor
        /// </param>
        public override void OnNext(IShipment value)
        {
            if (!Messages.Any())
            {
                return;
            }

            var formatter = PatternReplaceFormatter.GetPatternReplaceFormatter();

            // Add the replaceable patterns from the invoice
            formatter.AddOrUpdateReplaceablePattern(value.ReplaceablePatterns());

            foreach (var message in Messages)
            {
                if (message.SendToCustomer)
                {
                    // add the additional contacts to the recipients list
                    if (!message.Recipients.EndsWith(";"))
                    {
                        message.Recipients += ";";
                    }

                    if (message.Recipients[0] == ';')
                    {
                        message.Recipients = message.Recipients.TrimStart(';');
                    }

                    message.Recipients = string.Format("{0}{1}", message.Recipients, string.Join(";", value.Email));
                }

                // send the message
                NotificationContext.Send(message, formatter);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// contacts are not used
        /// </summary>
        /// <param name="value"></param>
        /// <param name="contacts"></param>
        public override void OnNext(IProduct value)
        {
            if (!Messages.Any())
            {
                return;
            }

            var patterns = new Dictionary <string, IReplaceablePattern>()
            {
                { "Name", new ReplaceablePattern("Name", "{{Name}}", value.Name.ToString()) },
                { "TrackInventory", new ReplaceablePattern("TrackInventory", "{{TrackInventory}}", value.TrackInventory.ToString()) },
                { "Barcode", new ReplaceablePattern("Barcode", "{{Barcode}}", value.Barcode) },
                { "Sku", new ReplaceablePattern("Sku", "{{Sku}}", value.Sku) },
                { "Height", new ReplaceablePattern("Height", "{{Height}}", value.Height.ToString()) },
                { "Length", new ReplaceablePattern("Length", "{{Length}}", value.Length.ToString()) },
                { "Width", new ReplaceablePattern("Width", "{{Width}}", value.Width.ToString()) },
                { "Weight", new ReplaceablePattern("Weight", "{{Weight}}", value.Weight.ToString()) }
            };

            var formatter = new PatternReplaceFormatter(patterns);

            foreach (var message in Messages.ToArray())
            {
                // send the message
                NotificationContext.Send(message, formatter);
            }
        }
        public void Can_Get_A_PatternReplaceFormatter_Populated_With_Configuration_Patterns()
        {
            //// Arrange

            //// Act
            var formatter = (PatternReplaceFormatter)PatternReplaceFormatter.GetPatternReplaceFormatter();

            //// Assert
            Assert.IsTrue(formatter.Patterns.Any());
        }
        /// <summary>
        /// Trigger call to notify the monitor of a change
        /// </summary>
        /// <param name="value">
        /// The model to be used by the monitor
        /// </param>
        public override void OnNext(IPaymentResultMonitorModel value)
        {
            if (!value.PaymentSuccess)
            {
                return;
            }

            if (!Messages.Any())
            {
                return;
            }

            var formatter = PatternReplaceFormatter.GetPatternReplaceFormatter();

            // Add the replaceable patterns from the invoice
            formatter.AddOrUpdateReplaceablePattern(value.Invoice.ReplaceablePatterns(value.CurrencySymbol));

            if (value.Payment != null)
            {
                formatter.AddOrUpdateReplaceablePattern(value.Payment.ReplaceablePatterns(value.CurrencySymbol));
            }

            if (value.Shipment != null)
            {
                formatter.AddOrUpdateReplaceablePattern(value.Shipment.ReplaceablePatterns(value.CurrencySymbol));
            }

            if (value.ShipMethod != null)
            {
                formatter.AddOrUpdateReplaceablePattern(value.ShipMethod.ReplaceablePatterns());
            }

            foreach (var message in Messages)
            {
                if (value.Contacts.Any() && message.SendToCustomer)
                {
                    // add the additional contacts to the recipients list
                    if (!message.Recipients.EndsWith(";"))
                    {
                        message.Recipients += ";";
                    }

                    if (message.Recipients[0] == ';')
                    {
                        message.Recipients = message.Recipients.TrimStart(';');
                    }

                    message.Recipients = string.Format("{0}{1}", message.Recipients, string.Join(";", value.Contacts));
                }

                // send the message
                NotificationContext.Send(message, formatter);
            }
        }
        public ActionResult SendMessage(ContactFormModel model)
        {
            if (!ModelState.IsValid)
            {
                return(CurrentUmbracoPage());
            }

            var umbraco = new UmbracoHelper(UmbracoContext);

            var content = umbraco.TypedContent(model.ContentId);

            //// Get the SMTP notification method from Merchello.  If it has not been configured, return
            if (SmtpProvider != null)
            {
                var method = SmtpProvider.GetAllNotificationGatewayMethods().FirstOrDefault();

                if (method == null)
                {
                    ViewBag.Mode         = ContactFormModel.DisplayMode.Error;
                    ViewBag.ErrorMessage = MvcHtmlString.Create("The SMTP provider does not have a method configured.");

                    return(CurrentUmbracoPage());
                }

                var patterns = new Dictionary <string, IReplaceablePattern>()
                {
                    { "name", new ReplaceablePattern("name", "{{name}}", model.FromName) },
                    { "message", new ReplaceablePattern("message", "{{message}}", model.Message) },
                    { "email", new ReplaceablePattern("email", "{{email}}", model.FromEmail) },
                    { "phone", new ReplaceablePattern("phone", "{{phone}}", model.Phone) }
                };

                var formatter = new PatternReplaceFormatter(patterns);

                var message = new NotificationMessage(method.NotificationMethod.Key, content.GetSafeString("subject"), model.FromEmail)
                {
                    BodyText   = content.GetSafeHtmlString("emailTemplate").ToHtmlString(),
                    Recipients = content.GetSafeString("to")
                };

                MerchelloContext.Current.Gateways.Notification.Send(message, formatter);

                ViewBag.ConfirmationMessage = content.GetSafeHtmlString("confirmationMessage").ToHtmlString();
                ViewBag.ViewMode            = ContactFormModel.DisplayMode.ConfirmationMessage;
            }
            else
            {
                ViewBag.ViewMode     = ContactFormModel.DisplayMode.Error;
                ViewBag.ErrorMessage = MvcHtmlString.Create("The SMTP provider has not been configured.");
            }

            return(CurrentUmbracoPage());
        }
        public void Can_Format_A_Message()
        {
            //// Arrange
            var formatter = PatternReplaceFormatter.GetPatternReplaceFormatter();

            formatter.AddOrUpdateReplaceablePattern(_invoice.ReplaceablePatterns());

            //// Act

            var text = formatter.Format(_message);

            Console.Write(text);

            //// Assert
            Assert.IsTrue(text.Contains("Mindfly"));
        }
        public void Can_Format()
        {
            IDictionary <string, IPatternReplacement> patterns = new Dictionary <string, IPatternReplacement>
            {
                { "{{pattern1}}", new PatternReplacement("Test 1") },
                { "{{pattern2}}", new PatternReplacement("Test 2") },
                { "{{pattern3}}", new PatternReplacement("Test 3") }
            };

            PatternReplaceFormatter formatter = new PatternReplaceFormatter(
                patterns: patterns);

            Assert.That("Test 1", Is.EqualTo(formatter.Format(input: "{{pattern1}}")));
            Assert.That("Test 2 Test 3", Is.EqualTo(formatter.Format(input: "{{pattern2}} {{pattern3}}")));
            Assert.That(string.Empty, Is.EqualTo(formatter.Format(input: string.Empty)));
        }
        public void Can_Update_PatternReplaceFormatter_Default_Data_With_Invoice_Data()
        {
            //// Arrange
            var formatter = (PatternReplaceFormatter)PatternReplaceFormatter.GetPatternReplaceFormatter();

            //// Act
            formatter.AddOrUpdateReplaceablePattern(_invoice.ReplaceablePatterns());

            //// Assert
            Assert.AreEqual(formatter.Patterns["InvoiceNumber"].Replacement, "123", "InvoiceNumber does not match");
            Assert.AreEqual(formatter.Patterns["BillToName"].Replacement, "Mindfly", "BillToname does not match");
            Assert.AreEqual(formatter.Patterns["BillToAddress1"].Replacement, "114 W. Magnolia St.", "BillToAddress1 does not match");
            Assert.AreEqual(formatter.Patterns["BillToAddress2"].Replacement, "Suite 300", "BillToAddress2 does not match");
            Assert.AreEqual(formatter.Patterns["BillToLocality"].Replacement, "Bellingham", "BillToLocality does not match");
            Assert.AreEqual(formatter.Patterns["BillToRegion"].Replacement, "WA", "BillToRegion does not match");
            Assert.AreEqual(formatter.Patterns["BillToPostalCode"].Replacement, "98225", "BillToPostalCode does not match");
            Assert.AreEqual(formatter.Patterns["BillToEmail"].Replacement, "*****@*****.**", "BillToEmail does not match");
            Assert.AreEqual(formatter.Patterns["BillToPhone"].Replacement, "555-555-5555", "BillToPhone does not match");
        }
        public void Can_Format_Array()
        {
            IDictionary <string, IPatternReplacement> patterns = new Dictionary <string, IPatternReplacement>
            {
                { "{{pattern1}}", new PatternReplacement("Test 1") },
                { "{{pattern2}}", new PatternReplacement("Test 2") },
                { "{{pattern3}}", new PatternReplacement("Test 3") }
            };

            PatternReplaceFormatter formatter = new PatternReplaceFormatter(
                patterns: patterns);

            string[] nullableArray = null;

            Assert.That(new string[] { "Test 1" }, Is.EqualTo(formatter.Format(input: new string[] { "{{pattern1}}" })));
            Assert.That(new string[] { "Test 2", "Test 3" }, Is.EqualTo(formatter.Format(input: new string[] { "{{pattern2}}", "{{pattern3}}" })));
            Assert.That(new string[0], Is.EqualTo(formatter.Format(input: new string[0])));
            Assert.That(null, Is.EqualTo(formatter.Format(input: nullableArray)));
        }