示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AsyncBackgroundProcessingServer"/>
        /// class and immediately starts all the given background processes.
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="processes"></param>
        /// <param name="properties"></param>
        /// <param name="options"></param>
        public AsyncBackgroundProcessingServer(
            [NotNull] JobStorage storage,
            [NotNull] IEnumerable <ITaskSource> processes,
            [NotNull] IDictionary <string, object> properties,
            [NotNull] BackgroundProcessingServerOptions options)
        {
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }
            if (processes == null)
            {
                throw new ArgumentNullException(nameof(processes));
            }
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _options = options;

            _processes.AddRange(GetRequiredTasks().Select(ExtensionMethods.Wrap));
            _processes.AddRange(storage.GetComponents().OfType <IBackgroundProcess>()
                                .Select(ExtensionMethods.Loop).Select(ExtensionMethods.Wrap));
            _processes.AddRange(processes);

            var context = new BackgroundProcessContext(
                GetGloballyUniqueServerId(),
                storage,
                properties,
                _cts.Token);

            _bootstrapTask = new BackgroundProcessWrapper(this).CreateTask(context);
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BackgroundProcessingServer"/>
        /// class and immediately starts all the given background processes.
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="processes"></param>
        /// <param name="properties"></param>
        /// <param name="options"></param>
        public BackgroundProcessingServer(
            [NotNull] JobStorage storage,
            [NotNull] IEnumerable <IBackgroundProcess> processes,
            [NotNull] IDictionary <string, object> properties,
            [NotNull] BackgroundProcessingServerOptions options)
        {
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }
            if (processes == null)
            {
                throw new ArgumentNullException(nameof(processes));
            }
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _options = options;

            _processes.AddRange(GetRequiredProcesses());
            _processes.AddRange(storage.GetComponents());
            _processes.AddRange(processes);

            var context = new BackgroundProcessContext(
                GetGloballyUniqueServerId(),
                storage,
                properties,
                _cts.Token);

            _bootstrapTask = WrapProcess(this).CreateTask(context);
        }
 private IEnumerable <IBackgroundProcessDispatcherBuilder> GetStorageComponents()
 {
     return(_storage.GetComponents().Select(component => new ServerProcessDispatcherBuilder(
                                                component,
                                                threadStart => BackgroundProcessExtensions.DefaultThreadFactory(1, component.GetType().Name, threadStart))));
 }