Ejemplo n.º 1
0
        public void TestAwaitDoesntChangeScheduler()
        {
            var scheduler = SingleThreadScheduler.RunOnSeparateThread(TestLifetime, "TestScheduler");
            var channel   = new AsyncChannel <Unit>(TestLifetime);
            var actor     = new Actor <int>("TestActor", TestLifetime, async x =>
            {
                Assert.AreEqual(scheduler, TaskScheduler.Current);
                var task = channel.ReceiveAsync();
                await task;
                Assert.AreEqual(scheduler, TaskScheduler.Current);
            }
                                            , scheduler);

            //first one - immediate
            actor.SendAsync(1);
            channel.SendAsync(Unit.Instance);

            //second one - await after timeout
            Thread.Sleep(50);
            channel.SendAsync(Unit.Instance);
            Thread.Sleep(50);
            channel.SendAsync(Unit.Instance);

            actor.WaitForEmpty();
        }
 public ACSStageController(ConnectMode mode, string address)
 {
     Ch   = new AsyncChannel();
     Axis = new Dictionary <string, int>()
            .Append("Y", 0)
            .Append("X", 1)
            .Append("Z", 2);
     Address = address;
 }
Ejemplo n.º 3
0
        public void TestInfiniteChannelAsync1Thread()
        {
            var def = new LifetimeDefinition();

            myChannel = new AsyncChannel <int>(def.Lifetime);

            Assert.True(myChannel.IsEmpty);

            Assert.True(myChannel.SendAsync(1).Status == TaskStatus.RanToCompletion);
            Assert.True(myChannel.SendAsync(2).Status == TaskStatus.RanToCompletion);
            Assert.AreEqual(1, myChannel.ReceiveAsync().With(t => Assert.AreEqual(TaskStatus.RanToCompletion, t.Status)).Result);
            Assert.AreEqual(2, myChannel.ReceiveAsync().With(t => Assert.AreEqual(TaskStatus.RanToCompletion, t.Status)).Result);

            def.Terminate();
            Assert.True(myChannel.SendAsync(0).IsCanceled);
            Assert.True(myChannel.ReceiveAsync().IsCanceled);
        }
Ejemplo n.º 4
0
        public void TestInfiniteChannelSync1Thread()
        {
            var def = new LifetimeDefinition();

            myChannel = new AsyncChannel <int>(def.Lifetime);

            Assert.True(myChannel.IsEmpty);

            myChannel.SendBlocking(1);
            myChannel.SendBlocking(2);
            myChannel.SendBlocking(3);
            Assert.AreEqual(1, myChannel.ReceiveBlocking());
            Assert.AreEqual(2, myChannel.ReceiveBlocking());
            Assert.AreEqual(3, myChannel.ReceiveBlocking());

            def.Terminate();
            Assert.Throws <AggregateException>(() => myChannel.SendBlocking(0));
            Assert.Throws <AggregateException>(() => myChannel.ReceiveBlocking());
        }
Ejemplo n.º 5
0
 /// <summary>
 /// provides a conversion of the AsyncChannel in a ContextChannel, useful to work with the OperationCOntext for example
 /// </summary>
 /// <typeparam name="TSync">the type of the async channel communication interface</typeparam>
 /// <param name="asyncChannel">the async channel to be converted</param>
 /// <returns>a IContextChannel version of the async comunication channel</returns>
 //HINT: probably it is better to duplicate the entire class hierarchy to enable the use with the
 //OperationContextScope object so to have for example an AsyncOperationContextScope that natively operates with AsyncChannel instead of return on the WCF types
 //so to avoid misure of the internal channel object
 public static IContextChannel ToContextChannel <TSync>(this AsyncChannel <TSync> asyncChannel)
 {
     return(asyncChannel.channel as IContextChannel);
 }
Ejemplo n.º 6
0
 public Task <OrderStatusDTO[]> GetOrderStatuses()
 {
     // return Channel.GetOrderStatuses();
     return(AsyncChannel.ContinueWith(x => x.Result.GetOrderStatuses()).Unwrap());
 }
Ejemplo n.º 7
0
 public Task <OrderDTO[]> GetOrdersByFilter(OrderFilterDTO filter)
 {
     return(AsyncChannel.ContinueWith(x => x.Result.GetOrdersByFilter(filter)).Unwrap());
 }
 public Task <CustomerDTO[]> GetAllCustomers()
 {
     return(AsyncChannel.ContinueWith(x => x.Result.GetAllCustomers()).Unwrap());
 }
 public Task <CompanyDTO[]> GetAllCompanies()
 {
     return(AsyncChannel.ContinueWith(x => x.Result.GetAllCompanies()).Unwrap());
 }