internal static SampleStructureMap Create(Stream groupsJSON)
{
var serializer = new DataContractJsonSerializer(typeof(SampleStructureMap));
SampleStructureMap structureMap = null;
try
{
// KD - Need two MemoryStreams? Need to investigate.
using (groupsJSON)
{
using (MemoryStream ms = new MemoryStream())
{
groupsJSON.CopyTo(ms);
var jsonInBytes = ms.ToArray();
using (MemoryStream ms2 = new MemoryStream(jsonInBytes))
{
structureMap = serializer.ReadObject(ms2) as SampleStructureMap;
structureMap.Samples = new List<SampleModel>();
}
}
}
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
#region CreateSamples
List<string> pathList = new List<string>();
foreach (var category in structureMap.Categories)
{
foreach (var subCategory in category.SubCategories)
{
if (subCategory.SampleInfos != null)
{
foreach (var sample in subCategory.SampleInfos)
{
pathList.Add(sample.Path.Replace("/", "."));
}
}
}
}
SampleModel sampleModel = new SampleModel();
foreach (var samplePath in pathList)
{
sampleModel = SampleModel.Create(samplePath);
if (sampleModel != null)
structureMap.Samples.Add(sampleModel);
}
foreach (var category in structureMap.Categories)
{
foreach (var subCategory in category.SubCategories)
{
if (subCategory.Samples == null)
subCategory.Samples = new List<SampleModel>();
foreach (var sampleName in subCategory.SampleInfos)
{
var sample = structureMap.Samples.FirstOrDefault(x => x.SampleName == sampleName.SampleName);
if (sample == null) continue;
subCategory.Samples.Add(sample);
}
}
}
#endregion
return structureMap;
}
#endregion