예제 #1
0
        public static void NotifyStartUp(IServiceProvider serviceProvider)
        {
            if (notifyStarted)
            {
                return;
            }
            lock (syncRoot)
            {
                if (notifyStarted)
                {
                    return;
                }

                var configuration  = serviceProvider.GetService <IConfiguration>();
                var cacheNotify    = serviceProvider.GetService <ICacheNotify <NotifyMessage> >();
                var cacheInvoke    = serviceProvider.GetService <ICacheNotify <NotifyInvoke> >();
                var options        = serviceProvider.GetService <IOptionsMonitor <ILog> >();
                var telegramHelper = serviceProvider.GetService <TelegramHelper>();

                NotifyContext = new NotifyContext(serviceProvider);

                INotifySender jabberSender   = new NotifyServiceSender(cacheNotify, cacheInvoke);
                INotifySender emailSender    = new NotifyServiceSender(cacheNotify, cacheInvoke);
                INotifySender telegramSender = new TelegramSender(options, telegramHelper);

                var postman = configuration["core:notify:postman"];

                if ("ases".Equals(postman, StringComparison.InvariantCultureIgnoreCase) || "smtp".Equals(postman, StringComparison.InvariantCultureIgnoreCase))
                {
                    jabberSender = new JabberSender(serviceProvider);

                    var properties = new Dictionary <string, string>
                    {
                        ["useCoreSettings"] = "true"
                    };
                    if ("ases".Equals(postman, StringComparison.InvariantCultureIgnoreCase))
                    {
                        emailSender                  = new AWSSender(serviceProvider, options);
                        properties["accessKey"]      = configuration["ses:accessKey"];
                        properties["secretKey"]      = configuration["ses:secretKey"];
                        properties["refreshTimeout"] = configuration["ses:refreshTimeout"];
                    }
                    else
                    {
                        emailSender = new SmtpSender(serviceProvider, options);
                    }
                    emailSender.Init(properties);
                }

                NotifyContext.NotifyService.RegisterSender(Constants.NotifyEMailSenderSysName, new EmailSenderSink(emailSender, serviceProvider, options));
                NotifyContext.NotifyService.RegisterSender(Constants.NotifyMessengerSenderSysName, new JabberSenderSink(jabberSender, serviceProvider));
                NotifyContext.NotifyService.RegisterSender(Constants.NotifyTelegramSenderSysName, new TelegramSenderSink(telegramSender, serviceProvider));

                NotifyContext.NotifyEngine.BeforeTransferRequest += NotifyEngine_BeforeTransferRequest;
                NotifyContext.NotifyEngine.AfterTransferRequest  += NotifyEngine_AfterTransferRequest;
                notifyStarted = true;
            }
        }
예제 #2
0
        private static void NotifyStartUp()
        {
            if (notifyStarted)
            {
                return;
            }
            lock (syncRoot)
            {
                if (notifyStarted)
                {
                    return;
                }

                notifyContext = new NotifyContext();

                INotifySender jabberSender = new NotifyServiceSender();
                INotifySender emailSender  = new NotifyServiceSender();

                var postman = ConfigurationManager.AppSettings["core.notify.postman"];

                if ("ases".Equals(postman, StringComparison.InvariantCultureIgnoreCase) || "smtp".Equals(postman, StringComparison.InvariantCultureIgnoreCase))
                {
                    jabberSender = new JabberSender();

                    var properties = new Dictionary <string, string>();
                    var s          = CoreContext.Configuration.SmtpSettings;
                    properties["host"]      = s.Host;
                    properties["port"]      = s.Port.GetValueOrDefault(25).ToString();
                    properties["enableSsl"] = s.EnableSSL.ToString();
                    properties["userName"]  = s.CredentialsUserName;
                    properties["password"]  = s.CredentialsUserPassword;
                    properties["domain"]    = s.CredentialsDomain;
                    if ("ases".Equals(postman, StringComparison.InvariantCultureIgnoreCase))
                    {
                        emailSender                  = new AWSSender();
                        properties["accessKey"]      = ConfigurationManager.AppSettings["ses.accessKey"];
                        properties["secretKey"]      = ConfigurationManager.AppSettings["ses.secretKey"];
                        properties["refreshTimeout"] = ConfigurationManager.AppSettings["ses.refreshTimeout"];
                    }
                    else
                    {
                        emailSender = new SmtpSender();
                    }
                    emailSender.Init(properties);
                }

                notifyContext.NotifyService.RegisterSender(Constants.NotifyEMailSenderSysName, new EmailSenderSink(emailSender));
                notifyContext.NotifyService.RegisterSender(Constants.NotifyMessengerSenderSysName, new JabberSenderSink(jabberSender));

                notifyContext.NotifyEngine.Scheduling             = ConfigurationManager.AppSettings["core.notify.scheduling"] != "false";
                notifyContext.NotifyEngine.BeforeTransferRequest += NotifyEngine_BeforeTransferRequest;
                notifyContext.NotifyEngine.AfterTransferRequest  += NotifyEngine_AfterTransferRequest;
                notifyStarted = true;
            }
        }
        private static void NotifyStartUp()
        {
            if (notifyStarted)
            {
                return;
            }
            lock (syncRoot)
            {
                if (notifyStarted)
                {
                    return;
                }

                notifyContext = new NotifyContext();

                INotifySender jabberSender = new NotifyServiceSender();
                INotifySender emailSender  = new NotifyServiceSender();

                var postman = ConfigurationManager.AppSettings["core:notify:postman"];

                if ("ases".Equals(postman, StringComparison.InvariantCultureIgnoreCase) || "smtp".Equals(postman, StringComparison.InvariantCultureIgnoreCase))
                {
                    jabberSender = new JabberSender();

                    var properties = new Dictionary <string, string>
                    {
                        ["useCoreSettings"] = "true"
                    };
                    if ("ases".Equals(postman, StringComparison.InvariantCultureIgnoreCase))
                    {
                        emailSender                  = new AWSSender();
                        properties["accessKey"]      = ConfigurationManager.AppSettings["ses:accessKey"];
                        properties["secretKey"]      = ConfigurationManager.AppSettings["ses:secretKey"];
                        properties["refreshTimeout"] = ConfigurationManager.AppSettings["ses:refreshTimeout"];
                    }
                    else
                    {
                        emailSender = new SmtpSender();
                    }
                    emailSender.Init(properties);
                }

                notifyContext.NotifyService.RegisterSender(Constants.NotifyEMailSenderSysName, new EmailSenderSink(emailSender));
                notifyContext.NotifyService.RegisterSender(Constants.NotifyMessengerSenderSysName, new JabberSenderSink(jabberSender));

                notifyContext.NotifyEngine.BeforeTransferRequest += NotifyEngine_BeforeTransferRequest;
                notifyContext.NotifyEngine.AfterTransferRequest  += NotifyEngine_AfterTransferRequest;
                notifyStarted = true;
            }
        }