示例#1
0
        /// <inheritdoc />
        public void Set(Type taskType, ITaskJobSettings settings)
        {
            Trace.WriteLine("ENTER: Setting task job settings '{0}' for task '{1}' ...".FormatInvariant(settings, taskType));

            if (taskType == null)
            {
                throw new ArgumentNullException(nameof(taskType));
            }

            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (!typeof(ITask).IsAssignableFrom(taskType))
            {
                throw new ArgumentException("Type '{0}' does not implement '{1}'.".FormatInvariant(taskType, typeof(ITask), nameof(taskType)));
            }

            byte[] content = this.serializer.Serialize(settings);

            if (this.serializer.CanDetermineEntityTypeFromContent)
            {
                this.provider.SetHashValue(RedisTaskJobSettingsRepository.RedisTaskJobSettingsHashKey, taskType.Name, content);
            }
            else
            {
                using (IRedisPipeline pipeline = this.provider.CreatePipeline())
                {
                    pipeline.SetHashValue(RedisTaskJobSettingsRepository.RedisTaskJobSettingsHashKey, taskType.Name, content);
                    pipeline.SetHashValue(RedisTaskJobSettingsRepository.RedisTaskJobSettingsHashKey, taskType.Name + "$Type", RedisConverter.ToString(settings.GetType(), false));

                    pipeline.Flush();
                }
            }

            Trace.WriteLine("EXIT: Task job settings '{0}' for task '{1}' set.".FormatInvariant(settings, taskType));
        }