当前位置: 首页>>代码示例>>C#>>正文


C# IMessageSerializer.Serialize方法代码示例

本文整理汇总了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);
        }
开发者ID:jdaigle,项目名称:CWServiceBus,代码行数:30,代码来源:NamespaceTests.cs

示例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)
     };
 }
开发者ID:nchistyakov,项目名称:Apworks,代码行数:10,代码来源:Message.cs

示例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;
 }
开发者ID:Zapote,项目名称:EzBus,代码行数:12,代码来源:ChannelMessageFactory.cs

示例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);
        }
开发者ID:rikace,项目名称:Orleankka,代码行数:13,代码来源:OrleansSerialization.cs

示例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);
            }
        }
开发者ID:Rationalle,项目名称:NServiceBus,代码行数:14,代码来源:IntegrationTests.cs

示例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));
        }
开发者ID:sasha-uk,项目名称:NServiceBus.Xms.2,代码行数:40,代码来源:XmsUtilities.cs

示例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);
        }
开发者ID:ssttgg,项目名称:Obvs.ActiveMQ,代码行数:24,代码来源:TestMessagePublisher.cs

示例8: Success

        public static MessageExecutionCompleted Success(MessageId sourceCommandId, IMessage payload, IMessageSerializer serializer)
        {
            var payloadBytes = serializer.Serialize(payload);

            return new MessageExecutionCompleted(sourceCommandId, payload.TypeId(), payloadBytes);
        }
开发者ID:MarouenK,项目名称:Zebus,代码行数:6,代码来源:MessageExecutionCompleted.cs


注:本文中的IMessageSerializer.Serialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。