Пример #1
0
        /// <summary>
        /// Called when this session is being setup.
        /// </summary>
        protected override void OnSetup()
        {
            base.OnSetup();

            // Determine if this session is running on the server or client to retrieve the worker thread pool.
            if (BaseSocket.Mode == SocketMode.Server)
            {
                Server = (RpcServer <TSession, TConfig>)BaseSocket;
            }
            else
            {
                Client = (RpcClient <TSession, TConfig>)BaseSocket;
            }

            SerializationCache = new SerializationCache(Config);

            RpcCallHandler = new RpcCallMessageHandler <TSession, TConfig>((TSession)this);
            MessageHandlers.Add(RpcCallHandler.Id, RpcCallHandler);
        }
Пример #2
0
    public void AddCallbacks()
    {
        // index all TestMessageID
        for (byte index = (byte)MinID; index <= (byte)MaxID; index++)
        {
            // if MessageHandlers not contains this key
            if (MessageHandlers.ContainsKey((TestMessageID)index) == false)
            {
                // add new handler
                MessageHandlers.Add((TestMessageID)index, null);
            }

            // add listener for this handler
            serverConnection.AddListener(index, connectionAdapter);
        }

        // set callback
        connectionAdapter.MessageReceivedCallback += OnMessageReceived;
    }
Пример #3
0
        /// <summary>
        /// Register all API modules that implement IApiModule
        /// </summary>
        private void RegisterModules()
        {
            var interfaceType = typeof(IModule);

            Modules = AppDomain.CurrentDomain.GetAssemblies()
                      .SelectMany(x => x.GetTypes())
                      .Where(x => interfaceType.IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract)
                      .Select(x => (IModule)Activator.CreateInstance(x, new object[] { this }))
                      .ToList();
            // Ordering modules before letting them register for item CRUD
            // events works in practice, but is not guarenteed. This should
            // be refactored.
            Modules.OrderBy(x => x.GetOrder()).ToList().ForEach((module) =>
            {
                Logger.LogDebug($"Module {module.GetType().Name}: loaded");
                module.GetManagers().ForEach(manager =>
                {
                    Logger.LogDebug($"Module {module.GetType().Name}: loading model manager {manager.GetType().Name}");
                    Managers.Add(manager);
                });
                Repositories.AddRange(module.GetRepositories());
                module.RegisterForMessages().ForEach(messageId =>
                {
                    if (MessageHandlers.ContainsKey(messageId))
                    {
                        MessageHandlers[messageId].Add(module);
                    }
                    else
                    {
                        MessageHandlers.Add(messageId, new List <IModule>()
                        {
                            module
                        });
                    }
                });
            });
            Modules.ForEach((module) =>
            {
                module.Initialize(Repositories);
                Logger.LogInformation($"Module {module.GetType().Name} initialized");
            });
            ModuleManagerReadyEvent?.Invoke();
        }
Пример #4
0
        internal void InternalRegisterMessageHandlers(Assembly assembly, IMessageHandlerConvention messageHandlerConvention)
        {
            Condition.Requires(assembly, "assembly").IsNotNull();
            Condition.Requires(messageHandlerConvention, "messageHandlerLocator").IsNotNull();

            Logger.DebugFormat("Scanning assembly '{0}' for message handlers.", assembly);
            Logger.DebugFormat("Using message handler convention '{0}'.", messageHandlerConvention);

            // Go through all types and all their methods looking for message handlers
            foreach (Type handler in assembly.GetTypes())
            {
                foreach (MethodInfo method in handler.GetMethods())
                {
                    // Only test single-parameter methods for handlers
                    ParameterInfo[] parameters = method.GetParameters();
                    if (parameters.Length == 1)
                    {
                        Type baseType = parameters[0].ParameterType;

                        if (messageHandlerConvention.IsMessageHandler(method, baseType))
                        {
                            // Go through all other messages that inherit from the handlers message parameter
                            foreach (Type messageType in GetAllInheritedClasses(baseType))
                            {
                                Logger.DebugFormat("Register message handler '{0}' on '{1}' for message type '{2}'.", method.Name, method.DeclaringType, messageType);
                                MessageHandlerRegistration registration = new MessageHandlerRegistration(messageType, method);
                                MessageHandlers.Add(registration);
                                if (!MessageHandlerIndex.ContainsKey(messageType))
                                {
                                    MessageHandlerIndex.Add(messageType, new List <MessageHandlerRegistration>());
                                }
                                MessageHandlerIndex[messageType].Add(registration);
                                if (!ObjectContainer.HasComponent(method.DeclaringType))
                                {
                                    ObjectContainer.AddComponent(method.DeclaringType, method.DeclaringType);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #5
0
 public Reader(MidiEventDelegate handler, bool generateMessageList = false)
     : this(true, generateMessageList)
 {
     MessageHandlers.Add(handler);
 }
Пример #6
0
 public MyWebApiConfiguration()
 {
     ConfigureRouting();
     MessageHandlers.Add(new PaginationLinkHeaderEnrichment());
 }