private static void WriteRuntimeValue(BinaryWriter writer, RuntimeValue value) { var type = value.ValueType; writer.Write((byte)type); if (type == RuntimeValueType.Scalar) { writer.Write(value.AsString() ?? string.Empty); } else if (type == RuntimeValueType.Vector) { var list = value.AsEnumerable().ToList(); SlimBinaryFormatter.WriteLength(writer, list.Count); foreach (var i in list) { WriteRuntimeValue(writer, i); } } else if (type == RuntimeValueType.Map) { WriteDictionary(writer, value.AsDictionary()); } else { throw new ArgumentException("Unknown value type: " + type); } }
public override object DeserializeResponse(Stream stream) { var reader = new BinaryReader(stream, InedoLib.UTF8Encoding); int?exitCode; if (stream.ReadByte() == 0) { exitCode = null; } else { exitCode = reader.ReadInt32(); } int count = SlimBinaryFormatter.ReadLength(stream); var output = new List <RuntimeValue>(count); for (int i = 0; i < count; i++) { output.Add(ReadRuntimeValue(reader)); } var vars = ReadDictionary(reader); return(new Result { ExitCode = exitCode, Output = output, OutVariables = vars }); }
private static RuntimeValue ReadRuntimeValue(BinaryReader reader) { var type = (RuntimeValueType)reader.ReadByte(); if (type == RuntimeValueType.Scalar) { return(reader.ReadString()); } else if (type == RuntimeValueType.Vector) { int length = SlimBinaryFormatter.ReadLength(reader); var list = new List <RuntimeValue>(length); for (int i = 0; i < length; i++) { list.Add(ReadRuntimeValue(reader)); } return(new RuntimeValue(list)); } else if (type == RuntimeValueType.Map) { return(new RuntimeValue(ReadDictionary(reader))); } else { throw new InvalidDataException("Unknown value type: " + type); } }
public override void SerializeResponse(Stream stream, object result) { var data = (Result)result; var writer = new BinaryWriter(stream, InedoLib.UTF8Encoding); if (data.ExitCode == null) { stream.WriteByte(0); } else { writer.Write((byte)1); writer.Write(data.ExitCode.Value); } SlimBinaryFormatter.WriteLength(stream, data.Output.Count); foreach (var s in data.Output) { WriteRuntimeValue(writer, s); } SlimBinaryFormatter.WriteLength(stream, data.OutVariables.Count); foreach (var v in data.OutVariables) { writer.Write(v.Key ?? string.Empty); WriteRuntimeValue(writer, v.Value); } }
public override void Deserialize(Stream stream) { this.DeleteExtra = (bool)SlimBinaryFormatter.Deserialize(stream); this.TempDirectoryName = (string)SlimBinaryFormatter.Deserialize(stream); this.TargetRootPath = (string)SlimBinaryFormatter.Deserialize(stream); this.ExpectedDirectories = (string[])SlimBinaryFormatter.Deserialize(stream); this.ExpectedFiles = (string[])SlimBinaryFormatter.Deserialize(stream); }
public override void Serialize(Stream stream) { SlimBinaryFormatter.Serialize(this.DeleteExtra, stream); SlimBinaryFormatter.Serialize(this.TempDirectoryName, stream); SlimBinaryFormatter.Serialize(this.TargetRootPath, stream); SlimBinaryFormatter.Serialize(this.ExpectedDirectories, stream); SlimBinaryFormatter.Serialize(this.ExpectedFiles, stream); }
private static void WriteDictionary(BinaryWriter writer, IDictionary <string, RuntimeValue> d) { SlimBinaryFormatter.WriteLength(writer, d?.Count ?? 0); if (d != null) { foreach (var p in d) { writer.Write(p.Key); WriteRuntimeValue(writer, p.Value); } } }
private static Dictionary <string, RuntimeValue> ReadDictionary(BinaryReader reader) { var d = new Dictionary <string, RuntimeValue>(StringComparer.OrdinalIgnoreCase); int length = SlimBinaryFormatter.ReadLength(reader); for (int i = 0; i < length; i++) { var key = reader.ReadString(); var value = ReadRuntimeValue(reader); d[key] = value; } return(d); }
public override void Serialize(Stream stream) { var writer = new BinaryWriter(stream, InedoLib.UTF8Encoding); writer.Write(this.ScriptText ?? string.Empty); writer.Write(this.DebugLogging); writer.Write(this.VerboseLogging); writer.Write(this.CollectOutput); writer.Write(this.LogOutput); writer.Write(this.Isolated); WriteDictionary(writer, this.Variables); WriteDictionary(writer, this.Parameters); SlimBinaryFormatter.WriteLength(writer, this.OutVariables?.Length ?? 0); foreach (var var in this.OutVariables ?? new string[0]) { writer.Write(var); } }
public override void Deserialize(Stream stream) { var reader = new BinaryReader(stream, InedoLib.UTF8Encoding); this.ScriptText = reader.ReadString(); this.DebugLogging = reader.ReadBoolean(); this.VerboseLogging = reader.ReadBoolean(); this.CollectOutput = reader.ReadBoolean(); this.LogOutput = reader.ReadBoolean(); this.Isolated = reader.ReadBoolean(); this.Variables = ReadDictionary(reader); this.Parameters = ReadDictionary(reader); int count = SlimBinaryFormatter.ReadLength(stream); this.OutVariables = new string[count]; for (int i = 0; i < count; i++) { this.OutVariables[i] = reader.ReadString(); } }