本文整理汇总了C#中IMessageSerializer.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# IMessageSerializer.Serialize方法的具体用法?C# IMessageSerializer.Serialize怎么用?C# IMessageSerializer.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMessageSerializer
的用法示例。
在下文中一共展示了IMessageSerializer.Serialize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Time
private void Time(IMessage[] messages, IMessageSerializer serializer) {
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 0; i < numberOfIterations; i++)
using (MemoryStream stream = new MemoryStream())
serializer.Serialize(messages, stream);
watch.Stop();
Debug.WriteLine("Serializing: " + watch.Elapsed);
watch.Reset();
MemoryStream s = new MemoryStream();
serializer.Serialize(messages, s);
byte[] buffer = s.GetBuffer();
s.Dispose();
Console.WriteLine(Encoding.ASCII.GetString(buffer));
watch.Start();
object[] result = null;
for (int i = 0; i < numberOfIterations; i++)
using (var forDeserializing = new MemoryStream(buffer))
result = serializer.Deserialize(forDeserializing);
watch.Stop();
Debug.WriteLine("Deserializing: " + watch.Elapsed);
}
示例2: FromObject
public static Message FromObject(object obj, IMessageSerializer serializer)
{
return new Message
{
AssemblyQualifiedName = obj.GetType().AssemblyQualifiedName,
ID = Guid.NewGuid(),
TypeName = obj.GetType().Name,
Body = serializer.Serialize(obj)
};
}
示例3: CreateChannelMessage
public static ChannelMessage CreateChannelMessage(object message, IMessageSerializer messageSerializer)
{
if (messageSerializer == null) throw new ArgumentNullException(nameof(messageSerializer));
var messageType = message.GetType();
var stream = messageSerializer.Serialize(message);
var channelMessage = new ChannelMessage(stream);
channelMessage.AddHeader(MessageHeaders.MessageType, messageType.FullName);
channelMessage.AddHeader(MessageHeaders.UserPrincipal, Environment.UserName);
channelMessage.AddHeader(MessageHeaders.SendingMachine, Environment.MachineName);
channelMessage.AddHeader(MessageHeaders.SendingModule, ResolveAssemblyFullName());
return channelMessage;
}
示例4: Reserialize
internal static object Reserialize(IMessageSerializer serializer, object message)
{
if (serializer == null)
return message;
var writer = new BinaryTokenStreamWriter();
serializer.Serialize(message, writer);
var bytes = writer.ToByteArray();
var reader = new BinaryTokenStreamReader(bytes);
return serializer.Deserialize(reader);
}
示例5: InvokeMutators
private IMessage InvokeMutators(IMessage message, IMessageSerializer serializer)
{
var messageToSerialize = messageMutator.MutateOutgoing(message);
using (var stream = new MemoryStream())
{
serializer.Serialize(new[] { messageToSerialize }, stream);
stream.Position = 0;
var result = serializer.Deserialize(stream)[0];
return messageMutator.MutateIncoming(result);
}
}
示例6: Convert
public static void Convert(TransportMessage message, IBytesMessage toSend, IMessageSerializer serializer)
{
byte[] body;
if (message.Body == null && message.BodyStream != null)
{
body = message.BodyStream.ToBytes();
}
else
{
var stream = new MemoryStream();
serializer.Serialize(message.Body, stream);
body = stream.ToBytes();
}
toSend.WriteBytes(body);
// TODO: clarify usage of JMSCorrelationID
toSend.JMSCorrelationID = message.CorrelationId;
toSend.JMSDeliveryMode = message.Recoverable ? DeliveryMode.Persistent : DeliveryMode.NonPersistent;
toSend.SetStringProperty(HEADER_RETURNADDRESS, message.ReturnAddress);
toSend.SetStringProperty(HEADER_IDFORCORRELATION, message.IdForCorrelation);
toSend.SetStringProperty(HEADER_WINDOWSIDENTITYNAME, message.WindowsIdentityName);
toSend.SetIntProperty(HEADER_MESSAGEINTENT, (int) message.MessageIntent);
//TODO: set message expiration
//toSend.JMSReplyTo = new Destination message.ReplyToAddress;
//if (message.TimeToBeReceived < MessageQueue.InfiniteTimeout)
//toSend.JMSExpiration = (long) UTCNow.message.TimeToBeReceived.TotalMilliseconds;
if (message.Headers == null)
message.Headers = new List<HeaderInfo>();
var nsbHeaderKeys = new List<string>();
foreach (var keyValue in message.Headers)
{
toSend.SetStringProperty(keyValue.Key.ToXmsFriendly(), keyValue.Value);
nsbHeaderKeys.Add(keyValue.Key.ToXmsFriendly());
}
toSend.SetStringProperty(HEADER_NBSKEYS, WrapKeys(nsbHeaderKeys));
}
示例7: SetUp
public void SetUp()
{
A.Fake<IConnectionFactory>();
_connection = A.Fake<IConnection>();
_lazyConnection = new Lazy<IConnection>(() =>
{
_connection.Start();
return _connection;
});
_session = A.Fake<ISession>();
_producer = A.Fake<IMessageProducer>();
_serializer = A.Fake<IMessageSerializer>();
_destination = A.Fake<IDestination>();
_message = A.Fake<ITextMessage>();
_messagePropertyProvider = A.Fake<IMessagePropertyProvider<IMessage>>();
A.CallTo(() => _connection.CreateSession(A<Apache.NMS.AcknowledgementMode>.Ignored)).Returns(_session);
A.CallTo(() => _session.CreateProducer(_destination)).Returns(_producer);
A.CallTo(() => _session.CreateTextMessage(A<string>._)).Returns(_message);
A.CallTo(() => _serializer.Serialize(A<object>._)).Returns("SerializedString");
_testScheduler = new TestScheduler();
_publisher = new MessagePublisher<IMessage>(_lazyConnection, _destination, _serializer, _messagePropertyProvider, _testScheduler);
}
示例8: Success
public static MessageExecutionCompleted Success(MessageId sourceCommandId, IMessage payload, IMessageSerializer serializer)
{
var payloadBytes = serializer.Serialize(payload);
return new MessageExecutionCompleted(sourceCommandId, payload.TypeId(), payloadBytes);
}