public void Run() { IFiberFactory factory = new FiberFactory(); int OperationsPerInvoke = 1_000; using IChannel <string> _input = new Channel <string>(); using IChannel <string> _queue = new QueueChannel <string>(); using IChannel <string> _output = new Channel <string>(); int count = 0; using AutoResetEvent reset = new AutoResetEvent(false); void Handler1(string x) { string u = x.ToUpper(); _queue.Publish(u); } void Handler(string x) { string l = x.ToLower(); _output.Publish(l); } void Action(string x) { int c = Interlocked.Increment(ref count); if (c >= OperationsPerInvoke) { reset.Set(); } } using ChannelAgent <string> fiber = new ChannelAgent <string>(factory, _input, Handler1); IDisposable[] middle = Enumerable.Range(0, 10) .Select(x => new ChannelAgent <string>(factory, _queue, Handler)).ToArray(); using ChannelAgent <string> fiberOut = new ChannelAgent <string>(factory, _output, Action); for (int i = 0; i < OperationsPerInvoke; i++) { _input.Publish("a"); } reset.WaitOne(TimeSpan.FromSeconds(20)); foreach (IDisposable t in middle) { t.Dispose(); } }
private static void Main() { IChannel <string> toProcess = new Channel <string>(); IChannel <string> completed = new Channel <string>(); //first fiber will place something on channel for 2nd fiber to process using (IFiber fiber1 = PoolFiber.StartNew()) //2nd fiber just writes to the completed channel using (IDisposable processor = new ChannelAgent <string>(toProcess, s => completed.Publish("Received " + s))) //A logger that watches the completed channel. Could be optional using (IDisposable logger = new ChannelAgent <string>(completed, Console.WriteLine)) { int count = 0; //Start sending a message after a second, every 2 seconds... fiber1.Schedule(() => toProcess.Publish("Test" + count++), TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2)); Console.ReadKey(); } }
private static void Main(string[] args) { IChannel<string> toProcess = new Channel<string>(); IChannel<string> completed = new Channel<string>(); //first fiber will place something on channel for 2nd fiber to process using (IFiber fiber1 = PoolFiber.StartNew()) //2nd fiber just writes to the completed channel using (IDisposable processor = new ChannelAgent<string>(toProcess, s => completed.Publish("Received " + s))) //A logger that watches the completed channel. Could be optional using (IDisposable logger = new ChannelAgent<string>(completed, Console.WriteLine)) { int count = 0; //Start sending a message after a second, every 2 seconds... fiber1.Schedule(() => toProcess.Publish("Test" + count++), TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2)); Console.ReadKey(); } }
public ChannelAgency CreateChannelAgency(ChannelAgent channelAgent, User user) { using (CurrentUnitOfWork.SetTenantId(user.TenantId)) { ChannelAgency channelAgency = new ChannelAgency() { UserId = user.Id, ChannelAgentId = channelAgent.Id, RebateRatio = channelAgent.RebateRatio }; ChannelAgencyRepository.Insert(channelAgency); CurrentUnitOfWork.SaveChanges(); user.IsChannelAgency = true; user.UserChannelAgencyId = channelAgency.Id; UserRepository.Update(user); ProcessChannlRelationChain(channelAgency); return(channelAgency); } }