public ContentMapProvider(
            Func <CrmDbContext> createContext,
            ISolutionDefinitionProvider solutionDefinitionProvider,
            EventHubJobSettings eventHubJobSettings,
            PortalSolutions portalSolutions)
        {
            this.CreateContext = createContext;
            this.SolutionDefinitionProvider = solutionDefinitionProvider;
            this.EventHubJobSettings        = eventHubJobSettings;
            this.PortalSolutions            = portalSolutions;

            _map = new Lazy <ContentMap>(this.GetContentMap);
        }
示例#2
0
        public static ContentMapProvider ConfigureContentMap(
            this IAppBuilder app,
            Func <CrmDbContext> createContext,
            CrmWebsite website,
            EventHubJobSettings eventHubJobSettings,
            PortalSolutions portalSolutions)
        {
            var solutionDefinitionProvider = new CmsSolutionDefinitionProvider(portalSolutions, website);
            var contentMapProvider         = new ContentMapProvider(createContext, solutionDefinitionProvider, eventHubJobSettings, portalSolutions);

            app.CreatePerOwinContext(() => contentMapProvider);

            // support legacy accessors
            AdxstudioCrmConfigurationProvider.Set(solutionDefinitionProvider);
            AdxstudioCrmConfigurationProvider.Set(contentMapProvider);

            return(contentMapProvider);
        }
示例#3
0
 public static void UsePortalBus <TMessage>(this IAppBuilder app, WebAppSettings webAppSettings, EventHubJobSettings eventHubJobSettings)
 {
     if (webAppSettings.AzureWebRoleEnabled)
     {
         UseRoleEnvironmentPortalBus(app, new ServiceDefinitionPortalBusOptions <TMessage>());
     }
     else if (webAppSettings.AppDataCachingEnabled && !eventHubJobSettings.IsEnabled)
     {
         UseAppDataPortalBus(app, new AppDataPortalBusOptions <TMessage>(webAppSettings));
     }
     else
     {
         UseLocalOnlyPortalBus <TMessage>(app);
     }
 }
示例#4
0
        /// <summary>
        /// Configure Event Hub based cache invalidation.
        /// </summary>
        /// <param name="app">The app.</param>
        /// <param name="websiteId">Current website id.</param>
        /// <param name="createContext">The context generator.</param>
        /// <param name="cacheEventHubJobSettings">The cache Event Hub job settings.</param>
        /// <param name="searchEventHubJobSettings">The search Event Hub job settings.</param>
        /// <param name="cacheInvalidationJobSettings">The cache invalidation job settings.</param>
        public static void ConfigureEventHubCacheInvalidation(this IAppBuilder app, Guid websiteId, Func <CrmDbContext> createContext, EventHubJobSettings cacheEventHubJobSettings, EventHubJobSettings searchEventHubJobSettings, CacheInvalidationJobSettings cacheInvalidationJobSettings)
        {
            WebAppConfigurationProvider.GetPortalEntityList();

            if (!cacheEventHubJobSettings.IsEnabled || !searchEventHubJobSettings.IsEnabled)
            {
                ADXTrace.Instance.TraceWarning(TraceCategory.Application, "Service Bus is not configured.");

                return;
            }

            var cacheManager  = new EventHubJobManager(createContext(), cacheEventHubJobSettings);
            var searchManager = new EventHubJobManager(createContext(), searchEventHubJobSettings);

            if (cacheManager.SubscriptionClient != null)
            {
                // warm up the client
                ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Subscription = '{0}' Topic = '{1}'", cacheManager.Subscription.Name, cacheManager.Subscription.TopicPath));
            }

            var registry = new Registry();

            registry.Schedule(
                () =>
            {
                new EventHubJob(cacheManager).Execute();
                new EventHubJob(searchManager).Execute();
                new CacheInvalidationJob(cacheInvalidationJobSettings, createContext(), websiteId).Execute();
            })
            .Reentrant(cacheEventHubJobSettings.Reentrant)
            .ToRunNow().AndEvery(cacheEventHubJobSettings.JobInterval).Seconds();

            JobManager.Initialize(registry);

            app.CreatePerOwinContext(() => cacheManager);

            WebAppConfigurationProvider.AppStartTime = cacheInvalidationJobSettings.StartedOn.ToString("MM/dd/yyyy HH:mm:ss");
        }
        public void ConfigurePortal(IAppBuilder app)
        {
            var host           = new PortalHostingEnvironment();
            var webAppSettings = WebAppSettings.Instance;

            // For cache we create one subscription per instance of web app, that's why we use instance id as the subscription name.
            var cacheEventHubJobSettings = new EventHubJobSettings(webAppSettings.InstanceId, EventHubSubscriptionType.CacheSubscription);

            // For search we create one subscription per webapp, that's why we use site name as the subscription name.
            var searchEventHubJobSettings = new EventHubJobSettings(webAppSettings.SiteName, EventHubSubscriptionType.SearchSubscription);

            var requireSslOptions = new RequireSslOptions(webAppSettings);

            var warmupCacheSettings = new WarmupCacheSettings();

            app.ConfigureApplicationLifecycleEvents();
            app.UseETWMiddleware();
            app.UseRequireSsl(requireSslOptions);
            app.UseAppInfo();
            app.UseHealth();
            app.UseScaleOutTelemetry();
            app.UseRequestTelemetry(SetupConfig.IsPortalConfigured);
            app.UseApplicationRestartPluginMessage(new PluginMessageOptions());
            app.UsePortalBus <ApplicationRestartPortalBusMessage>(webAppSettings, cacheEventHubJobSettings);
            app.UsePortalBus <CacheInvalidationPortalBusMessage>(webAppSettings, cacheEventHubJobSettings);
            app.CreatePerOwinContext <RequestElapsedTimeContext>(RequestElapsedTimeContext.Create);

            if (!SetupConfig.InitialSetupIsRunning() && !SetupConfig.ProvisioningInProgress())
            {
                using (PerformanceProfiler.Instance.StartMarker(PerformanceMarkerName.Startup, PerformanceMarkerArea.Crm, PerformanceMarkerTagName.StartUpConfiguration))
                {
                    // indepdendent components
                    app.CreatePerOwinContext(ApplicationDbContext.Create);
                    var portalSolutions = app.ConfigurePortalSolutionsDetails(ApplicationDbContext.Create());
                    app.CreatePerOwinContext <ApplicationOrganizationManager>(ApplicationOrganizationManager.Create);
                    app.CreatePerOwinContext <ApplicationWebsiteManager>(ApplicationWebsiteManager.Create);
                    app.CreatePerOwinContext <CrmWebsite>((options, context) => ApplicationWebsite.Create(options, context, host));

                    // Set the culture for this request.
                    app.UseCurrentThreadCulture();

                    ApplicationWebsiteManager websiteManager;

                    try
                    {
                        var settings = new CrmEntityStoreSettings {
                            PortalSolutions = portalSolutions
                        };
                        websiteManager = ApplicationWebsiteManager.Create(ApplicationDbContext.Create(), settings);
                    }
                    catch
                    {
                        //We need to unload app domain in order to reinitialize owin during next request
                        TelemetryState.ApplicationEndInfo = ApplicationEndFlags.Configuration;
                        Adxstudio.Xrm.Web.Extensions.RestartWebApplication();
                        return;
                    }

                    var website     = websiteManager.Find(HttpContext.Current.Request.RequestContext, host);
                    var hstsOptions = new StrictTransportSecurityOptions(website);

                    // components that depend on the website
                    app.UpdatePrimaryDomainName(websiteManager, website, portalSolutions);
                    app.ConfigureDisplayModes(website);
                    app.UseWebsiteHeaderSettings(website);
                    app.UseStrictTransportSecuritySettings(hstsOptions);
                    app.ConfigureSearchProvider(website);

                    var contentMapProvider = app.ConfigureContentMap(ApplicationDbContext.Create, website, cacheEventHubJobSettings, portalSolutions);

                    // configure user dependencies
                    this.ConfigureAuth(app, website);

                    // components that depend on the user
                    app.CreatePerOwinContext <ContextLanguageInfo>(ContextLanguageInfo.Create);

                    // Complete the authentication stage prior to invoking page handler
                    app.UseStageMarker(PipelineStage.Authenticate);

                    // components that depend on content map
                    app.ConfigureCulture(website, contentMapProvider, BundleTable.Bundles, BundleConfig.RegisterLanguageSpecificBundles);

                    // tail end components
                    app.ConfigureEventHubCacheInvalidation(website.Id, ApplicationDbContext.Create, cacheEventHubJobSettings, searchEventHubJobSettings, new CacheInvalidationJobSettings(webAppSettings));
                    app.WarmupCache(ApplicationDbContext.Create, warmupCacheSettings);
                    app.StartupComplete();
                }
            }
        }