/// <inheritdoc />
        public IScheduledTask GetById(Guid scheduledTaskId)
        {
            Trace.WriteLine("ENTER: Getting scheduled task with ID '{0}' ...".FormatInvariant(scheduledTaskId));

            string taskIdAsString = RedisConverter.ToString(scheduledTaskId);

            IScheduledTask result;

            byte[] scheduledTaskContent        = null;
            byte[] recurrenceDefinitionContent = null;

            using (IRedisPipeline pipeline = this.provider.CreatePipeline())
            {
                pipeline.GetHashBinaryValue(RedisScheduledTaskRepository.ScheduledTasksHashKey, taskIdAsString + "$Content", value => scheduledTaskContent = value);
                pipeline.GetHashBinaryValue(RedisScheduledTaskRepository.ScheduledTasksHashKey, taskIdAsString + "$RecurrenceDefinition", value => recurrenceDefinitionContent = value);

                if (this.serializer.CanDetermineEntityTypeFromContent)
                {
                    pipeline.Flush();

                    if ((scheduledTaskContent == null) || (scheduledTaskContent.Length == 0) || (recurrenceDefinitionContent == null) || (recurrenceDefinitionContent.Length == 0))
                    {
                        return(null);
                    }

                    result = (IScheduledTask)this.serializer.Deserialize(scheduledTaskContent);

                    result.Schedule = (IScheduleDefinition)this.serializer.Deserialize(recurrenceDefinitionContent);
                }
                else
                {
                    string scheduledTaskType        = null;
                    string recurrenceDefinitionType = null;

                    pipeline.GetHashTextValue(RedisScheduledTaskRepository.ScheduledTasksHashKey, taskIdAsString + "$Type", value => scheduledTaskType = value);
                    pipeline.GetHashTextValue(RedisScheduledTaskRepository.ScheduledTasksHashKey, taskIdAsString + "$RecurrenceDefinition$Type", value => recurrenceDefinitionType = value);

                    pipeline.Flush();

                    result = this.Deserialize(scheduledTaskId.ToString(), scheduledTaskContent, scheduledTaskType, recurrenceDefinitionContent, recurrenceDefinitionType);
                }
            }

            Trace.WriteLine("EXIT: Scheduled task '{0}' with ID '{1}' returned.".FormatInvariant(result, scheduledTaskId));

            return(result);
        }
Beispiel #2
0
        /// <inheritdoc />
        public ITaskJobSettings Get(Type taskType)
        {
            Trace.WriteLine("ENTER: Getting task job settings for task '{0}' ...".FormatInvariant(taskType));

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

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

            ITaskJobSettings result;

            if (this.serializer.CanDetermineEntityTypeFromContent)
            {
                byte[] content = this.provider.GetHashBinaryValue(RedisTaskJobSettingsRepository.RedisTaskJobSettingsHashKey, taskType.Name);

                result = (ITaskJobSettings)this.serializer.Deserialize(content);
            }
            else
            {
                byte[] content = null;

                string settingsTypeAsString = null;

                using (IRedisPipeline pipeline = this.provider.CreatePipeline())
                {
                    pipeline.GetHashBinaryValue(RedisTaskJobSettingsRepository.RedisTaskJobSettingsHashKey, taskType.Name, value => content = value);
                    pipeline.GetHashTextValue(RedisTaskJobSettingsRepository.RedisTaskJobSettingsHashKey, taskType.Name + "$Type", value => settingsTypeAsString = value);

                    pipeline.Flush();
                }

                if ((content == null) || (content.Length == 0))
                {
                    return(null);
                }

                if (string.IsNullOrEmpty(settingsTypeAsString))
                {
#if DEBUG
                    throw new TypeNotFoundInRedisException("Task job settings type for task '{0}' was not found in Redis.".FormatInvariant(taskType));
#else
                    Trace.TraceWarning("EXIT: Task job settings type for task '{0}' was not found in Redis.".FormatInvariant(taskType));

                    return(null);
#endif
                }

                Type settingsType;

#if DEBUG
                settingsType = Type.GetType(settingsTypeAsString, true);
#else
                settingsType = Type.GetType(settingsTypeAsString, false);

                if (settingsType == null)
                {
                    Trace.TraceWarning("EXIT: Task job settings type '{0}' cannot be resolved.", settingsTypeAsString);

                    return(null);
                }
#endif

                result = (ITaskJobSettings)this.serializer.Deserialize(content, settingsType);
            }

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

            return(result);
        }
        /// <inheritdoc />
        public ITaskSummary GetById(Guid taskId)
        {
            Trace.WriteLine("ENTER: Getting summary for task '{0}' ...".FormatInvariant(taskId));

            string taskIdAsString = RedisConverter.ToString(taskId);

            byte[] content = null;

            ITaskSummary result;

            if (this.serializer.CanDetermineEntityTypeFromContent)
            {
                content = this.provider.GetHashBinaryValue(RedisTaskSummaryRepository.RedisTaskSummaryHashKey, taskIdAsString);

                result = (ITaskSummary)this.serializer.Deserialize(content);
            }
            else
            {
                string summaryTypeAsString = null;

                using (IRedisPipeline pipeline = this.provider.CreatePipeline())
                {
                    pipeline.GetHashBinaryValue(RedisTaskSummaryRepository.RedisTaskSummaryHashKey, taskIdAsString, value => content = value);
                    pipeline.GetHashTextValue(RedisTaskSummaryRepository.RedisTaskSummaryHashKey, taskIdAsString + "$Type", value => summaryTypeAsString = value);

                    pipeline.Flush();
                }

                if ((content == null) || (content.Length == 0))
                {
                    return(null);
                }

                if (string.IsNullOrEmpty(summaryTypeAsString))
                {
#if DEBUG
                    throw new TypeNotFoundInRedisException("Task summary type for task '{0}' was not found in Redis.".FormatInvariant(taskId));
#else
                    Trace.TraceWarning("EXIT: Task summary type for task '{0}' was not found in Redis.".FormatInvariant(taskId));

                    return(null);
#endif
                }

                Type summaryType;

#if DEBUG
                summaryType = Type.GetType(summaryTypeAsString, true);
#else
                summaryType = Type.GetType(summaryTypeAsString, false);

                if (summaryType == null)
                {
                    Trace.TraceWarning("EXIT: Task summary type '{0}' cannot be resolved.", summaryTypeAsString);

                    return(null);
                }
#endif

                result = (ITaskSummary)this.serializer.Deserialize(content, summaryType);
            }

            Trace.WriteLine("EXIT: Return task summary '{0}' for task '{1}'.".FormatInvariant(result, taskId));

            return(result);
        }