Exemple #1
0
        public static string Execute(HttpListenerRequest req, HttpListenerResponse res, string reqBody)
        {
            string path = ApiCommon.GetApiPath(req.RawUrl);

            if (path != "/server")
            {
                res.StatusCode = 404;
                return("");
            }
            switch (req.HttpMethod)
            {
            case "GET":
            {
                Assembly     assembly = Assembly.GetExecutingAssembly();
                AssemblyName asmName  = assembly.GetName();
                Version      version  = asmName.Version;
                var          dic      = new Dictionary <string, string>();
                dic.Add("version", version.ToString());
                return(JsonSerializer.Serialize(dic));
            }

            // case "POST":
            //     return "";// (new CreateUserController(req, res, reqBody)).Execute();
            default:
                res.StatusCode = 405;
                return("");
            }
        }
Exemple #2
0
        public static async Task <string> Execute(HttpListenerRequest req, HttpListenerResponse res, string reqBody)
        {
            string path = ApiCommon.GetApiPath(req.RawUrl);

            if (path != "/voiceroid/process")
            {
                res.StatusCode = 404;
                return("");
            }
            switch (req.HttpMethod)
            {
            case "GET":
                return(await GET(req, res, reqBody));

            case "POST":
                return(await POST(req, res, reqBody));

            case "OPTIONS":
                res.StatusCode = 200;
                return("");

            default:
                res.StatusCode = 405;
                return("");
            }
        }
Exemple #3
0
        /// <summary>
        /// APIコントローラを実行する
        /// </summary>
        /// <param name="req">リクエスト情報</param>
        /// <param name="res">レスポンス情報</param>
        /// <param name="reqBody">リクエストボディ</param>
        /// <returns>レスポンス文字列</returns>
        private async Task <string> ExecuteController(HttpListenerRequest req, HttpListenerResponse res, string reqBody)
        {
            string path = ApiCommon.GetApiPath(req.RawUrl);

            if (path.StartsWith("/voiceroid/process"))
            {
                return(await VoiceroidProcess.Execute(req, res, reqBody));
            }
            else if (path.StartsWith("/voiceroid/task"))
            {
            }
            else if (path.StartsWith("/server"))
            {
                return(Server.Execute(req, res, reqBody));
            }
            else
            {
                res.StatusCode = 404;
            }

            /*
             * if ("/user/".Equals(path))
             * {
             *  switch (req.HttpMethod)
             *  {
             *      case "GET":
             *          return "";// (new ReadUserController(req, res, reqBody)).Execute();
             *      case "POST":
             *          return "";// (new CreateUserController(req, res, reqBody)).Execute();
             *      case "PUT":
             *          return "";// (new UpdateUserController(req, res, reqBody)).Execute();
             *      case "DELETE":
             *          return "";// (new DeleteUserController(req, res, reqBody)).Execute();
             *  }
             * }
             * if ("/users/".Equals(path) && "GET".Equals("GET"))
             * {
             *  return "";// (new ReadUsersController(req, res, reqBody)).Execute();
             * }
             */
            return("");
        }