Conversie van de TransSmart solution van BizTalk 2013 naar 2016.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

183 linhas
5.3KB

  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. using System.Runtime.InteropServices;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using Microsoft.BizTalk.Message.Interop;
  9. using Microsoft.BizTalk.Component;
  10. using Microsoft.BizTalk.Component.Interop;
  11. namespace TM.TransSmart.PipelineComponents
  12. {
  13. [ComponentCategory(CategoryTypes.CATID_PipelineComponent)]
  14. [ComponentCategory(CategoryTypes.CATID_DisassemblingParser)]
  15. [ComponentCategory(CategoryTypes.CATID_Streamer)]
  16. [Guid("B082AD3E-C313-4569-941E-AE527A7AFD6B")]
  17. public class CPL_Debatch : IBaseComponent, IDisassemblerComponent, IComponentUI, IPersistPropertyBag
  18. {
  19. private string docType = "";
  20. private const string XmlNormNamespaceURI = "http://schemas.microsoft.com/BizTalk/2003/xmlnorm-properties";
  21. private const string DocumentSpecNamePropertyName = "DocumentSpecName";
  22. private Queue<string> messages = new Queue<string>();
  23. private IBaseMessageContext msgContext = null;
  24. #region IBaseComponent Members
  25. public string Description
  26. {
  27. get { return "Streaming TransSmart Debatch Disassembler Component"; }
  28. }
  29. public string Name
  30. {
  31. get { return "TransSmart Debatch Disassembler"; }
  32. }
  33. public string Version
  34. {
  35. get { return "1.0"; }
  36. }
  37. #endregion
  38. #region IDisassemblerComponent Members
  39. public void Disassemble(IPipelineContext pContext, IBaseMessage pInMsg)
  40. {
  41. if (pInMsg == null) return;
  42. if (pInMsg.PartCount == 0) return;
  43. msgContext = PipelineUtil.CloneMessageContext(pInMsg.Context);
  44. Stream s2 = pInMsg.BodyPart.Data;
  45. // reset to begin of stream;
  46. s2.Seek(0, SeekOrigin.Begin);
  47. StreamReader history = new StreamReader(s2);
  48. String content = "";
  49. content = history.ReadToEnd();
  50. string replace1 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tbox=\"http://connect1.transwise.eu/TboxService/\"><SOAP-ENV:Header xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"/><soap:Body><tbox:carrierBooking>";
  51. string replaceWith1 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><tbox:carrierBooking xmlns:tbox=\"http://TM.TransSmart.Shipment\">";
  52. string replace2 = "</soap:Body></soap:Envelope>";
  53. string replaceWith2 = "";
  54. content = content.Replace(replace1, replaceWith1).Replace(replace2, replaceWith2);
  55. string line = null;
  56. StringBuilder sb = new StringBuilder(content);
  57. if (sb.Length != 0)
  58. {
  59. messages.Enqueue(sb.ToString());
  60. }
  61. }
  62. public IBaseMessage GetNext(IPipelineContext pContext)
  63. {
  64. // Queue is empty ?
  65. if (messages.Count == 0)
  66. {
  67. return null;
  68. }
  69. string currentDoc = messages.Dequeue();
  70. IBaseMessage ret = null;
  71. IDocumentSpec docSpec = null;
  72. docSpec = pContext.GetDocumentSpecByType(@"http://TM.TransSmart.Shipment#carrierBooking");
  73. IBaseMessage msg = pContext.GetMessageFactory().CreateMessage();
  74. IBaseMessagePart part = pContext.GetMessageFactory().CreateMessagePart();
  75. //UnicodeEncoding encoding = new UnicodeEncoding();
  76. //ASCIIEncoding encoding = new ASCIIEncoding();
  77. //Byte[] bytes = Encoding.Default.GetBytes(currentDoc);
  78. Byte[] bytes = Encoding.UTF8.GetBytes(currentDoc);
  79. MemoryStream ms = new MemoryStream();
  80. int count = 0;
  81. while (count < bytes.Length)
  82. {
  83. ms.WriteByte(bytes[count]);
  84. count++;
  85. }
  86. ms.Seek(0, SeekOrigin.Begin);
  87. part.Data = ms;
  88. msg.AddPart("body", part, true);
  89. msg.Context = msgContext;
  90. msg.Context.Write(DocumentSpecNamePropertyName, XmlNormNamespaceURI, docSpec.DocSpecStrongName);
  91. XmlDasmComp xmldasm = new XmlDasmComp();
  92. xmldasm.InitNew();
  93. if (xmldasm.Probe(pContext, msg))
  94. {
  95. xmldasm.Disassemble(pContext, msg);
  96. ret = xmldasm.GetNext(pContext);
  97. }
  98. return ret;
  99. }
  100. #endregion
  101. #region IComponentUI Members
  102. public IntPtr Icon
  103. {
  104. get { return IntPtr.Zero; }
  105. }
  106. public IEnumerator Validate(object projectSystem)
  107. {
  108. return new List<string>().GetEnumerator();
  109. }
  110. #endregion
  111. #region IPersistPropertyBag Members
  112. public void GetClassID(out Guid classID)
  113. {
  114. // Is the Same as GUID on Class level.
  115. classID = new Guid("B082AD3E-C313-4569-941E-AE527A7AFD6B");
  116. }
  117. public void InitNew()
  118. {
  119. // Called after "New" of component
  120. }
  121. public void Load(IPropertyBag propertyBag, int errorLog)
  122. {
  123. }
  124. public void Save(IPropertyBag propertyBag, bool clearDirty, bool saveAllProperties)
  125. {
  126. }
  127. #endregion
  128. }
  129. }