/// <summary> /// The main entry point for the application. /// </summary> static void Main() { string serviceFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); SqlServerTypes.Utilities.LoadNativeAssemblies(serviceFolder); System.Diagnostics.Debugger.Launch(); RockMemoryCache.Clear(); // set the current directory to the same as the current exe so that we can find the web.connectionstrings.config Directory.SetCurrentDirectory(serviceFolder); ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new JobScheduler() }; //// NOTE: To run and debug this service in Visual Studio uncomment out the debug code below //// Make sure you have a web.connectionstring.config in your debug/bin directory! //JobScheduler debug = new JobScheduler(); //debug.StartJobScheduler(); // if you'd rather debug the app running as an actual service do the following: // 1. Install the app as a service 'installutil <yourproject>.exe' (installutil is found C:\Windows\Microsoft.NET\Framework64\v4.0.30319\) // 2. Add the line System.Diagnostics.Debugger.Launch(); where you'd like to debug // // Note: to uninstall the service run 'installutil /u <yourproject>.exe' //System.Diagnostics.Debugger.Launch(); ServiceBase.Run(ServicesToRun); }
public override void Up() { // Make sure this is unique if (DefinedTypeCache.Read(new Guid("0913F7A9-A2BF-479C-96EC-6CDB56310A83")) == null) { RockMigrationHelper.AddDefinedType("Global", "Hospitals", "Hospital List", "0913F7A9-A2BF-479C-96EC-6CDB56310A83", @""); RockMigrationHelper.AddDefinedTypeAttribute("0913F7A9-A2BF-479C-96EC-6CDB56310A83", "9C204CD0-1233-41C5-818A-C5DA439445AA", "City", "Qualifier2", "", 0, "", "CEDC60C1-0F9E-4FE2-BE62-41716813C968"); RockMigrationHelper.AddDefinedTypeAttribute("0913F7A9-A2BF-479C-96EC-6CDB56310A83", "9C204CD0-1233-41C5-818A-C5DA439445AA", "Notes", "Qualifier8", "", 0, "", "C47A879E-F737-4156-A1FF-B7C465FDB9BC"); RockMigrationHelper.AddDefinedTypeAttribute("0913F7A9-A2BF-479C-96EC-6CDB56310A83", "9C204CD0-1233-41C5-818A-C5DA439445AA", "Phone", "Qualifier5", "", 0, "", "A4E41679-2CE6-479F-84D4-6821B25E3648"); RockMigrationHelper.AddDefinedTypeAttribute("0913F7A9-A2BF-479C-96EC-6CDB56310A83", "9C204CD0-1233-41C5-818A-C5DA439445AA", "Speed Dial", "Qualifier6", "", 0, "", "D97EC9DE-5D6A-42FD-B4CE-0516FD5455F6"); RockMigrationHelper.AddDefinedTypeAttribute("0913F7A9-A2BF-479C-96EC-6CDB56310A83", "9C204CD0-1233-41C5-818A-C5DA439445AA", "State", "Qualifier3", "", 0, "", "239E507C-7C1B-4B4D-84D4-33C368843F04"); RockMigrationHelper.AddDefinedTypeAttribute("0913F7A9-A2BF-479C-96EC-6CDB56310A83", "9C204CD0-1233-41C5-818A-C5DA439445AA", "Street Address", "Qualifier1", "", 0, "", "73AC0DCE-CE90-4835-AAE7-E98B08F52E9C"); RockMigrationHelper.AddDefinedTypeAttribute("0913F7A9-A2BF-479C-96EC-6CDB56310A83", "9C204CD0-1233-41C5-818A-C5DA439445AA", "Zip", "Qualifier4", "", 0, "", "46A83E00-D530-48AD-B935-52C015DCA901"); RockMigrationHelper.AddDefinedValue("0913F7A9-A2BF-479C-96EC-6CDB56310A83", "Sample Hospital", "", "0997ACB6-A4B4-4766-B573-3C44D14DF342", false); RockMigrationHelper.AddDefinedValueAttributeValue("0997ACB6-A4B4-4766-B573-3C44D14DF342", "239E507C-7C1B-4B4D-84D4-33C368843F04", @"KY"); RockMigrationHelper.AddDefinedValueAttributeValue("0997ACB6-A4B4-4766-B573-3C44D14DF342", "46A83E00-D530-48AD-B935-52C015DCA901", @"40023"); RockMigrationHelper.AddDefinedValueAttributeValue("0997ACB6-A4B4-4766-B573-3C44D14DF342", "73AC0DCE-CE90-4835-AAE7-E98B08F52E9C", @"1 Main St"); RockMigrationHelper.AddDefinedValueAttributeValue("0997ACB6-A4B4-4766-B573-3C44D14DF342", "A4E41679-2CE6-479F-84D4-6821B25E3648", @"(502) 111-1111"); RockMigrationHelper.AddDefinedValueAttributeValue("0997ACB6-A4B4-4766-B573-3C44D14DF342", "C47A879E-F737-4156-A1FF-B7C465FDB9BC", @""); RockMigrationHelper.AddDefinedValueAttributeValue("0997ACB6-A4B4-4766-B573-3C44D14DF342", "CEDC60C1-0F9E-4FE2-BE62-41716813C968", @"Louisville"); RockMigrationHelper.AddDefinedValueAttributeValue("0997ACB6-A4B4-4766-B573-3C44D14DF342", "D97EC9DE-5D6A-42FD-B4CE-0516FD5455F6", @""); } // Make sure this is unique if (DefinedTypeCache.Read(new Guid("4573E600-4E00-4BE9-BA92-D17093C735D6")) == null) { RockMigrationHelper.AddDefinedType("Global", "Nursing Homes", "Nursing Home List", "4573E600-4E00-4BE9-BA92-D17093C735D6", @""); RockMigrationHelper.AddDefinedTypeAttribute("4573E600-4E00-4BE9-BA92-D17093C735D6", "9C204CD0-1233-41C5-818A-C5DA439445AA", "City", "Qualifier2", "", 0, "", "CEDC60C1-0F9E-4FE2-BE62-41716813C969"); RockMigrationHelper.AddDefinedTypeAttribute("4573E600-4E00-4BE9-BA92-D17093C735D6", "9C204CD0-1233-41C5-818A-C5DA439445AA", "Notes", "Qualifier8", "", 0, "", "C47A879E-F737-4156-A1FF-B7C465FDB9BD"); RockMigrationHelper.AddDefinedTypeAttribute("4573E600-4E00-4BE9-BA92-D17093C735D6", "9C204CD0-1233-41C5-818A-C5DA439445AA", "Phone", "Qualifier5", "", 0, "", "A4E41679-2CE6-479F-84D4-6821B25E3649"); RockMigrationHelper.AddDefinedTypeAttribute("4573E600-4E00-4BE9-BA92-D17093C735D6", "9C204CD0-1233-41C5-818A-C5DA439445AA", "Pastoral Minister", "Qualifier6", "", 0, "", "D97EC9DE-5D6A-42FD-B4CE-0516FD5455F7"); RockMigrationHelper.AddDefinedTypeAttribute("4573E600-4E00-4BE9-BA92-D17093C735D6", "9C204CD0-1233-41C5-818A-C5DA439445AA", "State", "Qualifier3", "", 0, "", "239E507C-7C1B-4B4D-84D4-33C368843F05"); RockMigrationHelper.AddDefinedTypeAttribute("4573E600-4E00-4BE9-BA92-D17093C735D6", "9C204CD0-1233-41C5-818A-C5DA439445AA", "Street Address", "Qualifier1", "", 0, "", "73AC0DCE-CE90-4835-AAE7-E98B08F52E9D"); RockMigrationHelper.AddDefinedTypeAttribute("4573E600-4E00-4BE9-BA92-D17093C735D6", "9C204CD0-1233-41C5-818A-C5DA439445AA", "Zip", "Qualifier4", "", 0, "", "46A83E00-D530-48AD-B935-52C015DCA902"); RockMigrationHelper.AddDefinedValue("4573E600-4E00-4BE9-BA92-D17093C735D6", "Sample Nursing Home", "", "0997ACB6-A4B4-4766-B573-3C44D14DF343", false); RockMigrationHelper.AddDefinedValueAttributeValue("0997ACB6-A4B4-4766-B573-3C44D14DF343", "239E507C-7C1B-4B4D-84D4-33C368843F05", @"KY"); RockMigrationHelper.AddDefinedValueAttributeValue("0997ACB6-A4B4-4766-B573-3C44D14DF343", "46A83E00-D530-48AD-B935-52C015DCA902", @"40023"); RockMigrationHelper.AddDefinedValueAttributeValue("0997ACB6-A4B4-4766-B573-3C44D14DF343", "73AC0DCE-CE90-4835-AAE7-E98B08F52E9D", @"2 Main St"); RockMigrationHelper.AddDefinedValueAttributeValue("0997ACB6-A4B4-4766-B573-3C44D14DF343", "A4E41679-2CE6-479F-84D4-6821B25E3649", @"(502) 111-1111"); RockMigrationHelper.AddDefinedValueAttributeValue("0997ACB6-A4B4-4766-B573-3C44D14DF343", "C47A879E-F737-4156-A1FF-B7C465FDB9BD", @""); RockMigrationHelper.AddDefinedValueAttributeValue("0997ACB6-A4B4-4766-B573-3C44D14DF343", "CEDC60C1-0F9E-4FE2-BE62-41716813C969", @"Louisville"); RockMigrationHelper.AddDefinedValueAttributeValue("0997ACB6-A4B4-4766-B573-3C44D14DF343", "D97EC9DE-5D6A-42FD-B4CE-0516FD5455F7", @"John Adams"); } // Make sure to clear the Rock Cache so the defined type above will be there RockMemoryCache.Clear(); }
/// <summary> /// Handles the Start event of the Application control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void Application_Start(object sender, EventArgs e) { try { var stopwatch = System.Diagnostics.Stopwatch.StartNew(); LogMessage(APP_LOG_FILENAME, "Application Starting..."); if (System.Web.Hosting.HostingEnvironment.IsDevelopmentEnvironment) { System.Diagnostics.Debug.WriteLine(string.Format("Application_Start: {0}", RockDateTime.Now.ToString("hh:mm:ss.FFF"))); } // Clear all cache RockMemoryCache.Clear(); // Get a db context using (var rockContext = new RockContext()) { if (System.Web.Hosting.HostingEnvironment.IsDevelopmentEnvironment) { try { // default Initializer is CreateDatabaseIfNotExists, so set it to NULL so that nothing happens if there isn't a database yet Database.SetInitializer <Rock.Data.RockContext>(null); new AttributeService(rockContext).Get(0); System.Diagnostics.Debug.WriteLine(string.Format("ConnectToDatabase {2}/{1} - {0} ms", stopwatch.Elapsed.TotalMilliseconds, rockContext.Database.Connection.Database, rockContext.Database.Connection.DataSource)); } catch { // Intentionally Blank } } //// Run any needed Rock and/or plugin migrations //// NOTE: MigrateDatabase must be the first thing that touches the database to help prevent EF from creating empty tables for a new database MigrateDatabase(rockContext); // Preload the commonly used objects stopwatch.Restart(); LoadCacheObjects(rockContext); if (System.Web.Hosting.HostingEnvironment.IsDevelopmentEnvironment) { System.Diagnostics.Debug.WriteLine(string.Format("LoadCacheObjects - {0} ms", stopwatch.Elapsed.TotalMilliseconds)); } // Run any plugin migrations MigratePlugins(rockContext); RegisterRoutes(rockContext, RouteTable.Routes); // Configure Rock Rest API stopwatch.Restart(); GlobalConfiguration.Configure(Rock.Rest.WebApiConfig.Register); if (System.Web.Hosting.HostingEnvironment.IsDevelopmentEnvironment) { System.Diagnostics.Debug.WriteLine(string.Format("Configure WebApiConfig - {0} ms", stopwatch.Elapsed.TotalMilliseconds)); stopwatch.Restart(); } // setup and launch the jobs infrastructure if running under IIS bool runJobsInContext = Convert.ToBoolean(ConfigurationManager.AppSettings["RunJobsInIISContext"]); if (runJobsInContext) { ISchedulerFactory sf; // create scheduler sf = new StdSchedulerFactory(); sched = sf.GetScheduler(); // get list of active jobs ServiceJobService jobService = new ServiceJobService(rockContext); foreach (ServiceJob job in jobService.GetActiveJobs().ToList()) { const string errorLoadingStatus = "Error Loading Job"; try { IJobDetail jobDetail = jobService.BuildQuartzJob(job); ITrigger jobTrigger = jobService.BuildQuartzTrigger(job); sched.ScheduleJob(jobDetail, jobTrigger); //// if the last status was an error, but we now loaded successful, clear the error // also, if the last status was 'Running', clear that status because it would have stopped if the app restarted if (job.LastStatus == errorLoadingStatus || job.LastStatus == "Running") { job.LastStatusMessage = string.Empty; job.LastStatus = string.Empty; rockContext.SaveChanges(); } } catch (Exception ex) { // log the error LogError(ex, null); // create a friendly error message string message = string.Format("Error loading the job: {0}.\n\n{2}", job.Name, job.Assembly, ex.Message); job.LastStatusMessage = message; job.LastStatus = errorLoadingStatus; rockContext.SaveChanges(); } } // set up the listener to report back from jobs as they complete sched.ListenerManager.AddJobListener(new RockJobListener(), EverythingMatcher <JobKey> .AllJobs()); // start the scheduler sched.Start(); } // Force the static Liquid class to get instantiated so that the standard filters are loaded prior // to the custom RockFilter. This is to allow the custom 'Date' filter to replace the standard // Date filter. Liquid.UseRubyDateFormat = false; //// NOTE: This means that template filters will also use CSharpNamingConvention //// For example the dotliquid documentation says to do this for formatting dates: //// {{ some_date_value | date:"MMM dd, yyyy" }} //// However, if CSharpNamingConvention is enabled, it needs to be: //// {{ some_date_value | Date:"MMM dd, yyyy" }} Template.NamingConvention = new DotLiquid.NamingConventions.CSharpNamingConvention(); Template.FileSystem = new RockWeb.LavaFileSystem(); Template.RegisterSafeType(typeof(Enum), o => o.ToString()); Template.RegisterFilter(typeof(Rock.Lava.RockFilters)); // add call back to keep IIS process awake at night and to provide a timer for the queued transactions AddCallBack(); Rock.Security.Authorization.Load(); } EntityTypeService.RegisterEntityTypes(Server.MapPath("~")); FieldTypeService.RegisterFieldTypes(Server.MapPath("~")); BundleConfig.RegisterBundles(BundleTable.Bundles); // mark any user login stored as 'IsOnline' in the database as offline MarkOnlineUsersOffline(); SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~")); LogMessage(APP_LOG_FILENAME, "Application Started Successfully"); if (System.Web.Hosting.HostingEnvironment.IsDevelopmentEnvironment) { System.Diagnostics.Debug.WriteLine(string.Format("Application_Started_Successfully: {0}", RockDateTime.Now.ToString("hh:mm:ss.FFF"))); } } catch (Exception ex) { SetError66(); throw (new Exception("Error occurred during application startup", ex)); } }