public string EvaluateToString(string commandString)
{
bool flag = true;
string resultValueString = string.Empty;
bool hasReturnVariable = false;
string subCommand = string.Empty;
string subCommandReturnVariable = string.Empty;
try
{
subCommand = commandString.Substring(0, commandString.IndexOf("("));
}
catch (Exception exception1)
{
resultValueString = _log.LastError;
ProjectData.SetProjectError(exception1);
subCommand = "";
ProjectData.ClearProjectError();
}
if (commandString.Contains("<-"))
{
subCommand = subCommand.Substring(subCommand.IndexOf("-") + 1).Trim();
hasReturnVariable = true;
subCommandReturnVariable = commandString.Substring(0, commandString.IndexOf("<")).Trim();
}
if (subCommand.Contains("="))
{
subCommand = subCommand.Substring(subCommand.IndexOf("=") + 1).Trim();
hasReturnVariable = true;
subCommandReturnVariable = commandString.Substring(0, commandString.IndexOf("=")).Trim();
}
if (commandString.StartsWith("#"))
{
subCommand = "Comment";
}
switch (subCommand)
{
case "Comment":
resultValueString = "";
break;
case "help":
case "help.search":
try
{
resultValueString = Conversions.ToString(this._RServer.Evaluate(commandString).AsCharacter()[0]);
}
catch (Exception exception2)
{
ProjectData.SetProjectError(exception2);
Exception exception = exception2;
resultValueString = "Error!";
flag = true;
ProjectData.ClearProjectError();
logService.WriteToLogLevel("Could not execute and convert to string: < " + commandString + " >", LogLevelEnum.Error);
}
break;
case "library":
try
{
if (false)//RuntimeHelpers.GetObjectValue(this._RServer.Evaluate(commandString)) == null)
{
resultValueString = "Could not find library!";
}
else
{
resultValueString = "Library Loaded";
}
}
catch (Exception exception3)
{
ProjectData.SetProjectError(exception3);
resultValueString = "Could not find library!";
ProjectData.ClearProjectError();
logService.WriteToLogLevel("Could not execute: < " + commandString + " >", LogLevelEnum.Error);
}
break;
case "rm":
case "plot":
case "hist":
case "scatterplot3d":
case "scatter3d":
case "abline":
case "edit":
case "legend":
case "par":
case "barplot":
try
{
this._RServer.Evaluate(commandString);
resultValueString = "Done!";
if (false)//this._RServer.GetErrorText() != "no error")
{
resultValueString = "Error: " + "not imple for RDotNet";//this._RServer.GetErrorText();
}
}
catch (Exception exception4)
{
ProjectData.SetProjectError(exception4);
resultValueString = "There was an error!";
flag = true;
ProjectData.ClearProjectError();
logService.WriteToLogLevel("Could not execute:< " + commandString + " >", LogLevelEnum.Error);
}
break;
default:
if (subCommand == "model")
{
object obj4 = null;
try
{
if (subCommandReturnVariable == "")
{
subCommandReturnVariable = "Temporary_Model";
this._RServer.Evaluate("Temporary_Model<-" + commandString);
}
else
{
this._RServer.Evaluate(commandString);
}
if (false)//this._RServer.GetErrorText() != "no error")
{
resultValueString = "Error: " + "not imple in RDotNet";// this._RServer.GetErrorText();
}
else
{
}
break;
}
catch (Exception exception5)
{
logService.WriteToLogLevel("Could not execute:< " + commandString + " >", LogLevelEnum.Error);
ProjectData.SetProjectError(exception5);
resultValueString = "There was an error!";
flag = true;
ProjectData.ClearProjectError();
break;
}
}
if (hasReturnVariable)
{
try
{
this._RServer.Evaluate(commandString);
resultValueString = "Done!";
if (false)//this._RServer.GetErrorText() != "no error")
{
resultValueString = "Error: " + "no err impl in R.Net";// this._RServer.GetErrorText();
flag = true;
}
break;
}
catch (Exception exception6)
{
logService.WriteToLogLevel("Could not execute: < " + commandString + " >", LogLevelEnum.Error);
ProjectData.SetProjectError(exception6);
resultValueString = "There was an error!";
ProjectData.ClearProjectError();
break;
}
}
try
{
this._RServer.Evaluate("tmp<-" + commandString);//loading/closing dataset. maybe others commnd too
if (_log.LastError != null && _log.LastError.Trim().Length > 0)
resultValueString = GetErrorText();
else
resultValueString = string.Empty;
if (false)//this._RServer.GetErrorText() != "no error")
{
resultValueString = "Error: " + "No error R.net";//this._RServer.GetErrorText();
flag = true;
}
else if (!Conversions.ToBoolean(this._RServer.Evaluate("is.null(tmp)").AsLogical()[0]))
{
}
else
{
if(string.IsNullOrEmpty(resultValueString))
resultValueString = "No Result";// "No Result - Check Command";
}
}
catch (Exception exception7)
{
if (_log.LastError != null && _log.LastError.Trim().Length > 0)
resultValueString = GetErrorText();
logService.WriteToLogLevel("Could not execute: < " + commandString + " > ", LogLevelEnum.Error, exception7);
ProjectData.SetProjectError(exception7);
resultValueString = "There was an error!";
flag = true;
ProjectData.ClearProjectError();
}
break;
}
if (hasReturnVariable)
{
try
{
if (Conversions.ToBoolean(this._RServer.Evaluate("is.data.frame(" + subCommandReturnVariable + ")").AsLogical()[0]))
{
}
}
catch (Exception exception8)
{
logService.WriteToLogLevel("Could not execute and convert to bool:< " + "is.data.frame(" + subCommandReturnVariable + ")" + " >", LogLevelEnum.Error);
ProjectData.SetProjectError(exception8);
flag = true;
ProjectData.ClearProjectError();
}
}
if (flag)
{
return resultValueString;
}
else
{
return "Done!";
}
}