Exemplo n.º 1
0
        /// <param name="extensionDir">the directory where the entire extension is located, relative to application</param>
        /// <param name="files">an array files the extension consists of, relative to extensionDir</param>
        public void LoadExtension(String name, String extensionDir, String[] files)
        {
            String[] filesPath = new String[files.Length];
            int      i         = 0;

            foreach (String p in files)
            {
                filesPath[i] = Path.Combine(extensionDir, p);

                // check source code presence
                if (!File.Exists(filesPath[i]))
                {
                    throw new FileNotFoundException("Cannot find file for compiling extension", filesPath[i]);
                }

                i++;
            }

            // compile or load already compiled assembly
            String   assemblyPath = Path.Combine(extensionDir, name + ".dll");
            Assembly compiledAssembly;

            if (File.Exists(assemblyPath) && (!checkRecompiling(assemblyPath, filesPath)))
            {
                compiledAssembly = loadAssembly(assemblyPath);
            }
            else
            {
                File.Delete(assemblyPath);
                compiledAssembly = compileAssembly(assemblyPath, filesPath);
            }

            // process it by the layerFactory
            layerFactory.SearchAssembly(compiledAssembly);
            geometryFactory.SearchAssembly(compiledAssembly);

            // now run it
            ArrayList plugins = createInstances(compiledAssembly);

            foreach (IExtension p in plugins)
            {
                p.Init();
            }
        }