Exemple #1
0
        private void Excute(HttpListenerContext context)
        {
            HttpListenerRequest  request  = context.Request;
            HttpListenerResponse response = context.Response;

            if (!request.HttpMethod.CompareNC("GET"))
            {
                response.StatusCode        = 501;
                response.StatusDescription = "NotImplemented";
                try
                {
                    response.Close();
                }
                catch
                {
                }
                return;
            }
            string text = HttpUtility.UrlDecode(request.Url.AbsolutePath);

            string[] array = text.Split(new char[]
            {
                '/'
            }, StringSplitOptions.RemoveEmptyEntries);
            string path;

            if (array.Length == 0)
            {
                path = Util.GetWwwRootPath() + "/index.html";
            }
            else
            {
                if (array[0] == "webapi")
                {
                    try
                    {
                        WebApiBase arg_9D_0 = new WebApi(request, response);
                        string     fileName = Path.GetFileName(text);
                        arg_9D_0.Exec(fileName);
                    }
                    catch (Exception ex)
                    {
                        Log.Write(ex.Message);
                        Log.Write(1, ex.StackTrace);
                    }
                    try
                    {
                        response.Close();
                    }
                    catch (Exception)
                    {
                    }
                    return;
                }
                if (array[0] == "logo")
                {
                    path = Util.GetUserPath() + text;
                }
                else
                {
                    path = Util.GetWwwRootPath() + text;
                }
            }
            try
            {
                if (File.Exists(path))
                {
                    byte[] array2 = File.ReadAllBytes(path);
                    response.ContentType = this.GetContentType(path);
                    response.OutputStream.Write(array2, 0, array2.Length);
                    response.Close();
                }
                else
                {
                    response.StatusCode        = 404;
                    response.StatusDescription = "NotFound";
                    byte[] array3 = File.ReadAllBytes(Util.GetUserPath("404.html"));
                    response.ContentType = "text/html";
                    response.OutputStream.Write(array3, 0, array3.Length);
                    response.Close();
                }
            }
            catch (Exception ex2)
            {
                Log.Write("Webサーバのファイル転送時にエラーが発生しましたが、プログラムは続行します。\n[詳細]" + ex2.Message);
                Log.Write(1, ex2.StackTrace);
            }
        }