예제 #1
0
        public Task ReceiveReminderAsync(string reminderName, byte[] context, TimeSpan dueTime, TimeSpan period)
        {
            if (reminderName.Equals("HandleMovementTimeout"))
            {
                var previousLocation = ActorModel.GetResult(this.StateManager.GetStateAsync <Location>("CurrentLocation"));
                var location         = ActorModel.GetResult(this.House.GotoRoom());

                ActorModel.Log("[LOG] Person entered room {0}", location);
                ActorModel.Wait(this.StateManager.SetStateAsync("CurrentLocation", location));

                if (previousLocation == Location.Garden)
                {
                    ActorModel.Wait(this.Garden.PersonExits());
                }
                else if (previousLocation == Location.Kitchen)
                {
                    ActorModel.Wait(this.Kitchen.PersonExits());
                }
                else if (previousLocation == Location.Bedroom)
                {
                    ActorModel.Wait(this.Bedroom.PersonExits());
                }

                if (location == Location.Garden)
                {
                    ActorModel.Wait(this.Garden.PersonEnters());
                }
                else if (location == Location.Kitchen)
                {
                    ActorModel.Wait(this.Kitchen.PersonEnters());
                }
                else if (location == Location.Bedroom)
                {
                    ActorModel.Wait(this.Bedroom.PersonEnters());
                }
            }
            else if (reminderName.Equals("HandleActionTimeout"))
            {
                var location = ActorModel.GetResult(this.StateManager.GetStateAsync <Location>("CurrentLocation"));
                if (location == Location.Garden)
                {
                }
                else if (location == Location.Kitchen)
                {
                }
                else if (location == Location.Bedroom)
                {
                    ActorModel.Wait(this.Bedroom.AccessSafe());
                }
            }
            return(Task.FromResult(true));
        }
예제 #2
0
        static void Main(string[] args)
        {
            var        obj = ActorProxy.Create <IHuman>(new ActorId(2), "ABC");
            Task <int> t   = obj.Eat(9, 2, "qwer");
            int        x   = ActorModel.GetResult <int>(t);

            Console.WriteLine(x);

            //var obj = new HumanProxy(PSharpRuntime.Create());
            //Task<int> t = obj.Eat(10, 97, "asdf");
            //int x = ActorModel.GetResult<int>(t);
            //Console.WriteLine(x);

            Console.ReadLine();
        }
예제 #3
0
        //protected override Task OnActivateAsync()
        //{
        //    (this as IActor1).Foo();
        //    return base.OnActivateAsync();
        //}

        public Task Foo()
        {
            var actor2Proxy = ActorProxy.Create <IActor2>(new ActorId(1), "A2");
            int val         = 9;
            var t           = actor2Proxy.SetValue(val, this);

            Console.WriteLine("Actor1 is waiting for set value from Actor2");
            //ActorModel.Wait(t);

            Task <int> s = actor2Proxy.GetValue();
            var        r = ActorModel.GetResult <int>(s);

            Console.WriteLine(r);

            return(Task.FromResult(true));
        }
예제 #4
0
        public Task DoSomething(int numberOfItems)
        {
            var receiverProxy = ActorProxy.Create <IReceiver>(new ActorId(1), "ReceiverProxy");

            receiverProxy.StartTransaction();
            for (int i = 0; i < numberOfItems; i++)
            {
                receiverProxy.TransmitData("xyz" + i);
            }

            int transmitted = ActorModel.GetResult <int>(receiverProxy.GetCurrentCount());

            ActorModel.Assert(transmitted <= numberOfItems, "Items sent: " + numberOfItems + "; Transmitted: " + transmitted);

            return(Task.FromResult(true));
        }
예제 #5
0
        public Task ReceiveReminderAsync(string reminderName, byte[] context, TimeSpan dueTime, TimeSpan period)
        {
            ActorModel.Log("[LOG] Thief reminder {0}", reminderName);
            if (reminderName.Equals("HandleMovementTimeout"))
            {
                var previousLocation = ActorModel.GetResult(this.StateManager.GetStateAsync <Location>("CurrentLocation"));
                var location         = ActorModel.GetResult(this.House.GotoRoom());

                ActorModel.Log("[LOG] Thief tries to enter room {0}", location);
                bool canEnter = false;
                if (location == Location.Garden)
                {
                    canEnter = ActorModel.GetResult(this.Bedroom.TryEnterRoom());
                }
                else if (location == Location.Kitchen)
                {
                    canEnter = ActorModel.GetResult(this.Bedroom.TryEnterRoom());
                }
                else if (previousLocation == Location.Kitchen &&
                         location == Location.Bedroom)
                {
                    canEnter = ActorModel.GetResult(this.Bedroom.TryEnterRoom());
                }

                if (canEnter)
                {
                    ActorModel.Log("[LOG] Thief entered room {0}", location);
                    ActorModel.Wait(this.StateManager.SetStateAsync("CurrentLocation", location));
                }
            }
            else if (reminderName.Equals("HandleActionTimeout"))
            {
                Console.WriteLine("Thief is handling action timeout");
                var location = ActorModel.GetResult(this.StateManager.GetStateAsync <Location>("CurrentLocation"));
                if (location == Location.Garden)
                {
                }
                else if (location == Location.Kitchen)
                {
                }
                else if (location == Location.Bedroom)
                {
                    ActorModel.Wait(this.Bedroom.TryToStealMoney());
                }
            }
            return(Task.FromResult(true));
        }
예제 #6
0
        public static void Execute(PSharpRuntime runtime)
        {
            ActorModel.Start(runtime, () =>
            {
                var config = ClientConfiguration.LocalhostSilo();
                GrainClient.Initialize(config);

                var server = GrainClient.GrainFactory.GetGrain <IServer>(0);
                var client = GrainClient.GrainFactory.GetGrain <IClient>(1);

                var initTask      = client.Initialize(server);
                string initResult = ActorModel.GetResult(initTask);
                Console.WriteLine("Initialization: " + initResult);

                client.Ping();
            });
        }