public static IOperation[] loadOpsFile(string path, Type[] knownTypes)
{
//Open the operation file.
FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read);
//Read in the file and store each item to a list. Type is "anyType" but this will be cast to IOperation.
DataContractSerializer serializer = new DataContractSerializer(typeof(IOperation), knownTypes);
XmlReader read = XmlReader.Create(fs);
read.ReadToDescendant("z:anyType");
List<IOperation> opList = new List<IOperation>();
//Blurahegle
while (serializer.IsStartObject(read))
{
//Check each type when deserializing. Make sure we can cast it.
try
{
opList.Add((IOperation)serializer.ReadObject(read));
}
catch (Exception e)
{
MessageBox.Show("Invalid operation type encountered. Please ensure all required libraies are installed \n" + e.Message, "An error has occured",MessageBoxButtons.OK,MessageBoxIcon.Error);
fs.Close();
return null;
}
}
fs.Close();
return opList.ToArray();
//Done
}