public static Stream WriteBizMessageToStream(IBizMessage message) { IList <KeyValuePair <string, string> > headerList = new List <KeyValuePair <string, string> >(); headerList.Add(new KeyValuePair <string, string>(BizMessageType, message.Type.ToString())); headerList.Add(new KeyValuePair <string, string>(BizUniqueId, message.UniqueId)); headerList.Add(new KeyValuePair <string, string>(BizCreatedTime, message.CreatedTime.ToString())); int index = 0; string key; string value; foreach (BizMessageAction action in message.Actions) { key = PayloadSection + IndexSeperator + index; value = action.PayloadSection; headerList.Add(new KeyValuePair <string, string>(key, value)); key = Description + IndexSeperator + index; value = action.Description; headerList.Add(new KeyValuePair <string, string>(key, value)); key = Status + IndexSeperator + index; value = action.Status.ToString(); headerList.Add(new KeyValuePair <string, string>(key, value)); key = CreatedTime + IndexSeperator + index; value = action.CreatedTime.ToString(); headerList.Add(new KeyValuePair <string, string>(key, value)); key = LastUpdateTime + IndexSeperator + index; value = action.LastUpdateTime.ToString(); headerList.Add(new KeyValuePair <string, string>(key, value)); index++; } Stream headerStream = StreamHelper.SerializeHeadersToStream(headerList, true); Stream bodyStream = new MemoryStream(Encoding.UTF8.GetBytes(message.Payload)); return(new ConcatenatingStream(headerStream, bodyStream, null)); }
/// <summary> /// Has the logic to convert a FatpipeMessage into a Stream object that represents the storage logic /// </summary> /// <param name="msg"></param> /// <returns></returns> public static Stream WriteBizpipeMessageToStream(IFatpipeMessage message) { IList <KeyValuePair <string, string> > headerList = new List <KeyValuePair <string, string> >(); headerList.Add(new KeyValuePair <string, string>(MsgId, message.Header.Identifier)); headerList.Add(new KeyValuePair <string, string>(TenantId, message.Header.TenantIdentifier)); headerList.Add(new KeyValuePair <string, string>(CorrelationId, message.Header.CorrelationId)); if (message.Header.Context != null) { foreach (KeyValuePair <string, string> kvpair in message.Header.Context) { headerList.Add(new KeyValuePair <string, string>(kvpair.Key, kvpair.Value)); } } Stream headerStream = StreamHelper.SerializeHeadersToStream(headerList, true); Stream bodyStream = message.Body.Body; return(new ConcatenatingStream(headerStream, bodyStream, null)); }