public Stream GetFeatures(string processorId, string callback)
{
MemoryStream ms = new MemoryStream();
StreamWriter sw = new StreamWriter(ms);
sw.Write(callback + "({");
if (processorId != null)
{
EmdatProcessor processor = Program.Processors[processorId];
if (processor != null && processor.CollectingData)
{
processor.ProcessWindow();
IDictionary<Object, Object> features = processor.Features;
// sort by key
String[] sortedFeatures = new String[features.Count];
features.Keys.CopyTo(sortedFeatures, 0);
Array.Sort(sortedFeatures);
// convert to JSON
StringBuilder sb = new StringBuilder();
foreach (String feature in sortedFeatures)
{
sb.Append("\"" + feature + "\": \"" + features[feature] + "\",");
}
// remove trailing comma
if (sb.Length > 0)
{
sb.Length--;
}
sw.Write(sb.ToString());
}
}
sw.Write("})");
sw.Flush();
ms.Position = 0;
return ms;
}