/// <inheritdoc />
        public void Complete(Guid taskId, DateTime timestampUtc)
        {
            Trace.WriteLine("ENTER: Record task '{0}' completed ...".FormatInvariant(taskId));

            string taskIdAsString = RedisConverter.ToString(taskId);

            string entityKey = RedisTaskRuntimeInfoRepository.GetEntityKey(taskIdAsString);

            RedisTaskRuntimeInfo taskInfo = this.GetById(taskId, false);

            taskInfo.Percentage   = 100;
            taskInfo.Status       = TaskStatus.Success;
            taskInfo.CompletedUtc = timestampUtc;

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

            using (IRedisTransaction transaction = this.Provider.CreateTransaction())
            {
                transaction.RemoveKey(entityKey);
                transaction.RemoveFromList(RedisTaskRuntimeInfoRepository.ActiveTasksList, taskIdAsString);
                transaction.SetHashValue(RedisTaskRuntimeInfoRepository.ArchiveTasksHash, taskIdAsString, content);

                transaction.Commit();
            }

            Trace.WriteLine("EXIT: Task '{0}' completed recorded.".FormatInvariant(taskId));
        }
        private void OnMessage(string channel, string message)
        {
            Trace.WriteLine("ENTER: Receiving message '{0}' on channel '{1}' ...".FormatInvariant(message, channel));

            if (channel == ServiceStackSubscription.UnsubscribeChannel)
            {
                if (string.IsNullOrEmpty(message))
                {
                    this.subscription.UnSubscribeFromAllChannels();
                }
                else
                {
                    string[] channelToUnsubscribe = RedisConverter.ParseCollection <string>(message).ToArray();

                    this.subscription.UnSubscribeFromChannels(channelToUnsubscribe);
                }
            }
            else
            {
                EventHandler <RedisMessageEventArgs> messageReceivedEventHandler = this.MessageReceived;

                if (messageReceivedEventHandler != null)
                {
                    messageReceivedEventHandler(this, new RedisMessageEventArgs(channel, message));
                }
            }

            Trace.WriteLine("EXIT: Message '{0}' received on channel '{1}'.".FormatInvariant(message, channel));
        }
        private RedisTaskRuntimeInfo GetById(Guid taskId, bool fromArchive)
        {
            string taskIdAsString = RedisConverter.ToString(taskId);

            string entityKey = RedisTaskRuntimeInfoRepository.GetEntityKey(taskIdAsString);

            if (fromArchive)
            {
                byte[] content = this.provider.GetHashBinaryValue(RedisTaskRuntimeInfoRepository.ArchiveTasksHash, taskIdAsString);

                if (content == null)
                {
                    return(null);
                }

                return((RedisTaskRuntimeInfo)this.serializer.Deserialize(content, typeof(RedisTaskRuntimeInfo)));
            }
            else
            {
                IReadOnlyDictionary <string, string> values = this.provider.GetHashAsText(entityKey);

                if (values.Count == 0)
                {
                    return(null);
                }

                return(RedisTaskRuntimeInfoRepository.Convert(values));
            }
        }
Exemple #4
0
        /// <summary>
        /// De-serialize a <see cref="TaskProcessorPerformanceReport"/> instance from <see cref="String"/>.
        /// </summary>
        /// <param name="value">The string to de-serialize.</param>
        /// <returns>A <see cref="TaskProcessorPerformanceReport"/> instance de-serialized from the specified string.</returns>
        /// <exception cref="ArgumentNullException">Parameter <paramref name="value"/> is null or empty string.</exception>
        protected static TaskProcessorPerformanceReport DeserializeTaskProcessorPerformanceInfo(string value)
        {
            Trace.WriteLine("ENTER: De-serializing '{0}' to {1} ...".FormatInvariant(value, typeof(TaskProcessorPerformanceReport).Name));

            if (string.IsNullOrEmpty(value))
            {
                throw new ArgumentNullException("value");
            }

            string[] values1 = value.Split('#');

            string[] values2 = values1[0].Split(';');

            TaskProcessorPerformanceReport result = new TaskProcessorPerformanceReport(RedisConverter.ParseGuid(values2[0]))
            {
                CpuPercent = RedisConverter.ParseInteger(values2[1]),
                RamPercent = RedisConverter.ParseInteger(values2[2]),
            };

            for (int i = 1; i < values1.Length; i++)
            {
                values2 = values1[i].Split(';');

                result.TasksPerformance.Add(new TaskPerformanceReport(RedisConverter.ParseGuid(values2[0]))
                {
                    CpuPercent = RedisConverter.ParseFloat(values2[1]),
                    RamPercent = RedisConverter.ParseFloat(values2[2]),
                });
            }

            Trace.WriteLine("EXIT: '{0}' de-serialized to {1}.".FormatInvariant(value, typeof(TaskProcessorPerformanceReport).Name));

            return(result);
        }
        /// <inheritdoc />
        public void Add(Guid taskId, ITaskSummary summary)
        {
            Trace.WriteLine("ENTER: Adding summary '{0}' for task '{1}' ...".FormatInvariant(summary, taskId));

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

            string taskIdAsString = RedisConverter.ToString(taskId);

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

            if (this.serializer.CanDetermineEntityTypeFromContent)
            {
                this.provider.SetHashValue(RedisTaskSummaryRepository.RedisTaskSummaryHashKey, taskIdAsString, content);
            }
            else
            {
                using (IRedisTransaction transaction = this.provider.CreateTransaction())
                {
                    transaction.SetHashValue(RedisTaskSummaryRepository.RedisTaskSummaryHashKey, taskIdAsString, content);
                    transaction.SetHashValue(RedisTaskSummaryRepository.RedisTaskSummaryHashKey, taskIdAsString + "$Type", RedisConverter.ToString(summary.GetType(), false));

                    transaction.Commit();
                }
            }

            Trace.WriteLine("EXIT: Summary '{0}' added for task '{1}'.".FormatInvariant(summary, taskId));
        }
Exemple #6
0
        /// <summary>
        /// Serializes task processor performance info to <see cref="String"/>.
        /// </summary>
        /// <param name="performanceInfo">The performance info to serialize.</param>
        /// <returns>A string representing the task processor performance info.</returns>
        /// <exception cref="ArgumentNullException">Parameter <paramref name="performanceInfo"/> is null.</exception>
        public static string SerializeTaskProcessorPerformanceInfo(TaskProcessorPerformanceReport performanceInfo)
        {
            if (performanceInfo == null)
            {
                throw new ArgumentNullException("performanceInfo");
            }

            Trace.WriteLine("ENTER: Serializing {0} ...".FormatInvariant(performanceInfo.GetType().Name));

            StringBuilder result = new StringBuilder();

            result.AppendFormat(
                "{0};{1};{2}",
                RedisConverter.ToString(performanceInfo.TaskProcessorId),
                RedisConverter.ToString(performanceInfo.CpuPercent),
                RedisConverter.ToString(performanceInfo.RamPercent));

            foreach (TaskPerformanceReport taskPerformance in performanceInfo.TasksPerformance)
            {
                result.AppendFormat(
                    "#{0};{1};{2}",
                    RedisConverter.ToString(taskPerformance.TaskId),
                    RedisConverter.ToString(taskPerformance.CpuPercent),
                    RedisConverter.ToString(taskPerformance.RamPercent));
            }

            Trace.WriteLine("EXIT: {0} serialized to {1}.".FormatInvariant(performanceInfo.GetType().Name, result));

            return(result.ToString());
        }
        /// <summary>
        /// Reads the value from the cache for a specific key
        /// </summary>
        /// <typeparam name="TExpected">Expected type of the value</typeparam>
        /// <param name="keyName">Name of the key</param>
        /// <returns>Value for the key</returns>
        public Maybe <TExpected> Read <TExpected>(ICacheKey key)
        {
            try
            {
                // Retrieve the default db
                IDatabase defaultDb = GetDefaultRedisDb(readOnly: true);

                // Read the value
                RedisValue redisValue = defaultDb.StringGet(key.Name);
                if (redisValue.IsNull)
                {
                    return(new Maybe <TExpected>());
                }

                // Parse to the expected type
                TExpected value = RedisConverter.ConvertTo <TExpected>(redisValue);

                return(new Maybe <TExpected>(value));
            }
            catch (Exception ex)
            {
                string exceptionMessage = string.Format("Something went wrong while reading the key '{0}' from the cache.", key.Name);
                var    cacheException   = new CacheException(exceptionMessage, ex);

                return(new Maybe <TExpected>());
            }
        }
        private void AddOrUpdate(IScheduledTask scheduledTask)
        {
            string taskIdAsString = RedisConverter.ToString(scheduledTask.Id);

            if (this.serializer.CanDetermineEntityTypeFromContent)
            {
                this.provider.SetHashValues(
                    RedisScheduledTaskRepository.ScheduledTasksHashKey,
                    new Dictionary <string, byte[]>()
                {
                    { taskIdAsString + "$Content", this.serializer.Serialize(scheduledTask) },
                    { taskIdAsString + "$RecurrenceDefinition", this.serializer.Serialize(scheduledTask.Schedule) }
                });
            }
            else
            {
                using (IRedisTransaction transaction = this.provider.CreateTransaction())
                {
                    transaction.SetHashValue(RedisScheduledTaskRepository.ScheduledTasksHashKey, taskIdAsString + "$Content", this.serializer.Serialize(scheduledTask));
                    transaction.SetHashValue(RedisScheduledTaskRepository.ScheduledTasksHashKey, taskIdAsString + "$Type", RedisConverter.ToString(scheduledTask.GetType(), false));
                    transaction.SetHashValue(RedisScheduledTaskRepository.ScheduledTasksHashKey, taskIdAsString + "$RecurrenceDefinition", this.serializer.Serialize(scheduledTask.Schedule));
                    transaction.SetHashValue(RedisScheduledTaskRepository.ScheduledTasksHashKey, taskIdAsString + "$RecurrenceDefinition$Type", RedisConverter.ToString(scheduledTask.Schedule.GetType(), false));

                    transaction.Commit();
                }
            }
        }
        /// <inheritdoc />
        public void Fail(Guid taskId, DateTime timestampUtc, Exception error)
        {
            if (error == null)
            {
                throw new ArgumentNullException(nameof(error));
            }

            Trace.WriteLine("ENTER: Record task '{0}' failed with error '{1}' ...".FormatInvariant(taskId, error.Message));

            string taskIdAsString = RedisConverter.ToString(taskId);

            string entityKey = RedisTaskRuntimeInfoRepository.GetEntityKey(taskIdAsString);

            RedisTaskRuntimeInfo taskInfo = this.GetById(taskId, false);

            taskInfo.Status       = TaskStatus.Failed;
            taskInfo.CompletedUtc = timestampUtc;
            taskInfo.Error        = error.ToString();

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

            using (IRedisTransaction transaction = this.Provider.CreateTransaction())
            {
                transaction.RemoveKey(entityKey);
                transaction.RemoveFromList(RedisTaskRuntimeInfoRepository.ActiveTasksList, taskIdAsString);
                transaction.AddToList(RedisTaskRuntimeInfoRepository.FailedTasksList, taskIdAsString);
                transaction.SetHashValue(RedisTaskRuntimeInfoRepository.ArchiveTasksHash, taskIdAsString, content);

                transaction.Commit();
            }

            Trace.WriteLine("EXIT: Task '{0}' failed with error '{1}' recorded.".FormatInvariant(taskId, error.Message));
        }
        /// <inheritdoc />
        public void Add(Guid taskId, ITask task)
        {
            Trace.WriteLine("ENTER: Adding task '{0}' with ID '{1}' ...".FormatInvariant(task, taskId));

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

            string taskIdAsString = RedisConverter.ToString(taskId);

            if (this.serializer.CanDetermineEntityTypeFromContent)
            {
                this.provider.SetHashValue(RedisTaskRepository.TasksHashKey, taskIdAsString, this.serializer.Serialize(task));
            }
            else
            {
                using (IRedisTransaction transaction = this.provider.CreateTransaction())
                {
                    transaction.SetHashValue(RedisTaskRepository.TasksHashKey, taskIdAsString, this.serializer.Serialize(task));
                    transaction.SetHashValue(RedisTaskRepository.TasksHashKey, taskIdAsString + "$Type", RedisConverter.ToString(task.GetType(), true));

                    transaction.Commit();
                }
            }

            Trace.WriteLine("EXIT: Task '{0}' with ID '{1}' added.".FormatInvariant(task, taskId));
        }
        private static void ParseCollection <T>(params T[] values)
        {
            string value = RedisConverter.ToString(values);

            IEnumerable <T> values2 = RedisConverter.ParseCollection <T>(value);

            CollectionAssert.AreEquivalent(values, values2.ToList());
        }
        private static RedisTaskRuntimeInfo Convert(IReadOnlyDictionary <string, string> values)
        {
            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            RedisTaskRuntimeInfo result = new RedisTaskRuntimeInfo(
                RedisConverter.ParseGuid(values["Id"]),
                RedisConverter.ParseType(values["TaskType"]),
                RedisConverter.ParseDateTime(values["SubmittedUtc"]),
                RedisConverter.ParseEnum <TaskStatus>(values["Status"]));

            string value;

            if (values.TryGetValue("PollingQueue", out value))
            {
                result.PollingQueue = value;
            }

            if (values.TryGetValue("Priority", out value))
            {
                result.Priority = RedisConverter.ParseEnum <TaskPriority>(value);
            }

            if (values.TryGetValue("TaskProcessorId", out value))
            {
                result.TaskProcessorId = RedisConverter.ParseGuidOrNull(value);
            }

            if (values.TryGetValue("StartedUtc", out value))
            {
                result.StartedUtc = RedisConverter.ParseDateTimeOrNull(value);
            }

            if (values.TryGetValue("Percentage", out value))
            {
                result.Percentage = RedisConverter.ParseDouble(value);
            }

            if (values.TryGetValue("CanceledUtc", out value))
            {
                result.CanceledUtc = RedisConverter.ParseDateTimeOrNull(value);
            }

            if (values.TryGetValue("CompletedUtc", out value))
            {
                result.CompletedUtc = RedisConverter.ParseDateTimeOrNull(value);
            }

            if (values.TryGetValue("Error", out value))
            {
                result.Error = value;
            }

            return(result);
        }
        private void OnMessageReceived(object sender, RedisMessageEventArgs e)
        {
            switch (e.Channel)
            {
            case RedisScheduledTaskRepository.Channel:
                string[] data = RedisConverter.ParseCollection <string>(e.Message).ToArray();

                if (data.Length != 2)
                {
                    Trace.TraceWarning("Message '{0}' received on channel '{1}' cannot be parsed.", e.Message, e.Channel);

                    return;
                }

                Guid scheduledTaskId;

                try
                {
                    scheduledTaskId = RedisConverter.ParseGuid(data[1]);
                }
                catch (ArgumentException ex)
                {
                    Trace.TraceWarning(ex.Message);

                    return;
                }

                EventHandler <ScheduledTaskEventArgs> handler = null;

                switch (data[0])
                {
                case "Add":
                    handler = this.Added;
                    break;

                case "Update":
                    handler = this.Updated;
                    break;

                case "Delete":
                    handler = this.Deleted;
                    break;

                default:
                    Trace.TraceWarning("Unknown command in message '{0}' received on channel '{1}'.", e.Message, e.Channel);
                    return;
                }

                if (handler != null)
                {
                    handler(this, new ScheduledTaskEventArgs(scheduledTaskId));
                }

                break;
            }
        }
        /// <inheritdoc />
        public void Delete(Guid taskId)
        {
            Trace.WriteLine("ENTER: Deleting task '{0}' ...".FormatInvariant(taskId));

            string taskIdAsString = RedisConverter.ToString(taskId);

            this.provider.RemoveFromHash(RedisTaskRepository.TasksHashKey, taskIdAsString, taskIdAsString + "$Type");

            Trace.WriteLine("EXIT: Task '{0}' deleted.".FormatInvariant(taskId));
        }
        /// <inheritdoc />
        public void Assign(Guid taskId, Guid?taskProcessorId)
        {
            Trace.WriteLine("ENTER: Recording task '{0}' assigned to processor '{1}' ...".FormatInvariant(taskId, taskProcessorId));

            string entityKey = RedisTaskRuntimeInfoRepository.GetEntityKey(taskId);

            this.Provider.SetHashValue(entityKey, "TaskProcessorId", RedisConverter.ToString(taskProcessorId));

            Trace.WriteLine("EXIT: Task '{0}' assigned to processor '{1}' recorded.".FormatInvariant(taskId, taskProcessorId));
        }
Exemple #16
0
        private static IReadOnlyDictionary <string, string> Serialize(ITaskProcessorRuntimeInfo taskProcessorInfo)
        {
            Dictionary <string, string> result = new Dictionary <string, string>()
            {
                { "Id", RedisConverter.ToString(taskProcessorInfo.TaskProcessorId) },
                { "MachineName", RedisConverter.ToString(taskProcessorInfo.MachineName) }
            };

            RedisTaskProcessorConfigurationRepository.Serialize(taskProcessorInfo.Configuration, result, "Configuration");

            return(result);
        }
        /// <inheritdoc />
        public void Progress(Guid taskId, double percentage)
        {
            Trace.WriteLine("ENTER: Record task '{0}' progress to {1}% ...".FormatInvariant(taskId, percentage));

            if ((percentage < 0) || (percentage > 100))
            {
                throw new ArgumentOutOfRangeException("percentage");
            }

            string entityKey = RedisTaskRuntimeInfoRepository.GetEntityKey(taskId);

            this.Provider.SetHashValue(entityKey, "Percentage", RedisConverter.ToString(percentage));

            Trace.WriteLine("ENTER: Task '{0}' progress to {1}% recorded.".FormatInvariant(taskId, percentage));
        }
        public async Task <Book> CreateBook(Book book)
        {
            var db = await _redisProvider.Database();

            var bookKey   = new RedisKey(book.GetType().Name + ":" + book.Id);
            var authorKey = new RedisKey(book.GetType().Name + ":" + book.Id + ":authors");
            await db.HashSetAsync(bookKey, RedisConverter.ToHashEntries(book));

            foreach (var author in book.Authors)
            {
                await db.SetAddAsync(authorKey, author);
            }

            return(await GetBook(book.Id));
        }
        public async Task <Book> GetBook(string id)
        {
            var db = await _redisProvider.Database();

            var bookKey   = new RedisKey(new Book().GetType().Name + ":" + id);
            var authorKey = new RedisKey(new Book().GetType().Name + ":" + id + ":authors");

            var bookHash = db.HashGetAll(bookKey);
            var book     = RedisConverter.ConvertFromRedis <Book>(bookHash);
            var authors  = db.SetMembers(authorKey);

            book.Authors = authors.Select(author => author.ToString()).ToArray();

            return(book);
        }
Exemple #20
0
        private static ITaskProcessorRuntimeInfo Convert(IReadOnlyDictionary <string, string> values)
        {
            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            RedisTaskProcessorRuntimeInfo result = new RedisTaskProcessorRuntimeInfo(
                RedisConverter.ParseGuid(values["Id"]),
                values["MachineName"]);

            RedisTaskProcessorConfigurationRepository.Deserialize(values, result.Configuration, "Configuration");

            return(result);
        }
        private static void Deserialize(IReadOnlyDictionary <string, string> values, IPollingJobsConfiguration result, string prefix)
        {
            if (!string.IsNullOrEmpty(prefix) && !prefix.EndsWith(".", StringComparison.Ordinal))
            {
                prefix = prefix + ".";
            }

            foreach (KeyValuePair <string, string> pair in values.Where(v => v.Key.StartsWith(prefix, StringComparison.Ordinal) && v.Key.EndsWith(".Type", StringComparison.Ordinal)))
            {
                Type implementationType = RedisConverter.ParseType(pair.Value);

                IPollingJobConfiguration config = result.Add(implementationType);

                RedisTaskProcessorConfigurationRepository.Deserialize(values, config, prefix + implementationType.Name);
            }
        }
        private static void Serialize(IPollingJobsConfiguration configuration, IDictionary <string, string> result, string prefix)
        {
            if (!string.IsNullOrEmpty(prefix) && !prefix.EndsWith(".", StringComparison.Ordinal))
            {
                prefix = prefix + ".";
            }

            foreach (IPollingJobConfiguration config in configuration)
            {
                result.Add(
                    string.Concat(prefix, config.ImplementationType.Name, ".Type"),
                    RedisConverter.ToString(config.ImplementationType, false));

                RedisTaskProcessorConfigurationRepository.Serialize(config, result, prefix + config.ImplementationType.Name);
            }
        }
        /// <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);
        }
        /// <inheritdoc />
        public void Add(ITaskRuntimeInfo taskInfo)
        {
            if (taskInfo == null)
            {
                throw new ArgumentNullException("taskInfo");
            }

            Trace.WriteLine("ENTER: Adding runtime information for task '{0}' of type '{1}' with priority '{2}' in polling queue '{3}' ...".FormatInvariant(taskInfo.TaskId, taskInfo.TaskType, taskInfo.Priority, taskInfo.PollingQueue));

            taskInfo.ValidateForAdd();

            string entityKey = RedisTaskRuntimeInfoRepository.GetEntityKey(taskInfo.TaskId);

            string addToListKey;

            Dictionary <string, string> values = new Dictionary <string, string>()
            {
                { "Id", RedisConverter.ToString(taskInfo.TaskId) },
                { "TaskType", RedisConverter.ToString(taskInfo.TaskType, true) },
                { "SubmittedUtc", RedisConverter.ToString(taskInfo.SubmittedUtc) },
                { "Status", RedisConverter.ToString(taskInfo.Status) }
            };

            if (string.IsNullOrEmpty(taskInfo.PollingQueue))
            {
                values.Add("Priority", RedisConverter.ToString(taskInfo.Priority));

                addToListKey = RedisTaskRuntimeInfoRepository.PendingTasksList;
            }
            else
            {
                values.Add("PollingQueue", taskInfo.PollingQueue);

                addToListKey = RedisTaskRuntimeInfoRepository.GetPollingQueueRedisKey(taskInfo.PollingQueue, TaskStatus.Pending);
            }

            using (IRedisTransaction transaction = this.Provider.CreateTransaction())
            {
                transaction.SetHashValues(entityKey, values);

                transaction.AddToList(addToListKey, RedisConverter.ToString(taskInfo.TaskId));

                transaction.Commit();
            }

            Trace.WriteLine("EXIT: Runtime information for task '{0}' of type '{1}' with priority '{2}' in polling queue '{3}' added.".FormatInvariant(taskInfo.TaskId, taskInfo.TaskType, taskInfo.Priority, taskInfo.PollingQueue));
        }
        /// <inheritdoc />
        public void CompleteCancel(Guid taskId, DateTime timestampUtc)
        {
            Trace.WriteLine("ENTER: Record task '{0}' cancel completed ...".FormatInvariant(taskId));

            string taskIdAsString = RedisConverter.ToString(taskId);

            RedisTaskRuntimeInfo taskInfo = this.GetById(taskId, true);

            taskInfo.Status       = TaskStatus.Canceled;
            taskInfo.CompletedUtc = timestampUtc;

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

            this.provider.SetHashValue(RedisTaskRuntimeInfoRepository.ArchiveTasksHash, taskIdAsString, content);

            Trace.WriteLine("EXIT: Task '{0}' cancel completed recorded.".FormatInvariant(taskId));
        }
        /// <inheritdoc />
        public void Delete(Guid scheduledTaskId)
        {
            Trace.WriteLine("ENTER: Deleting scheduled task '{0}' ...".FormatInvariant(scheduledTaskId));

            string taskIdAsString = RedisConverter.ToString(scheduledTaskId);

            this.provider.RemoveFromHash(
                RedisScheduledTaskRepository.ScheduledTasksHashKey,
                taskIdAsString + "$Content",
                taskIdAsString + "$Type",
                taskIdAsString + "$RecurrenceDefinition",
                taskIdAsString + "$RecurrenceDefinition$Type");

            this.provider.PublishMessage(RedisScheduledTaskRepository.Channel, RedisConverter.ToString("Delete", scheduledTaskId));

            Trace.WriteLine("EXIT: Scheduled task '{0}' deleted.".FormatInvariant(scheduledTaskId));
        }
        private static void Serialize(IPollingConfiguration queueConfig, IDictionary <string, string> result, string prefix)
        {
            result.Add(
                string.Concat(prefix, ".Interval"),
                RedisConverter.ToString(queueConfig.PollInterval));

            result.Add(
                string.Concat(prefix, ".Master"),
                RedisConverter.ToString(queueConfig.IsMaster));

            result.Add(
                string.Concat(prefix, ".Active"),
                RedisConverter.ToString(queueConfig.IsActive));

            result.Add(
                string.Concat(prefix, ".Concurrent"),
                RedisConverter.ToString(queueConfig.IsConcurrent));
        }
        private static void Deserialize(IReadOnlyDictionary <string, string> values, ITaskProcessorPollingQueuesConfiguration result, string prefix)
        {
            if (!string.IsNullOrEmpty(prefix) && !prefix.EndsWith(".", StringComparison.Ordinal))
            {
                prefix = prefix + ".";
            }

            foreach (KeyValuePair <string, string> pair in values.Where(v => v.Key.StartsWith(prefix, StringComparison.Ordinal) && v.Key.EndsWith(".Type", StringComparison.Ordinal)))
            {
                string key = pair.Value;

                ITaskProcessorPollingQueueConfiguration config = result.Add(key);

                config.MaxWorkers = RedisConverter.ParseInteger(values[prefix + key + ".MaxWorkers"]);

                RedisTaskProcessorConfigurationRepository.Deserialize(values, config, prefix + key);
            }
        }
        private static void Deserialize(IReadOnlyDictionary <string, string> values, IPollingConfiguration result, string prefix)
        {
            string key = string.Concat(prefix, ".Interval");

            result.PollInterval = RedisConverter.ParseTimeSpan(values[key]);

            key = string.Concat(prefix, ".Master");

            result.IsMaster = RedisConverter.ParseBoolean(values[key]);

            key = string.Concat(prefix, ".Active");

            result.IsActive = RedisConverter.ParseBoolean(values[key]);

            key = string.Concat(prefix, ".Concurrent");

            result.IsConcurrent = RedisConverter.ParseBoolean(values[key]);
        }
 public void IsSupported()
 {
     Assert.IsTrue(RedisConverter.IsSupported(typeof(string)));
     Assert.IsTrue(RedisConverter.IsSupported(typeof(bool)));
     Assert.IsTrue(RedisConverter.IsSupported(typeof(bool?)));
     Assert.IsTrue(RedisConverter.IsSupported(typeof(int)));
     Assert.IsTrue(RedisConverter.IsSupported(typeof(int?)));
     Assert.IsTrue(RedisConverter.IsSupported(typeof(long)));
     Assert.IsTrue(RedisConverter.IsSupported(typeof(long?)));
     Assert.IsTrue(RedisConverter.IsSupported(typeof(Guid)));
     Assert.IsTrue(RedisConverter.IsSupported(typeof(Guid?)));
     Assert.IsTrue(RedisConverter.IsSupported(typeof(TimeSpan)));
     Assert.IsTrue(RedisConverter.IsSupported(typeof(TimeSpan?)));
     Assert.IsTrue(RedisConverter.IsSupported(typeof(DateTime)));
     Assert.IsTrue(RedisConverter.IsSupported(typeof(DateTime?)));
     Assert.IsTrue(RedisConverter.IsSupported(typeof(DisposeState)));
     Assert.IsTrue(RedisConverter.IsSupported(typeof(DisposeState?)));
     Assert.IsTrue(RedisConverter.IsSupported(typeof(Type)));
     Assert.IsTrue(RedisConverter.IsSupported(typeof(Version)));
 }