public NetContractHandler(IOperationDispatcher dispatcher, uint contractId, object implementer)
        {
            Implementer   = implementer;
            ServiceTypeId = contractId;
            Type implementerType           = implementer.GetType();
            NetContractDescription desc    = dispatcher.GetContract(contractId);
            InterfaceMapping       mapping = implementerType.GetInterfaceMap(desc.ContractType);

            foreach (NetOperationDescription operation in desc.Operations)
            {
                var handlerAttr = mapping.TargetMethods.First(m => m.Name == operation.Name).GetAttribute <NetOperationHandlerAttribute>();
                _handlerAttributes.Add(operation.RequestMessageId, handlerAttr ?? new NetOperationHandlerAttribute());
            }
        }
        public ActorRepository(IOperationDispatcher dispatcher, IEnumerable<Actor> actorPrototypes)
        {
            Dispatcher = dispatcher;

            foreach (var entity in actorPrototypes)
            {
                Type type = entity.GetType();
                var attr = type.GetAttribute<ActorAttribute>();
                var contracts = new List<NetContractDescription>();
                foreach (Type netContractType in entity.GetType().GetInterfaces())
                {
                    uint typeId;
                    if(dispatcher.TryGetContractId(netContractType, out typeId))
                        contracts.Add(Dispatcher.GetContract(typeId));
                }
                var actorDescription = new ActorDescription(type, contracts, attr);
                _descriptionsByTypeId.Add(actorDescription.PrimaryContract.TypeId, actorDescription);

                Log.Info("Registered {0}", type, actorDescription);
            }
        }
示例#3
0
        public ActorRepository(IOperationDispatcher dispatcher, IEnumerable <Actor> actorPrototypes)
        {
            Dispatcher = dispatcher;

            foreach (var entity in actorPrototypes)
            {
                Type type      = entity.GetType();
                var  attr      = type.GetAttribute <ActorAttribute>();
                var  contracts = new List <NetContractDescription>();
                foreach (Type netContractType in entity.GetType().GetInterfaces())
                {
                    uint typeId;
                    if (dispatcher.TryGetContractId(netContractType, out typeId))
                    {
                        contracts.Add(Dispatcher.GetContract(typeId));
                    }
                }
                var actorDescription = new ActorDescription(type, contracts, attr);
                _descriptionsByTypeId.Add(actorDescription.PrimaryContract.TypeId, actorDescription);

                Log.Info("Registered {0}", type, actorDescription);
            }
        }