///<summary> /// Initializes a new instance of JobClient class, injects data layer with connection and configuration strings. /// Only three options are used for the client: /// * DBConnectionString /// * UseCache /// * CacheConfigurationString /// * EncryptionKey (optional) /// /// If UseCache is true, the CacheConfigurationString is required, if false, then it is optional. ///</summary> ///<param name="config">Setup the database connection string, cache configuration.</param> /// public JobClient(ClientConfig config) { if (config == null) { throw new Exception("Unable to start with no configuration."); } if (string.IsNullOrWhiteSpace(config.StorageMode)) { throw new Exception("The storage mode must not be empty."); } if (string.IsNullOrWhiteSpace(config.DBConnectionString)) { throw new Exception("Unable to run without DB storage connection string."); } if (config.UseCache && string.IsNullOrWhiteSpace(config.CacheConfigurationString)) { throw new Exception("Unable to run without Cache configuration string."); } this.config = config; builder = new ContainerBuilder(); builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource()); RegisterAssembly.RegisterTypes(builder, config.StorageMode, config.DBConnectionString, config.UseCache, config.CacheConfigurationString, config.EncryptionKey); container = builder.Build(); jobDAL = container.Resolve <IJobDAL>(); }
///<summary> /// Initializes a new instance of JobClient class, injects data layer with connection and configuration strings. /// Only three options are used for the client: /// * DBConnectionString /// * UseCache /// * CacheConfigurationString /// * EncryptionKey (optional) /// /// If UseCache is true, the CacheConfigurationString is required, if false, then it is optional. ///</summary> ///<param name="config">Setup the database connection string, cache configuration.</param> /// public JobClient(ClientConfig config) { if (config == null) { throw new ArgumentNullException("Unable to start with no configuration."); } if (string.IsNullOrWhiteSpace(config.StorageMode)) { throw new ArgumentNullException("The storage mode must not be empty."); } if (string.IsNullOrWhiteSpace(config.DBConnectionString)) { throw new ArgumentNullException("Unable to run without DB storage connection string."); } var builder = new ContainerBuilder(); builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource()); RegisterAssembly.RegisterTypes(builder, config.StorageMode, config.DBConnectionString, config.EncryptionKey, config.DBAuthKey); var container = builder.Build(); //Use lifetime scope to avoid memory leak http://docs.autofac.org/en/latest/resolve/ using (var scope = container.BeginLifetimeScope()) { jobDAL = container.Resolve <IJobDAL>(); } }
private List <Worker> workerList = null; //reference to Workers ///<summary> ///Initializes a new instance of JobServer class, injects data layer with connection and configuration strings. ///</summary> ///<param name="config">Setup the database connection string, cache configuration, etc.</param> /// public JobServer(ServerConfig config) { if (config == null) { throw new ArgumentNullException("Unable to create with no configuration."); } if (string.IsNullOrWhiteSpace(config.StorageMode)) { throw new ArgumentNullException("The storage mode must not be empty."); } if (string.IsNullOrWhiteSpace(config.ProcessID)) { config.ProcessID = ProcessIDGenerator.Generate(true); } if (string.IsNullOrWhiteSpace(config.DBConnectionString)) { throw new ArgumentNullException("Unable to run without DB storage connection string."); } if (config.MaxRunnableJobs <= 0) { config.MaxRunnableJobs = 100; } this.config = config; this.workerList = new List <Worker>(); //OPTIONAL: Load all EXTERNAL DLLs needed by this process AppDomain.CurrentDomain.AssemblyResolve += AssemblyHelpers.OnAssemblyResolve; AssemblyHelpers.LoadAssemblies(config.AssemblyFolder, config.AssemblyListPath); //Create Worker var builder = new ContainerBuilder(); builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource()); RegisterAssembly.RegisterTypes(builder, config.StorageMode, config.DBConnectionString, config.EncryptionKey, config.DBAuthKey); var container = builder.Build(); //Use lifetime scope to avoid memory leak http://docs.autofac.org/en/latest/resolve/ using (var scope = container.BeginLifetimeScope()) { var jobDAL = scope.Resolve <IJobDAL>(); for (var i = 1; i <= config.Workers; i++) { var worker = new Worker(config, jobDAL, i); workerList.Add(worker); } } }
private List <Worker> workerList = null; //reference to Workers ///<summary> ///Initializes a new instance of JobServer class, injects data layer with connection and configuration strings. ///</summary> ///<param name="config">Setup the database connection string, cache configuration, etc.</param> /// public JobServer(ServerConfig config) { if (config == null) { throw new Exception("Unable to create with no configuration."); } if (string.IsNullOrWhiteSpace(config.StorageMode)) { throw new Exception("The storage mode must not be empty."); } if (string.IsNullOrWhiteSpace(config.ProcessID)) { throw new Exception("Unable to create with no ProcessID."); } if (string.IsNullOrWhiteSpace(config.DBConnectionString)) { throw new Exception("Unable to run without DB storage connection string."); } if (config.UseCache && string.IsNullOrWhiteSpace(config.CacheConfigurationString)) { throw new Exception("Unable to run without Cache configuration string."); } if (config.MaxRunnableJobs <= 0) { config.MaxRunnableJobs = 100; } this.config = config; builder = new ContainerBuilder(); builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource()); RegisterAssembly.RegisterTypes(builder, config.StorageMode, config.DBConnectionString, config.UseCache, config.CacheConfigurationString, config.EncryptionKey); container = builder.Build(); Initialize(); }