protected object Load(System.Type type, string namespaceUri, string path)
{
// check if already loaded.
if (m_loadedFiles.ContainsKey(namespaceUri))
{
return m_loadedFiles[namespaceUri];
}
// check if a valid path provided.
FileInfo fileInfo = null;
if (!String.IsNullOrEmpty(path))
{
fileInfo = new FileInfo(path);
if (fileInfo.Exists)
{
return LoadFile(type, path);
}
}
// check if path specified in the file table.
string location = null;
if (m_knownFiles.TryGetValue(namespaceUri, out location))
{
fileInfo = new FileInfo(location);
if (fileInfo.Exists)
{
return LoadFile(type, location);
}
// load embedded resource.
return LoadResource(type, location, type.Assembly);
}
if (!String.IsNullOrEmpty(path))
{
if (!File.Exists(path))
{
Assembly assembly = Assembly.GetExecutingAssembly();
if (namespaceUri == Namespaces.OpcUa)
{
path = "Opc.Ua.Model.Opc.Ua.Types.bsd";
assembly = Assembly.Load("Opc.Ua.Types");
}
// load embedded resource.
return LoadResource(type, path, assembly);
}
// check for file in the same directory as the input file.
FileInfo inputInfo = new FileInfo(m_inputPath);
fileInfo = new FileInfo(inputInfo.DirectoryName + "\\" + fileInfo.Name);
if (fileInfo.Exists)
{
return LoadFile(type, fileInfo.FullName);
}
// check for file in the process directory.
fileInfo = new FileInfo(Environment.CurrentDirectory + "\\" + fileInfo.Name);
if (fileInfo.Exists)
{
return LoadFile(type, fileInfo.FullName);
}
}
throw Exception("Cannot import file '{0}' from '{1}'.", namespaceUri, path);
}