當前位置: 首頁>>代碼示例>>C#>>正文


C# Actor.StartAllActors方法代碼示例

本文整理匯總了C#中Actor.StartAllActors方法的典型用法代碼示例。如果您正苦於以下問題:C# Actor.StartAllActors方法的具體用法?C# Actor.StartAllActors怎麽用?C# Actor.StartAllActors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Actor的用法示例。


在下文中一共展示了Actor.StartAllActors方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: RunSubscriber

       private Task RunSubscriber(NetMQContext context)
       {
            using (NetMQSocket syncClient = context.CreateRequestSocket())
            {
                syncClient.Connect(Pipe.PubSubControlBackAddressClient);
                syncClient.Send(string.Empty);
                syncClient.Receive();
                
                var actions = new Dictionary<string, Delegate>();
                actions.Add("MethodInfo", TestActors);
                actions.Add("ShutDownAllActors", ShutDownAllActors);

                using (var actor = new Actor<Order>(context, new BinarySerializer()))
                {
                    actor.RegisterActor(
                        "Display",
                        string.Empty,
                        "outRoute",
                        null,
                        new BinarySerializer(),
                        new DefaultSerializer(Exchange.ControlChannelEncoding),
                        actions);

                    actor.StartAllActors();
                }               
            }    

            return null;
        }
開發者ID:yonglehou,項目名稱:Daytona,代碼行數:29,代碼來源:ActorTests.cs

示例2: SendFiveMessageOfTypeConfigureActorToProcess

        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();
            }
        }
開發者ID:nka1,項目名稱:Daytona,代碼行數:56,代碼來源:PipeTests.cs

示例3: Main

        static void Main(string[] args)
        {
            //    AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            //    var directoryInfo = new DirectoryInfo(Environment.CurrentDirectory);
            //    var Files = directoryInfo.GetFiles();
            //    var path = Environment.CurrentDirectory + @"\NProxy.Core.dll";
            //    var assembly = Assembly.LoadFrom(path);

            Console.CancelKeyPress += new ConsoleCancelEventHandler(ConsoleCancelHandler);
            var binarySerializer = new BinarySerializer();
            var useActor = true;

            using (var context = NetMQContext.Create())
            {
                //if (!useActor)
                //{
                //    var subscriber = context.CreateSubscriberSocket();
                //    subscriber.Connect(Pipe.SubscribeAddressClient);
                //    subscriber.Subscribe(string.Empty);
                //    while (!interrupted)
                //    {
                //        var frame = subscriber.ReceiveFrame();
                //        try
                //        {
                //            Console.WriteLine(binarySerializer.Deserializer(frame, typeof(string)));
                //        }
                //        catch (Exception)
                //        {
                //        }

                //        while (subscriber.ReceiveMore)
                //        {
                //            var frame1 = subscriber.ReceiveFrame();
                //        }
                //    }
                //}
                //else
                //{
                using (var actorFactory = new Actor<Silo>(context, new BinarySerializer(), string.Empty))
                {
                    actorFactory.RegisterActor(
                        "Display",
                        "",
                        "outRoute",
                        new BinarySerializer(),
                        new DefaultSerializer(Exchange.ControlChannelEncoding),
                        (address, methodinfo, parameters, actor) =>
                            {
                                var firstParameter = string.Empty;
                                try
                                {
                                    firstParameter = parameters[0].ToString();
                                }
                                catch (Exception)
                                {
                                }

                                Console.WriteLine("Address: {0}, {1}", address, firstParameter);
                            });
                    actorFactory.StartAllActors();
                    Console.WriteLine("yada ");

                    while (!interrupted)
                    {
                        Console.ReadLine();
                    }
                }
                //}
            }
        }
開發者ID:yonglehou,項目名稱:Daytona,代碼行數:70,代碼來源:Program.cs

示例4: SendOneMessageOfTypeConfigureActorToProcess

        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();
            }
        }
開發者ID:nka1,項目名稱:Daytona,代碼行數:58,代碼來源:PipeTests.cs


注:本文中的Actor.StartAllActors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。