示例#1
0
        public bool TryRegisterTurnAction(string eventName, string serviceName, string actionName)
        {
            if (!_possibleEvents.ContainsKey(eventName))
            {
                return(false);
            }

            EventInfo targetEvent = _possibleEvents[eventName];

            if (!_availableServices.ContainsKey(serviceName))
            {
                return(false);
            }

            Service targetService = _availableServices[serviceName];

            if (!_availableServices[serviceName].Actions.ContainsKey(actionName))
            {
                return(false);
            }

            TurnAction targetAction = targetService.Actions[actionName];

            if (!IsActionTypeValid(targetEvent, targetAction))
            {
                return(false);
            }

            _subscribeOrder.Enqueue(new Tuple <TurnAction, Service, string>(targetAction, targetService, eventName));
            _registeredServices[targetService.Name] = targetService;
            return(true);
        }
示例#2
0
        public void CreateServicesAndSubscribeActions(Tdest dest, IReadOnlyDictionary <string, IReadOnlyDictionary <string, Constant> > constants)
        {
            Dictionary <string, object> createdServices = new();

            foreach (var subscribeElement in _subscribeOrder)
            {
                TurnAction action    = subscribeElement.Item1;
                Service    service   = subscribeElement.Item2;
                string     eventName = subscribeElement.Item3;

                if (!createdServices.ContainsKey(service.Name))
                {
                    object newService = CreateService(service);
                    Manager <Tdest, TRepository> .InitializeConstants(newService, constants[service.Name]);

                    createdServices[service.Name] = newService;
                }

                EventInfo eventInfo      = _possibleEvents[eventName];
                var       actionDelegate = Delegate.CreateDelegate(eventInfo.EventHandlerType !, createdServices[service.Name], action.Action);
                eventInfo.AddEventHandler(dest, actionDelegate);
            }
        }