protected void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register); //WebAPI AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AutofacConfiguration(); //Shift Client var clientConfig = new Shift.ClientConfig(); clientConfig.DBConnectionString = ConfigurationManager.ConnectionStrings["ShiftDBConnection"].ConnectionString; clientConfig.DBAuthKey = ConfigurationManager.AppSettings["DocumentDBAuthKey"]; clientConfig.EncryptionKey = ConfigurationManager.AppSettings["ShiftEncryptionParametersKey"]; //optional, will encrypt parameters in DB if exists clientConfig.StorageMode = ConfigurationManager.AppSettings["StorageMode"]; Application["Shift.JobClient"] = new JobClient(clientConfig); //only the DBConnectionString and CacheConfigurationString are required for Client's background job //Shift Server var serverConfig = new Shift.ServerConfig(); serverConfig.DBConnectionString = ConfigurationManager.ConnectionStrings["ShiftDBConnection"].ConnectionString; serverConfig.DBAuthKey = ConfigurationManager.AppSettings["DocumentDBAuthKey"]; serverConfig.EncryptionKey = ConfigurationManager.AppSettings["ShiftEncryptionParametersKey"]; //optional, will encrypt parameters in DB if exists serverConfig.MaxRunnableJobs = Convert.ToInt32(ConfigurationManager.AppSettings["MaxRunnableJobs"]); serverConfig.ProcessID = ConfigurationManager.AppSettings["ShiftPID"]; serverConfig.Workers = Convert.ToInt32(ConfigurationManager.AppSettings["ShiftWorkers"]); serverConfig.StorageMode = ConfigurationManager.AppSettings["StorageMode"]; var progressDBInterval = ConfigurationManager.AppSettings["ProgressDBInterval"]; if (!string.IsNullOrWhiteSpace(progressDBInterval)) { serverConfig.ProgressDBInterval = TimeSpan.Parse(progressDBInterval); //Interval when progress is updated in main DB } var autoDeletePeriod = ConfigurationManager.AppSettings["AutoDeletePeriod"]; serverConfig.AutoDeletePeriod = string.IsNullOrWhiteSpace(autoDeletePeriod) ? null : (int?)Convert.ToInt32(autoDeletePeriod); serverConfig.AutoDeleteStatus = new List <JobStatus?> { JobStatus.Completed }; //Auto delete only the jobs that had been Completed serverConfig.ForceStopServer = Convert.ToBoolean(ConfigurationManager.AppSettings["ForceStopServer"]); //Set to true to allow windows service to shut down after a set delay in StopServerDelay serverConfig.StopServerDelay = Convert.ToInt32(ConfigurationManager.AppSettings["StopServerDelay"]); //serverConfig.ServerTimerInterval = Convert.ToInt32(ConfigurationManager.AppSettings["ServerTimerInterval"]); //optional: default every 5 sec for server running jobs //serverConfig.ServerTimerInterval2 = Convert.ToInt32(ConfigurationManager.AppSettings["ServerTimerInterval2"]); //optional: default every 10 sec for server CleanUp() //serverConfig.AssemblyFolder = ConfigurationManager.AppSettings["AssemblyFolder"]; //serverConfig.AssemblyListPath = ConfigurationManager.AppSettings["AssemblyListPath"]; serverConfig.PollingOnce = Convert.ToBoolean(ConfigurationManager.AppSettings["PollingOnce"]); //For this demo, we're running the background process server in the same process as the web client //It's recommended to run the server in a separate process, such as windows service or Azure WebJob or another app. var jobServer = new Shift.JobServer(serverConfig); Application["Shift.JobServer"] = jobServer; }
private void ConfigureShiftServer(IMemoryCache cache) { var cacheOptions = new MemoryCacheEntryOptions().SetPriority(CacheItemPriority.NeverRemove).SetAbsoluteExpiration(TimeSpan.FromDays(999999)); //never expires? var shiftConfig = Configuration.GetSection("Shift"); //Shift Client var clientConfig = new Shift.ClientConfig(); clientConfig.DBConnectionString = shiftConfig["ShiftDBConnection"]; clientConfig.DBAuthKey = shiftConfig["DocumentDBAuthKey"]; clientConfig.EncryptionKey = shiftConfig["ShiftEncryptionParametersKey"]; //optional, will encrypt parameters in DB if exists clientConfig.StorageMode = shiftConfig["StorageMode"]; cache.Set("Shift.JobClient", new JobClient(clientConfig), cacheOptions); //only the DBConnectionString and CacheConfigurationString are required for Client's background job //Shift Server var serverConfig = new Shift.ServerConfig(); serverConfig.DBConnectionString = shiftConfig["ShiftDBConnection"]; serverConfig.DBAuthKey = shiftConfig["DocumentDBAuthKey"]; serverConfig.EncryptionKey = shiftConfig["ShiftEncryptionParametersKey"]; //optional, will encrypt parameters in DB if exists serverConfig.MaxRunnableJobs = Convert.ToInt32(shiftConfig["MaxRunnableJobs"]); //serverConfig.ProcessID = shiftConfig["ShiftPID"]; serverConfig.Workers = Convert.ToInt32(shiftConfig["ShiftWorkers"]); serverConfig.StorageMode = shiftConfig["StorageMode"]; var progressDBInterval = shiftConfig["ProgressDBInterval"]; if (!string.IsNullOrWhiteSpace(progressDBInterval)) { serverConfig.ProgressDBInterval = TimeSpan.Parse(progressDBInterval); //Interval when progress is updated in main DB } var autoDeletePeriod = shiftConfig["AutoDeletePeriod"]; serverConfig.AutoDeletePeriod = string.IsNullOrWhiteSpace(autoDeletePeriod) ? null : (int?)Convert.ToInt32(autoDeletePeriod); serverConfig.AutoDeleteStatus = new List <JobStatus?> { JobStatus.Completed }; //Auto delete only the jobs that had Stopped or with Error serverConfig.ForceStopServer = Convert.ToBoolean(shiftConfig["ForceStopServer"]); //Set to true to allow windows service to shut down after a set delay in StopServerDelay serverConfig.StopServerDelay = Convert.ToInt32(shiftConfig["StopServerDelay"]); //serverConfig.ServerTimerInterval = Convert.ToInt32(shiftConfig["ServerTimerInterval"]); //optional: default every 5 sec for server running jobs //serverConfig.ServerTimerInterval2 = Convert.ToInt32(shiftConfig["ServerTimerInterval2"]); //optional: default every 10 sec for server CleanUp() //serverConfig.AssemblyFolder = shiftConfig["AssemblyFolder"]; //serverConfig.AssemblyListPath = shiftConfig["AssemblyListPath"]; serverConfig.PollingOnce = Convert.ToBoolean(shiftConfig["PollingOnce"]); //For this demo, we're running the background process server in the same process as the web client //It's recommended to run the server in a separate process, such as windows service or Azure WebJob or another app. cache.Set("Shift.JobServer", new Shift.JobServer(serverConfig), cacheOptions); //only the DBConnectionString and CacheConfigurationString are required for Client's background job }