Exemplo n.º 1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();

            // BUGBUG: remove this when starting to deploy real production data
            //System.Data.Entity.Database.SetInitializer(new System.Data.Entity.DropCreateDatabaseIfModelChanges<WebTimer.WebRole.Models.UserDataContext>());

            // the database must exist for the role to run
            if (!UserDataContext.InitializeDatabase())
            {
                TraceLog.TraceFatal("Application_Start: Cannot initialize the user database");
            }
        }
Exemplo n.º 2
0
        public override void Run()
        {
            // initialize splunk logging (we do this here instead of OnStart so that the Azure logger has time to really start)
            TraceLog.TraceInfo("WorkerRole started");

            // the database must exist for the role to run
            if (!UserDataContext.InitializeDatabase())
            {
                TraceLog.TraceFatal("Cannot initialize the UserData database");
                return;
            }

#if DISABLE
            // check the database schema versions to make sure there is no version mismatch
            if (!Storage.NewUserContext.CheckSchemaVersion())
            {
                TraceLog.TraceFatal("User database schema is out of sync, unrecoverable error");
                return;
            }
            if (!Storage.NewSuggestionsContext.CheckSchemaVersion())
            {
                TraceLog.TraceFatal("Suggestions database schema is out of sync, unrecoverable error");
                return;
            }

            // (re)create the database constants if the code contains a newer version
            if (!Storage.NewUserContext.VersionConstants(Me))
            {
                TraceLog.TraceFatal("Cannot check and/or update the User database constants, unrecoverable error");
                return;
            }
            if (!Storage.NewSuggestionsContext.VersionConstants(Me))
            {
                TraceLog.TraceFatal("Cannot check and/or update the Suggestions database constants, unrecoverable error");
                return;
            }
#endif

            // get the number of workers (default is 0)
#if false
            int workflowWorkerCount = ConfigurationSettings.GetAsNullableInt(HostEnvironment.WorkflowWorkerCountConfigKey) ?? 0;
            var workflowWorkerArray = new WorkflowWorker.WorkflowWorker[workflowWorkerCount];
            int timerWorkerCount    = ConfigurationSettings.GetAsNullableInt(HostEnvironment.TimerWorkerCountConfigKey) ?? 0;
            var timerWorkerArray    = new TimerWorker.TimerWorker[timerWorkerCount];
            int mailWorkerCount     = ConfigurationSettings.GetAsNullableInt(HostEnvironment.MailWorkerCountConfigKey) ?? 0;
            var mailWorkerArray     = new MailWorker.MailWorker[mailWorkerCount];
#endif
            int analyticsWorkerCount = ConfigurationSettings.GetAsNullableInt(HostEnvironment.AnalyticsWorkerCountConfigKey) ?? 0;
            var analyticsWorkerArray = new WebTimer.AnalyticsWorker.AnalyticsWorker[analyticsWorkerCount];
            int processorWorkerCount = ConfigurationSettings.GetAsNullableInt(HostEnvironment.ProcessorWorkerCountConfigKey) ?? 0;
            var processorWorkerArray = new WebTimer.ProcessorWorker.ProcessorWorker[processorWorkerCount];

            // run an infinite loop doing the following:
            //   check whether the worker services have stopped (indicated by a null reference)
            //   (re)start the service on a new thread if necessary
            //   sleep for the timeout period
            while (true)
            {
#if false
                // start workflow and timer workers in both dev and deployed Azure fabric
                RestartWorkerThreads <WorkflowWorker.WorkflowWorker>(workflowWorkerArray);
                RestartWorkerThreads <TimerWorker.TimerWorker>(timerWorkerArray);

                // start mail and speech workers only in deployed Azure fabric
                if (!HostEnvironment.IsAzureDevFabric)
                {
                    RestartWorkerThreads <MailWorker.MailWorker>(mailWorkerArray);
                }
                if (!HostEnvironment.IsAzureDevFabric)
                {
                    RestartWorkerThreads <SpeechWorker.SpeechWorker>(speechWorkerArray);
                }
#endif
                // start Analytics worker in both dev and deployed Azure fabric
                RestartWorkerThreads <WebTimer.AnalyticsWorker.AnalyticsWorker>(analyticsWorkerArray);

                // start Processor worker in both dev and deployed Azure fabric
                RestartWorkerThreads <WebTimer.ProcessorWorker.ProcessorWorker>(processorWorkerArray);

                // sleep for the timeout period
                Thread.Sleep(timeout);
            }
        }