遍历Block输入数据,并保存到文件中
public override bool GroupRun(ref string message, ref CogToolResultConstants result)
{
// To let the execution stop in this script when a debugger is attached, uncomment the following lines.
// #if DEBUG
// if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break();
// #endif
StringBuilder sb = new StringBuilder();
foreach (CogToolBlockTerminal item in mToolBlock.Inputs)
{
if (item.ValueType==typeof(double)||item.ValueType==typeof(int)||item.ValueType==typeof(string))
{
var key = item.Name;
var val = item.Value.ToString();
string line = key + "," + val;
sb.AppendLine(line);
}
}
SaveToFile(sb.ToString(), "D:\\result.csv");
// Run each tool using the RunTool function
foreach(ICogTool tool in mToolBlock.Tools)
mToolBlock.RunTool(tool, ref message, ref result);
return false;
}
public void SaveToFile(string data, string strFilePath)
{
try
{
FileStream fs;
var myFile = new FileInfo(strFilePath);
if (!Directory.Exists(myFile.DirectoryName)) Directory.CreateDirectory(myFile.DirectoryName);
fs = new FileStream(strFilePath, FileMode.Append | FileMode.Create);
var sw = new StreamWriter(fs);
sw.WriteLine(data);
sw.Close();
fs.Close();
}
catch (Exception ex)
{
}
}