/// <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); }
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; } }
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); }
public void ParseGuidInvalid() { RedisConverter.ParseGuid("Dummy"); }
public void ParseGuidEmpty() { RedisConverter.ParseGuid(string.Empty); }
public void ParseGuidNull() { RedisConverter.ParseGuid(null); }
public void ParseGuid() { Assert.AreEqual(Guid.Empty, RedisConverter.ParseGuid(RedisConverter.ToString(Guid.Empty))); }