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


C# IConnection.Subscribe方法代码示例

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


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

示例1: RunClientSubscriber

        private void RunClientSubscriber(IConnection<SimpleMessage<int>, int> connection, IConnectionStubListener<SimpleMessage<int>, int> listener, ushort port)
        {
            listener.BindTo(new IPEndPoint(IPAddress.Any, port));
            var listenerTask = Task.Run(() => RunListenerSubscriber(listener));
            var ready = false;
            connection.Subscribe(0, (message, size) => ready = true);
            connection.Subscribe(1, (message, size) => TextMessageHandler("Client", message, size));
            connection.Connect(new IPEndPoint(IPAddress.Loopback, port));
            while (!ready)
                Thread.CurrentThread.Join(10);

            const int messages = 500;
            Console.WriteLine(@"Sending {0} messages with random data", 5);
            var rnd = new Random();
            for (var i = 0; i < messages; ++i)
            {
                var data = new byte[rnd.Next(16, 256)];
                rnd.NextBytes(data);
                connection.Send(new SimpleMessage<int>(1, Encoding.ASCII.GetBytes(Convert.ToBase64String(data))));
            }
            Console.WriteLine(@"Client: Done, sending exit message");
            connection.Send(new SimpleMessage<int>(2));
            connection.Disconnect();
            Console.WriteLine(@"Waiting for listener thread to exit");
            listenerTask.Wait();
            Console.WriteLine(@"Listener thread has exited");
            Console.WriteLine();
            Console.WriteLine(@"Press any key to exit");
            Console.ReadKey();
        }
开发者ID:Melamew,项目名称:iLynx.Common,代码行数:30,代码来源:TcpConnectionTests.cs

示例2: Subscribe

 private void Subscribe(IConnection connection)
 {
     Contract.Requires(connection != null);
     this.subscriptions = new List<IDisposable>
     {
         connection.Subscribe((AccountValueMessage message) => message.AccountName == this.account,
             this.OnAccountValueMessage),
         connection.Subscribe((AccountDownloadEndMessage message) => message.AccountName == this.account,
             this.OnAccountDownloadEndMessage)
     };
 }
开发者ID:qadmium,项目名称:ibapi,代码行数:11,代码来源:CreateAccountOperation.cs

示例3: Subscribe

        private void Subscribe(IConnection connection)
        {
            CodeContract.Requires(connection != null);
            this.subscriptions.AddRange(new []
            {
                connection.Subscribe((OrderStatusMessage message) => message.OrderId == this.Id,
                this.OnStatusUpdate),

                connection.Subscribe((ErrorMessage message) => message.RequestId == this.Id,
                this.OnError)
            });
        }
开发者ID:qadmium,项目名称:ibapi,代码行数:12,代码来源:Order.cs

示例4: Account

        public Account(string name, IConnection connection, IApiObjectsFactory factory, IExecutionStorageInternal executionStorage,
            IPositionsStorageInternal positionsesStorageInternal, IOrdersStorageInternal ordersStorageInternal,
            IIdsDispenser idsDispenser, CancellationTokenSource internalCancelationTokenSource,
            AccountCurrenciesFields accountCurrenciesFields)
        {
            CodeContract.Requires(!string.IsNullOrEmpty(name));
            CodeContract.Requires(connection != null);
            CodeContract.Requires(factory != null);
            CodeContract.Requires(executionStorage != null);
            CodeContract.Requires(positionsesStorageInternal != null);
            CodeContract.Requires(ordersStorageInternal != null);
            CodeContract.Requires(accountCurrenciesFields != null);
            CodeContract.Requires(idsDispenser != null);

            this.AccountName = name;
            this.AccountId = name;

            this.factory = factory;
            this.executionStorage = executionStorage;
            this.positionsesStorage = positionsesStorageInternal;
            this.ordersStorage = ordersStorageInternal;
            this.accountCurrenciesFields = accountCurrenciesFields;
            this.idsDispenser = idsDispenser;
            this.internalCancelationTokenSource = internalCancelationTokenSource;

            this.subscription =
                connection.Subscribe((AccountValueMessage message) => message.AccountName == this.AccountName,
                    this.OnAccountValueMessage);
        }
开发者ID:qadmium,项目名称:ibapi,代码行数:29,代码来源:Account.cs

示例5: Subscribe

 private void Subscribe(IConnection connection)
 {
     System.Diagnostics.Contracts.Contract.Requires(connection != null);
     this.subscription =
         connection.Subscribe((PortfolioValueMessage message) => message.AccountName == this.accountName,
             this.OnPositionUpdate);
 }
开发者ID:qadmium,项目名称:ibapi,代码行数:7,代码来源:PositionsStorage.cs

示例6: Subscribe

        private void Subscribe(IConnection connection, IIdsDispenser dispenser, SearchRequest request)
        {
            CodeContract.Requires(connection != null);
            CodeContract.Requires(dispenser != null);

            var requestId = dispenser.NextRequestId();
            
            this.subscriptions = new List<IDisposable>
            {
                connection.Subscribe((ContractDataMessage message) => message.RequestId == requestId,
                    this.OnContractDataMessage),
                connection.Subscribe((ContractDataEndMessage message) => message.RequestId == requestId,
                    this.OnContractDataEndMessage),
                connection.SubscribeForRequestErrors(requestId, this.OnError)
            };

            SendRequest(request, requestId, connection);
        }
开发者ID:qadmium,项目名称:ibapi,代码行数:18,代码来源:FindContractsOperation.cs

示例7: ReceiveManagedAccountsListOperation

 public ReceiveManagedAccountsListOperation(IConnection connection, CancellationToken cancellationToken)
 {
     Contract.Requires(connection != null);
     Contract.Requires(!cancellationToken.IsCancellationRequested);
     this.cancellationToken = cancellationToken;
     this.cancellationToken.Register(() =>
     {
         this.subscription.Dispose();
         this.taskCompletionSource.TrySetCanceled();
     });
     this.subscription = connection.Subscribe<ManagedAccountsListMessage>(this.OnManagedAccountList);
 }
开发者ID:qadmium,项目名称:ibapi,代码行数:12,代码来源:ReceiveManagedAccountsListOperation.cs

示例8: Subscribe

 private void Subscribe(IConnection connection)
 {
     Contract.Requires(connection != null);
     this.subscription = connection.Subscribe((OpenOrderMessage message) => message.Account == this.accountName,
         this.OnNewOrder);
 }
开发者ID:qadmium,项目名称:ibapi,代码行数:6,代码来源:OrdersStorage.cs

示例9: ContactViewModel

 public ContactViewModel(Contact model)
 {
     _connection = StreamFactory.Connect(model.Id);
     _connection.Subscribe(m => Model = m);
     _connection.Emit(model);
 }
开发者ID:envicase,项目名称:flip,代码行数:6,代码来源:ContactViewModel.cs

示例10: IdsDispenser

 public IdsDispenser(IConnection connection)
 {
     Contract.Requires(connection != null);
     this.subscription = connection.Subscribe((NextValidIdMessage message) => this.OnNextValidId(message));
 }
开发者ID:qadmium,项目名称:ibapi,代码行数:5,代码来源:IdsDispenser.cs


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