private void CreateEntityViewActors(Type classType, Type genericListType, string actorName, ISystemProcess process, IProcessSystemMessage msg)
        {
            var child = ctx.Child(string.Format(actorName, classType.Name));

            if (!Equals(child, ActorRefs.Nobody))
            {
                return;
            }

            var specificListType = genericListType.MakeGenericType(classType);

            try
            {
                Task.Run(() => { ctx.ActorOf(Props.Create(specificListType, process, msg), string.Format(actorName, classType.Name)); }).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Debugger.Break();
                EventMessageBus.Current.Publish(new ProcessEventFailure(failedEventType: msg.GetType(),
                                                                        failedEventMessage: msg,
                                                                        expectedEventType: typeof(ServiceStarted <>).MakeGenericType(specificListType),
                                                                        exception: ex,
                                                                        source: Source, processInfo: new StateEventInfo(msg.Process.Id, RevolutionData.Context.Process.Events.Error)), Source);
            }
        }
        public static IActorRef GetOrCreate <TActor>(this IUntypedActorContext context, string actorName)
            where TActor : ActorBase, new()
        {
            var actor = context.Child(actorName);

            return(actor.IsNobody() ? context.ActorOf(Props.Create(() => new TActor()), actorName) : actor);
        }
        public static IEventActor GetOrCreateEventActor(this IUntypedActorContext system, string name,
                                                        bool killOnFirstResponse = false)
        {
            var child = system.Child(name);

            return(child.Equals(ActorRefs.Nobody)
                ? EventActor.Create(system, name, killOnFirstResponse)
                : EventActor.From(child));
        }
Пример #4
0
        private void BotOnMessageReceived(object sender, MessageEventArgs e)
        {
            long id        = e.Message.Chat.Id;
            var  childName = "User" + id;

            var child = ThisContext.Child(childName);

            if (child == ActorRefs.Nobody)
            {
                var props = Props.Create(() => new User());
                child = ThisContext.ActorOf(props, childName);
            }

            child.Tell(e.Message);
        }
Пример #5
0
        public static IActorRef CreateActor(IUntypedActorContext context, Type actorType, string name)
        {
            var actorName = actorType.Name + "." + name;

            var actor = context.Child(actorName);

            if (!actor.Equals(ActorRefs.Nobody))
            {
                return(actor);
            }

            var actorProps = context.DI().Props(actorType);

            actor = context.ActorOf(actorProps, actorName);

            return(actor);
        }
Пример #6
0
        public HubConnection(IUntypedActorContext parentContext)
        {
            _parentContext = parentContext;
            
            Receive<Tcp.Received>(received =>
            {
                var messages = MessageSeriliazer.Deserialize(Context.System, received.Data);
                messages.ForEach(Self.Forward);
            });

            Receive<Tcp.ConnectionClosed>(closed =>
            {
                _log.Info($"Client connection {Self.Path.Name} was closed. Reason: {closed.GetErrorCause()}");

                foreach (var hubPair in _hubs.AllMinToMax)
                {
                    var name = hubPair.Key;
                    var hub = hubPair.Value;

                    hub.Forward(new Signal.Leave(name));
                }

                Context.Stop(Self);
            });

            Receive<Signal.Join>(join =>
            {
                if (_hubs.Contains(join.HubName))
                    return;

                var hub = _parentContext.Child(join.HubName);
                if (hub.IsNobody())
                {
                    Sender.Tell(WriteObject(new Signal.NotFound(join.HubName)));
                    return;
                }

                _hubs = _hubs.Add(join.HubName, hub);
                hub.Forward(join);
            });

            Receive<Signal.Leave>(leave =>
            {
                if (!_hubs.Contains(leave.HubName))
                    return;

                var hub = _parentContext.Child(leave.HubName);
                if (hub.IsNobody())
                {
                    Sender.Tell(WriteObject(new Signal.NotFound(leave.HubName)));
                    return;
                }

               _hubs = _hubs.Remove(leave.HubName);
                hub.Forward(leave);
            });

            Receive<Signal.Broadcast>(broadcast =>
            {
                var hub = _parentContext.Child(broadcast.HubName);
                if (hub.IsNobody())
                {
                    Sender.Tell(WriteObject(new Signal.NotFound(broadcast.HubName)));
                    return;
                }

                hub.Forward(broadcast);
            });
        }