Example #1
0
        string CutRestricted(string xmlString)
        {
            using (MemoryStream xmlStream = new MemoryStream())
            {
                WebUtils.Write(xmlStream, xmlString);
                xmlStream.Position = 0;

                using (var xml = new XmlDocument())
                {
                    xml.Load(xmlStream);

                    if (!DesignScriptCode)
                    {
                        xml.Root.SetProp("CodeRestricted", "true");
                        // cut script
                        var scriptItem = xml.Root.FindItem(nameof(Report.ScriptText));
                        if (scriptItem != null && !String.IsNullOrEmpty(scriptItem.Value))
                        {
                            scriptItem.Value = String.Empty;
                        }
                    }

                    // cut connection strings
                    var dictionary = xml.Root.FindItem(nameof(Report.Dictionary));
                    {
                        if (dictionary != null)
                        {
                            for (int i = 0; i < dictionary.Items.Count; i++)
                            {
                                var item = dictionary.Items[i];
                                if (!String.IsNullOrEmpty(item.GetProp("ConnectionString")))
                                {
                                    item.SetProp("ConnectionString", String.Empty);
                                }
                            }
                        }
                    }

                    // save prepared xml
                    using (MemoryStream secondXmlStream = new MemoryStream())
                    {
                        xml.Save(secondXmlStream);
                        secondXmlStream.Position = 0;
                        int    secondXmlLength = (int)secondXmlStream.Length;
                        bool   rent            = secondXmlLength > 1024;
                        byte[] buff            = rent ?
                                                 ArrayPool <byte> .Shared.Rent(secondXmlLength)
                            : new byte[secondXmlLength];

                        secondXmlStream.Read(buff, 0, secondXmlLength);
                        xmlString = Encoding.UTF8.GetString(buff, 0, secondXmlLength);
                        if (rent)
                        {
                            ArrayPool <byte> .Shared.Return(buff);
                        }
                    }
                }
            }
            return(xmlString);
        }
Example #2
0
        string PasteRestricted(string xmlString)
        {
            using (MemoryStream xmlStream1 = new MemoryStream())
                using (MemoryStream xmlStream2 = new MemoryStream())
                {
                    WebUtils.Write(xmlStream1, Report.SaveToString());
                    WebUtils.Write(xmlStream2, xmlString);
                    xmlStream1.Position = 0;
                    xmlStream2.Position = 0;
                    var xml1 = new XmlDocument();
                    var xml2 = new XmlDocument();
                    xml1.Load(xmlStream1);
                    xml2.Load(xmlStream2);

                    if (!DesignScriptCode)
                    {
                        xml2.Root.SetProp("CodeRestricted", "");
                        // paste old script
                        var scriptItem1 = xml1.Root.FindItem("ScriptText");
                        if (scriptItem1 != null && String.IsNullOrEmpty(scriptItem1.Value))
                        {
                            var scriptItem2 = xml2.Root.FindItem("ScriptText");
                            if (scriptItem2 != null)
                            {
                                scriptItem2.Value = scriptItem1.Value;
                                scriptItem2.Dispose();
                            }
                            else
                            {
                                xml2.Root.AddItem(scriptItem1);
                            }
                        }
                    }

                    // paste saved connection strings
                    var dictionary1 = xml1.Root.FindItem("Dictionary");
                    var dictionary2 = xml2.Root.FindItem("Dictionary");
                    if (dictionary1 != null && dictionary2 != null)
                    {
                        for (int i = 0; i < dictionary1.Items.Count; i++)
                        {
                            var    item1            = dictionary1.Items[i];
                            string connectionString = item1.GetProp("ConnectionString");
                            if (!String.IsNullOrEmpty(connectionString))
                            {
                                var item2 = dictionary2.FindItem(item1.Name);
                                if (item2 != null)
                                {
                                    item2.SetProp("ConnectionString", connectionString);
                                }
                            }
                        }
                    }

                    // save prepared xml
                    using (MemoryStream secondXmlStream = new MemoryStream())
                    {
                        xml2.Save(secondXmlStream);
                        secondXmlStream.Position = 0;
                        byte[] buff = new byte[secondXmlStream.Length];
                        secondXmlStream.Read(buff, 0, buff.Length);
                        xmlString = Encoding.UTF8.GetString(buff);
                    }
                    xml1.Dispose();
                    xml2.Dispose();
                }
            return(xmlString);
        }
Example #3
0
        // send report to the designer
        internal IActionResult DesignerGetReport()
        {
            string reportString = Report.SaveToString();
            string report       = CutRestricted(reportString);

            if (report.IndexOf("inherited") != -1)
            {
                List <string> reportInheritance = new List <string>();
                string        baseReport        = report;

                while (!String.IsNullOrEmpty(baseReport))
                {
                    reportInheritance.Add(baseReport);
                    using (MemoryStream xmlStream = new MemoryStream())
                    {
                        WebUtils.Write(xmlStream, baseReport);
                        xmlStream.Position = 0;
                        using (var xml = new XmlDocument())
                        {
                            xml.Load(xmlStream);
                            string baseReportFile = xml.Root.GetProp("BaseReport");
                            //string fileName = context.Request.MapPath(baseReportFile, webReport.Prop.ReportPath, true);
                            if (!Path.IsPathRooted(baseReportFile))
                            {
                                baseReportFile = Path.GetFullPath(Path.GetDirectoryName(Report.FileName) + Path.DirectorySeparatorChar + baseReportFile); //was ReportPath before(ToDo)
                            }
                            if (File.Exists(baseReportFile))
                            {
                                baseReport = File.ReadAllText(baseReportFile, Encoding.UTF8);
                            }
                            else
                            {
                                baseReport = String.Empty;
                            }
                        }
                    }
                }
                StringBuilder responseBuilder = new StringBuilder();
                responseBuilder.Append("{\"reports\":[");
                for (int i = reportInheritance.Count - 1; i >= 0; i--)
                {
                    string s = reportInheritance[i];
                    responseBuilder.Append("\"");
                    responseBuilder.Append(s.Replace("\r\n", "").Replace("\"", "\\\""));
                    if (i > 0)
                    {
                        responseBuilder.Append("\",");
                    }
                    else
                    {
                        responseBuilder.Append("\"");
                    }
                }
                responseBuilder.Append("]}");

                return(new ContentResult()
                {
                    StatusCode = (int)HttpStatusCode.OK,
                    ContentType = "text/html",
                    Content = responseBuilder.ToString(),
                });
            }

            return(new ContentResult()
            {
                StatusCode = (int)HttpStatusCode.OK,
                ContentType = "text/html",
                Content = report,
            });
        }