private void ExecuteCommandsAndCreateSinkFile(OutputWindow ow, CommandOutput lst, string seltext)//sending message and output to sink file
{
string objectname;
seltext = seltext.Replace('\n', ';').Replace('\r', ' ').Trim();
seltext = JoinCommaSeparatedStatment(seltext);
string stmt = "";
//////wrap in sink////////
string sinkfilefullpathname = Path.Combine(System.IO.Path.GetTempPath().Replace("\\", "/"), confService.GetConfigValueForKey("tempsink"));//23nov2012
// load default value if no path is set or invalid path is set
if (sinkfilefullpathname.Trim().Length == 0 || !IsValidFullPathFilename(sinkfilefullpathname, false))
{
//sinkfilefullpathname = confService.DefaultSettings["tempsink"];
MessageBox.Show(this, "Key 'tempsink' not found in config file. Aborting...");
return;
}
OpenSinkFile(@sinkfilefullpathname, "wt");
SetSink();
string _command = string.Empty;//05May2013
int bskyfrmtobjcount = 0;
bool breakfor = false;//, continuefor=false;//14Nov2013
for (int start = 0, end = 0; start < seltext.Length; start = start + end + 1) //28Jan2013 final condition was start < seltext.Length-1
{
objectname = "";
end = seltext.IndexOf(';', start) - start;
if (end < 0) // if ; not found
end = seltext.IndexOf('\n', start) - start;
if (end < 0)// if new line not found
end = seltext.Length - start;
stmt = seltext.Substring(start, end).Replace('\n', ' ').Replace('\r', ' ').Trim();
if (stmt.Trim().Length < 1 || stmt.Trim().IndexOf('#') == 0)
continue;
if (AdvancedLogging) logService.WriteToLogLevel("ExtraLogs: Syntax going to execute : " + stmt, LogLevelEnum.Info);
if (stmt.Trim().IndexOf('#') > 1) //12May2014 if any statment has R comments in the end in same line.
stmt = stmt.Substring(0, stmt.IndexOf("#"));
object o = null;
if (AdvancedLogging) logService.WriteToLogLevel("ExtraLogs: Categorizing command before execution.", LogLevelEnum.Info);
_command = ExtractCommandName(stmt);//07sep2012
RCommandType rct = GetRCommandType(_command);
if (AdvancedLogging) logService.WriteToLogLevel("ExtraLogs: Syntax command category : " + rct.ToString(), LogLevelEnum.Info);
try
{
switch (rct)
{
case RCommandType.CONDITIONORLOOP: //Block Commands
int end2 = end;
stmt = CurlyBracketParser(seltext, start, ref end);
if (stmt.Equals("ERROR"))
{
breakfor = true;
}
else
{
SendCommandToOutput(stmt, "R-Command");
ExecuteOtherCommand(ow, stmt);
}
//02Dec2014
ResetSink();
CloseSinkFile();
CreateOuput(ow);
OpenSinkFile(@sinkfilefullpathname, "wt");
SetSink();
///02Dec2015 Now add graphic (all of them, from temp location)
CreateAllGraphicOutput(ow);//get all grphics and send to output
break;
case RCommandType.GRAPHIC:
CommandRequest grpcmd = new CommandRequest();
grpcmd.CommandSyntax = "write(\"" + stmt.Replace("<", "<").Replace('"', '\'') + "\",fp)";// http://www.w3schools.com/xml/xml_syntax.asp
o = analytics.ExecuteR(grpcmd, false, false); //for printing command in file
CloseGraphicsDevice();
//GetGraphicSize()
ResetSink();
CloseSinkFile();
CreateOuput(ow);
OpenSinkFile(@sinkfilefullpathname, "wt");
SetSink();
OpenGraphicsDevice();//05May2013
//continuefor = true;
//continue;
break;
case RCommandType.GRAPHICXML:
ExecuteXMLTemplateDefinedCommands(stmt);
break;
case RCommandType.BSKYFORMAT:
ResetSink();
CloseSinkFile();
CreateOuput(ow);
SendCommandToOutput(stmt, "BSkyFormat");//26Aug2014 blue colored
ExecuteBSkyFormatCommand(stmt, ref bskyfrmtobjcount, ow); // this should be out of block and so "TRUE" must be passed in BSkyFormat
OpenSinkFile(@sinkfilefullpathname, "wt");
SetSink();
break;
case RCommandType.BSKYLOADREFRESHDATAFRAME: //BSkyLoadRefreshDataframe(dfname)
ResetSink();
CloseSinkFile();
CreateOuput(ow);
SendCommandToOutput(stmt, "Load-Refresh Dataframe");//26Aug2014 blue colored
bool success = ExecuteBSkyLoadRefreshDataframe(stmt);
if (!success)
SendErrorToOutput("Error:Cannot Load/Refresh Dataset. Dataframe does not exists. OR not 'data.frame' type.", ow); //03Jul2013
OpenSinkFile(@sinkfilefullpathname, "wt");
SetSink();
break;
case RCommandType.BSKYREMOVEREFRESHDATAFRAME: //BSkyRemoveRefreshDataframe(dfname)
ResetSink();
CloseSinkFile();
CreateOuput(ow);
ExecuteBSkyRemoveRefreshDataframe(stmt);
OpenSinkFile(@sinkfilefullpathname, "wt");
SetSink();
break;
case RCommandType.SPLIT: // set/remove split and refresh status bar in main window showing split vars
ResetSink();
CloseSinkFile();
CreateOuput(ow);
ExecuteSplit(stmt);
OpenSinkFile(@sinkfilefullpathname, "wt");
SetSink();
break;
case RCommandType.RCOMMAND:
SendCommandToOutput(stmt, "R-Command");
if (AdvancedLogging) logService.WriteToLogLevel("ExtraLogs: Categorized. Before execution.", LogLevelEnum.Info);
ExecuteOtherCommand(ow, stmt);
if (AdvancedLogging) logService.WriteToLogLevel("ExtraLogs: Categorized. After execution.", LogLevelEnum.Info);
ResetSink();
CloseSinkFile();
CreateOuput(ow);
OpenSinkFile(@sinkfilefullpathname, "wt");
SetSink();
if (AdvancedLogging) logService.WriteToLogLevel("ExtraLogs: Categorized. Before getting graphic if any.", LogLevelEnum.Info);
///02Dec2015 Now add graphic (all of them, from temp location)
CreateAllGraphicOutput(ow);//get all grphics and send to output
if (AdvancedLogging) logService.WriteToLogLevel("ExtraLogs: Categorized. After getting graphic if any.", LogLevelEnum.Info);
break;
case RCommandType.RDOTNET:
InitializeRDotNet();
RDotNetOpenDataset();
RDotNetExecute(ow);
DisposeRDotNet();
break;
default:
break;
}//switch
}
catch (Exception exc)
{
SendCommandToOutput(exc.Message, "Error:");
logService.WriteToLogLevel("Error executing: " + _command, LogLevelEnum.Error);
logService.WriteToLogLevel(exc.Message, LogLevelEnum.Error);
}
if (breakfor)
break;
}/////for
//////wrap in sink////////
ResetSink();
CloseSinkFile();
}