示例#1
0
        //private static void ParseRequest(Guid clientId, byte[] requestData)
        //{
        //    MSMQQueueWrapper.QueueCommand(new ParseRequestCommand(clientId, requestData));
        //}


        private void LoadHandlers(SocketServerConfiguration config)
        {
            foreach (RequestHandlerConfigurationElement element in config.Handlers)
            {
                // try to find enum type first
                requestHandlers.Add(element.Key, element);
            }
        }
示例#2
0
        //public event EventHandler<ClientRequestEventArgs> ClientRequestReceived;

        /// <summary>
        /// Initializes a new instance of the <see cref="SocketManager"/> class.
        /// </summary>
        public SocketManager(SocketServerConfiguration config)
        {
            LoadHandlers(config);

            // TODO: Move filename into configuration
            _socketServer = new SocketServer(new MessageRegistry("messages.desc"));

            _socketServer.ClientConnected    += SocketServerClientConnecting;
            _socketServer.ClientDisconnected += SocketServerClientDisconnecting;
            _socketServer.MessageReceived    += new EventHandler <MessageEventArgs>(socketServer_MessageReceived);
        }
示例#3
0
        static MSMQQueueWrapper()
        {
            SocketServerConfiguration config = ServerConfigurationHelper.GetServerConfiguration();

            if (config.Queues.Count > 0)
            {
                QueuePath = config.Queues[0].QueuePath;
            }

            EnsureQueueExists(QueuePath);
        }
示例#4
0
        public SocketService()
        {
            SocketServerConfiguration config = ServerConfigurationHelper.GetServerConfiguration();

            if (config.Queues.Count > 0)
            {
                _messageServer = new CommandServer(config.Queues[0].QueueName, config.Queues[0].QueuePath);
            }

            _serverManager = new SocketManager(config);
            InitializeComponent();
        }
示例#5
0
        static MSMQQueueWrapper()
        {
            SocketServerConfiguration config = ServerConfigurationHelper.GetServerConfiguration();

            if (config.Queues.Count > 0)
            {
                QueuePath = config.Queues[0].QueuePath;
            }
            else
            {
                throw new Exception("No queues specified in configuration.");
            }
        }
示例#6
0
        //protected virtual void OnClientRequestReceived(Guid clientId, RequestHeader header, object request)
        //{
        //    EventHandler<ClientRequestEventArgs> clientRequestReceived = ClientRequestReceived;
        //    if (clientRequestReceived != null)
        //    {
        //        var args = new ClientRequestEventArgs(clientId, header, request);
        //        clientRequestReceived(this, args);
        //    }
        //}

        /// <summary>
        /// Starts the server.
        /// </summary>
        public void StartServer()
        {
            SocketServerConfiguration configuration = null;

            try
            {
                configuration = ServerConfigurationHelper.GetServerConfiguration();
            }
            catch (Exception exception)
            {
                Logger.Error(exception.ToString());
            }

            if (configuration != null)
            {
                MSMQQueueWrapper.QueueCommand(new ServerStartingCommand());

                _socketServer.StartServer(configuration.ListenPort);

                Logger.InfoFormat("Server started and listening on {0}", configuration.ListenPort);
            }
        }
        /// <summary>
        /// Gets the handler list by type.
        /// </summary>
        /// <returns></returns>
        //public List<IServiceHandler> GetHandlerListByType(Type type)
        //{
        //    List<IServiceHandler> serviceHandlers = HandlerList
        //        .Where(h => h.Metadata.HandlerType == type)
        //        .Select(lz => lz.Value)
        //        .ToList();

        //    return serviceHandlers;
        //}

        /// <summary>
        /// Loads the handlers.
        /// </summary>
        //public void LoadHandlers()
        //{
        ////try
        ////{
        ////    (SocketServiceConfiguration) ConfigurationManager.GetSection("SocketServerConfiguration");
        ////}
        ////catch (Exception)
        ////{
        ////}

        //var aggregateCatalog = new AggregateCatalog();

        //var callingAssembly = Assembly.GetExecutingAssembly();

        //// an assembly catalog to load information about parts from this assembly
        //var assemblyCatalog = new AssemblyCatalog(callingAssembly);

        //var assemblyLocation = Path.GetDirectoryName(callingAssembly.Location);
        //if (assemblyLocation != null)
        //{
        //    var directoryCatalog = new DirectoryCatalog(assemblyLocation, "*.dll");

        //    aggregateCatalog.Catalogs.Add(assemblyCatalog);
        //    aggregateCatalog.Catalogs.Add(directoryCatalog);
        //}

        //// create a container for our catalogs
        //var container = new CompositionContainer(aggregateCatalog);

        //// finally, compose the parts
        //container.ComposeParts(this);
        //}

        private void LoadHandlers(SocketServerConfiguration config)
        {
            foreach (RequestHandlerConfigurationElement element in config.Handlers)
            {
                string key = element.Key;

                Type requestType = ReflectionHelper.FindType(element.RequestType);
                Type handlerType = ReflectionHelper.FindType(element.HandlerType);

                if (handlerType != null && requestType != null)
                {
                    // create an instance of the handler
                    object handler = ReflectionHelper.ActivateObject(handlerType, null);
                    if (handler != null)
                    {
                        Type interfaceType = ReflectionHelper.FindGenericInterfaceMethod(InterfaceName, new Type[] { requestType }, handlerType);
                        if (interfaceType != null)
                        {
                            // we are in business
                            try
                            {
                                MethodInfo mi = interfaceType.GetMethod(MethodName);
                                if (mi != null)
                                {
                                    ServiceHandler helper = new ServiceHandler(handler, mi);
                                    _handlerMap.Add(key, helper);
                                }
                            }
                            catch (Exception ex)
                            {
                                Logger.ErrorFormat("Error in HandleRequest\n. {0}", ex);
                            }
                        }

                        Logger.InfoFormat("Adding handler for request tag {0} - handler type ({1}), request type ({2})", element.Key, element.HandlerType, element.RequestType);
                    }
                }
            }
        }
        /// <summary>
        /// Initializes the <see cref="ServiceHandlerLookup"/> class.
        /// </summary>
        static ServiceHandlerRepository()
        {
            SocketServerConfiguration config = ServerConfigurationHelper.GetServerConfiguration();

            Instance.LoadHandlers(config);
        }