コード例 #1
0
 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);
 }
コード例 #2
0
 public static void Generate()
 {
     JsonMessageSerializer serializer = new JsonMessageSerializer(new MessageMapper());
     string 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("\"", "\"\"")));
 }
コード例 #3
0
        private static JsonMessageSerializer CreateSerializer()
        {
            var mapper = new MessageMapper();
            var ser = new JsonMessageSerializer(mapper);

            //ser.JsonSerializerSettings.ContractResolver = new DefaultContractResolver
            //{
            //    DefaultMembersSearchFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance
            //};

            //ser.JsonSerializerSettings.MissingMemberHandling = MissingMemberHandling.Error;
            //ser.JsonSerializerSettings.TypeNameHandling = TypeNameHandling.All;

            return ser;
        }
コード例 #4
0
        public static void SendMessage(string connectionString, string queue, string messageBody, Dictionary<string, string> headers)
        {
            string insertSql = @"INSERT INTO [" + queue + "] ([Id],[Recoverable],[Headers],[Body]) VALUES (@Id,@Recoverable,@Headers,@Body)";
            using (var scope = new TransactionScope())
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    using (SqlCommand command = new SqlCommand(insertSql, connection))
                    {
                        SqlParameterCollection parameters = command.Parameters;
                        command.CommandType = CommandType.Text;
                        parameters.Add("Id", SqlDbType.UniqueIdentifier).Value = Guid.NewGuid();
                        string serializeHeaders = new JsonMessageSerializer(null).SerializeObject(headers);
                        parameters.Add("Headers", SqlDbType.VarChar).Value = serializeHeaders;
                        parameters.Add("Body", SqlDbType.VarBinary).Value = Encoding.UTF8.GetBytes(messageBody);
                        parameters.Add("Recoverable", SqlDbType.Bit).Value = true;

                        command.ExecuteNonQuery();
                    }
                }
                scope.Complete();
            }
        }