Guest User

Untitled

a guest
Oct 17th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Runtime.Serialization;
  5. using System.Runtime.Serialization.Json;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using MassTransit;
  9. using MassTransit.Turnout;
  10. using Messages;
  11. using Newtonsoft.Json;
  12. using Newtonsoft.Json.Linq;
  13.  
  14. namespace Consumers
  15. {
  16. public class OtherIssuerAddConsumer : IConsumer<JObject>
  17. {
  18. public Task Consume(ConsumeContext<JObject> context)
  19. {
  20. Console.WriteLine(context);
  21. var ser = new DataContractJsonSerializer(typeof(KnownCommandType),
  22. new DataContractJsonSerializerSettings
  23. {
  24. SerializeReadOnlyTypes = true,
  25. MaxItemsInObjectGraph = 256,
  26. DateTimeFormat = new DateTimeFormat("yyyy-MM-dd'T'HH:mm:ss.FFFFFFFZ")
  27. });
  28.  
  29. var msg = (JObject)JsonConvert.DeserializeObject(context.Message.ToString());
  30.  
  31. JToken messageToken;
  32. JObject message;
  33.  
  34. var hasContent = msg.TryGetValue("Content", StringComparison.CurrentCultureIgnoreCase, out messageToken);
  35.  
  36. if (hasContent)
  37. {
  38. var target = ser.ReadObject(
  39. new MemoryStream(Encoding.UTF8.GetBytes(JObject.Parse(messageToken.ToString()).ToString())));
  40. }
  41.  
  42. return Task.CompletedTask;
  43. }
  44. }
  45. }
Add Comment
Please, Sign In to add comment