public void InjectScripts(string fullSourceCode, string repxFileName, bool replaceOriginal = false) { if (fullSourceCode == null) throw new ArgumentNullException("fullSourceCode"); if (!fullSourceCode.Contains(XtraReportSyncMarkers.StartMarker)) throw new ArgumentException("fullSourceCode does not contain a valid ScriptSourceStartMarker"); if (!fullSourceCode.Contains(XtraReportSyncMarkers.EndMarker)) throw new ArgumentException("fullSourceCode does not contain a valid ScriptSourceEndMarker"); XtraReportScriptParser parser = new XtraReportScriptParser(); string collectedUsingReferences = parser.CollectUsingReferences(fullSourceCode); string scriptSource = parser.RemoveIgnoredSections(fullSourceCode); scriptSource = parser.MaximumUnindent(scriptSource); scriptSource = Environment.NewLine + collectedUsingReferences + Environment.NewLine + scriptSource; var temporaryReportFileName = Path.ChangeExtension(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()), ".repx"); Report.ScriptsSource = scriptSource; try { Report.SaveLayout(temporaryReportFileName); AssertReportContainsScriptSource(temporaryReportFileName, scriptSource); if (replaceOriginal) File.Copy(temporaryReportFileName, repxFileName, true); } finally { File.Delete(temporaryReportFileName); } }
private void AssertReportContainsScriptSource(string repxFileName, String expectedScriptSource) { var reader = new XtraReportScriptExtractor(new XtraReportLoader(new XtraReport(), repxFileName)); string source = reader.ExtractScripts(); var parser = new XtraReportScriptParser(); if (parser.RemoveIgnoredSections(expectedScriptSource) != parser.RemoveIgnoredSections(source)) throw new Exception("Expected scripts source does not match."); }
private string GetScriptSection() { StringBuilder sb = new StringBuilder(); sb.AppendLine(); sb.AppendLine("// -- Anything above this line will be ignored when converting back to repx. --"); sb.AppendLine(XtraReportSyncMarkers.StartMarker); var parser = new XtraReportScriptParser(); sb.AppendLine(parser.MaximumUnindent(ScriptExtractor.ExtractScripts())); sb.AppendLine(XtraReportSyncMarkers.EndMarker); sb.AppendLine("// -- Anything below this line will be ignored when converting back to repx. --"); sb.AppendLine(); return sb.ToString(); }
public string GetScriptsCode() { string scriptSection = GetScriptSection(); var parser = new XtraReportScriptParser(); StringBuilder sb = new StringBuilder(); sb.AppendLine(""); sb.AppendLine(parser.CollectUsingReferences(scriptSection)); sb.AppendLine(); sb.AppendLine("namespace " + NamespaceHelper.Get() + "." + NameSpace + " {"); sb.AppendLine(" public partial class " + ClassName); sb.AppendLine(" {"); sb.AppendLine(parser.RemoveUsingReferences(scriptSection)); sb.AppendLine(" }"); sb.AppendLine("}"); return sb.ToString(); }