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


C# Message.Clone方法代码示例

本文整理汇总了C#中Message.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Message.Clone方法的具体用法?C# Message.Clone怎么用?C# Message.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Message的用法示例。


在下文中一共展示了Message.Clone方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnSendInMessage

			protected override void OnSendInMessage(Message message)
			{
				_currentTime = message.LocalTime;

				switch (message.Type)
				{
					case MessageTypes.Connect:
					{
						if (!_isInitialized)
						{
							//CreateInnerAdapters();

							_isInitialized = true;
						}
					
						GetSortedAdapters().ForEach(a => a.SendInMessage(message.Clone()));
						break;
					}

					case MessageTypes.OrderRegister:
					case MessageTypes.OrderReplace:
					case MessageTypes.OrderPairReplace:
					case MessageTypes.OrderCancel:
					case MessageTypes.OrderGroupCancel:
					case MessageTypes.MarketData:
						base.OnSendInMessage(message);
						break;

					case MessageTypes.CandleTimeFrame:
					case MessageTypes.CandlePnF:
					case MessageTypes.CandleRange:
					case MessageTypes.CandleRenko:
					case MessageTypes.CandleTick:
					case MessageTypes.CandleVolume:
						GetSortedAdapters().ForEach(a => a.SendInMessage(message.Clone()));
						break;

					default:
						GetSortedAdapters().ForEach(a => a.SendInMessage(message)); //TODO Clone работает не для всех месседжей
						break;
				}
			}
开发者ID:vikewoods,项目名称:StockSharp,代码行数:42,代码来源:BatchEmulation.cs

示例2: SendInMessage

		/// <summary>
		/// Send incoming message.
		/// </summary>
		/// <param name="message">Message.</param>
		public void SendInMessage(Message message)
		{
			if (message.Type == MessageTypes.Connect)
			{
				if (!Platform.IsCompatible())
				{
					SendOutMessage(new ConnectMessage
					{
						Error = new InvalidOperationException(LocalizedStrings.Str169Params.Put(GetType().Name, Platform))
					});

					return;
				}
			}

			InitMessageLocalTime(message);

			switch (message.Type)
			{
				case MessageTypes.PortfolioLookup:
				{
					if (!IsSupportNativePortfolioLookup)
						_pfLookupTimeOut.StartTimeOut(((PortfolioLookupMessage)message).TransactionId);

					break;
				}
				case MessageTypes.SecurityLookup:
				{
					if (!IsSupportNativeSecurityLookup)
						_secLookupTimeOut.StartTimeOut(((SecurityLookupMessage)message).TransactionId);

					break;
				}
			}

			try
			{
				OnSendInMessage(message);
			}
			catch (Exception ex)
			{
				this.AddErrorLog(ex);

				switch (message.Type)
				{
					case MessageTypes.Connect:
						SendOutMessage(new ConnectMessage { Error = ex });
						return;

					case MessageTypes.Disconnect:
						SendOutMessage(new DisconnectMessage { Error = ex });
						return;

					case MessageTypes.OrderRegister:
					case MessageTypes.OrderReplace:
					case MessageTypes.OrderCancel:
					case MessageTypes.OrderGroupCancel:
					{
						var replyMsg = ((OrderMessage)message).CreateReply();
						SendOutErrorExecution(replyMsg, ex);
						return;
					}
					case MessageTypes.OrderPairReplace:
					{
						var replyMsg = ((OrderPairReplaceMessage)message).Message1.CreateReply();
						SendOutErrorExecution(replyMsg, ex);
						return;
					}

					case MessageTypes.MarketData:
					{
						var reply = (MarketDataMessage)message.Clone();
						reply.OriginalTransactionId = reply.TransactionId;
						reply.Error = ex;
						SendOutMessage(reply);
						return;
					}

					case MessageTypes.SecurityLookup:
					{
						var lookupMsg = (SecurityLookupMessage)message;
						SendOutMessage(new SecurityLookupResultMessage
						{
							OriginalTransactionId = lookupMsg.TransactionId,
							Error = ex
						});
						return;
					}

					case MessageTypes.PortfolioLookup:
					{
						var lookupMsg = (PortfolioLookupMessage)message;
						SendOutMessage(new PortfolioLookupResultMessage
						{
							OriginalTransactionId = lookupMsg.TransactionId,
							Error = ex
//.........这里部分代码省略.........
开发者ID:RakotVT,项目名称:StockSharp,代码行数:101,代码来源:MessageAdapter.cs

示例3: OnSendInMessage


//.........这里部分代码省略.........
										else
											_lookupFeed.RequestCandles(mdMsg.TransactionId, mdMsg.SecurityId.SecurityCode, intervalType, strArg, from, to);
									}
									else
									{
										throw new InvalidOperationException(LocalizedStrings.Str2139Params.Put(tf));
									}
								}
								else
								{
									string strArg, intervalType;
									GetCandleParams(mdMsg.DataType, mdMsg.Arg, out strArg, out intervalType);

									if (mdMsg.Count != 0)
										_lookupFeed.RequestCandles(mdMsg.TransactionId, mdMsg.SecurityId.SecurityCode, intervalType, strArg, mdMsg.Count);
									else
										_lookupFeed.RequestCandles(mdMsg.TransactionId, mdMsg.SecurityId.SecurityCode, intervalType, strArg, from, to);
								}
							}
							else
							{
								_derivativeFeed.UnSubscribeCandles(mdMsg.SecurityId.SecurityCode, mdMsg.OriginalTransactionId);
							}

							break;
						}
						default:
						{
							SendOutMarketDataNotSupported(mdMsg.TransactionId);
							return;
						}
					}

					var reply = (MarketDataMessage)message.Clone();
					reply.OriginalTransactionId = mdMsg.TransactionId;
					SendOutMessage(reply);

					break;
				}

				case MessageTypes.SecurityLookup:
				{
					var lookupMsg = (SecurityLookupMessage)message;

					var securityTypes = new HashSet<SecurityTypes>();

					if (lookupMsg.SecurityTypes != null)
						securityTypes.AddRange(lookupMsg.SecurityTypes);
					else if (lookupMsg.SecurityType != null)
						securityTypes.Add(lookupMsg.SecurityType.Value);

					if (_isDownloadSecurityFromSite)
					{
						_isDownloadSecurityFromSite = false;

						using (var zip = new ZipArchive(
							SecuritiesFile.IsEmpty()
								? IQFeedHelper.DownloadSymbols().To<Stream>()
								: File.OpenRead(SecuritiesFile)))
						{
							var entry = zip.GetEntry("mktsymbols_v2.txt");

							using (var reader = entry.Open())
							{
								reader
									.ReadLines()
开发者ID:reddream,项目名称:StockSharp,代码行数:67,代码来源:IQFeedMarketDataMessageAdapter.cs

示例4: OnProcess

		/// <summary>
		/// Process message.
		/// </summary>
		/// <param name="message">Message.</param>
		/// <returns>The result of processing. If <see langword="null" /> is returned, then generator has no sufficient data to generate new message.</returns>
		protected override Message OnProcess(Message message)
		{
			if (_boardDefinition == null)
			{
				if (message.Type == MessageTypes.Board)
					_boardDefinition = (BoardMessage)message.Clone();
				
				return null;
			}

			DateTimeOffset time;

			switch (message.Type)
			{
				case MessageTypes.Level1Change:
				{
					var l1Msg = (Level1ChangeMessage)message;

					var value = l1Msg.Changes.TryGetValue(Level1Fields.LastTradePrice);

					if (value != null)
						_lastTradePrice = (decimal)value;

					value = l1Msg.Changes.TryGetValue(Level1Fields.BestBidPrice);

					if (value != null)
						_bestBidPrice = (decimal)value;

					value = l1Msg.Changes.TryGetValue(Level1Fields.BestAskPrice);

					if (value != null)
						_bestAskPrice = (decimal)value;

					time = l1Msg.ServerTime;

					break;
				}
				case MessageTypes.Execution:
				{
					var execMsg = (ExecutionMessage)message;

					switch (execMsg.ExecutionType)
					{
						case ExecutionTypes.Tick:
						{
							var tradePrice = execMsg.TradePrice;

							if (null == _prevTradePrice)
							{
								_prevTradePrice = tradePrice;
								_bestAskPrice = tradePrice;
								_bestBidPrice = tradePrice;
							}

							switch (execMsg.OriginSide)
							{
								case null:
								{
									if (tradePrice > _prevTradePrice)
									{
										_bestAskPrice = tradePrice;
										//BestBid = PrevTrade;
										_prevTradePrice = tradePrice;
									}
									else if (tradePrice < _prevTradePrice)
									{
										_bestBidPrice = tradePrice;
										//BestAsk = PrevTrade;
										_prevTradePrice = tradePrice;
									}

									break;
								}
								case Sides.Buy:
									_bestAskPrice = tradePrice;
									break;
								default:
									_bestBidPrice = tradePrice;
									break;
							}

							_lastTradePrice = tradePrice;
							_newTrades = true;

							break;
						}
						default:
							return null;
					}

					time = execMsg.ServerTime;

					break;
				}
				case MessageTypes.Time:
//.........这里部分代码省略.........
开发者ID:vikewoods,项目名称:StockSharp,代码行数:101,代码来源:MarketDepthGenerator.cs

示例5: Clone

        public void Clone()
        {
            var m = new Message("topic");

            var deep = "field";
            m.Init(deep, 1, 2);

            var mess = "message";
            m.Init(mess, new Message("inner"));

            var n = m.Clone() as Message;

            Assert.AreEqual(m[deep], n[deep]); // same content...
            Assert.AreNotEqual(m[deep].GetHashCode(), n[deep].GetHashCode()); // ...but unique bin...

            m[deep].First = 42;
            Assert.AreNotEqual(m[deep].First, n[deep].First); // ...but unique bin...

            Assert.AreEqual(m[mess], n[mess]); // same content...
            Assert.AreNotEqual(m[mess].GetHashCode(), n[mess].GetHashCode()); // ...but unique bin

            var inner = m[mess].First as Message;
            inner.Topic = "changeIt!"; // only change once

            var innerCopy = n[mess].First as Message;
            Assert.AreEqual(inner.Topic, innerCopy.Topic); // both now have a topic called "changeIt!"
        }
开发者ID:velcrome,项目名称:vvvv-Message,代码行数:27,代码来源:MessageTest.cs

示例6: PipelineProcessingTest

		public void PipelineProcessingTest()
		{
			var appHostMock = new Mock<ApplicationHost>();
			appHostMock.CallBase = true;
			var appHost = appHostMock.Object;

			var receiveEndpoint = new Mock<IEndpoint>();
			var sendEndpoint = new Mock<IEndpoint>();
			var decoderMock = new Mock<IPipelineComponent>().As<IDecoder>();
			var encoderMock = new Mock<IPipelineComponent>().As<IEncoder>();
			var disassemblerMock = new Mock<IPipelineComponent>().As<IDisassembler>();
			var assemblerMock = new Mock<IPipelineComponent>().As<IAssembler>();

			appHostMock.Setup(host => host.PublishMessage(It.IsNotNull<object>(), It.IsNotNull<Message>()));

			// Receive decoder and disassembler
			appHost.AddPipelineComponent(receiveEndpoint.Object, decoderMock.Object);
			appHost.AddPipelineComponent(receiveEndpoint.Object, disassemblerMock.Object);

			// Send assembler and encoder
			appHost.AddPipelineComponent(sendEndpoint.Object, assemblerMock.Object);
			appHost.AddPipelineComponent(sendEndpoint.Object, encoderMock.Object);

			// Setup pipeline to produce data
			decoderMock.SetupSequence(decoder => decoder.Decode(It.IsAny<byte[]>()))
				.Returns(new byte[] { 0x00 })
				.Returns(new byte[] { 0x01 })
				.Returns(new byte[] { 0x02 })
				.Returns(new byte[] { 0x03 })
				;

			assemblerMock.SetupSequence(assembler => assembler.Assemble())
				.Returns(new byte[] { 0x00 })
				.Returns(new byte[] { 0x01 })
				.Returns(new byte[] { 0x02 })
				.Returns(new byte[] { 0x03 })
				;

			disassemblerMock.SetupSequence(disassembler => disassembler.NextMessage())
				.Returns(new Message("").SetValueFrom("1"))
				.Returns(new Message("").SetValueFrom("2"))
				.Returns(new Message("").SetValueFrom("3"))
				.Returns(new Message("").SetValueFrom("4"))
				;

			// Receive pipeline tests

			byte[] data = new byte[0];
			appHost.PushPipelineData(receiveEndpoint.Object, data);
			appHost.PushPipelineData(receiveEndpoint.Object, data);
			appHost.PushPipelineData(receiveEndpoint.Object, data);
			appHost.PushPipelineData(receiveEndpoint.Object, data);

			decoderMock.Verify(decoder => decoder.Decode(data), Times.Exactly(4));

			disassemblerMock.Verify(disassembler => disassembler.Disassemble(It.IsAny<byte[]>()), Times.Exactly(4));
			disassemblerMock.Verify(disassembler => disassembler.Disassemble(It.Is<byte[]>(bytes => bytes[0] == 0x00)), Times.Once);
			disassemblerMock.Verify(disassembler => disassembler.Disassemble(It.Is<byte[]>(bytes => bytes[0] == 0x01)), Times.Once);
			disassemblerMock.Verify(disassembler => disassembler.Disassemble(It.Is<byte[]>(bytes => bytes[0] == 0x02)), Times.Once);
			disassemblerMock.Verify(disassembler => disassembler.Disassemble(It.Is<byte[]>(bytes => bytes[0] == 0x03)), Times.Once);

			appHostMock.Verify(host => host.PublishMessage(It.IsAny<IEndpoint>(), It.IsAny<Message>()), Times.Exactly(4));
			appHostMock.Verify(host => host.PublishMessage(It.IsAny<IEndpoint>(), It.Is<Message>(msg => msg.GetString(null).Equals("1"))), Times.Once);
			appHostMock.Verify(host => host.PublishMessage(It.IsAny<IEndpoint>(), It.Is<Message>(msg => msg.GetString(null).Equals("2"))), Times.Once);
			appHostMock.Verify(host => host.PublishMessage(It.IsAny<IEndpoint>(), It.Is<Message>(msg => msg.GetString(null).Equals("3"))), Times.Once);
			appHostMock.Verify(host => host.PublishMessage(It.IsAny<IEndpoint>(), It.Is<Message>(msg => msg.GetString(null).Equals("4"))), Times.Once);

			// Send pipeline tests

			Message message = new Message("nothing");
			appHost.PushPipelineData(sendEndpoint.Object, message.Clone());
			appHost.PushPipelineData(sendEndpoint.Object, message.Clone());
			appHost.PushPipelineData(sendEndpoint.Object, message.Clone());
			appHost.PushPipelineData(sendEndpoint.Object, message.Clone());

			assemblerMock.Verify(assembler => assembler.AddMessage(It.IsNotNull<Message>()), Times.Exactly(4));

			encoderMock.Verify(encoder => encoder.Encode(It.IsAny<byte[]>()), Times.Exactly(4));
			encoderMock.Verify(encoder => encoder.Encode(It.Is<byte[]>(bytes => bytes[0] == 0x00)), Times.Once);
			encoderMock.Verify(encoder => encoder.Encode(It.Is<byte[]>(bytes => bytes[0] == 0x01)), Times.Once);
			encoderMock.Verify(encoder => encoder.Encode(It.Is<byte[]>(bytes => bytes[0] == 0x02)), Times.Once);
			encoderMock.Verify(encoder => encoder.Encode(It.Is<byte[]>(bytes => bytes[0] == 0x03)), Times.Once);

			// sendEndpointMock.Verify( verify that it receive data from the pipeline for sending )
		}
开发者ID:NiclasOlofsson,项目名称:HIE,代码行数:85,代码来源:PipelineTest.cs

示例7: PublishMessage

		public virtual void PublishMessage(object source, Message message)
		{
			// Store message in queue (message box). Not yet implemented, but is what publish/subscribe will do

			// Process messages

			if (source is IEndpoint)
			{
				foreach (var application in Applications)
				{
					foreach (var channel in application.Channels)
					{
						if (channel.Source.AcceptMessage(source, message))
						{
							channel.Source.ProcessMessage(source, message.Clone());
						}
					}
				}
			}
			else if (source is Source)
			{
				// This is coming from source after transformation
				foreach (Destination destination in ((Source) source).Channel.Destinations)
				{
					if (destination.AcceptMessage((Source) source, message))
					{
						destination.ProcessMessage((Source) source, message.Clone());
					}
				}
			}
			else if (source is Destination)
			{
				foreach (var application in Applications)
				{
					foreach (var port in application.Ports)
					{
						ProcessInPipeline(port.Endpoint, message);
					}
				}
			}
			else
			{
				throw new Exception(string.Format("Illegal route. Source: {0}, Message {2}", source, message.Id));
			}
		}
开发者ID:NiclasOlofsson,项目名称:HIE,代码行数:45,代码来源:ApplicationHost.cs


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