コード例 #1
0
        public ActionResult TestSettings(TestSmsSettings testSettings)
        {
            ILogger logger = null;

            try {
                var fakeLogger          = new FakeLogger();
                var smsChannelComponent = _smsChannel as Component;
                if (smsChannelComponent != null)
                {
                    logger = smsChannelComponent.Logger;
                    smsChannelComponent.Logger = fakeLogger;
                }

                // Temporarily update settings so that the test will actually use the specified host, port, etc.
                var smsSettings = _orchardServices.WorkContext.CurrentSite.As <SmsSettingsPart>();

                smsSettings.AccountSid   = testSettings.AccountSid;
                smsSettings.AuthToken    = testSettings.AuthToken;
                smsSettings.TwilioNumber = testSettings.From;

                if (!smsSettings.IsValid())
                {
                    fakeLogger.Error("Invalid settings.");
                }
                else
                {
                    _smsChannel.Process(new Dictionary <string, object> {
                        { "Recipients", testSettings.To },
                        { "Body", testSettings.Body }
                    });
                }

                if (!String.IsNullOrEmpty(fakeLogger.Message))
                {
                    return(Json(new { error = fakeLogger.Message }));
                }

                return(Json(new { status = T("Message sent.").Text }));
            }
            catch (Exception e) {
                return(Json(new { error = e.Message }));
            }
            finally {
                var smsChannelComponent = _smsChannel as Component;
                if (smsChannelComponent != null)
                {
                    smsChannelComponent.Logger = logger;
                }

                // Undo the temporarily changed smtp settings.
                _orchardServices.TransactionManager.Cancel();
            }
        }
コード例 #2
0
        public ActionResult TestSettings(TestSmsSettings testSettings)
        {
            ILogger logger = null;
            try {
                var fakeLogger = new FakeLogger();
                var smsChannelComponent = _smsChannel as Component;
                if (smsChannelComponent != null) {
                    logger = smsChannelComponent.Logger;
                    smsChannelComponent.Logger = fakeLogger;
                }

                // Temporarily update settings so that the test will actually use the specified host, port, etc.
                var smsSettings = _orchardServices.WorkContext.CurrentSite.As<SmsSettingsPart>();

                smsSettings.AccountSid = testSettings.AccountSid;
                smsSettings.AuthToken = testSettings.AuthToken;
                smsSettings.TwilioNumber = testSettings.From;

                if (!smsSettings.IsValid()) {
                    fakeLogger.Error("Invalid settings.");
                }
                else {
                    _smsChannel.Process(new Dictionary<string, object> {
                        {"Recipients", testSettings.To},
                        {"Body", testSettings.Body}
                    });
                }

                if (!String.IsNullOrEmpty(fakeLogger.Message)) {
                    return Json(new { error = fakeLogger.Message });
                }

                return Json(new {status = T("Message sent.").Text});
            }
            catch (Exception e) {
                return Json(new {error = e.Message});
            }
            finally {
                var smsChannelComponent = _smsChannel as Component;
                if (smsChannelComponent != null) {
                    smsChannelComponent.Logger = logger;
                }

                // Undo the temporarily changed smtp settings.
                _orchardServices.TransactionManager.Cancel();
            }
        }