Example #1
0
        private PID CreateActor <T>(string id, Proto.IContext parent, Func <Props> producer)
            where T : IActor
        {
            if (!_registry.RegisteredProps.TryGetValue(typeof(T), out var props))
            {
                props = x => x;
            }

            var props2 = props(producer());

            if (parent == null)
            {
                return(Actor.SpawnNamed(props2, id));
            }

            return(parent.SpawnNamed(props2, id));
        }
Example #2
0
        public PID GetActor(string id, string address, Proto.IContext parent, Func <PID> create)
        {
            address = address ?? "nonhost";

            var pidId = id;

            if (parent != null)
            {
                pidId = $"{parent.Self.Id}/{id}";
            }

            var pid  = new PID(address, pidId);
            var reff = ProcessRegistry.Instance.Get(pid);

            if (reff is DeadLetterProcess)
            {
                pid = create();
            }
            return(pid);
        }
Example #3
0
        public Task ReceiveAsync(Proto.IContext protoContext)
        {
            var context = new Context(protoContext);

            return(_service.ReceiveAsync(context));
        }
Example #4
0
 public PID GetActor(string id, string address = null, Proto.IContext parent = null)
 {
     return(GetActor(id, address, parent, () => throw new InvalidOperationException($"Actor not created {id}")));
 }
Example #5
0
 public PID GetActor <T>(string id = null, string address = null, Proto.IContext parent = null)
     where T : IActor
 {
     id = id ?? typeof(T).FullName;
     return(GetActor(id, address, parent, () => CreateActor <T>(id, parent, () => new Props().WithProducer(() => _container.GetInstance <T>()))));
 }
Example #6
0
 public PID RegisterActor <T>(T actor, string id = null, string address = null, Proto.IContext parent = null)
     where T : IActor
 {
     id = id ?? typeof(T).FullName;
     return(GetActor(id, address, parent, () => CreateActor <T>(id, parent, () => new Props().WithProducer(() => actor))));
 }
        protected async override Task ReceiveAsyncInternal(Proto.IContext context)
        {
            if (await HandleSystemMessages(context))
            {
                return;
            }
            var msg = FormatMessage(context.Message);

            if (msg is HomeCenter.Model.Messages.ActorMessage ic)
            {
                ic.Context = context;
            }

            if (msg is RefreshCommand command_0)
            {
                await Handle(command_0).ConfigureAwait(false);

                return;
            }
            else if (msg is TurnOnCommand command_1)
            {
                await Handle(command_1).ConfigureAwait(false);

                return;
            }
            else if (msg is TurnOffCommand command_2)
            {
                await Handle(command_2).ConfigureAwait(false);

                return;
            }
            else if (msg is VolumeUpCommand command_3)
            {
                await Handle(command_3).ConfigureAwait(false);

                return;
            }
            else if (msg is VolumeDownCommand command_4)
            {
                await Handle(command_4).ConfigureAwait(false);

                return;
            }
            else if (msg is VolumeSetCommand command_5)
            {
                await Handle(command_5).ConfigureAwait(false);

                return;
            }
            else if (msg is MuteCommand command_6)
            {
                await Handle(command_6).ConfigureAwait(false);

                return;
            }
            else if (msg is UnmuteCommand command_7)
            {
                await Handle(command_7).ConfigureAwait(false);

                return;
            }
            else if (msg is InputSetCommand command_8)
            {
                await Handle(command_8).ConfigureAwait(false);

                return;
            }

            if (msg is DiscoverQuery query_0)
            {
                var result = Discover(query_0);
                context.Respond(result);
                return;
            }

            ;
            await UnhandledMessage(msg);
        }
Example #8
0
 static PID CreateActor(string id, IContext parent, Func <Props> producer) => parent == null?Actor.SpawnNamed(producer(), id) : parent.SpawnNamed(producer(), id);
Example #9
0
 public PID Get(Type aggregateType, Guid id, string address = null, IContext parent = null)
 {
     return((PID)_getGenericMethod.MakeGenericMethod(aggregateType).Invoke(this, new object[] { id, address, parent }));
 }
Example #10
0
 public PID Get <T>(Guid id, string address = null, IContext parent = null) where T : IActor
 {
     return(Get(id.ToString(), address, parent, () => CreateActor(id.ToString(), parent,
                                                                  () => new Props().WithProducer(() => _serviceProvider.GetInstance <T>()))));
 }