コード例 #1
0
ファイル: Global.asax.cs プロジェクト: BOONRewardsInc/rewards
        /// <summary>
        /// The register services.
        /// </summary>
        /// <param name="container">
        /// The container.
        /// </param>
        private void RegisterServices(IUnityContainer container)
        {
            EmailsBasePath = this.GetMandatorySetting(EmailsBasePathSetting);
            string storageAccount                 = this.GetMandatorySetting(StorageSetting);
            string emailJobsQueueName             = this.GetMandatorySetting(EmailJobsQueueNameSetting);
            string userDalConnectionString        = CloudConfigurationManager.GetSetting(UsersDalConnectionStringSetting);
            bool   isDebugSecurityProviderEnabled = bool.Parse(this.GetMandatorySetting(DebugSecurityProviderEnabled));
            Uri    bingOffersBaseUri              = new Uri(this.GetMandatorySetting(BingOffersBasePathUriSetting));

            // Read Email Confirmation Settings
            EntityConfirmationSettings entityConfirmationSettings = new EntityConfirmationSettings
            {
                BingOffersBaseUri = bingOffersBaseUri
            };

            var      emailJobsQueue         = new JobsQueue <EmailCargo>(storageAccount, emailJobsQueueName);
            var      priorityEmailJobsQueue = new PriorityEmailJobsQueue <PriorityEmailCargo>(storageAccount);
            UsersDal usersDal = new UsersDal(userDalConnectionString, queue: priorityEmailJobsQueue);

            container.RegisterInstance(entityConfirmationSettings);
            container.RegisterInstance <IJobsQueue <EmailCargo> >(emailJobsQueue);
            container.RegisterInstance <IPriorityEmailJobsQueue <PriorityEmailCargo> >(priorityEmailJobsQueue);
            container.RegisterInstance <IUsersDal>(usersDal);
            container.RegisterInstance <IEmailClient>(new EmailSendGridClient());

            // Authentication Modules
            // Add modules that perform authorization
            if (isDebugSecurityProviderEnabled)
            {
                Security.Add("user_debug", new UserDebugSecurityProvider(usersDal));
            }

            Security.Add("lomo", new LomoSecurityProvider(usersDal));
        }
コード例 #2
0
        /// <summary>
        /// Bootstraps the job agents
        /// </summary>
        /// <param name="idPrefix">
        /// The agent id Prefix.
        /// </param>
        /// <returns>
        /// List of instantiaged job processors
        /// </returns>
        public IEnumerable <IJobProcessor> Bootstrap(string idPrefix)
        {
            int jobProcessorCount = int.Parse(CloudConfigurationManager.GetSetting(JobsProcessorCountSetting));

            Log.Verbose("Mailing Manager. Bootstrap Start - agents number = {0}", jobProcessorCount);

            string storageSetting     = CloudConfigurationManager.GetSetting(StorageSetting);
            string emailJobsQueueName = CloudConfigurationManager.GetSetting(EmailJobsQueueNameSetting);

            //Initialize the jobs queue
            IJobsQueue <EmailCargo> emailJobsQueue = new JobsQueue <EmailCargo>(storageSetting, emailJobsQueueName);
            IPriorityEmailJobsQueue <PriorityEmailCargo> priorityEmailJobsQueue = new PriorityEmailJobsQueue <PriorityEmailCargo>();

            //Initialize the Merchant Email handler
            IEmailJobHandler merchantEmailJobHandler = new MerchantEmailJobHandler();

            merchantEmailJobHandler.Initialize();

            //Initialize the Deals Email handler
            IEmailJobHandler dealsEmailJobHandler = new DealsEmailJobHandler();

            dealsEmailJobHandler.Initialize();

            //Initialize the Remainder Email handler
            IEmailJobHandler remainderMailHandler = new RemainderEmailJobHandler();

            remainderMailHandler.Initialize();

            //Initialize the Campaign Email handler
            IEmailJobHandler campaignEmailJobHandler = new CampaignEmailJobHandler();

            campaignEmailJobHandler.Initialize();

            //Initialize the Priority Email handler
            IPriorityEmailJobHandler confirmationEmailHandler = new ConfirmationEmailJobHandler();

            confirmationEmailHandler.Initialize();

            //TODO: Having a different emailhandler and emailcargo for priority email is not right.
            //      The priority email handler and priority email cargo should be of type IEmailJobHandler and EmailCargo respectively
            //      This change has to be done once the users dal is decoupled out of commerce and merchant. We could then have all the jobs and their cargo inside
            //      userservicesstorage.
            //Register the handlers
            Dictionary <Type, object> jobHandlers = new Dictionary <Type, object>
            {
                { typeof(MerchantReportEmailCargo), merchantEmailJobHandler },
                { typeof(DealsEmailCargo), dealsEmailJobHandler },
                { typeof(ConfirmationEmailCargo), confirmationEmailHandler },
                { typeof(PromotionalEmailCargo), remainderMailHandler },
                { typeof(CampaignEmailCargo), campaignEmailJobHandler }
            };

            List <EmailJobProcessor> agents = new List <EmailJobProcessor>();

            for (int i = 0; i < jobProcessorCount; i++)
            {
                EmailJobProcessor agent = new EmailJobProcessor(idPrefix + "_" + i, emailJobsQueue, priorityEmailJobsQueue, jobHandlers);
                agents.Add(agent);
            }

            Log.Verbose("Mailing Manager. Bootstrap Completed - agents number = {0}", jobProcessorCount);

            return(agents);
        }