Example #1
0
 public Byte[] SaveImage(String url, String files, DesktopResponse dr)
 {
     dr.ContentType = "application/json";
     try
     {
         var fileColl = new SimpleHttpFileCollection(files);
         var list     = _controller.SaveAttachments(TenantId, url, fileColl, UserId, CompanyId).Result;
         var rval     = new ExpandoObject();
         rval.Set("status", "OK");
         rval.Set("ids", list);
         String result = JsonConvert.SerializeObject(rval, JsonHelpers.StandardSerializerSettings);
         return(Encoding.UTF8.GetBytes(result));
     }
     catch (Exception ex)
     {
         if (ex.InnerException != null)
         {
             ex = ex.InnerException;
         }
         MimeType   = "text/plain";
         StatusCode = 255;
         String msg = $"{ex.Message}";
         return(Encoding.UTF8.GetBytes(msg));
     }
 }
Example #2
0
        public void Report(String url, DesktopResponse dr)
        {
            var reportController = new ReportController();
            var qry = HttpUtility.ParseQueryString(Search?.ToLowerInvariant());
            /*  /export/{id} */
            var urlParts = url.ToLowerInvariant().Split('/');
            var rep      = qry.Get("rep");
            var baseUrl  = qry.Get("base");
            var format   = qry.Get("format");
            var id       = urlParts[urlParts.Length - 1];

            if (urlParts[1] == "export")
            {
                DesktopReport ri = new DesktopReport()
                {
                    Report                = rep,
                    Base                  = baseUrl,
                    Id                    = id,
                    Format                = format,
                    UserId                = UserId,
                    TenantId              = TenantId,
                    CompanyId             = CompanyId,
                    AddContentDisposition = true
                };
                reportController.ExportDesktop(ri, dr).Wait();
            }
            else if (urlParts[1] == "print")
            {
                DesktopReport ri = new DesktopReport()
                {
                    Report                = rep,
                    Base                  = baseUrl,
                    Id                    = id,
                    Format                = "pdf",
                    UserId                = UserId,
                    TenantId              = TenantId,
                    CompanyId             = CompanyId,
                    AddContentDisposition = false
                };
                reportController.ExportDesktop(ri, dr).Wait();
            }
        }
Example #3
0
 public Byte[] UploadFiles(String url, String files, DesktopResponse dr)
 {
     try
     {
         dr.ContentType = "application/json";
         var fileColl = new SimpleHttpFileCollection(files);
         _controller.SaveFiles("/" + url, fileColl, SetQueryStringAndSqlQueryParams, dr.Output).Wait();
         MimeType   = dr.ContentType;
         StatusCode = dr.StatusCode;
         return(Encoding.UTF8.GetBytes(dr.Output.ToString()));
     }
     catch (Exception ex)
     {
         if (ex.InnerException != null)
         {
             ex = ex.InnerException;
         }
         MimeType   = "text/plain";
         StatusCode = 255;
         String msg = $"{ex.Message}";
         return(Encoding.UTF8.GetBytes(msg));
     }
 }
Example #4
0
 Byte[] ProcessRequestImpl(String url, String search, Byte[] post, Boolean postMethod)
 {
     if (url.StartsWith("admin/"))
     {
         url = url.Substring(6);
         _controller.Admin = 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("_page/"))
             {
                 Render(RequestUrlKind.Page, url.Substring(6), search, dr.Output);
             }
             else if (url.StartsWith("_dialog/"))
             {
                 Render(RequestUrlKind.Dialog, url.Substring(8), search, dr.Output);
             }
             else if (url.StartsWith("_popup/"))
             {
                 Render(RequestUrlKind.Popup, url.Substring(7), search, 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, SetSqlParams, jsonData, dr).Wait();
                 MimeType = dr.ContentType;
                 if (dr.IsBinaryWrited)
                 {
                     return(dr.GetBytes());
                 }
             }
             else if (url.StartsWith("_image/"))
             {
                 if (postMethod)
                 {
                     SaveImage("/" + url, dr.Output);
                 }
                 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, search, dr);
                 MimeType           = dr.ContentType;
                 ContentDisposition = dr.Headers["Content-Disposition"];
                 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
         String msg = $"<div>{ex.Message}</div>";
         return(Encoding.UTF8.GetBytes(msg));
     }
 }
Example #5
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)));
            }
        }