diff --git a/instat/Model/Output/clsOutputLogger.vb b/instat/Model/Output/clsOutputLogger.vb index 9905d4c7ea3..1c6b5d4396d 100644 --- a/instat/Model/Output/clsOutputLogger.vb +++ b/instat/Model/Output/clsOutputLogger.vb @@ -71,52 +71,51 @@ Public Class clsOutputLogger End Property Public Sub AddOutput(strScript As String, strOutput As String, bAsFile As Boolean, bDisplayOutputInExternalViewer As Boolean) - 'Note this always takes the last script added as corresponding script + ' Note this always takes the last script added as corresponding script If String.IsNullOrWhiteSpace(strScript) Then Throw New Exception("Cannot find script to attach output to.") Exit Sub End If - 'add the R script as an output element + ' Add the R script as an output element Dim rScriptElement As New clsOutputElement rScriptElement.SetContent(strScript, OutputType.Script, "") _outputElements.Add(rScriptElement) - 'raise event for output pages + ' Raise event for output pages RaiseEvent NewOutputAdded(rScriptElement, False) - - If Not String.IsNullOrEmpty(strOutput) Then - Dim outputElement As New clsOutputElement - Dim outputType As OutputType - If bAsFile Then - Dim strFileExtension As String = Path.GetExtension(strOutput).ToLower - Select Case strFileExtension - Case ".png" - outputType = OutputType.ImageOutput - Case ".html" - outputType = OutputType.HtmlOutput - Case ".txt" - outputType = OutputType.TextOutput - Case Else - MessageBox.Show("The file type to be added is currently not suported", - "Developer Error", - MessageBoxButtons.OK, - MessageBoxIcon.Error) - Exit Sub - End Select - Else - outputType = OutputType.TextOutput + ' Split the strOutput into an array of lines, removing empty entries + Dim arrFilesPaths() As String = strOutput.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries) + + For Each output In arrFilesPaths + If Not String.IsNullOrEmpty(output) Then + Dim outputElement As New clsOutputElement + Dim outputType As OutputType + + If bAsFile Then + Dim strFileExtension As String = Path.GetExtension(output).ToLower + Select Case strFileExtension + Case ".png" + outputType = OutputType.ImageOutput + Case ".html" + outputType = OutputType.HtmlOutput + Case ".txt" + outputType = OutputType.TextOutput + Case Else + MessageBox.Show("The file type to be added is currently not supported", "Developer Error", MessageBoxButtons.OK, MessageBoxIcon.Error) + Exit Sub + End Select + Else + outputType = OutputType.TextOutput + End If + + ' Add the output with its R script as another output element + outputElement.SetContent("", outputType, output) + _outputElements.Add(outputElement) + ' Raise event for output pages + RaiseEvent NewOutputAdded(outputElement, bDisplayOutputInExternalViewer) End If - - 'add the output with it's R script as another output element - outputElement.SetContent("", outputType, strOutput) - _outputElements.Add(outputElement) - 'raise event for output pages - RaiseEvent NewOutputAdded(outputElement, bDisplayOutputInExternalViewer) - - End If - - + Next End Sub diff --git a/instat/clsRLink.vb b/instat/clsRLink.vb index 4a686600ca7..6a5935e111a 100644 --- a/instat/clsRLink.vb +++ b/instat/clsRLink.vb @@ -749,22 +749,9 @@ Public Class RLink bShowWaitDialogOverride:=Nothing) End If - ' Split the strOutput into an array of lines, removing empty entries - Dim arrFilesPaths() As String = strOutput.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries) - - ' Check if arrFilesPaths has at least one element before iterating - If arrFilesPaths.Length > 0 Then - ' Iterate through each file path - For Each _path In arrFilesPaths - ' Add output to logger - clsOutputLogger.AddOutput(clsRStatement.Text, _path, bAsFile:=True, + ' Add output to logger + clsOutputLogger.AddOutput(clsRStatement.Text, strOutput, bAsFile:=True, bDisplayOutputInExternalViewer:=clsRStatement.TextNoFormatting.StartsWith("view_object_data")) - Next - Else - ' Add output to logger - clsOutputLogger.AddOutput(clsRStatement.Text, strOutput, bAsFile:=True, - bDisplayOutputInExternalViewer:=clsRStatement.TextNoFormatting.StartsWith("view_object_data")) - End If ' Log the script LogScript(clsRStatement.Text.TrimEnd(vbCr, vbLf)) @@ -1012,22 +999,8 @@ Public Class RLink End If End If - If bAsFile Then - ' Split the strOutput into an array of lines, removing empty entries - Dim arrFilesPaths() As String = strOutput.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries) - ' Iterate through each HTML files - For Each _path In arrFilesPaths - ' Add each HTML file as an output to clsOutputLogger - ' strScriptWithComment: the script with associated comments - ' _path: the path to the HTML file - ' bAsFile: a boolean indicating whether the output should be treated as a file - ' bDisplayOutputInExternalViewer: a boolean indicating whether to display the output in an external viewer - clsOutputLogger.AddOutput(strScriptWithComment, _path, bAsFile, bDisplayOutputInExternalViewer) - Next - Else - ' If strOutput is empty or does not contain valid HTML files, add strOutput itself as an output - clsOutputLogger.AddOutput(strScriptWithComment, strOutput, bAsFile, bDisplayOutputInExternalViewer) - End If + ' If strOutput is empty or does not contain valid HTML files, add strOutput itself as an output + clsOutputLogger.AddOutput(strScriptWithComment, strOutput, bAsFile, bDisplayOutputInExternalViewer) Catch e As Exception