/// <summary> /// Save report from designer /// </summary> internal IActionResult DesignerSaveReport(HttpContext context) { var result = new ContentResult() { StatusCode = (int)HttpStatusCode.OK, ContentType = "text/html", }; string reportString = GetPOSTReport(context); try { // paste restricted back in report before save Report.LoadFromString(PasteRestricted(reportString)); SaveDesignedReportEventArgs e = new SaveDesignedReportEventArgs(); e.Stream = new MemoryStream(); Report.Save(e.Stream); e.Stream.Position = 0; OnSaveDesignedReport(e); if (!DesignerSaveCallBack.IsNullOrWhiteSpace()) { string report = Report.SaveToString(); var reportName = (!String.IsNullOrEmpty(Report.ReportInfo.Name) ? Report.ReportInfo.Name : Path.GetFileNameWithoutExtension(Report.FileName)); string reportFileName = $"{reportName}.frx"; UriBuilder uri = new UriBuilder { Scheme = context.Request.Scheme, Host = context.Request.Host.Host }; //if (!FastReportGlobal.FastReportOptions.CloudEnvironmet) if (context.Request.Host.Port != null) { uri.Port = (int)context.Request.Host.Port; } else if (uri.Scheme == "https") { uri.Port = 443; } else { uri.Port = 80; } // TODO: //uri.Path = webReport.ResolveUrl(webReport.DesignerSaveCallBack); uri.Path = DesignerSaveCallBack; //var designerSaveCallBack = new Uri(DesignerSaveCallBack); //if (!designerSaveCallBack.IsAbsoluteUri) //{ // designerSaveCallBack = new UriBuilder() // { // Scheme = context.Request.Scheme, // Host = context.Request.Host.Host, // Port = context.Request.Host.Port ?? 80, // Path = DesignerSaveCallBack, // }.Uri; //} //uri.Path = designerSaveCallBack.ToString(); // TODO: rename param names string queryToAppend = $"reportID={ID}&reportUUID={reportFileName}"; if (uri.Query != null && uri.Query.Length > 1) { uri.Query = uri.Query.Substring(1) + "&" + queryToAppend; } else { uri.Query = queryToAppend; } string callBackURL = uri.ToString(); // return "true" to force the certificate to be accepted. ServicePointManager.ServerCertificateValidationCallback = (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => true; WebRequest request = WebRequest.Create(callBackURL); if (request != null) { // set up the custom headers if (RequestHeaders != null) { request.Headers = RequestHeaders; } WebUtils.CopyCookies(request, context); // TODO: why here?? // if save report in reports folder if (!String.IsNullOrEmpty(DesignerSavePath)) { string savePath = WebUtils.MapPath(DesignerSavePath); // TODO: do we really need this? if (Directory.Exists(savePath)) { File.WriteAllText(Path.Combine(savePath, reportFileName), report, Encoding.UTF8); } else { result = new ContentResult() { StatusCode = (int)HttpStatusCode.NotFound, ContentType = "text/html", Content = "DesignerSavePath does not exist", }; } request.Method = "GET"; } else // send report directly in POST { request.Method = "POST"; request.ContentType = "text/xml"; byte[] postData = Encoding.UTF8.GetBytes(report); request.ContentLength = postData.Length; Stream reqStream = request.GetRequestStream(); reqStream.Write(postData, 0, postData.Length); postData = null; reqStream.Close(); } // Request call-back try { using (HttpWebResponse resp = request.GetResponse() as HttpWebResponse) { //context.Response.StatusCode = (int)resp.StatusCode; //context.Response.Write(resp.StatusDescription); result = new ContentResult() { StatusCode = (int)resp.StatusCode, ContentType = "text/html", Content = resp.StatusDescription, }; } } catch (WebException err) { result = new ContentResult() { StatusCode = (int)HttpStatusCode.InternalServerError, ContentType = "text/html", }; if (Debug) { using (Stream data = err.Response.GetResponseStream()) using (StreamReader reader = new StreamReader(data)) { string text = reader.ReadToEnd(); if (!String.IsNullOrEmpty(text)) { int startExceptionText = text.IndexOf("<!--"); int endExceptionText = text.LastIndexOf("-->"); if (startExceptionText != -1) { text = text.Substring(startExceptionText + 6, endExceptionText - startExceptionText - 6); } result.Content = text; result.StatusCode = (int)(err.Response as HttpWebResponse).StatusCode; } } } else { result.Content = err.Message; } } } request = null; } } catch (Exception e) { result.StatusCode = (int)HttpStatusCode.InternalServerError; if (Debug) { result.Content = e.Message; } } return(result); }
/// <summary> /// Runs on designed report save /// </summary> public void OnSaveDesignedReport(SaveDesignedReportEventArgs e) { SaveDesignedReport?.Invoke(this, e); }