public static IGenerator OpenModel(string filePath, out LoadResultConstants loadResult)
{
loadResult = LoadResultConstants.Failed;
IGenerator retVal = null;
var file = new FileInfo(filePath);
var xmlAttributeAssembleValue = string.Empty;
if (file.Exists)
{
var processKey = string.Empty;
try
{
var xDoc = new XmlDocument();
string type = null;
FileInfo assemblyName = null;
xDoc.Load(file.FullName);
type = Common.Util.XmlHelper.GetAttributeValue(xDoc.DocumentElement, "type", string.Empty);
xmlAttributeAssembleValue = Common.Util.XmlHelper.GetAttributeValue(xDoc.DocumentElement, "assembly", string.Empty);
Uri assemblyUri = null;
try { assemblyUri = new Uri(xmlAttributeAssembleValue); }
catch { }
//Change the old name to the new name
if (xmlAttributeAssembleValue.ToLower() == "widgetsphere.generator.dll")
xmlAttributeAssembleValue = "nHydrate.Generator.dll";
if (assemblyUri != null) assemblyName = new FileInfo(assemblyUri.AbsolutePath);
else assemblyName = new FileInfo(xmlAttributeAssembleValue);
//processKey = UIHelper.ProgressingStarted();
var assemblyFile = Path.Combine(AddinAppData.Instance.ExtensionDirectory, assemblyName.Name);
var currentAssemblyFile = new FileInfo(assemblyFile);
if (currentAssemblyFile.Exists)
{
retVal = (IGenerator)ReflectionHelper.CreateInstance(currentAssemblyFile.FullName, type);
retVal.XmlLoad(xDoc.DocumentElement);
retVal.FileName = filePath;
//UIHelper.ProgressingComplete(processKey);
loadResult = retVal.ProcessPostModelLoad();
}
else
{
//UIHelper.ProgressingComplete(processKey);
GlobalHelper.ShowError("The model cannot be opened. You do not have the appropriate assembly. " + currentAssemblyFile.FullName);
}
}
catch (Exception ex)
{
throw new Exception(file.FullName + " does not have the correct format.", ex);
}
finally
{
//UIHelper.ProgressingComplete(processKey);
}
}
else
{
throw new Exception("File does not exist:");
}
return retVal;
}