/// <summary> /// Registers external services for commerce like MVC constructs, security providers and Analytics /// </summary> internal static void RegisterExternalServices() { // Register log. LogInitializer.CreateLogInstance(CommerceServiceConfig.Instance.LogVerbosity, CommerceServiceConfig.Instance.ForceEventLog, General.CommerceLogSource, CommerceServiceConfig.Instance); // Register MVC constructs. WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); // Register security providers. IUsersDal usersDal = PartnerFactory.UsersDal(CommerceServiceConfig.Instance); if (CommerceServiceConfig.Instance.EnableDebugSecurityProvider == true) { Security.Add("user_debug", new UserDebugSecurityProvider(usersDal)); } Security.Add("usertoken", new UserTokenSecurityProvider()); // Register Analytics Service Analytics.Initialize(CommerceServiceConfig.Instance); }
/// <summary> /// Registers external services for commerce like MVC constructs, security providers and Analytics /// </summary> internal static void RegisterExternalServices() { // Use only for debugging // TelemetryConfiguration.Active.TelemetryChannel.DeveloperMode = true; TelemetryConfiguration.Active.InstrumentationKey = CloudConfigurationManager.GetSetting("APPINSIGHTS_INSTRUMENTATIONKEY"); // Register log. LogInitializer.CreateLogInstance(CommerceServiceConfig.Instance.LogVerbosity, CommerceServiceConfig.Instance.ForceEventLog, General.CommerceLogSource, CommerceServiceConfig.Instance); Log.Info("Started Commerce MBI service."); // Register MVC constructs. WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); // Bing FrontDoor and user debug security providers. IUsersDal usersDal = PartnerFactory.UsersDal(CommerceServiceConfig.Instance); if (CommerceServiceConfig.Instance.EnableDebugSecurityProvider == true) { Security.Add("user_debug", new UserDebugSecurityProvider(usersDal)); } Security.Add("lomo", new LomoSecurityProvider(usersDal)); // Register the mutual SSL security provider. Security.Add(MutualSslSecurityProvider.Name, new MutualSslSecurityProvider()); // Register the Simple Web Token security provider. string environment = string.Concat("commerce-", CommerceServiceConfig.Instance.Environment); string resourceTemplate = string.Concat(string.Format("https://{0}.TODO_INSERT_YOUR_DOMAIN_HERE/api/commerce/service/", environment), "{0}"); Security.Add(SimpleWebTokenSecurityProvider.Name, new SimpleWebTokenSecurityProvider(environment, resourceTemplate, CommerceServiceConfig.Instance.SimpleWebTokenKey)); // Amex payment authorization SWT security provider Security.Add("Bearer", new SimpleWebTokenSecurityProvider(environment, string.Concat(string.Format("https://{0}.TODO_INSERT_YOUR_DOMAIN_HERE/api/commerce/amex/", environment), "{0}"), CommerceServiceConfig.Instance.SimpleWebTokenKey)); // Register Analytics Service Analytics.Initialize(CommerceServiceConfig.Instance); }
/// <summary> /// When the worker role starts, we do the following: /// 1. Initialize Logger to be used /// 2. Schedule Extract Processing job on startup if configured for. /// 3. Schedule Ping Job /// </summary> /// <remarks> /// If we schedule Extract Processing job at the same time everyday, we might get /// duplicate jobs to execute at the same time (which might be a problem when we have /// more than one instance of the role). We can revisit this later, but for now we will /// schedule it at the start. /// </remarks> /// <returns> /// boolean status about startup /// </returns> public override bool OnStart() { // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 100 * Environment.ProcessorCount; // Use only for debugging // TelemetryConfiguration.Active.TelemetryChannel.DeveloperMode = true; //TelemetryConfiguration.Active.InstrumentationKey = CloudConfigurationManager.GetSetting("APPINSIGHTS_INSTRUMENTATIONKEY"); // Create a CommerceLog instance to funnel log entries to the log. LogInitializer.CreateLogInstance(CommerceWorkerConfig.Instance.LogVerbosity, CommerceWorkerConfig.Instance.ForceEventLog, CommerceLogSource, CommerceWorkerConfig.Instance); Log = new CommerceLog(Guid.NewGuid(), CommerceWorkerConfig.Instance.LogVerbosity, CommerceLogSource); ConfigChangeHandler = new ConfigChangeHandler(Log, ExemptConfigurationItems); // turn off processing jobs at start ProcessJobs = Convert.ToBoolean(CloudConfigurationManager.GetSetting(ProcessJobsPropertyKey)); // role should not exit even after processing jobs stop ExitRole = false; // event handlers RoleEnvironment.Changing += RoleEnvironmentChanging; RoleEnvironment.Changed += RoleEnvironmentChanged; if (!string.IsNullOrEmpty(ConcurrencyMonitorConnectionString)) { Log.Verbose("Initializing Jobs."); using (ConcurrencyMonitor monitor = new ConcurrencyMonitor(ConcurrencyMonitorConnectionString)) { monitor.InvokeWithLease(() => PartnerJobInitializer.InitializeJobs(Scheduler)); } Log.Verbose("Initialized Jobs."); } return(base.OnStart()); }