Ejemplo n.º 1
0
 public void Setup(PlayerTeam playerTeam, PlayerCharacter playerCharacter, Inventory inventory, Town town)
 {
     this.playerCharacter = playerCharacter;
     this.playerTeam      = playerTeam;
     this.inventory       = inventory;
     this.rest            = town.restModule;
 }
Ejemplo n.º 2
0
        public static void HttpRestServer()
        {
            var server = new Server();
            var module = new RestModule();

            module.Endpoints.Add(new ReceiveRestEndpoint());
            module.Endpoints.Add(new SyncRestEndpoint());
            module.Endpoints.Add(new StopRestEndpoint());

            server.Add(module);

            // use one http listener.
            server.Add(HttpServer.HttpListener.Create(IPAddress.Loopback, DebugKeys.HttpListenerPort));
            server.Start(5);
        }
Ejemplo n.º 3
0
 public override void Init()
 {
     base.Init();
     _blazorModule = BlazorModule();
     Application   = _blazorModule.Application.ToBlazor();
 }
Ejemplo n.º 4
0
        void ListenerCallback(IAsyncResult asyncRequest)
        {
            HttpListenerContext context  = m_httpListener.EndGetContext(asyncRequest);
            RestRequest         request  = new RestRequest(context.Request);
            RestResponse        response = new RestResponse(context.Response);
            Type   restModuleType        = null;
            string result = "";

            bool        isNewSession = false;
            RestSession session      = m_sessionManager.GetSession(request, out isNewSession);

            m_logger.LogInfo("Server received: " + request.ToString());

            if (m_restModuleTypes.TryGetValue(request.RESTModuleName, out restModuleType))
            {
                // Find the method on the module by name
                MethodInfo method = restModuleType.GetMethod(request.RESTMethodName);

                if (method != null)
                {
                    // Attempt to convert convert all string arguments over to the corresponding native types
                    try
                    {
                        ParameterInfo[] methodParameters = method.GetParameters();
                        object[]        parameters       = new object[methodParameters.Length];

                        for (int parameterIndex = 0; parameterIndex < parameters.Length; parameterIndex++)
                        {
                            Type   parameterType   = methodParameters[parameterIndex].ParameterType;
                            string parameterName   = methodParameters[parameterIndex].Name;
                            string stringParameter = request.RESTMethodParameters[parameterName];

                            parameters[parameterIndex] = Convert.ChangeType(stringParameter, parameterType);
                        }

                        // Attempt to call the REST method
                        try
                        {
                            ICacheAdapter    applicationCacheAdapter = new DictionaryCacheAdapter(m_applicationCache);
                            ISessionAdapter  sessionAdapter          = session;
                            IResponseAdapter responseAdapter         = response;

                            RestModule restModule =
                                (RestModule)Activator.CreateInstance(
                                    restModuleType,
                                    applicationCacheAdapter,
                                    sessionAdapter,
                                    responseAdapter);

                            object methodResult = method.Invoke(restModule, parameters);

                            result = methodResult.ToString();
                        }
                        catch (System.Exception ex)
                        {
                            result = "Failed to invoke REST Method: " + ex.Message;
                            m_logger.LogError(result);
                        }
                    }
                    catch (System.Exception ex)
                    {
                        result = "Malformed REST Parameters: " + ex.Message;
                        m_logger.LogError(result);
                    }
                }
                else
                {
                    result = "Unknown REST Method: " + request.RESTMethodName;
                    m_logger.LogError(result);
                }
            }
            else
            {
                result = "Unknown REST Module: " + request.RESTModuleName;
                m_logger.LogError(result);
            }

            // If the module wants the session to be abandoned free it from the session manager
            if (session.IsAbandoned)
            {
                m_sessionManager.FreeSession(session);
            }
            // If this is a new session, give the client the session cookie
            else if (isNewSession)
            {
                response.AppendSessionIdCookie(session);
            }

            // If there was any result string from the rest method, assign it to the result
            if (result.Length > 0)
            {
                response.SetBody(result);
            }

            response.Close();
        }