本文整理汇总了C#中LogEntry.Add方法的典型用法代码示例。如果您正苦于以下问题:C# LogEntry.Add方法的具体用法?C# LogEntry.Add怎么用?C# LogEntry.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogEntry
的用法示例。
在下文中一共展示了LogEntry.Add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Eval
public bool Eval(List<LogEntry> logEntries, string code)
{
EditorApplication.LockReloadAssemblies();
bool status = false,
hasOutput = false,
hasAddedLogToEntries = false;
object output = null;
string res = null,
tmpCode = code.Trim();
LogEntry cmdEntry = new LogEntry() {
logEntryType = LogEntryType.Command,
command = tmpCode
};
try {
FluffReporter();
if(tmpCode.StartsWith("=")) {
// Special case handling of calculator mode. The problem is that
// expressions involving multiplication are grammatically ambiguous
// without a var declaration or some other grammatical construct.
tmpCode = "(" + tmpCode.Substring(1, tmpCode.Length-1) + ");";
}
Application.RegisterLogCallback(delegate(string cond, string sTrace, LogType lType) {
cmdEntry.Add(new LogEntry() {
logEntryType = LogEntryType.ConsoleLog,
condition = cond,
stackTrace = sTrace,
consoleLogType = lType
});
});
res = Evaluator.Evaluate(tmpCode, out output, out hasOutput);
//if(res == tmpCode)
// Debug.Log("Unfinished input...");
} catch(Exception e) {
cmdEntry.Add(new LogEntry() {
logEntryType = LogEntryType.EvaluationError,
error = e.ToString().Trim() // TODO: Produce a stack trace a la Debug, and put it in stackTrace so we can filter it.
});
output = new Evaluator.NoValueSet();
hasOutput = false;
status = true; // Need this to avoid 'stickiness' where we let user
// continue editing due to incomplete code.
} finally {
status = res == null;
Application.RegisterLogCallback(null);
if(res != tmpCode) {
logEntries.Add(cmdEntry);
hasAddedLogToEntries = true;
}
status = CatchMessages(cmdEntry, status);
}
if(hasOutput) {
if(status) {
outputBuffer.Length = 0;
try {
FluffReporter();
PrettyPrint.PP(outputBuffer, output, true);
} catch(Exception e) {
cmdEntry.Add(new LogEntry() {
logEntryType = LogEntryType.EvaluationError,
error = e.ToString().Trim() // TODO: Produce a stack trace a la Debug, and put it in stackTrace so we can filter it.
});
if(!hasAddedLogToEntries) {
logEntries.Add(cmdEntry);
hasAddedLogToEntries = true;
}
} finally {
bool result = CatchMessages(cmdEntry, true);
if(!result && !hasAddedLogToEntries) {
logEntries.Add(cmdEntry);
hasAddedLogToEntries = true;
}
}
string tmp = outputBuffer.ToString().Trim();
if(!String.IsNullOrEmpty(tmp)) {
cmdEntry.Add(new LogEntry() {
logEntryType = LogEntryType.Output,
output = outputBuffer.ToString().Trim()
});
if(!hasAddedLogToEntries) {
logEntries.Add(cmdEntry);
hasAddedLogToEntries = true;
}
}
}
}
EditorApplication.UnlockReloadAssemblies();
return status;
}
示例2: CatchMessages
private bool CatchMessages(LogEntry cmdEntry, bool status)
{
StringBuilder outBuffer = reportOutWriter.GetStringBuilder();
StringBuilder errBuffer = reportErrorWriter.GetStringBuilder();
string tmpOut = outBuffer.ToString().Trim(),
tmpErr = errBuffer.ToString().Trim();
outBuffer.Length = 0;
errBuffer.Length = 0;
if(outWriter != null)
System.Console.SetOut(outWriter);
if(errWriter != null)
System.Console.SetError(errWriter);
if(!String.IsNullOrEmpty(tmpOut)) {
cmdEntry.Add(new LogEntry() {
logEntryType = LogEntryType.SystemConsoleOut,
error = tmpOut
});
status = false;
}
if(!String.IsNullOrEmpty(tmpErr)) {
cmdEntry.Add(new LogEntry() {
logEntryType = LogEntryType.SystemConsoleErr,
error = tmpErr
});
status = false;
}
return status;
}
示例3: Eval
public bool Eval(List<LogEntry> logEntries, string code)
{
EditorApplication.LockReloadAssemblies();
bool status = false;
bool hasOutput = false;
object output = null;
LogEntry cmdEntry = null;
string tmpCode = code.Trim();
cmdEntry = new LogEntry() {
logEntryType = LogEntryType.Command,
command = tmpCode
};
bool isExpression = false;
try {
if(tmpCode.StartsWith("=")) {
tmpCode = "(" + tmpCode.Substring(1, tmpCode.Length-1) + ");";
isExpression = true;
}
Application.RegisterLogCallback(delegate(string cond, string sTrace, LogType lType) {
cmdEntry.Add(new LogEntry() {
logEntryType = LogEntryType.ConsoleLog,
condition = cond,
stackTrace = sTrace,
consoleLogType = lType
});
});
status = Evaluator.Evaluate(tmpCode, out output, out hasOutput) == null;
if(status)
logEntries.Add(cmdEntry);
} catch(Exception e) {
cmdEntry.Add(new LogEntry() {
logEntryType = LogEntryType.EvaluationError,
error = e.ToString().Trim() // TODO: Produce a stack trace a la Debug, and put it in stackTrace so we can filter it.
});
output = new Evaluator.NoValueSet();
hasOutput = false;
status = true; // Need this to avoid 'stickiness' where we let user
// continue editing due to incomplete code.
logEntries.Add(cmdEntry);
} finally {
Application.RegisterLogCallback(null);
}
// Catch compile errors that are not dismissed as a product of interactive
// editing by Mono.CSharp.Evaluator...
StringBuilder buffer = FluffReporter();
string tmp = buffer.ToString().Trim();
buffer.Length = 0;
if(!String.IsNullOrEmpty(tmp)) {
cmdEntry.Add(new LogEntry() {
logEntryType = LogEntryType.SystemConsole,
error = tmp
});
status = false;
}
if(hasOutput && (isExpression || output is REPLMessage)) {
if(status) {
outputBuffer.Length = 0;
PrettyPrint.PP(outputBuffer, output);
cmdEntry.Add(new LogEntry() {
logEntryType = LogEntryType.Output,
output = outputBuffer.ToString().Trim()
});
}
}
EditorApplication.UnlockReloadAssemblies();
return status;
}