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


C# IConnector.Connect方法代码示例

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


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

示例1: SetUp

        public void SetUp()
        {
            acceptor = new UdpAcceptor(IPAddress.Any, 8765,
                new TransportFactory<UdpHandle>(BaseUdpTransport.SequencedProtocolDescriptor,
                    h => new UdpSequencedServerTestTransport(h),
                    t => t is UdpSequencedServerTestTransport));
            connector = new UdpConnector(
                new TransportFactory<UdpClient>(BaseUdpTransport.SequencedProtocolDescriptor,
                    h => new UdpSequencedClientTestTransport(h),
                    t => t is UdpSequencedClientTestTransport));

            acceptor.NewTransportAccepted += delegate(ITransport transport, IDictionary<string, string> capabilities)
            {
                serverTransport = (UdpSequencedServerTestTransport)transport;
            };
            acceptor.Start();
            Thread acceptorThread = new Thread(delegate()
            {
                for (int i = 0; serverTransport == null && i < 100; i++)
                {
                    try
                    {
                        acceptor.Update();
                        Thread.Sleep(50);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Acceptor Thread: " + e);
                    }
                }
            });
            acceptorThread.IsBackground = true;
            acceptorThread.Name = "Acceptor Thread";
            acceptorThread.Start();
            Thread.Sleep(50);

            clientTransport = (UdpSequencedClientTestTransport)connector.Connect("127.0.0.1", "8765", new Dictionary<string, string>());
            acceptorThread.Join();
            Assert.IsNotNull(clientTransport);
            Assert.IsNotNull(serverTransport);

            acceptor.Dispose();
            connector.Dispose();
        }
开发者ID:briandealwis,项目名称:gt,代码行数:44,代码来源:TransportTests.cs

示例2: TestTransport

        public void TestTransport(IAcceptor acc, IConnector conn, string address, string port)
        {
            acceptor = acc;
            connector = conn;

            acceptor.Start();
            acceptor.NewTransportAccepted += SetupServer;
            acceptorThread = new Thread(RunAcceptor);
            acceptorThread.Name = "Acceptor";
            acceptorThread.IsBackground = true;
            acceptorThread.Start();

            client = connector.Connect(address, port, new Dictionary<string, string>());
            Assert.IsNotNull(client);
            client.PacketReceived += ClientReceivedPacket;

            for (int i = 0; i < 10; i++)
            {
                sourceData[0] = (byte)i;
                Debug("client: sending packet#" + i + ": "
                    + ByteUtils.DumpBytes(sourceData, 0, sourceData.Length));
                client.SendPacket(new TransportPacket(sourceData));
                if (failure.Length != 0)
                {
                    Assert.Fail(failure);
                }
                Thread.Sleep(500);
                client.Update();
            }
            Assert.AreEqual(10, serverPacketCount);
            Assert.AreEqual(10, clientPacketCount);

            try
            {
                client.SendPacket(new TransportPacket(new byte[client.MaximumPacketSize * 2]));
                Assert.Fail("Transport allowed sending packets exceeding its capacity");
            }
            catch (ContractViolation) { /* expected */ }
        }
开发者ID:briandealwis,项目名称:gt,代码行数:39,代码来源:TransportTests.cs

示例3: ConnectClick

		private void ConnectClick(object sender, RoutedEventArgs e)
		{
			var isDde = IsDde.IsChecked == true;

			if (isDde && Path.Text.IsEmpty())
			{
				MessageBox.Show(this, LocalizedStrings.Str2969);
				return;
			}

			if (Connector != null && !(Connector is FakeConnector))
				return;

			PosChart.Positions.Clear();
			PosChart.AssetPosition = null;
			PosChart.Refresh(1, 1, default(DateTimeOffset), default(DateTimeOffset));

			// создаем подключение
			Connector = new QuikTrader(Path.Text)
			{
				IsDde = isDde
			};

			if (isDde)
			{
				// изменяем метаданные так, чтобы начали обрабатывать дополнительные колонки опционов
				var columns = ((QuikTrader)Connector).SecuritiesTable.Columns;
				columns.Add(DdeSecurityColumns.Strike);
				columns.Add(DdeSecurityColumns.ImpliedVolatility);
				columns.Add(DdeSecurityColumns.UnderlyingSecurity);
				columns.Add(DdeSecurityColumns.TheorPrice);
				columns.Add(DdeSecurityColumns.OptionType);
				columns.Add(DdeSecurityColumns.ExpiryDate);
			}

			//_trader = new PlazaTrader { IsCGate = true };
			//_trader.Tables.Add(_trader.TableRegistry.Volatility);

			Portfolio.Connector = Connector;

			PosChart.MarketDataProvider = Connector;
			PosChart.SecurityProvider = Connector;

			// добавляем базовые активы в список
			Connector.NewSecurities += securities =>
				_assets.AddRange(securities.Where(s => s.Type == SecurityTypes.Future));

			Connector.SecuritiesChanged += securities =>
			{
				if ((PosChart.AssetPosition != null && securities.Contains(PosChart.AssetPosition.Security)) || PosChart.Positions.Cache.Select(p => p.Security).Intersect(securities).Any())
					_isDirty = true;
			};

			// подписываемся на событие новых сделок чтобы обновить текущую цену фьючерса
			Connector.NewTrades += trades =>
			{
				var assetPos = PosChart.AssetPosition;
				if (assetPos != null && trades.Any(t => t.Security == assetPos.Security))
					_isDirty = true;
			};

			Connector.NewPositions += positions => this.GuiAsync(() =>
			{
				var asset = SelectedAsset;

				if (asset == null)
					return;

				var assetPos = positions.FirstOrDefault(p => p.Security == asset);
				var newPos = positions.Where(p => p.Security.UnderlyingSecurityId == asset.Id).ToArray();

				if (assetPos == null && newPos.Length == 0)
					return;

				if (assetPos != null)
					PosChart.AssetPosition = assetPos;

				if (newPos.Length > 0)
					PosChart.Positions.AddRange(newPos);

				RefreshChart();
			});

			Connector.PositionsChanged += positions => this.GuiAsync(() =>
			{
				if ((PosChart.AssetPosition != null && positions.Contains(PosChart.AssetPosition)) || positions.Intersect(PosChart.Positions.Cache).Any())
					RefreshChart();
			});

			Connector.Connect();
		}
开发者ID:hbwjz,项目名称:StockSharp,代码行数:91,代码来源:MainWindow.xaml.cs


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