本文整理汇总了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();
}
示例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)
};
}
示例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)
});
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例8: Subscribe
private void Subscribe(IConnection connection)
{
Contract.Requires(connection != null);
this.subscription = connection.Subscribe((OpenOrderMessage message) => message.Account == this.accountName,
this.OnNewOrder);
}
示例9: ContactViewModel
public ContactViewModel(Contact model)
{
_connection = StreamFactory.Connect(model.Id);
_connection.Subscribe(m => Model = m);
_connection.Emit(model);
}
示例10: IdsDispenser
public IdsDispenser(IConnection connection)
{
Contract.Requires(connection != null);
this.subscription = connection.Subscribe((NextValidIdMessage message) => this.OnNextValidId(message));
}