本文整理汇总了C#中Message.SetValueFrom方法的典型用法代码示例。如果您正苦于以下问题:C# Message.SetValueFrom方法的具体用法?C# Message.SetValueFrom怎么用?C# Message.SetValueFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Message
的用法示例。
在下文中一共展示了Message.SetValueFrom方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessMessage
public void ProcessMessage(object source, Message message)
{
string jsonScript = "var msg = " + JsonConvert.SerializeXmlNode(message.GetXmlDocument(), Formatting.Indented, true);
Engine engine = new Engine();
engine.SetValue("message", message);
engine.Execute(jsonScript);
engine.Execute(Script);
engine.Execute("var jsonMsg = JSON.stringify(msg);");
JsValue obj = engine.GetValue("jsonMsg");
string jsonString = obj.AsString();
var document = JsonConvert.DeserializeXNode(jsonString, "HL7Message");
message.SetValueFrom(document);
}
示例2: ProcessMessageTest
public void ProcessMessageTest()
{
string fileInputPath = "Hl7DisassemblerTest-hl7.xml";
var input = XDocument.Load(fileInputPath);
Message message = new Message("");
message.SetValueFrom(input);
JavaScriptTransformer transformer = new JavaScriptTransformer
{
Script = @"
if(msg['MSH']['MSH.8'] != null) delete msg['MSH']['MSH.8'];
msg['MSH']['MSH.2'] = 'TEST';
"
};
// Execute
transformer.ProcessMessage(null, message);
// Assert
XDocument expected = new XDocument(input);
expected.Descendants("MSH.8").Remove();
expected.Element("HL7Message").Element("MSH").Element("MSH.2").SetValue("TEST");
var result = message.RetrieveAs<XDocument>();
Assert.IsTrue(XNode.DeepEquals(expected, result));
}
示例3: NextMessage
public Message NextMessage()
{
if (_data != null)
{
Message message = new Message("");
message.SetValueFrom(_data);
_data = null;
return message;
}
return null;
}
示例4: NextMessage
public Message NextMessage()
{
if (_stream.Position == _stream.Length) return null;
// This implementation doesn't really do that much since
// it doesn't do envelope splitting yet.
var message = new Message("text/xml");
// Change this to use XmlReader in order to set the original encoding of the stream
// Actually, this string representation should really go away in the end. Message.Value
// doesn't have a place in the future.
XmlDocument document = new XmlDocument();
document.Load(_stream);
message.SetValueFrom(document.OuterXml);
return message;
}
示例5: AssembleTest
public void AssembleTest()
{
XDocument document = XDocument.Load("Hl7DisassemblerTest-hl7.xml");
Message message = new Message("");
message.SetValueFrom(document);
Hl7Assembler assembler = new Hl7Assembler();
assembler.AddMessage(message);
byte[] result = assembler.Assemble();
Assert.IsNotNull(result);
byte[] expected;
using (StreamReader reader = new StreamReader("Hl7DisassemblerTest-hl7-2.txt"))
{
string text = reader.ReadToEnd();
expected = Encoding.UTF8.GetBytes(text);
}
Assert.IsTrue(expected.SequenceEqual(result));
}
示例6: BasicRoutingFilteringTransformationTest
public void BasicRoutingFilteringTransformationTest()
{
// A new application
Application application = new Application();
// Ports
Port receivePort = new Port();
IEndpoint endpoint = new EndpointMock();
receivePort.Endpoint = endpoint;
{
IEncoder encoder = new PipelineComponentMock();
receivePort.Encoders.Add(encoder);
IDisassembler disassembler = new PipelineComponentMock();
receivePort.Assembers.Add(disassembler);
}
application.Ports.Add(receivePort);
Port sendPort = new Port();
IEndpoint sendEndpoint = new EndpointMock();
sendPort.Endpoint = sendEndpoint;
{
IEncoder encoder = new PipelineComponentMock();
sendPort.Encoders.Add(encoder);
IDisassembler disassembler = new PipelineComponentMock();
sendPort.Assembers.Add(disassembler);
}
application.Ports.Add(sendPort);
// Add a channel
Channel channel = new Channel();
application.Channels.Add(channel);
// Source setup
Source source = new Source();
channel.Source = source;
source.Filters.Add(new DelegateFilter((src, message) => true));
source.Filters.Add(new JavaScriptFilter { Script = "true" });
source.Transformers.Add(new DelegateTransformer());
source.Transformers.Add(new DelegateTransformer((src, message) => { }));
source.Transformers.Add(new DelegateTransformer((src, message) => message.SetValueFrom(message.GetString())));
{
Destination destination = new Destination();
destination.Target = sendEndpoint;
destination.Filters.Add(new DelegateFilter((src, message) => true));
destination.Filters.Add(new JavaScriptFilter { Script = "true" });
destination.Transformers.Add(new DelegateTransformer((src, message) => { }));
destination.Transformers.Add(new DelegateTransformer((src, message) => message.SetValueFrom(message.GetString())));
channel.Destinations.Add(destination);
}
{
// This destination will filter out the message
Destination destination = new Destination();
destination.Target = sendEndpoint;
destination.Filters.Add(new DelegateFilter((src, message) => false));
channel.Destinations.Add(destination);
}
{
// This destination will transform the message
Destination destination = new Destination();
destination.Target = sendEndpoint;
destination.Filters.Add(new DelegateFilter((src, message) => true));
destination.Transformers.Add(new DelegateTransformer((src, message) => message.SetValueFrom(message.GetString() + "test")));
channel.Destinations.Add(destination);
}
// Host
ApplicationHost applicationHost = new ApplicationHost();
Assert.IsNotNull(applicationHost.Applications);
applicationHost.Deploy(application);
// Start the processing
Message testMessage = new Message("text/json");
testMessage.SetValueFrom("AAAA");
// Mock method for sending a test message
((EndpointMock) endpoint).SendTestMessage(testMessage);
// Check that endpoint received the message
EndpointMock endpointMock = sendEndpoint as EndpointMock;
Assert.IsNotNull(endpointMock);
Assert.IsNotNull(endpointMock.Messages);
Assert.AreEqual(2, endpointMock.Messages.Count);
foreach (byte[] data in endpointMock.Messages)
{
string actual = Encoding.UTF8.GetString(data);
if (actual.EndsWith("test"))
{
Assert.AreEqual(testMessage.GetString() + "test", actual);
}
else
{
Assert.AreEqual(testMessage.GetString(), actual);
}
}
}
示例7: PushPipelineData
public void PushPipelineData(IEndpoint endpoint, byte[] data)
{
// Find pipeline for endpoint and process..
Queue<IPipelineComponent> pipeline;
if (!_pipelines.TryGetValue(endpoint, out pipeline))
{
// Temporary. Remove during refactoring of endpoints.
Message message = new Message("text/plain");
message.SetValueFrom(data);
PublishMessage(endpoint, message);
}
else
{
byte[] decoded = null;
foreach (IDecoder component in pipeline.OfType<IDecoder>())
{
decoded = component.Decode(data);
if (decoded != null) break;
}
if (decoded == null) decoded = data;
foreach (IDisassembler component in pipeline.OfType<IDisassembler>())
{
component.Disassemble(decoded);
Message message;
do
{
message = component.NextMessage();
if (message != null) PublishMessage(endpoint, message);
} while (message != null);
}
}
}
示例8: TransformerTest
private void TransformerTest(object source, Message message)
{
XDocument doc = message.GetXDocument();
doc.Descendants("MSH.11").Remove();
message.SetValueFrom(doc);
}