public static void SerializeWrappedNativeMessag() { var serializer = new JsonMessageSerializer(new SimpleMessageMapper()); var serializedMessage = serializer.SerializeObject(new NativeMessage { Content = "Hello from native sender", SendOnUtc = DateTime.UtcNow }); Debug.WriteLine("Serialized message:\n"); Debug.WriteLine($"@\"{serializedMessage.Replace("\"", "\"\"")}\""); var headers = new Dictionary<string, string> { { "NServiceBus.EnclosedMessageTypes", typeof(NativeMessage).FullName }, { "NServiceBus.MessageIntent", "Send" } }; var toSend = new MessageWrapper { Id = Guid.NewGuid().ToString(), Body = Encoding.UTF8.GetBytes(serializedMessage), Headers = headers, MessageIntent = MessageIntentEnum.Send, ReplyToAddress = "native-sender" }; using (var stream = new MemoryStream()) { serializer.Serialize(toSend, stream); var st = Encoding.UTF8.GetString(stream.ToArray()); Console.WriteLine("\nWrapped message:\n"); Debug.WriteLine($"@\"{st.Replace("\"", "\"\"")}\""); } }
internal static string ToDictionaryString(this Dictionary <string, string> dictionary) { if (dictionary != null && dictionary.Count > 0) { return(Serializer.SerializeObject(dictionary)); } return(null); }
public static void SerializeNativeMessage() { var serializer = new JsonMessageSerializer(new SimpleMessageMapper()); var serializedMessage = serializer.SerializeObject(new NativeMessage { Content = "Hello from native sender", SendOnUtc = DateTime.UtcNow }); Debug.WriteLine("Serialized message to paste in code:\n"); Debug.WriteLine($"@\"{serializedMessage.Replace("\"", "\"\"")}\""); }
public static void Generate() { var serializer = new JsonMessageSerializer(new SimpleMessageMapper()); var serializedMessage = serializer.SerializeObject(new NativeMessage { Content = "This is a native message", SendOnUtc = DateTime.UtcNow }); Console.WriteLine(serializedMessage); }
public static void Generate() { var serializer = new JsonMessageSerializer(new SimpleMessageMapper()); var serializedMessage = serializer.SerializeObject(new NativeMessage { Content = "Hello from native sender", SendOnUtc = DateTime.UtcNow }); Debug.WriteLine("Serialized message to paste in code:\n"); Debug.WriteLine(string.Format("@\"{0}\"", serializedMessage.Replace("\"", "\"\""))); }
private static void ExecuteQuery(TransportMessage message, SqlCommand command) { command.Parameters.Add("Id", SqlDbType.UniqueIdentifier).Value = Guid.Parse(message.Id); command.Parameters.Add("CorrelationId", SqlDbType.VarChar).Value = GetValue(message.CorrelationId); if (message.ReplyToAddress == null) // Sendonly endpoint { command.Parameters.Add("ReplyToAddress", SqlDbType.VarChar).Value = DBNull.Value; } else { command.Parameters.Add("ReplyToAddress", SqlDbType.VarChar).Value = message.ReplyToAddress.ToString(); } command.Parameters.Add("Recoverable", SqlDbType.Bit).Value = message.Recoverable; if (message.TimeToBeReceived == TimeSpan.MaxValue) { command.Parameters.Add("Expires", SqlDbType.DateTime).Value = DBNull.Value; } else { command.Parameters.Add("Expires", SqlDbType.DateTime).Value = DateTime.UtcNow.Add(message.TimeToBeReceived); } command.Parameters.Add("Headers", SqlDbType.VarChar).Value = Serializer.SerializeObject(message.Headers); if (message.Body == null) { command.Parameters.Add("Body", SqlDbType.VarBinary).Value = DBNull.Value; } else { command.Parameters.Add("Body", SqlDbType.VarBinary).Value = message.Body; } command.ExecuteNonQuery(); }
public static void SaveToDisk(ServiceInfo ms) { var ser = new JsonMessageSerializer(); var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ms.Name + ".json"); File.WriteAllBytes(path, ser.SerializeObject(ms)); }