.NET Automation
/// SP3D CommonMiddle Registry
/// 13.12.12
static FormMain()
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);
}
///
/// SP3D CommonMiddle Registry
///
/// 13.12.12
public static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
{
//This handler is called only when the common language runtime tries to bind to the assembly and fails.
//Retrieve the list of referenced assemblies in an array of AssemblyName.
//Loop through the array of referenced assemblies.
foreach (AssemblyName strAssmbName in Assembly.GetExecutingAssembly().GetReferencedAssemblies())
{
//Look for the assembly names that have raised the "AssemblyResolve" event.
if (((strAssmbName.Name.EndsWith("CommonMiddle")) /*&& (strAssmbName.FullName.Substring(0, strAssmbName.FullName.IndexOf(","))
== args.Name.Substring(0, args.Name.IndexOf(",")))) ? 1 : 0) != 0*/))
{
//We only have this handler to deal with loading of CommonMiddle. Rest everything we don't bother.
AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(MyResolveEventHandler);
object regKeyValue;
//Build the path of the assembly from where it has to be loaded.
//Check CurrentUser,LocalMachine, 64bit CurrentUser,LocalMachine
regKeyValue = Registry.GetValue(Registry.CurrentUser + @"\Software\Intergraph\SP3D\Installation", "INSTALLDIR", "");
if (regKeyValue == null)
{
regKeyValue = Registry.GetValue(Registry.LocalMachine + @"\Software\Intergraph\SP3D\Installation", "INSTALLDIR", "");
}
if (regKeyValue == null)
{
regKeyValue = Registry.GetValue(Registry.CurrentUser + @"\Software\Wow6432Node\Intergraph\SP3D\Installation", "INSTALLDIR", "");
}
if (regKeyValue == null)
{
regKeyValue = Registry.GetValue(Registry.LocalMachine + @"\Software\Wow6432Node\Intergraph\SP3D\Installation", "INSTALLDIR", "");
}
if (regKeyValue == null)
{
throw new Exception("Error Reading SmartPlant 3D Installation Directory from Registry !!! Exiting");
}
string sInstallPath = regKeyValue.ToString();
if (!sInstallPath.EndsWith(@"\"))
{
sInstallPath = sInstallPath + @"\";
}
sInstallPath = sInstallPath + @"Core\Container\Bin\Assemblies\Release\";
//Load the assembly from the specified path and return it.
return Assembly.LoadFrom(sInstallPath + "CommonMiddle.dll");
}
}
return null;
}
댓글
댓글 쓰기