Exemple #1
0
        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);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Instantiate the data layer and loads all the referenced assemblies defined in the assembly list text file
        /// in Options.AssemblyListPath and Options.AssemblyBaseDir
        /// </summary>
        private void Initialize()
        {
            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
            for (var i = 1; i <= config.Workers; i++)
            {
                var worker = new Worker(config, container, i);
                workerList.Add(worker);
            }
        }