public void InitForExecution()
{
string fileName = "", fileFolder = "";
if (ForOutput)
{
//Check custom Output Parameters and CSS
Parameter.CopyParameters(OutputToExecute.ViewParameters, OutputToExecute.View.Parameters);
Parameter.CopyParameters(OutputToExecute.ViewCSS, OutputToExecute.View.CSS);
//Add the security context for the output if specified
if (!string.IsNullOrWhiteSpace(OutputToExecute.UserName) || !string.IsNullOrWhiteSpace(OutputToExecute.UserGroups))
{
SecurityContext = new SecurityUser(Repository.Security) { Name = OutputToExecute.UserName };
string[] groups= OutputToExecute.UserGroups.Replace(";", "\r").Replace("\n", "").Split('\r');
foreach (string group in groups) SecurityContext.AddSecurityGroup(group);
}
if (!string.IsNullOrEmpty(OutputToExecute.UserCulture))
{
SecurityContext.SetDefaultCulture(OutputToExecute.UserCulture);
}
}
try
{
var template = ExecutionView.Template; //This force to init parameters
fileName = ResultFileName;
fileFolder = ResultFolder;
if (ForOutput && OutputToExecute.Device is OutputFolderDevice)
{
//For folder output, we do not need a unique file name
ResultFilePath = Path.Combine(ResultFolder, Path.GetFileNameWithoutExtension(fileName)) + (!HasExternalViewer || string.IsNullOrEmpty(ExecutionView.ExternalViewerExtension) ? Path.GetExtension(fileName) : "." + ExecutionView.ExternalViewerExtension);
}
else
{
//get unique file name in the result folder
ResultFilePath = FileHelper.GetUniqueFileName(Path.Combine(ResultFolder, fileName), "." + ExecutionView.ExternalViewerExtension);
}
ResultFilePrefix = FileHelper.GetResultFilePrefix(ResultFilePath);
if (Repository.Configuration.IsLocal && ExecutionContext != ReportExecutionContext.WebReport && ExecutionContext != ReportExecutionContext.WebOutput && !Directory.Exists(Path.Combine(ResultFolder, "images")) && !ExecutionView.Views.Exists(i => i.Template.Name == ReportViewTemplate.ModelCSVExcelName))
{
try
{
//copy images folder (for jquery images)
FileHelper.CopyDirectory(Path.Combine(Repository.ViewContentFolder, "images"), Path.Combine(ResultFolder, "images"), false);
}
catch { }
}
//Display path is always an HTML one...
HTMLDisplayFilePath = FileHelper.GetUniqueFileName(Path.Combine(DisplayFolder, ResultFilePrefix + ".htm"));
//Clear some cache values...
_displayNameEx = null;
}
catch (Exception ex)
{
Cancel = true;
if (string.IsNullOrEmpty(fileFolder) && OutputToExecute != null && !string.IsNullOrEmpty(OutputToExecute.FolderPath)) fileFolder = OutputToExecute.FolderPath;
ExecutionErrors += string.Format("Error initializing report Path, check your report execution or output Path '{0}'\r\n{1}\r\n", Path.Combine(fileFolder, fileName), ex.Message);
}
if (!string.IsNullOrEmpty(InitScript))
{
try
{
Helper.ParseRazor(InitScript, this);
}
catch(Exception ex2)
{
ExecutionErrors += string.Format("Error executing init script\r\n{0}\r\n", ex2.Message);
}
}
}