예제 #1
0
        Byte[] ProcessRequestImpl(String url, Byte[] post, Boolean postMethod)
        {
            if (url.StartsWith("admin/"))
            {
                url = url.Substring(6);
                _controller.Host.SetAdmin(true);
            }

            _controller.Host.StartApplication(_controller.Admin);
            try
            {
                MimeType = MIME_HTML;
                using (var dr = new DesktopResponse())
                {
                    if (String.IsNullOrEmpty(url))
                    {
                        RenderIndex(dr.Output);
                    }
                    else if (url.StartsWith("shell/"))
                    {
                        Shell(url.Substring(6).ToLowerInvariant(), dr.Output, out String shellMime);
                        MimeType = shellMime;
                    }
                    else if (url.StartsWith("report/"))
                    {
                        Report(url.Substring(6).ToLowerInvariant(), dr);
                        MimeType           = dr.ContentType;
                        ContentDisposition = dr.Headers["Content-Disposition"];
                        if (dr.IsBinaryWrited)
                        {
                            return(dr.GetBytes());
                        }
                    }
                    else if (url.StartsWith("_page/"))
                    {
                        Render(RequestUrlKind.Page, url.Substring(6), dr.Output);
                    }
                    else if (url.StartsWith("_dialog/"))
                    {
                        Render(RequestUrlKind.Dialog, url.Substring(8), dr.Output);
                    }
                    else if (url.StartsWith("_popup/"))
                    {
                        Render(RequestUrlKind.Popup, url.Substring(7), dr.Output);
                    }
                    else if (url.StartsWith("_data/"))
                    {
                        var command = url.Substring(6);
                        dr.ContentType = "application/json";
                        String jsonData = Encoding.UTF8.GetString(post);
                        _controller.Data(command, SetSqlQueryParams, jsonData, dr).Wait();
                        MimeType = dr.ContentType;
                        if (dr.IsBinaryWrited)
                        {
                            return(dr.GetBytes());
                        }
                    }
                    else if (url.StartsWith("_image/"))
                    {
                        if (postMethod)
                        {
                            throw new NotImplementedException("SaveImage (post)");
                        }
                        else
                        {
                            var bytes = LoadImage("/" + url, dr);
                            MimeType = dr.ContentType;
                            return(bytes);
                        }
                    }
                    else if (url.StartsWith("_static_image/"))
                    {
                        var bytes = StaticImage(url.Substring(14).Replace('-', '.'), dr);
                        MimeType = dr.ContentType;
                        return(bytes);
                    }
                    else if (url.StartsWith("_export/"))
                    {
                        Export("/" + url, dr);
                        MimeType           = dr.ContentType;
                        ContentDisposition = dr.Headers["Content-Disposition"];
                        return(dr.GetBytes());
                    }
                    else if (url.StartsWith("_application/"))
                    {
                        if (!postMethod)
                        {
                            throw new InvalidOperationException();
                        }
                        var    command  = url.Substring(13);
                        String jsonData = Encoding.UTF8.GetString(post);
                        _controller.ApplicationCommand(command, SetUserTenantToParams, jsonData, dr).Wait();
                        MimeType = MIME_JSON;
                        if (dr.OutputStream.Length == 0)
                        {
                            dr.Output.WriteLine("{}");
                        }
                        return(Encoding.UTF8.GetBytes(dr.Output.ToString()));
                    }
                    else if (url.StartsWith("fragment/"))
                    {
                        LoadFragment(url.Substring(9), dr);
                        MimeType = dr.ContentType;
                        return(dr.GetBytes());
                    }
                    else
                    {
                        RenderIndex(dr.Output);
                    }
                    return(Encoding.UTF8.GetBytes(dr.Output.ToString()));
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                // TODO:: /exception
                StatusCode = 255;
                return(Encoding.UTF8.GetBytes(_controller.Localize(ex.Message)));
            }
        }