/// <summary> /// Deserializes a task processor configuration from a Redis dictionary. /// </summary> /// <param name="values">The dictionary stored in Redis.</param> /// <param name="result">The instance where to deserialize the data.</param> /// <param name="prefix">The prefix that has been added before each dictionary key during serialization.</param> internal static void Deserialize(IReadOnlyDictionary <string, string> values, ITaskProcessorConfiguration result, string prefix) { if (!string.IsNullOrEmpty(prefix) && !prefix.EndsWith(".", StringComparison.Ordinal)) { prefix = prefix + "."; } RedisTaskProcessorConfigurationRepository.Deserialize(values, result.Tasks, prefix + "Tasks"); RedisTaskProcessorConfigurationRepository.Deserialize(values, result.PollingQueues, prefix + "PollingQueues"); RedisTaskProcessorConfigurationRepository.Deserialize(values, result.PollingJobs, prefix + "PollingJobs"); }
/// <summary> /// Serializes a task processor configuration to a dictionary to be stored in Redis. /// </summary> /// <param name="configuration">The configuration to serialize.</param> /// <param name="result">The dictionary where to add the serialized key/value pairs.</param> /// <param name="prefix">The prefix to add before each dictionary key.</param> internal static void Serialize(ITaskProcessorConfiguration configuration, IDictionary <string, string> result, string prefix) { if (!string.IsNullOrEmpty(prefix) && !prefix.EndsWith(".", StringComparison.Ordinal)) { prefix = prefix + "."; } RedisTaskProcessorConfigurationRepository.Serialize(configuration.Tasks, result, prefix + "Tasks"); RedisTaskProcessorConfigurationRepository.Serialize(configuration.PollingQueues, result, prefix + "PollingQueues"); RedisTaskProcessorConfigurationRepository.Serialize(configuration.PollingJobs, result, prefix + "PollingJobs"); }
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); }
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); } }
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 Serialize(ITaskProcessorPollingQueuesConfiguration configuration, IDictionary <string, string> result, string prefix) { if (!string.IsNullOrEmpty(prefix) && !prefix.EndsWith(".", StringComparison.Ordinal)) { prefix = prefix + "."; } foreach (ITaskProcessorPollingQueueConfiguration config in configuration) { result.Add( string.Concat(prefix, config.Key, ".Type"), RedisConverter.ToString(config.Key)); result.Add( string.Concat(prefix, config.Key, ".MaxWorkers"), RedisConverter.ToString(config.MaxWorkers)); RedisTaskProcessorConfigurationRepository.Serialize(config, result, prefix + config.Key); } }