in ReadTraceNexusImporter/ReadTraceNexusImporter.cs [144:256]
public bool ExtractReadTraceReports()
{
if (SkipExtractReports == true)
{
return true; //skip extracting
}
Util.Logger.LogMessage(@"ReadtraceNexusImporter: extracting reports");
bool ret = true;
try
{
Assembly assembly;
Type type;
assembly = Assembly.LoadFile(Util.GetReadTracePath() + @"\reporter.exe");
type = assembly.GetType("RMLReports.RDLCHelper.CNexusExchange", true);
MethodInfo method = type.GetMethod("GetReports");
Dictionary<string, string> dict = (Dictionary<string, string>)method.Invoke(null, null);
//String reportPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\sqlnexus\reports\";
String reportPath = Application.StartupPath + @"\Reports\";
if (!Directory.Exists(reportPath))
Directory.CreateDirectory(reportPath);
String[] oldFiles = Directory.GetFiles(reportPath, "*readtrace*.*");
//delete old trace file
foreach (String f in oldFiles)
{
Util.Logger.LogMessage("Enumerating and deletting file from old directory " + f);
File.Delete(f);
}
//this is to delete old fles in appdata which we no longer use
string[] oldFiles2 = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\sqlnexus\reports\", "*readtrace*.*");
foreach (String f in oldFiles2)
{
Util.Logger.LogMessage("Enumerating and deletting file from old directory " + f);
File.Delete(f);
}
Util.Logger.LogMessage("Report path " + reportPath);
MethodInfo GetSetupSQLScript = type.GetMethod("GetSetupSQLScript");
MethodInfo GetValidateSQLScript = type.GetMethod("GetValidateSQLScript");
if (GetSetupSQLScript != null)
{
String setupscript = (string) GetSetupSQLScript.Invoke(null, null);
String postScriptFile = reportPath + "ReadTracePostProcessing.sql";
if (File.Exists (postScriptFile))
File.Delete(postScriptFile);
StreamWriter sr = File.CreateText(postScriptFile);
sr.Write(setupscript);
sr.Flush();
sr.Close();
HasPostScript = true;
}
bool HasValidateScript = false;
string ValidateScriptName = "ReadTraceReportValidate.sql";
if (GetValidateSQLScript != null)
{
HasValidateScript = true;
String validateScriptString = (string) GetValidateSQLScript.Invoke(null, null);
String validateScriptFile = reportPath + ValidateScriptName;
if (File.Exists(validateScriptFile))
File.Delete(validateScriptFile);
StreamWriter sr = File.CreateText(validateScriptFile);
sr.Write(validateScriptString);
sr.Flush();
sr.Close();
}
foreach (string key in dict.Keys)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(key);
XmlNode n = doc["report"];
String reportName = n.Attributes["name"].Value;
bool isChildReport = bool.Parse(n.Attributes["ischild"].Value);
String reportDefinition = dict[key];
XmlDocument reportDoc = new XmlDocument();
reportDoc.LoadXml(reportDefinition);
String reportExt = ".RDLC"; //(isChildReport ? ".RDLC" : ".RDL");
String reportFullFileName = reportPath + reportName + reportExt;
reportDoc.Save(reportFullFileName);
if (HasValidateScript == true)
{
String validateXml = "<report><validate script=\"" + ValidateScriptName + "\"/></report>";
XmlDocument validateDoc = new XmlDocument();
validateDoc.LoadXml(validateXml);
validateDoc.Save(reportFullFileName + ".xml");
}
}
}
catch (Exception ex)
{
ret = false;
Util.Logger.LogMessage("Extract readtrace report failed with error " + ex.ToString());
}
return ret;
}