本文整理汇总了C#中Channel类的典型用法代码示例。如果您正苦于以下问题:C# Channel类的具体用法?C# Channel怎么用?C# Channel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Channel类属于命名空间,在下文中一共展示了Channel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: can_read_after_select_on_queued_Channels
public void can_read_after_select_on_queued_Channels()
{
var ch1 = new Channel<int>(1);
var ch2 = new Channel<bool>(1);
ThreadPool.QueueUserWorkItem(state => {
ch1.Send(123);
ch2.Send(true);
ch2.Close();
ch1.Send(124);
ch1.Close();
});
using (var select = new Channels(Op.Recv(ch1), Op.Recv(ch2))) {
var got = select.Select();
Debug.Print("got.Index = " + got.Index);
if (got.Index == 0) {
Assert.AreEqual(123, got.Value, "got.Value");
Assert.AreEqual(Maybe<bool>.Some(true), ch2.Recv());
}
else {
Assert.AreEqual(1, got.Index, "got.Index");
Assert.AreEqual(true, got.Value, "got.Value");
Assert.AreEqual(Maybe<int>.Some(123), ch1.Recv());
}
select.ClearAt(1);
got = select.Select();
Assert.AreEqual(0, got.Index, "got.Index, value =" + got.Value);
Assert.AreEqual(124, got.Value, "got.Value");
}
}
示例2: Main
static void Main(string[] args)
{
Channel channel = new Channel();
HelloService service = new HelloService();
channel.AddMethod<HelloRequest, HelloSerializer>("maid.example.HelloService.HelloNotify", service.HelloNotify);
channel.AddMethod<HelloRequest, HelloSerializer, HelloResponse, HelloSerializer>("maid.example.HelloService.HelloRpc", service.HelloRpc);
channel.ConnectedCallback.Add(() =>
{
Console.WriteLine("连接上了");
});
channel.Connect("192.168.0.99", 8888);
while (true)
{
channel.Update();
HelloRequest request = new HelloRequest();
request.message = "this message from protobuf-net";
try
{
channel.CallMethod("maid.example.HelloService.HelloNotify", request);
channel.CallMethod("maid.example.HelloService.HelloRpc", request);
}
catch (Exception ){ }
if (channel.Connecting)
{
Console.WriteLine("连接中");
}
}
}
示例3: can_recv_one_item_before_closing
public void can_recv_one_item_before_closing()
{
var ch = new Channel<int>(1);
ThreadPool.QueueUserWorkItem(state => { ch.Send(123); ch.Close(); });
Assert.AreEqual(Maybe<int>.Some(123), ch.Recv());
Assert.AreEqual(Maybe<int>.None(), ch.TryRecv());
}
示例4: BatchingWithKey
public void BatchingWithKey()
{
using (var fiber = new ThreadFiber())
{
fiber.Start();
var counter = new Channel<int>();
var reset = new ManualResetEvent(false);
Action<IDictionary<String, int>> cb = delegate(IDictionary<String, int> batch)
{
if (batch.ContainsKey("9"))
{
reset.Set();
}
};
Converter<int, String> keyResolver = x => x.ToString();
counter.SubscribeToKeyedBatch<int, String>(fiber, cb, keyResolver, 0);
for (var i = 0; i < 10; i++)
{
counter.Publish(i);
}
Assert.IsTrue(reset.WaitOne(10000, false));
}
}
示例5: CommandContext
public CommandContext(Client irc, UserCollection users, User from, Channel channel, string message)
{
this._irc = irc;
this._users = users;
this.From = from;
this._channel = channel;
if (message[0] == '!' || message[0] == '.')
{
this._replyNotice = true;
}
else
{
this._replyNotice = false;
}
if (message[0] == '!' || message[0] == '.' || message[0] == '@')
{
this.Message = message.Substring(1);
}
else
{
this.Message = message;
}
}
示例6: ChatServerMessage
public ChatServerMessage(Channel chan, string message, Global.Character actor)
: base(PacketType.ChatServerMessage)
{
Channel = chan;
Message = message;
Actor = actor;
}
示例7: Init
public override void Init(Channel ch, ProtocolHeader hdr)
{
if (hdr.Major != 0 && hdr.Minor != 10)
{
throw new ProtocolVersionException((sbyte) hdr.Major, (sbyte) hdr.Minor);
}
}
示例8: GetMillivolts
public double GetMillivolts(Channel channel, Gain gain = Gain.Volt5, SamplesPerSecond sps = SamplesPerSecond.SPS1600) {
lock (deviceLock) {
byte[] result = new byte[2];
// Set disable comparator and set "single shot" mode
config = 0x0003 | 0x8000; // | 0x100;
config |= (ushort)SamplePerSecondMap[(int)sps];
config |= (ushort)channel;
config |= (ushort)programmableGainMap[(int)gain];
data[0] = REG_CFG;
data[1] = (byte)((config >> 8) & 0xFF);
data[2] = (byte)(config & 0xFF);
I2CDevice.Write(data);
// delay in milliseconds
//int delay = (1000.0 / SamplesPerSecondRate[(int)sps] + .1;
// int delay = 1;
Task.Delay(TimeSpan.FromMilliseconds(.5)).Wait();
I2CDevice.WriteRead(new byte[] { (byte)REG_CONV, 0x00 }, result);
//var r = (((result[0] << 8) | result[1]) >> 4);
//Debug.WriteLine(r.ToString());
return (ushort)(((result[0] << 8) | result[1]) >> 4) * programmableGain_Scaler[(int)gain] / 2048;
}
}
示例9: _AddChannel
private void _AddChannel(Channel channel)
{
ChannelColorStateControl control = new ChannelColorStateControl(channel.Name);
_channelControls[channel.Id] = control;
control.Dock = DockStyle.Top;
Controls.Add(control);
}
示例10: Start
public void Start(Channel channel, int numWorkerThreads)
{
channelReceiver = channelFactory.GetReceiver(channel.Type);
channelReceiver.DataReceived += DataReceivedOnChannel;
channelReceiver.Start(channel.Address,numWorkerThreads);
}
示例11: YPitchBendCube
public YPitchBendCube(Point3D center, double radius,
Pitch pitch, Instrument instrument, OutputDevice device, Channel channel)
: base(center, radius, new InstrumentNoteAction(device, channel, pitch)) {
outputDevice = device;
this.channel = channel;
}
示例12: ProtocolFaultResponseException
/// <summary>
/// Initializes a new instance of the <see cref="ProtocolFaultResponseException"/> class
/// such that it can be sent as a protocol message response to a remote caller.
/// </summary>
/// <param name="channel">The channel to use when encoding the response message.</param>
/// <param name="errorResponse">The message to send back to the HTTP client.</param>
/// <param name="faultedMessage">The message that was the cause of the exception. May be null.</param>
/// <param name="innerException">The inner exception.</param>
/// <param name="message">The message for the exception.</param>
protected internal ProtocolFaultResponseException(Channel channel, IDirectResponseProtocolMessage errorResponse, IProtocolMessage faultedMessage = null, Exception innerException = null, string message = null)
: base(message ?? (innerException != null ? innerException.Message : null), faultedMessage, innerException) {
Requires.NotNull(channel, "channel");
Requires.NotNull(errorResponse, "errorResponse");
this.channel = channel;
this.ErrorResponseMessage = errorResponse;
}
示例13: AttemptToCloseChannel
protected void AttemptToCloseChannel(Channel channel)
{
if (channel.UserCount == 0
&& channel != Channel_Main
&& channel != Channel_Void)
Channels.Remove(channel);
}
示例14: Start
public void Start(Channel channel)
{
channelReceiver = (IChannelReceiver)builder.Build(channel.Receiver);
channelReceiver.DataReceived += DataReceivedOnChannel;
channelReceiver.Start(channel.ReceiveAddress, channel.NumWorkerThreads);
}
示例15: Hook_PRIV
public override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message)
{
if (message.StartsWith(Configuration.System.CommandPrefix + "translate "))
{
message = message.Substring(11);
List<string> parts = new List<string>(message.Split(' '));
if (parts.Count < 3)
{
IRC.DeliverMessage("Invalid number of parameters", channel);
return;
}
string target = null;
string source_language = parts[0];
string target_language = parts[1];
if (!IsValid(source_language) || !IsValid(target_language))
{
IRC.DeliverMessage(invoker.Nick + ": invalid language!", channel);
return;
}
string text = message.Substring(message.IndexOf(parts[1]) + parts[1].Length + 1);
if (text.Contains("|"))
{
target = text.Substring(text.IndexOf("|") + 1).Trim();
text = text.Substring(0, text.IndexOf("|"));
}
// schedule a message
Ring.Add(new Buffer.Item(channel, source_language, target_language, target, text));
}
}