コード例 #1
0
ファイル: PipeTests.cs プロジェクト: nka1/Daytona
        public void InProcOnlyWithForwarder ()
        {
            string expectedAddress = "XXXX";
            string message = "hello its me";
            int count = 0;
            using (var context = ZmqContext.Create())
            {
                Pipe pipe = new Pipe();
                pipe.Start(context);

                Task.Run(() =>
                {
                    return RunSubscriber(context);
                });

                using (ZmqSocket pub = Helper.GetConnectedPublishSocket(context, Pipe.PublishAddressClient), 
                   syncService = context.CreateSocket(SocketType.REP))
                {
                    syncService.Connect(Pipe.PubSubControlFrontAddressClient);
                    for (int i = 0; i < 1; i++)
                    {
                        syncService.Receive(Encoding.Unicode);
                        syncService.Send("", Encoding.Unicode);
                    }
    
                    Helper.SendOneSimpleMessage(expectedAddress, message, pub);
                           

                }
                pipe.Exit();
            }          
        }
コード例 #2
0
ファイル: PipeTests.cs プロジェクト: nka1/Daytona
        public void SendOneMessage()
        {
            string input = string.Empty;
            string expectedAddress = "XXXXxxxx";
            string message = string.Empty;
            var count = 2;

            using (var context = ZmqContext.Create())
            {
                var pipe = new Pipe();
                pipe.Start(context);
                using (var pub = Helper.GetConnectedPublishSocket(context))
                {
                    using (var sub = Helper.GetConnectedSubscribeSocket(context))
                    {

                        Helper.SendOneSimpleMessage(expectedAddress, message, pub);

                        var zmqMessage = Helper.ReceiveMessage(sub);

                        Assert.AreEqual(count, zmqMessage.FrameCount);
                        Frame frame = zmqMessage[0];
                        var address = Encoding.Unicode.GetString(frame.Buffer);
                        Assert.AreEqual(expectedAddress, address);
                    }
                }

                pipe.Exit();
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: nka1/Daytona
        static void Main(string[] args)
        {
            var input = string.Empty;
            Console.CancelKeyPress += new ConsoleCancelEventHandler(ConsoleCancelHandler);

            using (var context = ZmqContext.Create())
            {
                using (var pipe = new Pipe())
                {
                    pipe.Start(context);
                    Console.WriteLine("enter to exit=>");
                    input = Console.ReadLine();
                }
            }
        }
コード例 #4
0
ファイル: PipeTests.cs プロジェクト: nka1/Daytona
        public void SendFiveMessageOfTypeConfigureActorToProcess()
        {
             string input = string.Empty;
            string expectedAddress = "XXXXxxxx";
            string message = string.Empty;

            using (var context = ZmqContext.Create())
            {
                var pipe = new Pipe();
                pipe.Start(context);
                using (var pub = Helper.GetConnectedPublishSocket(context))
                {
                    using (var sub = Helper.GetConnectedSubscribeSocket(context))
                    {
                        using (var actor = new Actor(context))
                        {
                            ISerializer serializer = new Serializer(Encoding.Unicode);
                            actor.RegisterActor<Customer>("Basic", expectedAddress, "OutRoute", serializer, (Message, InRoute, OutRoute, Socket, Actor) =>
                            {
                                var customer = (Customer)Message;
                                if (!Actor.PropertyBag.ContainsKey("Count"))
                                {
                                    Actor.PropertyBag.Add("Count", "0");
                                }
                                var count = int.Parse(Actor.PropertyBag["Count"]);
                                count++;
                                Actor.PropertyBag["Count"] = count.ToString();

                                //Assert.AreEqual(cust.Firstname, customer.Firstname);
                                Helper.SendOneSimpleMessage("log", customer.Firstname + " " + customer.Lastname + " " + " Count " + Actor.PropertyBag["Count"], Socket);
                            }).RegisterActor("Logger", "log", (Message, InRoute) =>
                                {
                                    Helper.Writeline(Message);
                                });
                            actor.StartAllActors();

                            Task.Delay(5000);

                            for (int i = 0; i < 5; i++)
                            {
                                ISerializer serializer2 = new Serializer(Encoding.Unicode);
                                Customer cust = new Customer();
                                cust.Firstname = "John" + i.ToString();
                                cust.Lastname = "Wilson" + i.ToString();

                                Helper.SendOneMessageOfType<Customer>(expectedAddress, cust, serializer2, pub);
                            }

                            Helper.SendOneSimpleMessage(expectedAddress, "Stop", pub);
                            Task.Delay(5000);
                        }
                    }
                }
                pipe.Exit();
            }
        }
コード例 #5
0
ファイル: PipeTests.cs プロジェクト: nka1/Daytona
        public void SendOneMessageOfTypeConfigureActorToProcess()
        {
            using (var pipeContext = ZmqContext.Create())
            {
                var pipe = new Pipe();
                var task2 = Task.Run(() =>
                    {
                        pipe.Start(pipeContext);
                    });

                var task = Task.Run(() =>
                    {
                        string input = string.Empty;
                        string expectedAddress = "XXXXxxxx";
                        string message = string.Empty;

                        using (var context = ZmqContext.Create())
                        {

                            using (var pub = Helper.GetConnectedPublishSocket(context))
                            {
                                //using (var sub = GetConnectedSubscribeSocket(context))
                                //{
                                ISerializer serializer = new Serializer(Encoding.Unicode);
                                Customer cust = new Customer();
                                cust.Firstname = "Johnx";
                                cust.Lastname = "Wilson";

                                using (var actor = new Actor(context))
                                {
                                    actor.RegisterActor<Customer>("Basic", expectedAddress, "OutRoute", serializer, (Message, InRoute, OutRoute, Socket, Actor) =>
                                        {
                                            var customer = (Customer)Message;
                                            Assert.AreEqual(cust.Firstname, customer.Firstname);
                                            Helper.Writeline(customer.Firstname, @"c:\dev\xx.log");
                                        });
                                    actor.StartAllActors();

                                    Thread.Sleep(0);
                                }

                                for (int i = 0; i < 10; i++)
                                {
                                    cust.Firstname = i.ToString();
                                    Helper.SendOneMessageOfType<Customer>(expectedAddress, cust, serializer, pub);
                                    Thread.Sleep(0);
                                }
                                Helper.SendOneSimpleMessage(expectedAddress, "stop", pub);
                                Thread.Sleep(0);
                            }
                            //pipe.Exit();
                            //Thread.Sleep(0);
                        }
                    });
                Task.WaitAll(task, task2);
                pipe.Exit();
            }
        }
コード例 #6
0
ファイル: PipeTests.cs プロジェクト: nka1/Daytona
        public void SendOneMessageOfType()
        {
            string input = string.Empty;
            string expectedAddress = "XXXXxxxx";
            string message = string.Empty;

            using (var context = ZmqContext.Create())
            {
                var pipe = new Pipe();
                pipe.Start(context);
                using (var pub = Helper.GetConnectedPublishSocket(context))
                {
                    using (var sub = Helper.GetConnectedSubscribeSocket(context))
                    {
                        ISerializer serializer = new Serializer(Encoding.Unicode);
                        Customer cust = new Customer();
                        cust.Firstname = "John";
                        cust.Lastname = "Wilson";

                        Helper.SendOneMessageOfType<Customer>(expectedAddress, cust, serializer, pub);

                        Customer customer = Helper.ReceiveMessageofType<Customer>(sub);

                        Assert.AreEqual(cust.Firstname, customer.Firstname);
                        Assert.AreEqual(cust.Lastname, customer.Lastname);
                    }
                }

                pipe.Exit();
            }
        }